Skip to content

test(python): add unit tests for sign_eip2612_permit#2344

Open
VedantAnand17 wants to merge 1 commit into
x402-foundation:mainfrom
VedantAnand17:test/python-eip2612-permit-signing-tests
Open

test(python): add unit tests for sign_eip2612_permit#2344
VedantAnand17 wants to merge 1 commit into
x402-foundation:mainfrom
VedantAnand17:test/python-eip2612-permit-signing-tests

Conversation

@VedantAnand17
Copy link
Copy Markdown
Contributor

Summary

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 #2278 took for sign_erc20_approval_transaction in the sibling erc20_approval_gas_sponsoring extension.

No production code changes; tests-only.

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 Eip2612GasSponsoringInfo shape (all fields populated, signature hex-prefixed),
    • nonce read against the token contract via EIP2612_NONCES_ABI with the signer address,
    • EIP-712 domain (name, version, chainId, verifyingContract) and Permit primary type,
    • message int coercion (value, nonce, deadline) plus correct owner/spender (Permit2),
    • 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, 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.

python/CONTRIBUTING.md calls this out:

MATCH EXISTING PATTERNS: TypeScript SDK uses pattern X → Python SDK MUST use pattern X.

The TypeScript and Go sides of the EIP-2612 extension on feat/eip2612-extension-implementations already ship dedicated unit tests for their permit-signing paths; this brings Python to parity for the function that already lives in main.

Test plan

  • uv run pytest x402/tests/unit/extensions/test_eip2612_gas_sponsoring.py — 18 passed (5 new).
  • Full Python suite: uv run pytest — 1140 passed, 45 skipped.
  • uv run ruff check — clean.
  • uv run ruff format --check — 234 files already formatted.
  • No production code touched: tests + changelog fragment only.

Made with Cursor

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.
@vercel
Copy link
Copy Markdown

vercel Bot commented May 17, 2026

@VedantAnand17 is attempting to deploy a commit to the Coinbase Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added sdk Changes to core v2 packages python labels May 17, 2026
@VedantAnand17
Copy link
Copy Markdown
Contributor Author

@Must-be-Ash @phdargen can you please check this out :)

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

Labels

python sdk Changes to core v2 packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant