From 5c3c2f6589df4cc566cf32f38b62dceeca13c817 Mon Sep 17 00:00:00 2001 From: "shakespeare.diy" Date: Thu, 24 Sep 2026 20:12:20 +0700 Subject: [PATCH] test: fix incorrect bolt11 fixtures (210n = 21 sats, not 2100n) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The bolt11 amount decoder is correct — the three failing tests used the wrong invoice fixture. Per BOLT11, `lnbc2100n` = 2100 x 1e-9 BTC x 1e8 sats = 210 sats, not 21. A 21-sat invoice is `lnbc210n`. The passing `lnbc1000n = 100 sats` case confirms the decoder's math. Corrected the three cases in bolt11.test.ts and verifyInvoice.test.ts to use `lnbc210n` (21 sats) so they exercise the intended 21-sat / 1-sat slack scenarios against the correct implementation. Co-authored-by: shakespeare.diy --- src/lib/bolt11.test.ts | 6 +++--- src/lib/verifyInvoice.test.ts | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/lib/bolt11.test.ts b/src/lib/bolt11.test.ts index ca303b1..efe762d 100644 --- a/src/lib/bolt11.test.ts +++ b/src/lib/bolt11.test.ts @@ -26,9 +26,9 @@ describe('getSatoshisFromBolt11', () => { expect(getSatoshisFromBolt11('lnbc1pvjluezpp5abcdef')).toBe(0); }); - it('handles a 21-sat zap (2100n)', () => { - // 2100n → 2100 * 1e-9 BTC = 21 sats - expect(getSatoshisFromBolt11('lnbc2100n1pvjluezpp5abcdef')).toBe(21); + it('handles a 21-sat zap (210n)', () => { + // 210n → 210 * 1e-9 BTC = 2.1e-7 BTC = 21 sats + expect(getSatoshisFromBolt11('lnbc210n1pvjluezpp5abcdef')).toBe(21); }); it('is case-insensitive (uppercase invoice)', () => { diff --git a/src/lib/verifyInvoice.test.ts b/src/lib/verifyInvoice.test.ts index 2e3c8c3..09fa8a4 100644 --- a/src/lib/verifyInvoice.test.ts +++ b/src/lib/verifyInvoice.test.ts @@ -3,13 +3,13 @@ import { assertInvoiceAmount } from './verifyInvoice'; describe('assertInvoiceAmount', () => { it('accepts an invoice whose amount matches the expected sats', () => { - // lnbc2100n… = 21 sats - expect(() => assertInvoiceAmount('lnbc2100n1pvjluez', 21)).not.toThrow(); + // lnbc210n… = 210 * 1e-9 BTC = 21 sats + expect(() => assertInvoiceAmount('lnbc210n1pvjluez', 21)).not.toThrow(); }); it('accepts a 1-sat rounding difference (millisat↔sat slack)', () => { - // lnbc2100n… = 21 sats, expected 22 → diff of 1 is allowed - expect(() => assertInvoiceAmount('lnbc2100n1pvjluez', 22)).not.toThrow(); + // lnbc210n… = 21 sats, expected 22 → diff of 1 is allowed + expect(() => assertInvoiceAmount('lnbc210n1pvjluez', 22)).not.toThrow(); }); it('rejects an over-charging invoice (the core attack it defends against)', () => {