Skip to content

fix(scripts): normalize contract name in formatError and add test coverage (Fixes #856, #855) - #886

Closed
kleitonbernardino-lab wants to merge 1 commit into
MergeFi:mainfrom
kleitonbernardino-lab:fix/error-codes-normalization-856
Closed

kleitonbernardino-lab wants to merge 1 commit into
MergeFi:mainfrom
kleitonbernardino-lab:fix/error-codes-normalization-856

Conversation

@kleitonbernardino-lab

Copy link
Copy Markdown

Fixes #856, Fixes #855

Summary

Normalize contract names in formatError to match canonical keys in errorMappings, reject unrecognized contract names with a descriptive error, and add dedicated unit test coverage for error-codes.mjs.

Root Cause

formatError filters decoded meanings by matching against contractName + ":". While escrow and milestones match their keys directly, the maintenance pool contract is keyed in camelCase as maintenancePool. Invoking with CONTRACT_NAME=maintenance-pool (the naming used across directory names, packages, and Make targets) filtered all entries out, causing formatError to print No known mapping for error code N even when a valid error mapping existed (#856). Furthermore, error-codes.mjs lacked a dedicated test file to verify error extraction and decoding branches (#855).

Changes

  • Implemented normalizeContractName(name) in scripts/error-codes.mjs:
    • Strips hyphens and underscores and normalizes casing to resolve maintenance-pool, maintenance_pool, and maintenancePool to maintenancePool.
    • Normalizes escrow and milestones.
    • Throws an informative error listing valid contract names if an unrecognized name is passed.
  • Updated formatError to use normalizeContractName(contractName) when filtering decoded error entries.
  • Created scripts/error-codes.test.mjs with comprehensive test coverage:
    • Contract name normalization and rejection of unknown contract names.
    • Error code extraction across free-text, JSON payloads, and error objects.
    • Multi-contract and single-contract error code decoding.
    • Narrowing behavior in formatError with various contract name formats.

Verification

Ran test suite:

node --test scripts/error-codes.test.mjs

Result: 17 passed, 0 failed, 4 suites (100% pass).

…erage (Fixes MergeFi#856, MergeFi#855)

Signed-off-by: Kleiton Bernardino <kleiton.bernardino@gmail.com>
@vercel

vercel Bot commented Nov 11, 2026

Copy link
Copy Markdown

@kleitonbernardino-lab is attempting to deploy a commit to the chonilius' projects Team on Vercel.

A member of the Team first needs to authorize it.

@chonilius chonilius closed this Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants