From 3b5c50184dbfd20d552982a8e58a1e6c94dc2190 Mon Sep 17 00:00:00 2001 From: water <672684719@qq.com> Date: Mon, 10 Aug 2026 09:19:18 +0800 Subject: [PATCH 1/2] test(formatXlm): add edge case coverage for large numbers, fractional amounts, and negative values --- __tests__/lib/formatXlm.test.ts | 33 --------------------------------- 1 file changed, 33 deletions(-) diff --git a/__tests__/lib/formatXlm.test.ts b/__tests__/lib/formatXlm.test.ts index 07a576e9..e69de29b 100644 --- a/__tests__/lib/formatXlm.test.ts +++ b/__tests__/lib/formatXlm.test.ts @@ -1,33 +0,0 @@ -import { formatXlm, XLM_DISPLAY_DECIMALS } from '@/lib/formatXlm'; - -describe('formatXlm', () => { - it('formats whole numbers with the standard decimal precision', () => { - expect(formatXlm(1)).toBe('1.00'); - expect(formatXlm(12)).toBe('12.00'); - }); - - it('rounds long trailing decimals to the configured precision', () => { - expect(formatXlm(4.999999)).toBe('5.00'); - expect(formatXlm(1.006)).toBe('1.01'); - expect(formatXlm(0.123456789)).toBe('0.12'); - }); - - it('accepts numeric strings', () => { - expect(formatXlm('5')).toBe('5.00'); - expect(formatXlm('7.5')).toBe('7.50'); - }); - - it('falls back to zero for non-finite or unparsable input', () => { - expect(formatXlm(NaN)).toBe('0.00'); - expect(formatXlm('not-a-number')).toBe('0.00'); - }); - - it('handles zero', () => { - expect(formatXlm(0)).toBe('0.00'); - }); - - it('uses the exported precision constant', () => { - expect(XLM_DISPLAY_DECIMALS).toBe(2); - expect(formatXlm(3.14159).split('.')[1]).toHaveLength(XLM_DISPLAY_DECIMALS); - }); -}); From 87425d185a5f5d057c6a2b931aa8729c6770858f Mon Sep 17 00:00:00 2001 From: water <672684719@qq.com> Date: Mon, 10 Aug 2026 09:19:45 +0800 Subject: [PATCH 2/2] test(formatXlm): add edge case coverage for large numbers, fractional amounts, and negative values --- __tests__/lib/formatXlm.test.ts | 50 +++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/__tests__/lib/formatXlm.test.ts b/__tests__/lib/formatXlm.test.ts index e69de29b..57c60fae 100644 --- a/__tests__/lib/formatXlm.test.ts +++ b/__tests__/lib/formatXlm.test.ts @@ -0,0 +1,50 @@ +import { formatXlm, XLM_DISPLAY_DECIMALS } from '@/lib/formatXlm'; + +describe('formatXlm', () => { + it('formats whole numbers with the standard decimal precision', () => { + expect(formatXlm(1)).toBe('1.00'); + expect(formatXlm(12)).toBe('12.00'); + }); + + it('rounds long trailing decimals to the configured precision', () => { + expect(formatXlm(4.999999)).toBe('5.00'); + expect(formatXlm(1.006)).toBe('1.01'); + expect(formatXlm(0.123456789)).toBe('0.12'); + }); + + it('accepts numeric strings', () => { + expect(formatXlm('5')).toBe('5.00'); + expect(formatXlm('7.5')).toBe('7.50'); + }); + + it('falls back to zero for non-finite or unparsable input', () => { + expect(formatXlm(NaN)).toBe('0.00'); + expect(formatXlm('not-a-number')).toBe('0.00'); + }); + + it('handles zero', () => { + expect(formatXlm(0)).toBe('0.00'); + }); + + it('uses the exported precision constant', () => { + expect(XLM_DISPLAY_DECIMALS).toBe(2); + expect(formatXlm(3.14159).split('.')[1]).toHaveLength(XLM_DISPLAY_DECIMALS); + }); + + it('handles very large XLM amounts without scientific notation', () => { + expect(formatXlm(1_000_000)).toBe('1000000.00'); + expect(formatXlm(999999999)).toBe('999999999.00'); + }); + + it('handles extremely small fractional amounts', () => { + expect(formatXlm(0.0000001)).toBe('0.00'); + expect(formatXlm(0.004)).toBe('0.00'); + expect(formatXlm(0.006)).toBe('0.01'); + }); + + it('formats negative values with a minus sign', () => { + expect(formatXlm(-1)).toBe('-1.00'); + expect(formatXlm(-0.5)).toBe('-0.50'); + expect(formatXlm('-10')).toBe('-10.00'); + }); +}); \ No newline at end of file