feat: add usd_to_atomic helper - #23
Merged
Merged
Conversation
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>
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.
Summary
decimalsplaces, exported fromagentscore_commerce.payment.usd_to_atomic.ROUND_HALF_UPso values at exactly half a base unit round away from zero.str,float,int, andDecimal. Whitespace-padded strings are trimmed.Tests
@agent-score/commerce'susdToAtomic.pytest.mark.parametrizeso multiple drifts surface independently.Test plan
uv run pytest tests/test_amounts.py— 38 tests passuv 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