Skip to content

test(python/evm): add unit tests for EthAccountSignerWithRPC#147

Open
0xAxiom wants to merge 1 commit intocoinbase:mainfrom
0xAxiom:test/python-evm-signer-with-rpc-unit-tests
Open

test(python/evm): add unit tests for EthAccountSignerWithRPC#147
0xAxiom wants to merge 1 commit intocoinbase:mainfrom
0xAxiom:test/python-evm-signer-with-rpc-unit-tests

Conversation

@0xAxiom
Copy link
Copy Markdown

@0xAxiom 0xAxiom commented May 4, 2026

Summary

EthAccountSignerWithRPC (in python/x402/mechanisms/evm/signers.py) was the only signer class in that module without dedicated unit tests. tests/unit/mechanisms/evm/test_signer.py already covered EthAccountSigner and FacilitatorWeb3Signer, but the RPC-extended client signer used by gas-sponsoring extensions (EIP-2612, ERC-20 approval) had no tests.

This PR adds 9 tests in a new TestEthAccountSignerWithRPC class covering the constructor, the inherited surface, and each of the four added RPC methods (read_contract, sign_transaction, get_transaction_count, estimate_fees_per_gas), including the baseFeePerGas-missing fallback path.

Tests

  • test_should_create_signer_and_inherit_address — address inherited from EthAccountSigner
  • test_should_be_subclass_of_eth_account_signerisinstance(EthAccountSigner) holds
  • test_should_construct_web3_with_rpc_urlWeb3.HTTPProvider wired with the given URL
  • test_should_inherit_sign_typed_data — inherited sign_typed_data still produces a 65+ byte signature
  • test_read_contract_should_call_function_and_return_value — checksums the contract address and returns the call() value
  • test_sign_transaction_should_return_hex_prefixed_raw_tx — returns "0x" + raw_transaction.hex() and forwards account.key
  • test_get_transaction_count_should_checksum_address — passes a checksummed address to web3.eth.get_transaction_count
  • test_estimate_fees_per_gas_should_compute_eip1559_fees — returns (base*2 + priority, priority) from eth.get_block("latest")
  • test_estimate_fees_per_gas_should_default_base_fee_when_missing — falls back to 1 gwei base when the block omits baseFeePerGas (legacy / non-EIP-1559 chain path)
  • test_implements_client_evm_signer_protocol — verifies the inherited + added surface is present and callable

Verification

cd python/x402
uv run pytest tests/unit/mechanisms/evm/test_signer.py -q
# 20 passed (12 prior + 8 new)

uv run pytest tests/unit/mechanisms/evm/ -q
# 264 passed — no regressions

uvx ruff format tests/unit/mechanisms/evm/test_signer.py
uvx ruff check tests/unit/mechanisms/evm/test_signer.py
# All checks passed!

No changeset fragment per the contributor guide (test-only changes are skipped).

Scope

Tests only. No changes to signers.py itself.

EthAccountSignerWithRPC was the only signer class in
python/x402/mechanisms/evm/signers.py without dedicated unit tests
(test_signer.py covered EthAccountSigner and FacilitatorWeb3Signer
but not the RPC-extended subclass used by gas-sponsoring extensions).

Tests cover:
- TestEthAccountSignerWithRPC: address inheritance from EthAccountSigner,
  isinstance subclass relationship, Web3.HTTPProvider construction wiring,
  inherited sign_typed_data still works, read_contract checksums the
  contract address and returns the call() value, sign_transaction returns
  the '0x'-prefixed hex of raw_transaction bytes and forwards account.key,
  get_transaction_count checksums the input address before the RPC call,
  estimate_fees_per_gas computes (base*2 + priority, priority) from the
  latest block, estimate_fees_per_gas falls back to 1 gwei base when the
  block omits baseFeePerGas (legacy chain path), and the RPC-extended
  client signer surface is present and callable.
@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