Skip to content

test(python/tvm): add unit tests for codecs/common.py#2252

Closed
0xAxiom wants to merge 1 commit intox402-foundation:mainfrom
0xAxiom:test/python-tvm-codecs-common-unit-tests
Closed

test(python/tvm): add unit tests for codecs/common.py#2252
0xAxiom wants to merge 1 commit intox402-foundation:mainfrom
0xAxiom:test/python-tvm-codecs-common-unit-tests

Conversation

@0xAxiom
Copy link
Copy Markdown
Contributor

@0xAxiom 0xAxiom commented May 8, 2026

Add 41 unit tests for python/x402/x402/mechanisms/tvm/codecs/common.py — the only file in mechanisms/tvm/codecs/ without a dedicated unit-test module after the TVM SDK landed in #1944.

Coverage

All 8 helpers in codecs/common.py:

  • normalize_address — raw wc:hex passthrough, Address object input, user-friendly to raw conversion, parity between string and Address inputs, invalid-address rejection (AddressError).
  • address_to_stack_item — slice typing ({"type": "slice", "value": <base64>}), base64 BoC round-trip via Cell.one_from_boc, user-friendly input acceptance.
  • decode_base64_boc — round-trip with encode_base64_boc, non-string rejection covering bytes/None/int with ValueError("base64-encoded BoC string"), invalid-base64 rejection.
  • make_zero_bit_cellCell instance type, single zero-bit payload (remaining_bits == 1, load_bit() == 0), determinism across calls, exact byte parity with manual Builder().store_bit(0).end_cell().
  • encode_base64_boc — string return type, exact byte parity with cell.to_boc(), round-trip with richer cells (uint + address).
  • get_network_global_id — mainnet tvm:-239-239, testnet tvm:-3-3, positive ID tvm:4242, missing/uppercase prefix rejection (ValueError("Unsupported TVM network")), non-numeric payload rejection.
  • parse_amount — decimal-to-smallest-unit, zero, zero-decimals, sub-unit truncation via int(), nine-decimal native TON amounts (11_000_000_000, 0.0000000011), InvalidOperation on non-numeric.
  • parse_money_to_decimalint/float passthrough, $ prefix, USD/USDT and lowercase suffixes with and without separating whitespace, combined $ ... USD prefix+suffix, surrounding whitespace, float type guarantee on string inputs, ValueError on unparseable strings.

Verification

  • uv run pytest tests/unit/mechanisms/tvm/test_common.py -q41 passed in 0.11s
  • uv run pytest tests/unit/mechanisms/tvm/ -q229 passed in 0.69s (no regressions in existing TVM suite)
  • uv run ruff format clean, uv run ruff check clean
  • Commit GPG-signed (RSA 7C3D4BFE44B598C90CE31DCCA190D7A3B1700D63)

Test file follows the established TVM convention: pytest.importorskip("pytoniq_core") so the suite skips cleanly when the optional [tvm] extras are not installed.

Add 41 unit tests for python/x402/x402/mechanisms/tvm/codecs/common.py — the only file in mechanisms/tvm/codecs/ without a dedicated unit-test module after the TVM SDK landed in x402-foundation#1944.

Covers all 8 helpers:
- normalize_address: raw passthrough, Address object input, user-friendly to raw conversion, string/object parity, invalid-address rejection
- address_to_stack_item: slice typing, base64 BoC round-trip, user-friendly input
- decode_base64_boc: round-trip with encode_base64_boc, non-string rejection (bytes/None/int), invalid-base64 rejection
- make_zero_bit_cell: Cell instance, single zero-bit payload, determinism, parity with manual Builder().store_bit(0).end_cell()
- encode_base64_boc: string return, exact byte parity, round-trip with richer cells
- get_network_global_id: mainnet -239, testnet -3, positive ID, missing/uppercase prefix rejection, non-numeric rejection
- parse_amount: decimal-to-smallest-unit, zero, zero-decimals, sub-unit truncation, nine-decimal native TON amounts, non-numeric rejection
- parse_money_to_decimal: int/float passthrough, $ prefix, USD/USDT and lowercase suffixes with/without whitespace, combined prefix+suffix, surrounding whitespace, float type guarantee, unparseable rejection

All 41 new tests pass, full TVM unit suite stays at 229 passed, ruff format and ruff check clean.
@vercel
Copy link
Copy Markdown

vercel Bot commented May 8, 2026

@0xAxiom 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 8, 2026
@phdargen phdargen closed this May 8, 2026
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.

2 participants