Skip to content

Add precision regression tests for formatAmount/feeInBps with large Stellar amounts #78

Description

@Jagadeeshftw

📌 Description

formatAmount and feeInBps in src/lib/format.ts format numeric amounts for display across MetricsBar, StatCard, and the tables. Stellar amounts can carry seven decimal places of precision and large magnitudes; if these helpers pass values through plain JS Number arithmetic, values beyond Number.MAX_SAFE_INTEGER-adjacent ranges risk silent precision loss in the displayed figure.

🧩 Requirements and context

  • Add tests for large amounts (e.g. near Number.MAX_SAFE_INTEGER) and high-precision decimal amounts, asserting the formatted output matches the expected exact string.
  • If precision loss is confirmed for realistic Stellar-scale amounts, consider a string/bigint-safe formatting path as a follow-up (flag it in the issue rather than necessarily fixing it here if it requires an API/type change).
  • Keep formatAmount's existing output format for typical/small amounts unchanged.

🛠️ Suggested execution

  • Add the large/high-precision cases to src/lib/format.test.ts.
  • If a real precision bug is found and fixable within format.ts's current number-based signature, fix it; otherwise document the limitation clearly in a code comment.

✅ Acceptance criteria

  • Large and high-precision amounts are covered by tests with exact expected output.
  • Any precision-loss bug found is either fixed or explicitly documented as a known limitation.
  • Existing typical-amount formatting is unaffected.

🔒 Security notes

Display-only; a precision-loss bug here would mislead a user about an amount's exact value without affecting the actual on-chain/backend accounting.

📋 Guidelines

  • Minimum 95% test coverage
  • Clear documentation
  • Timeframe: 96 hours

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial Campaign | FWC26Campaign: Official Campaign | FWC26testingTests and coverage

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions