test(python/svm): add unit tests for ExactSvmSchemeV1 facilitator#152
Open
0xAxiom wants to merge 1 commit intocoinbase:mainfrom
Open
test(python/svm): add unit tests for ExactSvmSchemeV1 facilitator#1520xAxiom wants to merge 1 commit intocoinbase:mainfrom
0xAxiom wants to merge 1 commit intocoinbase:mainfrom
Conversation
Add 41 unit tests for python/x402/x402/mechanisms/svm/exact/v1/facilitator.py - the only file in mechanisms/svm/exact/v1/ without a dedicated test module after PR x402-foundation#151 landed test_exact_v1_client.py. test_facilitator.py covers ExactSvmFacilitatorScheme (V2) and only borrows ExactSvmSchemeV1 for one shared-cache cross-version case; the V1 verify/settle pipelines themselves had no direct coverage. Coverage: - Constructor + scheme/caip_family attributes + default-vs-injected SettlementCache (via the optional settlement_cache constructor arg). - get_extra picks one of the signer's addresses; get_signers returns a fresh list, not the signer's internal storage. - V1 top-level scheme and network mismatch gates (V1 stores both at the payload top level; V2 only puts them on the requirements). - feePayer extra missing/None/non-string/unmanaged paths all surface the expected invalid_reason without touching the transaction bytes. - Transaction decode failures: invalid base64 and empty-base64 payload both surface ERR_TRANSACTION_DECODE_FAILED before instruction parsing. - Happy-path verify against a real V1 transaction built via the V1 client (ExactSvmClientV1) with mocked RPC, so the verify pipeline runs against the bytes the client actually emits. - V1-specific max_amount_required gate: below threshold returns ERR_AMOUNT_INSUFFICIENT with the payer surfaced; exact threshold accepts. - mint mismatch (asset diverges from transaction mint), recipient ATA mismatch (pay_to diverges from on-chain destination), and fee_payer_transferring (authority is in the facilitator's managed set). - memo extra match accepts; memo extra mismatch returns ERR_MEMO_MISMATCH with the payer surfaced. - Simulation failure surfaces ERR_SIMULATION_FAILED with the underlying error string in invalid_message; sign-failure during verify maps to the same ERR_SIMULATION_FAILED branch. - Compute-budget price-cap gate exercised by patching MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS to 0; sanity guard pins the current constant value at 5_000_000. - Settle short-circuits on verify failure with the network reported from payload.network in V1 (V2 reports requirements.network). - Settle happy path returns mockSignature123 with send_transaction + confirm_transaction call ordering captured. - Settle send/confirm/missing-feePayer error paths all surface ERR_TRANSACTION_FAILED with the original exception string in error_message and transaction="". - Settle propagates the requirements.extra feePayer into sign_transaction. - Settle duplicate-cache check works same-instance and across two V1 facilitators sharing the same SettlementCache. - Helper round-trip smoke test ensures the V1 client output decodes to the 3-6 instruction range the facilitator accepts; parametrized payload smoke test covers V1 'solana-devnet' and 'solana' networks. All 41 tests pass; ruff format and ruff check clean across python/x402. Full unit suite (852 tests) still passes.
🟡 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
Add 41 unit tests for
python/x402/x402/mechanisms/svm/exact/v1/facilitator.py— the only file inmechanisms/svm/exact/v1/without a dedicated test module after #151 landedtest_exact_v1_client.py.test_facilitator.pycoversExactSvmFacilitatorScheme(V2) and only borrowsExactSvmSchemeV1for one shared-cache cross-version case; the V1 verify/settle pipelines themselves had no direct coverage.Coverage
scheme,caip_family, default-vs-injectedSettlementCache.get_extra/get_signers— multi-address selection, fresh-list return.schememismatch,networkmismatch (V1 stores both at the payload top level, unlike V2).feePayerextra gates — missing /None/ non-string / unmanaged paths all surface the expectedinvalid_reasonwithout touching the transaction bytes.ERR_TRANSACTION_DECODE_FAILEDbefore instruction parsing.ExactSvmClientV1) with mocked RPC.max_amount_requiredgate — below threshold returnsERR_AMOUNT_INSUFFICIENTwith payer surfaced; exact threshold accepts.fee_payer_transferring— all exercised against the real V1 transaction bytes.ERR_MEMO_MISMATCHwith payer when it doesn't.ERR_SIMULATION_FAILEDwith the underlying error string ininvalid_message.MAX_COMPUTE_UNIT_PRICE_MICROLAMPORTS; sanity guard pins the constant at5_000_000.payload.network(V1 differs from V2 here).mockSignature123withsend_transaction+confirm_transactionordering captured.ERR_TRANSACTION_FAILEDwith the original exception string inerror_message.requirements.extraintosign_transaction.Test plan
uv run pytest tests/unit/mechanisms/svm/test_exact_v1_facilitator.py— 41/41 passinguv run pytest tests/unit/mechanisms/svm/— 161/161 passing (no regressions in sibling suites)uv run pytest tests/unit/— 852/852 passinguv run ruff format --check .— 191 files cleanuv run ruff check .— cleanpython/x402/changelog.d/python-svm-exact-v1-facilitator-tests.doc.md