test(python/evm): add unit tests for FacilitatorWeb3Signer methods#148
Open
0xAxiom wants to merge 1 commit intocoinbase:mainfrom
Open
test(python/evm): add unit tests for FacilitatorWeb3Signer methods#1480xAxiom wants to merge 1 commit intocoinbase:mainfrom
0xAxiom wants to merge 1 commit intocoinbase:mainfrom
Conversation
The existing test_signer.py only covered the constructor, address
property, and protocol surface of FacilitatorWeb3Signer in
python/x402/x402/mechanisms/evm/signers.py. The actual on-chain
methods were not exercised. This commit fills that gap.
Tests cover:
- get_chain_id: RPC call + caching (mutating the underlying mock after
first call still returns the cached value).
- read_contract: address checksumming on the contract address, function
invocation, and {"from": signer.address} propagation in call().
- verify_typed_data: EOA happy path against the matching account, EOA
mismatch with no contract code (EIP-1271 path skipped), bytes nonce
normalized to hex without mutating the caller's message dict, raw
dict domain (Permit2-style, no version) accepted as-is, and any
internal exception swallowed to return False.
- write_contract: build → sign → send raw flow with checksummed
contract address and propagated nonce/gas/gasPrice.
- send_transaction: raw tx build with checksummed `to`, account
signing, and hex tx-hash return.
- wait_for_transaction_receipt: status=1 maps to TX_STATUS_SUCCESS,
non-1 maps to 0, and a tx_hash without 0x prefix is normalized in
both the web3 call and the returned receipt.
- get_balance: zero-address routes to native eth.get_balance, empty
string also routes to native, and a real token address goes through
the ERC20 contract path with checksummed addresses.
- get_code: address checksumming and bytes() wrapping for both
contract and EOA cases.
17 new tests, 27 total in the file. All tests in
tests/unit/mechanisms/evm/ continue to pass (271 total).
Signed-off-by: Axiom Bot <0xAxiom@users.noreply.github.com>
🟡 Heimdall Review Status
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
tests/unit/mechanisms/evm/test_signer.pypreviously covered only the constructor,addressproperty, and protocol surface ofFacilitatorWeb3Signerinpython/x402/x402/mechanisms/evm/signers.py. The actual on-chain methods were untested. This PR adds 17 unit tests that exercise every method's behavior with a mockedWeb3client.Coverage Added
get_chain_id— RPC call + caching (mutating the mock after the first call still returns the cached value)read_contract— contract-address checksumming, function invocation, and{\"from\": signer.address}propagation in.call(...)verify_typed_data—bytesnonce normalized to hex without mutating the caller's message dictdictdomain (Permit2-style, noversion) accepted as-isFalsewrite_contract— build → sign → send-raw flow with checksummed contract address and propagatednonce/gas/gasPricesend_transaction— raw tx build with checksummedto, account signing, hex tx-hash returnwait_for_transaction_receipt—status=1 → TX_STATUS_SUCCESS, non-1 →0, and atx_hashwithout0xprefix normalized in both the web3 call and the returned receiptget_balance— zero-address routes to nativeeth.get_balance, empty-string token routes to native, real token address routes through ERC20 contract path with checksummed addressesget_code— address checksumming andbytes()wrapping for both contract and EOA casesTest plan
uv run pytest tests/unit/mechanisms/evm/test_signer.py→ 27 passed (10 existing + 17 new)uv run pytest tests/unit/mechanisms/evm/→ 271 passed (no regressions)uvx ruff formatapplieduvx ruff checkcleanpython/x402/changelog.d/🤖 Generated with Claude Code