test(formatXlm): add edge case coverage for large numbers, fractional amounts, and negative values - #975
Open
waterWang wants to merge 2 commits into
Open
Conversation
… amounts, and negative values
… amounts, and negative values
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
Closes #871
Expands
__tests__/lib/formatXlm.test.tswith edge-case coverage requested in the issue:1_000_000,999999999) — verifies output is a fixed-point string without scientific notation.0.0000001,0.004,0.006) — verifies rounding to the configured 2-decimal precision at Stellar's smallest unit.-1,-0.5,-10as string) — documents thattoFixedproduces a leading minus sign.Existing tests (whole numbers, long trailing decimals, numeric strings, non-finite input, zero, precision constant) are preserved unchanged.
Test Plan
The new cases follow the existing
toFixed(XLM_DISPLAY_DECIMALS)behaviour offormatXlm:formatXlm(1_000_000)→'1000000.00'(no scientific notation)formatXlm(0.0000001)→'0.00'(rounds to 2 dp)formatXlm(0.006)→'0.01'(rounds up)formatXlm(-1)→'-1.00'(leading minus sign)Run with:
npx jest __tests__/lib/formatXlm.test.ts