Skip to content

test(python/tvm): add unit tests for codecs/jetton.py#2349

Closed
0xAxiom wants to merge 1 commit into
x402-foundation:mainfrom
0xAxiom:test/tvm-codecs-jetton-unit-tests
Closed

test(python/tvm): add unit tests for codecs/jetton.py#2349
0xAxiom wants to merge 1 commit into
x402-foundation:mainfrom
0xAxiom:test/tvm-codecs-jetton-unit-tests

Conversation

@0xAxiom
Copy link
Copy Markdown
Contributor

@0xAxiom 0xAxiom commented May 18, 2026

Summary

python/x402/mechanisms/tvm/codecs/jetton.py is the only TVM codec source file without a dedicated unit test module. This PR adds 27 unit tests covering all three public functions.

Tests added

TestBuildJettonTransferBodyFields (11 tests)

  • Opcode stored as first 32 bits (JETTON_TRANSFER_OPCODE = 0x0F8A7EA5)
  • Amount stored correctly as varuint coins
  • Destination address stored and reads back normalized
  • No responseDestination in extra stores None address slot
  • responseDestination in extra stores and reads back normalized
  • Custom-payload bit is always 0 (no custom payload support)
  • forwardTonAmount stored as coins
  • Zero forwardTonAmount accepted
  • Negative forwardTonAmount raises ValueError
  • No forwardPayload in extra stores two zero bits (Either Cell path)
  • forwardPayload (base64 BoC) stored as a ref

TestBuildJettonTransferBody (3 tests)

  • Delegates amount and pay_to from PaymentRequirements
  • String amount coerced to int
  • Returns a Cell instance

TestParseJettonTransfer (13 tests)

  • Round-trip: destination, jetton amount, forward ton amount
  • source_wallet set to jetton_wallet argument
  • body_hash equals body.hash
  • attached_ton_amount is always 0 (hardcoded)
  • Response destination is None when absent
  • Response destination normalized when present
  • Wrong opcode raises ValueError(ERR_EXACT_TVM_INVALID_JETTON_TRANSFER)
  • Custom-payload bit set raises ValueError
  • Null destination raises ValueError
  • Forward payload extracted from ref (bit=1 path)
  • Forward payload extracted from slice (bit=0 path)

Test plan

  • uv run pytest tests/unit/mechanisms/tvm/test_jetton.py — 27 passed, 0 failed, 0.08s
  • uv run ruff check tests/unit/mechanisms/tvm/test_jetton.py — clean
  • uv run ruff format --check tests/unit/mechanisms/tvm/test_jetton.py — already formatted
  • No production code touched: tests + changelog fragment only

🤖 Generated with Claude Code

Add 27 unit tests for python/x402/x402/mechanisms/tvm/codecs/jetton.py —
the only TVM codec source file without a dedicated test module.

TestBuildJettonTransferBodyFields (11 tests): opcode stored as first 32
bits, amount stored as coins, destination address round-trip, no
responseDestination stores None address, responseDestination stored,
custom-payload bit is always 0, forwardTonAmount stored, zero accepted,
negative raises ValueError, no forwardPayload stores two zero bits,
forwardPayload stored as ref.

TestBuildJettonTransferBody (3 tests): delegates amount+pay_to from
requirements, amount coerced from string, returns Cell instance.

TestParseJettonTransfer (13 tests): round-trip destination, amount, and
forward_ton_amount extraction, source_wallet set to jetton_wallet arg,
body_hash equals cell.hash, attached_ton_amount always 0, response
destination None vs normalized, wrong opcode raises, custom_payload bit
raises, null destination raises, forward_payload from ref vs slice.

Full unit suite: 27 passed, 0 failed. ruff check + format clean.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 18, 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 18, 2026
@phdargen phdargen closed this May 18, 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