test(python/tvm): add unit tests for codecs/common.py#2252
Closed
0xAxiom wants to merge 1 commit intox402-foundation:mainfrom
Closed
test(python/tvm): add unit tests for codecs/common.py#22520xAxiom wants to merge 1 commit intox402-foundation:mainfrom
0xAxiom wants to merge 1 commit intox402-foundation:mainfrom
Conversation
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.
|
@0xAxiom is attempting to deploy a commit to the Coinbase Team on Vercel. A member of the Team first needs to authorize it. |
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.
Add 41 unit tests for
python/x402/x402/mechanisms/tvm/codecs/common.py— the only file inmechanisms/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— rawwc:hexpassthrough,Addressobject input, user-friendly to raw conversion, parity between string andAddressinputs, invalid-address rejection (AddressError).address_to_stack_item— slice typing ({"type": "slice", "value": <base64>}), base64 BoC round-trip viaCell.one_from_boc, user-friendly input acceptance.decode_base64_boc— round-trip withencode_base64_boc, non-string rejection covering bytes/None/int withValueError("base64-encoded BoC string"), invalid-base64 rejection.make_zero_bit_cell—Cellinstance type, single zero-bit payload (remaining_bits == 1,load_bit() == 0), determinism across calls, exact byte parity with manualBuilder().store_bit(0).end_cell().encode_base64_boc— string return type, exact byte parity withcell.to_boc(), round-trip with richer cells (uint + address).get_network_global_id— mainnettvm:-239→-239, testnettvm:-3→-3, positive IDtvm:42→42, missing/uppercase prefix rejection (ValueError("Unsupported TVM network")), non-numeric payload rejection.parse_amount— decimal-to-smallest-unit, zero, zero-decimals, sub-unit truncation viaint(), nine-decimal native TON amounts (1→1_000_000_000,0.000000001→1),InvalidOperationon non-numeric.parse_money_to_decimal—int/floatpassthrough,$prefix,USD/USDTand lowercase suffixes with and without separating whitespace, combined$ ... USDprefix+suffix, surrounding whitespace,floattype guarantee on string inputs,ValueErroron unparseable strings.Verification
uv run pytest tests/unit/mechanisms/tvm/test_common.py -q→ 41 passed in 0.11suv run pytest tests/unit/mechanisms/tvm/ -q→ 229 passed in 0.69s (no regressions in existing TVM suite)uv run ruff formatclean,uv run ruff checkclean7C3D4BFE44B598C90CE31DCCA190D7A3B1700D63)Test file follows the established TVM convention:
pytest.importorskip("pytoniq_core")so the suite skips cleanly when the optional[tvm]extras are not installed.