Skip to content

feat: x402 v2 SDK, AssetRegistry, and E2E Test Suite#7

Closed
Hades-Ye wants to merge 23 commits intomainfrom
feat/e2e-test-optimization
Closed

feat: x402 v2 SDK, AssetRegistry, and E2E Test Suite#7
Hades-Ye wants to merge 23 commits intomainfrom
feat/e2e-test-optimization

Conversation

@Hades-Ye
Copy link
Copy Markdown
Contributor

Summary

This PR introduces the second generation (v2) of the x402 SDK, modularized and ported to the bankofai namespace. It also adds a comprehensive E2E testing framework, asset registry, and extensive examples.

Key Changes

  • Modular SDK Architecture: Ported and refactored from Coinbase x402 v2 for both Python and TypeScript.
  • AssetRegistry: Centralized registry for token metadata (symbol, address, decimals) across multiple chains (TRON, BSC, etc.).
  • Auto-Adaptive Protocol: Support for both v1 and v2 protocols, allowing clients and servers to negotiate the best available mechanism.
  • E2E Testing Framework:
    • Automated testing of various client/server/facilitator combinations.
    • Integration tests for Express, Hono, Next.js, FastAPI, Flask, and MCP servers.
    • Multi-chain support (BSC Testnet with DHLU token, TRON, etc.).
  • CI/CD Workflows: Added GitHub Actions for linting, formatting, type-checking, and running E2E tests.
  • Extensive Examples: New examples directory showcasing real-world integrations and advanced usage patterns.

Verification

  • Ran E2E tests locally on BSC Testnet.
  • Verified v1/v2 interoperability.
  • CI workflows are in place to ensure code quality and protocol correctness.

Hades-Ye added 23 commits March 9, 2026 19:47
- Deprecate existing bofai SDKs (python/x402-deprecated, typescript/packages/x402-deprecated)
  with deprecation warnings
- Fork coinbase Python SDK v2.3.0 as bankofai.x402 with src/bankofai/x402 namespace layout
- Fork coinbase TypeScript SDK v2.6.0 as @bankofai/x402-* (20 packages: core, http/*, mechanisms/*, etc.)
- Fork coinbase legacy v1 packages as @bankofai/x402-*-legacy
- Fork examples and e2e tests with updated package references
- Update .gitignore to exclude build artifacts and agent config
- All Python tests pass (677 passed), all TypeScript builds and tests pass (40/40 tasks)
Add AssetRegistry class (TS + Python) that maps (network, symbol) to
token metadata, enabling B-form shorthand where developers specify
assets: ["USDT", "USDC"] instead of manual addresses/decimals.

- New AssetRegistry with built-in tokens for EVM (eip155:1/56/97) and
  TRON (mainnet/shasta/nile) networks
- convertMoney utility for Money → smallest-unit conversion
- Global singleton (globalAssetRegistry / global_asset_registry)
- ResourceConfig and PaymentOption gain optional assets field
- x402ResourceServer auto-expands B-form to D-form PaymentRequirements
- 25 TS + 25 Python unit tests for registry and conversion
- Fix import ordering in __init__.py
- Remove unused AssetInfo import in server_base.py
- Collapse unnecessary multi-line expressions per ruff format
Internal test tokens no longer needed in the built-in registry.
feat: add AssetRegistry for multi-asset symbol-based token lookup
…t SDKs

Verify the existing v1/v2 auto-detection and routing behavior end-to-end
without modifying source code. Covers client payload creation, HTTP header
encoding, round-tripper flow, and mixed v1+v2 scheme registration.

Python (25 new test cases):
- Unit: v1 payload creation (async+sync), auto-adaptive routing, v1 hooks
- Integration: parameterized sync/async v1 flow, auto-adaptive routing, HTTP layer
- HTTP: v1 handle_402, v1 round-tripper with X-PAYMENT header

TypeScript (16 new test cases):
- Unit: v1 payload creation, auto-adaptive v1/v2 routing, version isolation
- HTTP: v1/v2 header encoding, body parsing, settle response, priority tests
The assets field from PaymentOption was not forwarded to ResourceConfig
in buildPaymentRequirementsFromOptions, causing AssetRegistry-based
price resolution to never trigger via the HTTP middleware path.
Project only has Python + TypeScript SDKs. Coinbase Go SDK compatibility
tests will be added in a separate test directory later.
…runner

Previously the hardcoded check at startup required SVM env vars even
when running EVM-only tests (e.g. --families=evm). Move validation
after scenario filtering so only variables for the actually-tested
protocol families are required.
…LU token

Migrate all e2e test infrastructure to BSC Testnet (eip155:97) using
DHLU token (0x375cADdd2cB68cE82e3D9B075D551067a7b4B816, decimals: 6,
EIP712 name="DA HULU", version="1"). DHLU supports EIP-3009, EIP-2612,
and ERC-20 approval, enabling all payment transfer methods with a single
token.

- Update v2 servers (express, hono, next, fastapi, flask) with
  pre-parsed DHLU price objects (also fixes permit2 endpoints that
  had extra at wrong level when using $0.001 shorthand)
- Update MCP servers (TypeScript, Python) with DHLU price config
- Update facilitators (TypeScript, Python) RPC URLs and network IDs
- Update clients (fetch, axios, mcp-typescript) chain references
- Update legacy servers/clients to use bsc-testnet network name
- Update permit2-approval script for BSC Testnet + DHLU
@Hades-Ye Hades-Ye closed this Mar 11, 2026
boboliu-1010 pushed a commit that referenced this pull request Apr 24, 2026
- solutions.md #7: BSC testnet has no EIP-2612 permit-capable token.
  Captures why exact_permit_testnet returns 404 and lists the options
  (Sepolia / custom test token / rely on unit suites), so the next
  person doesn't rediscover it.
- solutions.md #8: integration runner doesn't expand ${VAR:-default}.
  Captures the os.path.expandvars limitation that caused the testnet
  scenarios to silently break on a literal fallback string.
- testnet/README.md: add "Current status" table with today's verified
  BSC tx hash as evidence, and a "Gotchas" section linking back to
  solutions #7 / #8, the tx-hash regex, and the log locations.

No code change — just freezing today's testnet run state so future
attempts start from known ground.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
boboliu-1010 pushed a commit that referenced this pull request Apr 24, 2026
…anisms

Permit-family facilitator mechanisms (EVM exact_permit, TRON exact_permit,
TRON exact_gasfree) all inherit BaseExactPermitFacilitatorMechanism which
requires a base_fee: dict[str, int] allow-list at construction time.
examples/facilitator/server.py was constructing them without base_fee, so
every token in every registry was reported Unsupported and every testnet
run of the permit/gasfree tiers silently returned HTTP 404.

- server.py now reads FACILITATOR_BASE_FEE as a JSON dict and passes it
  to all three permit/gasfree mechanism constructors; logs a clear warning
  when a permit/gasfree scheme is registered without it.
- testnet scenario configs now forward FACILITATOR_BASE_FEE into the
  facilitator subprocess.
- .env.example / README updated.
- docs/solutions.md #7 corrected — the earlier entry blaming BSC testnet
  USDT for not implementing EIP-2612 was a misdiagnosis; USDT does
  implement permit. The real cause was the missing base_fee config.

Verified live 2026-04-24:
- exact_permit_testnet: BSC tx 0xfc8b32decb99d02cdfc684d3f6f1c7c0a91c8b0ff1f632f98d86d9f334198a23 (USDT permit + transferFrom, block 103475005)
- exact_gasfree_testnet: fee_quote / verify / settle all traverse; final
  settle reports insufficient balance in the derived GasFree custodial
  wallet when it isn't funded — structural path end-to-end works.

Regression: 217 pytest + 51 vitest + 8 mock e2e all green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant