Skip to content

feat: add usd_to_atomic helper - #23

Merged
vvillait88 merged 1 commit into
mainfrom
tec-302-usd-to-atomic
May 14, 2026
Merged

feat: add usd_to_atomic helper#23
vvillait88 merged 1 commit into
mainfrom
tec-302-usd-to-atomic

Conversation

@vvillait88

Copy link
Copy Markdown
Contributor

Summary

  • Convert a USD amount to atomic units for a token with decimals places, exported from agentscore_commerce.payment.usd_to_atomic.
  • Decimal-based with ROUND_HALF_UP so values at exactly half a base unit round away from zero.
  • Accepts str, float, int, and Decimal. Whitespace-padded strings are trimmed.
  • Rejects negative, NaN, infinite, and unparseable inputs.

Tests

  • 22-fixture corpus with hardcoded atomic values locked as the cross-language contract with @agent-score/commerce's usdToAtomic.
  • Parametrized via pytest.mark.parametrize so multiple drifts surface independently.

Test plan

  • uv run pytest tests/test_amounts.py — 38 tests pass
  • uv run pytest — full suite 929 pass / 3 skip, coverage 95.04%
  • uv run ruff check, uv run ruff format --check, uv run ty check — green

🤖 Generated with Claude Code

Convert a USD amount to atomic units for a token with `decimals` places.
Decimal-based with ROUND_HALF_UP so values at exactly half a base unit
round away from zero, matching the cross-language Node sibling.

Rejects negative, NaN, infinite, and unparseable inputs. Accepts str,
float, int, and Decimal; whitespace-padded strings are trimmed.

Tests lock 22 fixtures with hardcoded atomic values as the cross-language
contract with @agent-score/commerce's usdToAtomic. Parametrized so
multiple drifts surface independently.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vvillait88
vvillait88 merged commit 55125ea into main May 14, 2026
7 checks passed
@vvillait88
vvillait88 deleted the tec-302-usd-to-atomic branch May 14, 2026 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant