Skip to content

fix error data propagation viem adapter#237

Merged
aelmanaa merged 2 commits into
mainfrom
fix/sdk-viem-revert-data
Apr 24, 2026
Merged

fix error data propagation viem adapter#237
aelmanaa merged 2 commits into
mainfrom
fix/sdk-viem-revert-data

Conversation

@aelmanaa
Copy link
Copy Markdown
Collaborator

This pull request enhances the error-handling path for EVM chain interactions in the SDK, particularly when using the Viem transport provider. The main focus is to ensure that revert data from failed contract calls is preserved and correctly decoded, achieving parity between the Viem-based and ethers.js-based providers. It also adds comprehensive tests to verify this behavior.

Error handling and data preservation improvements:

  • Updated ViemTransportProvider in client-adapter.ts to walk the Viem error chain and extract revert data, forwarding it in the JSON-RPC error envelope. This enables downstream decoding of custom errors, such as TokenMaxCapacityExceeded, by the SDK.
  • Improved error message handling by preferring .raw revert bytes when available, and using the EIP-1474 execution-reverted error code when revert data is present.

Testing and validation:

  • Added a new test suite in fork.test.ts that sends over-capacity transactions through both the Viem and ethers.js providers, asserting that the SDK decodes and surfaces custom errors identically in both cases. This ensures functional parity and robustness of the error decoding logic.
  • Imported Viem client and transport provider in fork.test.ts to support the new test cases. [1] [2]
  • Included Viem's BaseError in the adapter for improved error introspection.

@aelmanaa aelmanaa requested review from a team and PabloMansanet as code owners April 24, 2026 15:48
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 24, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ccip-tools-ts Ready Ready Preview, Comment Apr 24, 2026 4:01pm

Request Review

@github-actions
Copy link
Copy Markdown

👋 aelmanaa, thanks for creating this pull request!

To help reviewers, please consider creating future PRs as drafts first. This allows you to self-review and make any final changes before notifying the team.

Once you're ready, you can mark it as "Ready for review" to request feedback. Thanks!

@aelmanaa aelmanaa force-pushed the fix/sdk-viem-revert-data branch from a4a2cd3 to 5c94628 Compare April 24, 2026 15:48
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 24, 2026

Coverage Report

ℹ tests 793
ℹ suites 231
ℹ pass 791
ℹ fail 0
ℹ cancelled 0
ℹ skipped 2
ℹ todo 0
ℹ duration_ms 147500.186047

> @chainlink/[email protected] test
> node --test

Verbose mode enabled
▶ getCtx
  ▶ output — always stdout
    ✔ output.write goes to stdout (2.058062ms)
    ✔ output.table goes to stdout (1.553937ms)
  ✔ output — always stdout (5.080479ms)
  ▶ logger — always stderr
    ✔ logger.info goes to stderr (1.151929ms)
    ✔ logger.warn goes to stderr (0.486947ms)
    ✔ logger.error goes to stderr (0.736596ms)
  ✔ logger — always stderr (2.65333ms)
  ▶ verbose mode
    ✔ logger.debug is a no-op when verbose is false (0.613246ms)
    ✔ logger.debug goes to stderr when verbose is true (3.379705ms)
  ✔ verbose mode (5.125014ms)
  ▶ destroy signal
    ✔ returns a working destroy function (16.825033ms)
    ✔ calling destroy twice does not throw (0.958327ms)
  ✔ destroy signal (18.03115ms)
✔ getCtx (32.175831ms)
▶ lane-latency command
  ✔ should output JSON format correctly (5.18197ms)
  ✔ should resolve chain IDs to chain selectors (1.105313ms)
  ✔ should use custom API URL when provided (2.127601ms)
  ✔ should output log format correctly (1.06532ms)
  ✔ should handle chain IDs as input (0.690907ms)
  ✔ should handle chain selectors as input (2.437498ms)
  ✔ should throw CCIPApiClientNotAvailableError when --no-api flag is set (1.004948ms)
  ✔ should work normally when --no-api flag is false (0.591744ms)
  ✔ should forward blockConfirmations to API URL (0.530411ms)
  ✔ should not include numOfBlocks when blockConfirmations is not provided (0.730059ms)
  ▶ CCIP_API environment variable integration
    ✔ should respect CCIP_API=false environment variable (0.53644ms)
  ✔ CCIP_API environment variable integration (0.766487ms)
