Skip to content

test(python/evm): add unit tests for register helpers#143

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

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

Conversation

@0xAxiom
Copy link
Copy Markdown

@0xAxiom 0xAxiom commented May 4, 2026

Summary

Adds 30 unit tests for python/x402/x402/mechanisms/evm/exact/register.py — the only source file in mechanisms/evm/exact/ without a dedicated unit test module.

The three public helpers (register_exact_evm_client, register_exact_evm_server, register_exact_evm_facilitator) are the canonical entry points users hit when wiring EVM exact schemes into x402Client, x402ResourceServer, and x402Facilitator (and their sync variants), so direct coverage is worthwhile.

What's tested

register_exact_evm_client (13 tests)

  • Returns the same client for chaining
  • Default registration: eip155:* V2 wildcard + V1 schemes for every entry in V1_NETWORKS
  • networks="eip155:8453" (string) registers a single V2 entry; networks=["eip155:8453", "eip155:1", "eip155:137"] registers each
  • Explicit networks suppresses the wildcard fallback but does not suppress the V1 fanout
  • policies=[...] appends to the client's policy list; omitting policies leaves it untouched
  • Registered V2 scheme is ExactEvmClientScheme with _signer is signer; V1 scheme on "base" is ExactEvmSchemeV1 with _signer is signer
  • Bare eth_account.LocalAccount is auto-wrapped in EthAccountSigner via _wrap_if_local_account
  • Works against x402ClientSync as well as x402Client

register_exact_evm_server (7 tests)

  • Returns the same server for chaining
  • Default eip155:* wildcard; networks arg as string or list registers exactly those networks
  • Registered scheme is ExactEvmServerScheme
  • No V1 entries are added (server registration is V2-only)
  • Works against x402ResourceServerSync as well as x402ResourceServer

register_exact_evm_facilitator (10 tests)

  • Returns the same facilitator for chaining
  • networks as string or list registers each V2 network correctly
  • V1 registration always covers the full V1_NETWORKS set
  • Registered V2 facilitator is ExactEvmScheme (facilitator) with _signer is signer; V1 is ExactEvmSchemeV1 (facilitator) with _signer is signer
  • Default config: both deploy_erc4337_with_eip6492 and simulate_in_settle are False on V2 and V1 configs
  • Both flags are propagated identically to V2 and V1 configs
  • Setting only one flag leaves the other at default
  • Works against x402FacilitatorSync as well as x402Facilitator

Test fixture notes

Client tests use a real EthAccountSigner wrapping a fresh eth_account.Account.create() (no network calls). Facilitator tests use a MagicMock signer with an address attribute — sufficient because register_exact_evm_facilitator only stores the signer reference on the scheme; no signer methods are invoked during registration.

Verification

$ uv run pytest tests/unit/mechanisms/evm/test_register.py -v
======================== 30 passed, 1 warning in 1.13s =========================

$ uv run pytest tests/unit/ -q
======================== 841 passed, 1 warning in 2.84s =========================

$ uvx ruff format tests/unit/mechanisms/evm/test_register.py
1 file left unchanged

$ uvx ruff check tests/unit/mechanisms/evm/test_register.py
All checks passed!

Changelog

Added python/x402/changelog.d/register-helpers-unit-tests.doc.md.

Test plan

  • All 30 new tests pass
  • Full Python unit suite (841 tests) passes — no regressions
  • ruff format and ruff check clean
  • Commit GPG-signed and DCO Signed-off-by line included

Add 30 unit tests for python/x402/x402/mechanisms/evm/exact/register.py
covering register_exact_evm_client, register_exact_evm_server, and
register_exact_evm_facilitator. This is the only file in
mechanisms/evm/exact/ that previously lacked a dedicated unit test
module.

Coverage:
- register_exact_evm_client: default wildcard + V1 fanout, str/list
  networks, suppression of wildcard when networks specified, policy
  registration (with and without policies arg), V2/V1 scheme instance
  binding to signer, LocalAccount auto-wrapping, sync variant.
- register_exact_evm_server: default wildcard, str/list networks, no V1
  registration, scheme instance type, sync variant.
- register_exact_evm_facilitator: str/list networks, V1 fanout across
  all V1_NETWORKS, V2/V1 scheme instance binding to signer, default
  config flags (False), full propagation of deploy_erc4337_with_eip6492
  and simulate_in_settle to both V2 and V1 configs, partial flag
  propagation, sync variant.

Signed-off-by: Axiom Bot <0xAxiom@users.noreply.github.com>
@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