diff --git a/frontend/src/utils/amount.test.ts b/frontend/src/utils/amount.test.ts index a7b0165f..0b2d1efc 100644 --- a/frontend/src/utils/amount.test.ts +++ b/frontend/src/utils/amount.test.ts @@ -6,6 +6,32 @@ import { hasValidPrecision, } from "./amount"; +describe("parseAmount edge cases (negative, excessive precision, rounding)", () => { + it("handles negative amounts correctly", () => { + // parseAmount treats negative values as invalid/zero (returns 0n) + expect(parseAmount("-1.5", 7)).toBe(0n); + expect(parseAmount("-0", 7)).toBe(0n); + }); + + it("handles excessive precision by truncating extra decimal places", () => { + // 7 decimals max, input has 9 + expect(parseAmount("1.123456789", 7)).toBe(11234567n); + expect(parseAmount("0.000000123", 7)).toBe(1n); + }); + + it("handles halfway rounding / boundary inputs correctly", () => { + // parseAmount currently floors/truncates excess precision rather than rounding + expect(parseAmount("1.12345674", 7)).toBe(11234567n); + expect(parseAmount("1.12345676", 7)).toBe(11234567n); + }); + + it("round-trips positive boundary values properly", () => { + const val = 1234567n; + const formatted = formatAmount(val, 7); + expect(parseAmount(formatted, 7)).toBe(val); + }); +}); + describe("amount parser locale, exponent, whitespace, and empty strings", () => { describe("parseAmount with locale and edge inputs", () => { it("handles empty and whitespace-only strings", () => {