@@ -3,10 +3,25 @@ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
33// Mock the bolt11 module to avoid infinite loop bug
44vi . mock ( '../lib/bolt11' , ( ) => ( {
55 decode : vi . fn ( ( invoice ) => {
6- if ( invoice . includes ( 'lnbc' ) ) {
6+ if ( invoice . startsWith ( 'lnbcrt' ) ) {
7+ return {
8+ complete : true ,
9+ prefix : 'lnbcrt' ,
10+ coinType : 'regtest' ,
11+ satoshis : 500 ,
12+ millisatoshis : 500000 ,
13+ timestamp : 1672531200 ,
14+ tags : [
15+ { tagName : 'payment_hash' , data : '0001020304050607080900010203040506070809000102030405060708090102' } ,
16+ { tagName : 'description' , data : 'Regtest invoice' } ,
17+ ] ,
18+ } ;
19+ }
20+ if ( invoice . startsWith ( 'lnbc' ) ) {
721 return {
822 complete : true ,
923 prefix : 'lnbc' ,
24+ coinType : 'bitcoin' ,
1025 satoshis : 1000 ,
1126 millisatoshis : 1000000 ,
1227 timestamp : 1672531200 ,
@@ -17,10 +32,25 @@ vi.mock('../lib/bolt11', () => ({
1732 ] ,
1833 } ;
1934 }
20- if ( invoice . includes ( 'lntb' ) ) {
35+ if ( invoice . startsWith ( 'lntbs' ) ) {
36+ return {
37+ complete : true ,
38+ prefix : 'lntbs' ,
39+ coinType : 'signet' ,
40+ satoshis : 500 ,
41+ millisatoshis : 500000 ,
42+ timestamp : 1672531200 ,
43+ tags : [
44+ { tagName : 'payment_hash' , data : '0001020304050607080900010203040506070809000102030405060708090102' } ,
45+ { tagName : 'description' , data : 'Signet invoice' } ,
46+ ] ,
47+ } ;
48+ }
49+ if ( invoice . startsWith ( 'lntb' ) ) {
2150 return {
2251 complete : true ,
2352 prefix : 'lntb' ,
53+ coinType : 'testnet' ,
2454 satoshis : 500 ,
2555 millisatoshis : 500000 ,
2656 timestamp : 1672531200 ,
@@ -139,6 +169,19 @@ describe('parseInvoice', () => {
139169 expect ( result . data . satoshis ) . toBe ( 1000 ) ;
140170 } ) ;
141171
172+ it . each ( [
173+ [ 'testnet/testnet4' , 'lntb1pjtestnet' , 'testnet' ] ,
174+ [ 'signet' , 'lntbs1pjsignet' , 'signet' ] ,
175+ [ 'regtest' , 'lnbcrt1pjregtest' , 'regtest' ] ,
176+ ] ) ( 'strips lightning: prefix from BOLT11 %s invoice strings' , async ( _ , invoice , coinType ) => {
177+ const { parseInvoice } = await import ( './invoices' ) ;
178+ const result = await parseInvoice ( `lightning:${ invoice } ` ) ;
179+
180+ expect ( result . isLNURL ) . toBe ( false ) ;
181+ expect ( result . data ) . toBeDefined ( ) ;
182+ expect ( result . data . coinType ) . toBe ( coinType ) ;
183+ } ) ;
184+
142185 it ( 'does not strip lightning: when it appears inside an unrelated string' , async ( ) => {
143186 const { parseInvoice } = await import ( './invoices' ) ;
144187 const result = await parseInvoice ( `not-a-prefix-lightning:${ VALID_BOLT11 } ` ) ;
@@ -246,6 +289,19 @@ describe('parseInvoice', () => {
246289 expect ( result . data ) . toBeDefined ( ) ;
247290 expect ( result . data . satoshis ) . toBe ( 1000 ) ;
248291 } ) ;
292+
293+ it . each ( [
294+ [ 'testnet/testnet4' , 'lntb1pjtestnet' , 'testnet' ] ,
295+ [ 'signet' , 'lntbs1pjsignet' , 'signet' ] ,
296+ [ 'regtest' , 'lnbcrt1pjregtest' , 'regtest' ] ,
297+ ] ) ( 'handles raw BOLT11 %s invoice strings' , async ( _ , invoice , coinType ) => {
298+ const { parseInvoice } = await import ( './invoices' ) ;
299+ const result = await parseInvoice ( invoice ) ;
300+
301+ expect ( result . isLNURL ) . toBe ( false ) ;
302+ expect ( result . data ) . toBeDefined ( ) ;
303+ expect ( result . data . coinType ) . toBe ( coinType ) ;
304+ } ) ;
249305 } ) ;
250306
251307 describe ( 'invalid inputs' , ( ) => {
0 commit comments