From b559affd2913fc087d52119d0969bb1e1ccca827 Mon Sep 17 00:00:00 2001 From: Uche Okafor Date: Tue, 27 Oct 2026 09:08:55 +0100 Subject: [PATCH] test: cover estimateSellProceeds edge cases estimateSellProceeds (added in #419) shipped with no dedicated test coverage. #419 merged into main instead of dev, so its closes tag never auto-closed the issue even though the helper is already on dev. Adds coverage for the happy path and every null/invalid-input guard clause: missing key price, missing current supply, non-positive sell quantity, and non-finite values. Closes #403 --- .../__tests__/keyPriceDisplay.utils.test.ts | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/utils/__tests__/keyPriceDisplay.utils.test.ts b/src/utils/__tests__/keyPriceDisplay.utils.test.ts index b53e7275..25464ccd 100644 --- a/src/utils/__tests__/keyPriceDisplay.utils.test.ts +++ b/src/utils/__tests__/keyPriceDisplay.utils.test.ts @@ -1,5 +1,6 @@ import { describe, expect, it } from 'vitest'; import { + estimateSellProceeds, formatCreatorKeyPriceDisplay, formatDisplayKeyPrice, resolveCreatorKeyPriceStroops, @@ -43,6 +44,33 @@ describe('formatCreatorKeyPriceDisplay', () => { }); }); +describe('estimateSellProceeds', () => { + it('multiplies key price by sell quantity', () => { + expect(estimateSellProceeds(1_000_000, 50, 3)).toBe(3_000_000); + }); + + it('returns null when key price is null or undefined', () => { + expect(estimateSellProceeds(null, 50, 3)).toBeNull(); + expect(estimateSellProceeds(undefined, 50, 3)).toBeNull(); + }); + + it('returns null when current supply is null or undefined', () => { + expect(estimateSellProceeds(1_000_000, null, 3)).toBeNull(); + expect(estimateSellProceeds(1_000_000, undefined, 3)).toBeNull(); + }); + + it('returns null when sell quantity is zero or negative', () => { + expect(estimateSellProceeds(1_000_000, 50, 0)).toBeNull(); + expect(estimateSellProceeds(1_000_000, 50, -1)).toBeNull(); + }); + + it('returns null for non-finite inputs', () => { + expect(estimateSellProceeds(NaN, 50, 3)).toBeNull(); + expect(estimateSellProceeds(1_000_000, Infinity, 3)).toBeNull(); + expect(estimateSellProceeds(1_000_000, 50, Infinity)).toBeNull(); + }); +}); + describe('formatKeyPrice', () => { it('formats zero correctly with 4 decimal places', () => { expect(formatKeyPrice(0n)).toBe('0.0000 XLM'); @@ -64,4 +92,3 @@ describe('formatKeyPrice', () => { expect(formatKeyPrice(10_000_000_000n)).toBe('1,000.00 XLM'); }); }); -