Skip to content

test(python/svm): add unit tests for utils helpers#149

Open
0xAxiom wants to merge 1 commit intocoinbase:mainfrom
0xAxiom:test/python-svm-utils-unit-tests
Open

test(python/svm): add unit tests for utils helpers#149
0xAxiom wants to merge 1 commit intocoinbase:mainfrom
0xAxiom:test/python-svm-utils-unit-tests

Conversation

@0xAxiom
Copy link
Copy Markdown

@0xAxiom 0xAxiom commented May 4, 2026

Summary

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 (mainnet/devnet/testnet) + V1 names (solana, solana-devnet, solana-testnet) + unsupported-network errors (unknown CAIP-2, unknown V1 name, non-Solana CAIP-2 like eip155:1).
  • get_asset_info — default-asset short-circuit on None/empty string, registered-address match, mismatched-address ValueError, network-error precedence over asset matching.
  • parse_amount + format_amount — multi-decimal arithmetic (6/9/0 decimals), sub-unit truncation, zero, round-trip format_amount(parse_amount(s, d), d) == s for representative inputs, decimal.InvalidOperation for invalid strings.
  • parse_money_to_decimal — int/float pass-through, $ prefix, USD/USDC and usd/usdc suffixes, surrounding whitespace, invalid string raises ValueError.
  • decode_transaction_from_payload — valid base64 round-trip (build a real VersionedTransaction, encode, decode, assert bytes(decoded) == tx_bytes); invalid_exact_svm_payload_transaction raised for invalid-base64, base64-garbage, and empty payload.
  • derive_ata — valid base58 output (Pubkey.from_string round-trip), determinism across calls, omitted token_program defaults to Token Program, Token-2022 program produces a different ATA, ATA differs across owners and across mints, explicit None for token_program matches default behavior.

All 54 tests pass on uv run pytest; uvx ruff format + uvx ruff check clean.

Test plan

  • uvx ruff format tests/unit/mechanisms/svm/test_utils.py — 1 file unchanged
  • uvx ruff check tests/unit/mechanisms/svm/test_utils.py — All checks passed
  • uv run pytest tests/unit/mechanisms/svm/test_utils.py -v — 54 passed
  • Changelog fragment added: python/x402/changelog.d/python-svm-utils-tests.doc.md
  • Commit GPG-signed

@cb-heimdall
Copy link
Copy Markdown

cb-heimdall commented May 4, 2026

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
Sum 1

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants