From 692592ded5063139d12509d255d5c9041480ca12 Mon Sep 17 00:00:00 2001 From: gcoinstash-cmd Date: Sun, 6 Sep 2026 04:25:47 -0700 Subject: [PATCH] test(formatters): add Soroban token balance decimal precision formatter specs --- .../wave8_currency_formatter.test.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/utils/__tests__/wave8_currency_formatter.test.ts diff --git a/src/utils/__tests__/wave8_currency_formatter.test.ts b/src/utils/__tests__/wave8_currency_formatter.test.ts new file mode 100644 index 0000000..b73c4c1 --- /dev/null +++ b/src/utils/__tests__/wave8_currency_formatter.test.ts @@ -0,0 +1,19 @@ +describe('Wave 8 Rebalance: Soroban Token Balance Precision Formatter', () => { + const formatTokenBalance = (rawUnits: bigint, decimals: number = 7): string => { + const divisor = BigInt(10 ** decimals); + const whole = rawUnits / divisor; + const fraction = rawUnits % divisor; + const fractionStr = fraction.toString().padStart(decimals, '0').replace(/0+$/, ''); + return fractionStr.length > 0 ? `${whole}.${fractionStr}` : `${whole}.0`; + }; + + it('should format 7-decimal Stellar Soroban token balance correctly', () => { + const raw = BigInt(10500000); // 1.05 tokens + expect(formatTokenBalance(raw, 7)).toBe('1.05'); + }); + + it('should format whole number token balances with single trailing zero', () => { + const raw = BigInt(50000000); // 5 tokens + expect(formatTokenBalance(raw, 7)).toBe('5.0'); + }); +});