✔ lane-latency command (18.0862ms)
▶ selectRequest non-interactive behavior
  ✔ returns the single request without prompting (1.538016ms)
  ✔ returns the request matching logIndex (0.355052ms)
  ✔ throws CCIPInteractiveRequiredError for multiple requests without logIndex (2.543694ms)
✔ selectRequest non-interactive behavior (6.203377ms)
▶ CCIPInteractiveRequiredError
  ✔ has correct code and is not transient (0.492962ms)
  ✔ uses default recovery when none provided (0.487299ms)
  ✔ preserves context fields (0.321821ms)
✔ CCIPInteractiveRequiredError (1.642312ms)
▶ preprocessArgv TTY auto-detection
  ✔ --interactive flag is defined in globalOpts (0.260641ms)
✔ preprocessArgv TTY auto-detection (0.411487ms)
▶ search messages command
  ✔ should throw CCIPApiClientNotAvailableError when --no-api flag is set (2.534668ms)
  ✔ should output JSON format correctly (13.436218ms)
  ✔ should pass sender filter to API (3.55953ms)
  ✔ should pass receiver filter to API (4.333227ms)
  ✔ should resolve source chain to selector (4.17316ms)
  ✔ should resolve dest chain to selector (4.783809ms)
  ✔ should pass manual-exec-only filter to API (4.493723ms)
  ✔ should treat limit 0 as unlimited (8.359586ms)
  ✔ should respect limit parameter (8.851577ms)
  ✔ should warn when no results found (1.568015ms)
  ✔ should use custom API URL when provided (3.112222ms)
  ✔ should warn on negative limit and fall back to default (2.36237ms)
  ✔ should output log format (2.355609ms)
✔ search messages command (66.10801ms)
▶ e2e command show EVM
  ▶ pretty format (default)
    ✔ should show complete CCIP transaction details EVM to EVM (10201.947488ms)
  ✔ pretty format (default) (10203.028091ms)
  ▶ json format
    ✔ should output a single valid JSON envelope with all expected fields (7704.683507ms)
  ✔ json format (7704.939058ms)
  ▶ log format
    ✔ should output in log format with object assignments (7922.361361ms)
  ✔ log format (7922.564461ms)
  ▶ verbose flag
    ✔ should work with verbose flag enabled (8923.808914ms)
  ✔ verbose flag (8924.005546ms)
  ▶ error handling
    ✔ should handle invalid transaction hash gracefully (6591.869893ms)
    ✔ should require transaction hash argument (1511.346129ms)
  ✔ error handling (8103.491361ms)
  ✔ should show complete CCIP transaction details EVM to Aptos (12453.655537ms)
  ✔ should show complete CCIP transaction details EVM to Solana (5858.199173ms)
✔ e2e command show EVM (61171.383769ms)
▶ e2e command show Solana
  ✔ should show complete CCIP transaction details Solana to EVM (9102.999665ms)
✔ e2e command show Solana (9103.232465ms)
▶ e2e command show Aptos
  ✔ should show complete CCIP transaction details Aptos to EVM (7977.164518ms)
✔ e2e command show Aptos (7977.323414ms)
﹣ e2e command show TON (0.054005ms) # SKIP
▶ formatCCIPError
  ✔ should return null for non-CCIPError instances (1.555153ms)
  ✔ should format CCIPError with code and message (0.622023ms)
  ✔ should include help section with recovery hint (0.234921ms)
  ✔ should include note section for transient errors (0.338252ms)
  ✔ should include retry timing for transient errors with retryAfterMs (0.395304ms)
  ✔ should not include note section for permanent errors (0.272094ms)
  ✔ should format error with structured output (0.269377ms)
  ✔ should include stack trace when verbose is true (0.396881ms)
  ✔ should not include stack trace when verbose is false (0.18418ms)
✔ formatCCIPError (5.974636ms)
ℹ tests 59
ℹ suites 21
ℹ pass 59
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 80901.605008
-------------------------------|---------|----------|---------|---------|---------------------------
File                           | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s         
-------------------------------|---------|----------|---------|---------|---------------------------
All files                      |   74.96 |    76.93 |   61.83 |   74.96 |                           
 ccip-cli/src                  |   89.47 |    61.53 |      75 |   89.47 |                           
  index.ts                     |   89.47 |    61.53 |      75 |   89.47 | ...47-151,157-158,163-168 
 ccip-cli/src/commands         |   51.08 |    72.45 |   52.72 |   51.08 |                           
  index.ts                     |     100 |      100 |     100 |     100 |                           
  lane-latency.ts              |   72.56 |     90.9 |   33.33 |   72.56 | 41-56,63-70,105-111       
  manual-exec.ts               |   25.36 |      100 |       0 |   25.36 | 62-116,123-133,135-274    
  parse.ts                     |   57.14 |      100 |       0 |   57.14 | 46-50,57-64,66-91         
  search.ts                    |   81.25 |      100 |       0 |   81.25 | 24-29                     
  send.ts                      |   15.06 |      100 |       0 |   15.06 | ...72-179,189-220,222-458 
  show.ts                      |   77.62 |    61.42 |   66.66 |   77.62 | ...49-257,261-274,305-306 
  supported-tokens.ts          |   17.66 |      100 |       0 |   17.66 | ...11-243,245-319,321-334 
  token.ts                     |   22.72 |      100 |       0 |   22.72 | 24-53,60-67,69-132        
  types.ts                     |     100 |      100 |     100 |     100 |                           
  utils.ts                     |   85.94 |    74.82 |    92.3 |   85.94 | ...99-609,617-625,635-641 
 ccip-cli/src/commands/search  |   49.39 |    83.33 |   14.28 |   49.39 |                           
  messages.ts                  |   49.39 |    83.33 |   14.28 |   49.39 | ...86-188,190-212,214-249 
 ccip-cli/src/providers        |   49.46 |    75.51 |      16 |   49.46 |                           
  aptos.ts                     |   51.47 |      100 |       0 |   51.47 | ...74,82-89,95-96,105-136 
  evm.ts                       |    36.3 |      100 |       0 |    36.3 | 27,47-63,69-104,116-168   
  index.ts                     |   80.16 |    72.72 |      80 |   80.16 | 51-52,193-237             
  solana.ts                    |   47.44 |      100 |       0 |   47.44 | ...,92-98,102-103,112-137 
  sui.ts                       |   64.28 |      100 |       0 |   64.28 | 10-14                     
  ton.ts                       |   15.03 |      100 |       0 |   15.03 | 24-153                    
 ccip-sdk/src                  |   94.44 |    82.15 |   92.77 |   94.44 |                           
  chain.ts                     |   93.04 |    81.01 |   71.42 |   93.04 | ...58,1708-1709,1742-1743 
  commits.ts                   |     100 |    95.23 |     100 |     100 | 52                        
  execution.ts                 |   92.19 |     92.3 |     100 |   92.19 | 130-137,149-156           
  explorer.ts                  |     100 |      100 |     100 |     100 |                           
  extra-args.ts                |      99 |    86.11 |     100 |      99 | 282-284                   
  gas.ts                       |   89.75 |       40 |     100 |   89.75 | 108-119,147-151           
  http-status.ts               |     100 |      100 |     100 |     100 |                           
  index.ts                     |     100 |      100 |     100 |     100 |                           
  messages.ts                  |   88.53 |    45.09 |     100 |   88.53 | ...20-221,230-231,255-256 
  offchain.ts                  |   94.14 |    79.54 |     100 |   94.14 | ...90,208,223-225,234-235 
  requests.ts                  |   90.63 |    80.55 |     100 |   90.63 | ...82-283,351-364,366-370 
  supported-chains.ts          |     100 |      100 |     100 |     100 |                           
  types.ts                     |     100 |      100 |     100 |     100 |                           
  utils.ts                     |   96.36 |    90.32 |     100 |   96.36 | ...67,783,884-885,892-900 
 ccip-sdk/src/api              |   93.75 |       85 |   94.11 |   93.75 |                           
  index.ts                     |   93.75 |       85 |   94.11 |   93.75 | ...39-744,755-758,761-764 
 ccip-sdk/src/aptos            |    55.7 |    69.46 |   55.73 |    55.7 |                           
  exec.ts                      |   29.31 |      100 |       0 |   29.31 | 18-58                     
  hasher.ts                    |   76.31 |       80 |   66.66 |   76.31 | 19-38,52-58               
  index.ts                     |    56.4 |       75 |   58.13 |    56.4 | ...26-828,832-858,862-873 
  logs.ts                      |   78.52 |    57.44 |      75 |   78.52 | ...90-196,200-233,264-268 
  send.ts                      |    25.2 |      100 |       0 |    25.2 | 10-51,62-79,92-123        
  token.ts                     |   23.75 |       75 |     100 |   23.75 | 35-156                    
  types.ts                     |   65.62 |      100 |       0 |   65.62 | 25-32,64-88               
 ccip-sdk/src/errors           |   87.41 |    76.16 |   48.38 |   87.41 |                           
  CCIPError.ts                 |     100 |      100 |     100 |     100 |                           
  codes.ts                     |     100 |      100 |     100 |     100 |                           
  index.ts                     |     100 |      100 |     100 |     100 |                           
  recovery.ts                  |     100 |      100 |     100 |     100 |                           
  specialized.ts               |   84.66 |    71.25 |   45.76 |   84.66 | ...27,3348-3357,3378-3387 
  utils.ts                     |   94.44 |    81.48 |     100 |   94.44 | 15,17,22,24               
 ccip-sdk/src/evm              |   83.39 |     75.4 |   89.02 |   83.39 |                           
  const.ts                     |     100 |      100 |     100 |     100 |                           
  errors.ts                    |   93.16 |    82.41 |     100 |   93.16 | ...02,156-161,170-172,219 
  extra-args.ts                |   94.47 |    61.01 |     100 |   94.47 | ...85-186,211-212,328-340 
  fork.test.data.ts            |     100 |      100 |     100 |     100 |                           
  gas.ts                       |   97.97 |    53.33 |     100 |   97.97 | 72-73,75                  
  hasher.ts                    |     100 |     92.3 |     100 |     100 | 134                       
  index.ts                     |   79.92 |    75.75 |   90.16 |   79.92 | ...56,2120-2136,2162-2169 
  logs.ts                      |   34.32 |    68.42 |      25 |   34.32 | ...13-214,229-258,275-302 
  messages.ts                  |     100 |      100 |     100 |     100 |                           
  offchain.ts                  |   81.25 |    33.33 |     100 |   81.25 | 11,13-14                  
  types.ts                     |     100 |      100 |     100 |     100 |                           
 ccip-sdk/src/evm/viem         |   79.76 |    90.62 |   69.23 |   79.76 |                           
  client-adapter.ts            |     100 |       90 |     100 |     100 | 48,74                     
  index.ts                     |     100 |      100 |     100 |     100 |                           
  wallet-adapter.ts            |   63.09 |     90.9 |   55.55 |   63.09 | ...6,53-73,91-124,131-157 
 ccip-sdk/src/hasher           |   94.29 |    78.94 |     100 |   94.29 |                           
  common.ts                    |     100 |      100 |     100 |     100 |                           
  hasher.ts                    |     100 |    66.66 |     100 |     100 | 19                        
  index.ts                     |     100 |      100 |     100 |     100 |                           
  merklemulti.ts               |   93.43 |       78 |     100 |   93.43 | ...59-260,306-307,315-316 
 ccip-sdk/src/shared           |   88.05 |    69.23 |     100 |   88.05 |                           
  bcs-codecs.ts                |   87.87 |    66.66 |     100 |   87.87 | 75-87,104-106             
  constants.ts                 |     100 |      100 |     100 |     100 |                           
 ccip-sdk/src/solana           |   73.14 |    68.13 |   77.01 |   73.14 |                           
  cleanup.ts                   |   26.63 |    66.66 |   33.33 |   26.63 | 43-53,59-101,113-226      
  exec.ts                      |   69.05 |    62.96 |   66.66 |   69.05 | ...61-463,468-472,512-513 
  fork.test.data.ts            |     100 |      100 |     100 |     100 |                           
  hasher.ts                    |   96.58 |    81.81 |     100 |   96.58 | 67-70                     
  index.ts                     |   76.68 |       75 |   78.84 |   76.68 | ...58,1562-1583,1587-1620 
  logs.ts                      |   74.83 |    38.88 |     100 |   74.83 | 38-39,50-51,53-54,56-88   
  offchain.ts                  |     100 |      100 |     100 |     100 |                           
  patchBorsh.ts                |   78.31 |       50 |     100 |   78.31 | 34-35,41-47,65-66,72-78   
  send.ts                      |   77.55 |    33.33 |      80 |   77.55 | ...45-346,351-359,402-441 
  types.ts                     |     100 |      100 |     100 |     100 |                           
  utils.ts                     |   67.41 |    68.96 |   63.63 |   67.41 | ...36-439,442-444,476-491 
 ccip-sdk/src/sui              |   32.62 |    89.47 |   17.24 |   32.62 |                           
  discovery.ts                 |   14.86 |      100 |       0 |   14.86 | 20-36,49-185,188-222      
  events.ts                    |    19.9 |      100 |       0 |    19.9 | ...18-275,280-397,406-427 
  exec.ts                      |   31.29 |      100 |       0 |   31.29 | 31-74,86-131              
  hasher.ts                    |   98.16 |    66.66 |     100 |   98.16 | 33,49                     
  index.ts                     |   40.44 |    93.18 |   17.94 |   40.44 | ...12-813,817-818,822-823 
  objects.ts                   |   18.93 |      100 |       0 |   18.93 | ...04-119,133-184,195-338 
 ccip-sdk/src/sui/manuallyExec |   39.63 |      100 |       0 |   39.63 |                           
  encoder.ts                   |   47.67 |      100 |       0 |   47.67 | 42-86                     
  index.ts                     |   34.35 |      100 |       0 |   34.35 | 46-131                    
 ccip-sdk/src/ton              |   76.52 |    80.63 |   71.42 |   76.52 |                           
  exec.ts                      |     100 |      100 |     100 |     100 |                           
  extra-args.ts                |   98.66 |    72.72 |     100 |   98.66 | 156-157,222               
  hasher.ts                    |   77.95 |    77.77 |      75 |   77.95 | 99-107,155-186            
  index.ts                     |   70.86 |    76.72 |   55.55 |   70.86 | ...05,1212-1213,1220-1221 
  logs.ts                      |     100 |    98.43 |     100 |     100 | 56                        
  send.ts                      |   95.93 |       70 |     100 |   95.93 | 37-44                     
  types.ts                     |   77.94 |    69.23 |   66.66 |   77.94 | ...-73,91,118-131,133-136 
  utils.ts                     |   63.02 |    78.18 |    90.9 |   63.02 | ...22-328,336-394,396-399 
-------------------------------|---------|----------|---------|---------|---------------------------

@aelmanaa aelmanaa merged commit 782749c into main Apr 24, 2026
13 checks passed
@aelmanaa aelmanaa deleted the fix/sdk-viem-revert-data branch April 24, 2026 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants