test(python): add unit tests for sign_eip2612_permit#2344
Open
VedantAnand17 wants to merge 1 commit into
Open
Conversation
The Python `eip2612_gas_sponsoring` extension's `sign_eip2612_permit` client function had no direct unit coverage — only the surrounding declaration / serialization / extraction / payment-validation paths were tested. This mirrors the testing approach PR x402-foundation#2278 took for `sign_erc20_approval_transaction` in the sibling `erc20_approval_gas_sponsoring` extension. ### Changes - `python/x402/tests/unit/extensions/test_eip2612_gas_sponsoring.py`: add a `_StubPermitSigner` (records every `read_contract` and `sign_typed_data` call) plus a `TestSignEip2612Permit` class with five focused tests covering: returned info shape, nonce read against the token contract, EIP-712 domain + primary type, message int coercion with correct owner/spender, and `MaxUint256` amount support. - Towncrier `misc` fragment under `python/x402/changelog.d/`. ### Why `sign_eip2612_permit` constructs the EIP-712 payload that downstream facilitators verify on-chain. A regression in the domain (`name`, `version`, `chainId`, `verifyingContract`), the `Permit` primary type, the int-coerced message fields, or the spender (must be `PERMIT2_ADDRESS`) would silently break Permit2 gas sponsoring on every chain that opts into it. Tests now lock those invariants in. No production code changes; tests-only. ## Test plan - [x] `uv run pytest tests/unit/extensions/test_eip2612_gas_sponsoring.py` — 18 passed (5 new). - [x] Full Python suite: `uv run pytest` — 1140 passed, 45 skipped. - [x] `uv run ruff check` — clean. - [x] `uv run ruff format --check` — 234 files already formatted.
|
@VedantAnand17 is attempting to deploy a commit to the Coinbase Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
Author
|
@Must-be-Ash @phdargen can you please check this out :) |
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
The Python
eip2612_gas_sponsoringextension'ssign_eip2612_permitclient function had no direct unit coverage — only the surrounding declaration / serialization / extraction / payment-validation paths were tested. This mirrors the testing approach #2278 took forsign_erc20_approval_transactionin the siblingerc20_approval_gas_sponsoringextension.No production code changes; tests-only.
Changes
python/x402/tests/unit/extensions/test_eip2612_gas_sponsoring.py: add a_StubPermitSigner(records everyread_contractandsign_typed_datacall) plus aTestSignEip2612Permitclass with five focused tests covering:Eip2612GasSponsoringInfoshape (all fields populated, signature hex-prefixed),EIP2612_NONCES_ABIwith the signer address,name,version,chainId,verifyingContract) andPermitprimary type,value,nonce,deadline) plus correctowner/spender(Permit2),MaxUint256amount support.miscfragment underpython/x402/changelog.d/.Why
sign_eip2612_permitconstructs the EIP-712 payload that downstream facilitators verify on-chain. A regression in the domain, thePermitprimary type, the int-coerced message fields, or the spender (must bePERMIT2_ADDRESS) would silently break Permit2 gas sponsoring on every chain that opts into it. Tests now lock those invariants in.python/CONTRIBUTING.mdcalls this out:The TypeScript and Go sides of the EIP-2612 extension on
feat/eip2612-extension-implementationsalready ship dedicated unit tests for their permit-signing paths; this brings Python to parity for the function that already lives inmain.Test plan
uv run pytest x402/tests/unit/extensions/test_eip2612_gas_sponsoring.py— 18 passed (5 new).uv run pytest— 1140 passed, 45 skipped.uv run ruff check— clean.uv run ruff format --check— 234 files already formatted.Made with Cursor