test: fix incorrect bolt11 fixtures (210n = 21 sats, not 2100n)
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 <assistant@shakespeare.diy>
This commit is contained in:
parent
f25fc2bd74
commit
5c3c2f6589
2 changed files with 7 additions and 7 deletions
|
|
@ -26,9 +26,9 @@ describe('getSatoshisFromBolt11', () => {
|
||||||
expect(getSatoshisFromBolt11('lnbc1pvjluezpp5abcdef')).toBe(0);
|
expect(getSatoshisFromBolt11('lnbc1pvjluezpp5abcdef')).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles a 21-sat zap (2100n)', () => {
|
it('handles a 21-sat zap (210n)', () => {
|
||||||
// 2100n → 2100 * 1e-9 BTC = 21 sats
|
// 210n → 210 * 1e-9 BTC = 2.1e-7 BTC = 21 sats
|
||||||
expect(getSatoshisFromBolt11('lnbc2100n1pvjluezpp5abcdef')).toBe(21);
|
expect(getSatoshisFromBolt11('lnbc210n1pvjluezpp5abcdef')).toBe(21);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('is case-insensitive (uppercase invoice)', () => {
|
it('is case-insensitive (uppercase invoice)', () => {
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,13 @@ import { assertInvoiceAmount } from './verifyInvoice';
|
||||||
|
|
||||||
describe('assertInvoiceAmount', () => {
|
describe('assertInvoiceAmount', () => {
|
||||||
it('accepts an invoice whose amount matches the expected sats', () => {
|
it('accepts an invoice whose amount matches the expected sats', () => {
|
||||||
// lnbc2100n… = 21 sats
|
// lnbc210n… = 210 * 1e-9 BTC = 21 sats
|
||||||
expect(() => assertInvoiceAmount('lnbc2100n1pvjluez', 21)).not.toThrow();
|
expect(() => assertInvoiceAmount('lnbc210n1pvjluez', 21)).not.toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('accepts a 1-sat rounding difference (millisat↔sat slack)', () => {
|
it('accepts a 1-sat rounding difference (millisat↔sat slack)', () => {
|
||||||
// lnbc2100n… = 21 sats, expected 22 → diff of 1 is allowed
|
// lnbc210n… = 21 sats, expected 22 → diff of 1 is allowed
|
||||||
expect(() => assertInvoiceAmount('lnbc2100n1pvjluez', 22)).not.toThrow();
|
expect(() => assertInvoiceAmount('lnbc210n1pvjluez', 22)).not.toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('rejects an over-charging invoice (the core attack it defends against)', () => {
|
it('rejects an over-charging invoice (the core attack it defends against)', () => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue