Skip to content

test(python/evm): add unit tests for eip3009_utils helpers#139

Open
0xAxiom wants to merge 1 commit into
coinbase:mainfrom
0xAxiom:test/python-evm-eip3009-utils-unit-tests
Open

test(python/evm): add unit tests for eip3009_utils helpers#139
0xAxiom wants to merge 1 commit into
coinbase:mainfrom
0xAxiom:test/python-evm-eip3009-utils-unit-tests

Conversation

@0xAxiom
Copy link
Copy Markdown

@0xAxiom 0xAxiom commented May 3, 2026

Summary

Adds 61 unit tests for python/x402/x402/mechanisms/evm/exact/eip3009_utils.py — the largest source file in the EVM mechanism without a dedicated test module. Covers every public helper plus the _split_signature_parts private helper that gates ECDSA signature handling for transferWithAuthorization.

Coverage

Function Tests Notes
parse_eip3009_authorization 7 field round-trip, numeric coercion, nonce length validation (short/long/empty/no-prefix), bad value raises
_split_signature_parts 8 v=27/28 passthrough, v=0/1 normalization, 64/66/0-byte inputs raise, high-v values pass through unchanged
parse_eip3009_transfer_error 10 expired / not-yet-valid / used / insufficient-balance / invalid-signature variants, case insensitivity, unknown→ERR_TRANSACTION_FAILED, first-match priority
classify_eip3009_signature 6 valid EOA, valid smart wallet (ERC-6492 wrapper), valid non-65-byte inner, invalid w/ deployed code, invalid w/ deployment info but no code (undeployed), invalid plain EOA
simulate_eip3009_transfer 8 undeployed multicall success/failure/raise/short-results; 65-byte EOA success and revert; non-65-byte fallback path
diagnose_eip3009_simulation_failure 12 multicall raise, short results, authState failure/used, name/version mismatch, insufficient balance, empty token_name/token_version skips check, balance failure swallowed, non-int balance handled, all-clean default
execute_transfer_with_authorization 3 VRS ABI for 65-byte EOA, bytes ABI for smart wallet, authorization args forwarded

FacilitatorEvmSigner and multicall are mocked — the goal is to lock in the control-flow contracts (which ABI is chosen, which error code is returned, which arguments are forwarded), not to replay an actual EVM RPC.

Test plan

  • uv run pytest tests/unit/mechanisms/evm/test_eip3009_utils.py — 61 passed
  • uv run pytest tests/unit/mechanisms/evm/ — 315 passed (no regressions)
  • uv run ruff check tests/unit/mechanisms/evm/test_eip3009_utils.py
  • uv run ruff format --check tests/unit/mechanisms/evm/test_eip3009_utils.py
  • GPG-signed commit
  • Changelog fragment added (python/x402/changelog.d/139.doc.md)

AI usage

This PR was AI-assisted (Claude). Test cases were derived from reading eip3009_utils.py directly — assertions follow the actual control flow, not a fabricated spec. Reviewed before submission.

Add 61 unit tests for python/x402/x402/mechanisms/evm/exact/eip3009_utils.py,
the largest source file in the EVM mechanism without a dedicated test
module. All public helpers plus the _split_signature_parts private helper
are covered.

- parse_eip3009_authorization (7): field round-trip, numeric coercion,
  nonce length validation (short/long/empty/no-prefix), bad value raises.
- _split_signature_parts (8): v=27/28 passthrough, v=0/1 normalization,
  64/66/0-byte ECDSA inputs raise, high-v values pass through unchanged.
- parse_eip3009_transfer_error (10): expired, not-yet-valid, used,
  insufficient-balance, invalid-signature variants; case insensitivity;
  unknown/empty fall back to ERR_TRANSACTION_FAILED; first-match priority.
- classify_eip3009_signature (6): valid EOA, valid smart wallet (ERC-6492
  wrapper), valid non-65-byte inner, invalid w/ deployed code, invalid w/
  deployment info but no code (undeployed), invalid plain EOA.
- simulate_eip3009_transfer (8): undeployed multicall success/failure/raise/
  short-results; 65-byte EOA success and revert; non-65-byte fallback path.
- diagnose_eip3009_simulation_failure (12): multicall raise, short results,
  authState failure/used, name/version mismatch, insufficient balance,
  empty token_name/version skips check, balance failure swallowed,
  non-int balance handled, all-clean default.
- execute_transfer_with_authorization (3): VRS ABI for 65-byte EOA,
  bytes ABI for smart wallet, authorization arguments forwarded.
@cb-heimdall
Copy link
Copy Markdown

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
Sum 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants