test(python/svm): add unit tests for utils helpers#149
Open
0xAxiom wants to merge 1 commit intocoinbase:mainfrom
Open
test(python/svm): add unit tests for utils helpers#1490xAxiom wants to merge 1 commit intocoinbase:mainfrom
0xAxiom wants to merge 1 commit intocoinbase:mainfrom
Conversation
🟡 Heimdall Review Status
|
Add 54 unit tests for python/x402/x402/mechanisms/svm/utils.py helpers without prior dedicated coverage. test_index.py already covers the public re-exports (normalize_network, validate_svm_address, get_usdc_address, convert_to_token_amount); the new test_utils.py covers the remaining helpers: - get_network_config: CAIP-2 + V1 names + unsupported-network errors - get_asset_info: default-asset short-circuit on None/empty string, registered-address match, mismatched-address error, network-error precedence - parse_amount + format_amount: multi-decimal arithmetic, sub-unit truncation, zero, round-trip through parse_amount - parse_money_to_decimal: int/float pass-through, dollar prefix, USD/USDC and usd/usdc suffixes, surrounding whitespace, invalid string - decode_transaction_from_payload: valid base64 round-trip plus invalid_exact_svm_payload_transaction for invalid-base64, base64-garbage, and empty payload - derive_ata: valid base58 output, determinism, default vs explicit Token Program, Token-2022 divergence, sensitivity to owner and mint All 54 tests pass; ruff format and ruff check clean.
521d62d to
ac879c1
Compare
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 54 unit tests for
python/x402/x402/mechanisms/svm/utils.pyhelpers without prior dedicated coverage.test_index.pyalready covers the public re-exports (normalize_network,validate_svm_address,get_usdc_address,convert_to_token_amount); the newtest_utils.pycovers the remaining helpers:solana,solana-devnet,solana-testnet) + unsupported-network errors (unknown CAIP-2, unknown V1 name, non-Solana CAIP-2 likeeip155:1).None/empty string, registered-address match, mismatched-addressValueError, network-error precedence over asset matching.format_amount(parse_amount(s, d), d) == sfor representative inputs,decimal.InvalidOperationfor invalid strings.$prefix,USD/USDCandusd/usdcsuffixes, surrounding whitespace, invalid string raisesValueError.VersionedTransaction, encode, decode, assertbytes(decoded) == tx_bytes);invalid_exact_svm_payload_transactionraised for invalid-base64, base64-garbage, and empty payload.Pubkey.from_stringround-trip), determinism across calls, omittedtoken_programdefaults to Token Program, Token-2022 program produces a different ATA, ATA differs across owners and across mints, explicitNonefortoken_programmatches default behavior.All 54 tests pass on
uv run pytest;uvx ruff format+uvx ruff checkclean.Test plan
uvx ruff format tests/unit/mechanisms/svm/test_utils.py— 1 file unchangeduvx ruff check tests/unit/mechanisms/svm/test_utils.py— All checks passeduv run pytest tests/unit/mechanisms/svm/test_utils.py -v— 54 passedpython/x402/changelog.d/python-svm-utils-tests.doc.md