Skip to content

test(python/schemas): add unit tests for hooks dataclasses#2196

Closed
0xAxiom wants to merge 1 commit intox402-foundation:mainfrom
0xAxiom:test/python-schemas-hooks-unit-tests
Closed

test(python/schemas): add unit tests for hooks dataclasses#2196
0xAxiom wants to merge 1 commit intox402-foundation:mainfrom
0xAxiom:test/python-schemas-hooks-unit-tests

Conversation

@0xAxiom
Copy link
Copy Markdown
Contributor

@0xAxiom 0xAxiom commented May 5, 2026

Summary

Add 34 unit tests for python/x402/x402/schemas/hooks.py — the largest source file in the schemas/ package without dedicated unit-test coverage. Mirrors the same coverage pattern as recent unit-test PRs (tests/unit/mechanisms/...) into a new tests/unit/schemas/ directory.

The hooks module defines lifecycle dataclasses used by x402Client, x402ResourceServer, and x402Facilitator. Several context subclasses use __post_init__ validation to enforce that an inherited-with-default field (result, error, payment_payload) is always set explicitly. Those validations had no test coverage; this PR pins them.

What's covered

  • AbortResult, RecoveredPayloadResult, RecoveredVerifyResult, RecoveredSettleResult — field storage and equality
  • VerifyContext, SettleContext — optional payload_bytes / requirements_bytes default to None and accept explicit bytes
  • VerifyResultContext, SettleResultContext, PaymentCreatedContext — happy path stores inherited fields plus the new field, and __post_init__ raises ValueError when the new field is missing or explicitly None
  • VerifyFailureContext, SettleFailureContext, PaymentCreationFailureContext — same pattern for the error field
  • PaymentCreationContextpayment_required and selected_requirements storage

Tests use unittest.mock.MagicMock for the forward-referenced payload / requirements / response types, keeping the suite free of network and pydantic-validation overhead.

Test plan

  • uv run pytest tests/unit/schemas/test_hooks.py -v — 34 passed
  • uv run pytest tests/unit — 888 passed (full unit suite)
  • uvx ruff format tests/unit/schemas/ — clean
  • uvx ruff check tests/unit/schemas/ — All checks passed
  • GPG-signed commit

No source-code changes; tests-only. No changelog fragment per python/CONTRIBUTING.md (towncrier fragments are for user-facing changes).

Add 34 unit tests for python/x402/x402/schemas/hooks.py — the largest
schemas source file without dedicated unit-test coverage. Covers all
hook result and context dataclasses:

- AbortResult / RecoveredPayloadResult / RecoveredVerifyResult /
  RecoveredSettleResult: field storage and equality
- VerifyContext / SettleContext: optional payload_bytes /
  requirements_bytes default to None and accept explicit bytes
- VerifyResultContext / SettleResultContext / PaymentCreatedContext:
  happy path stores the inherited fields plus the new field, and
  __post_init__ raises ValueError when the new field is missing or
  explicitly None
- VerifyFailureContext / SettleFailureContext /
  PaymentCreationFailureContext: same pattern for the error field
- PaymentCreationContext: payment_required and selected_requirements
  storage

Tests use unittest.mock.MagicMock for forward-referenced payload /
requirements / response types so the unit tests stay free of network
or pydantic validation. All 34 tests pass; ruff format + check clean;
full unit suite (888 tests) passes.
@vercel
Copy link
Copy Markdown

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