@@ -16,6 +16,8 @@ import {
16
16
getLightningAuthKeychains ,
17
17
updateWalletCoinSpecific ,
18
18
LightningOnchainWithdrawParams ,
19
+ PaymentInfo ,
20
+ PaymentQuery ,
19
21
} from '@bitgo/abstract-lightning' ;
20
22
21
23
import { BitGo , common , GenerateLightningWalletOptions , Wallet , Wallets } from '../../../../src' ;
@@ -313,7 +315,7 @@ describe('Lightning wallets', function () {
313
315
it ( 'listInvoices should throw error if wp response is invalid' , async function ( ) {
314
316
const listInvoicesNock = nock ( bgUrl )
315
317
. get ( `/api/v2/wallet/${ wallet . wallet . id ( ) } /lightning/invoice` )
316
- . reply ( 200 , [ { valueMsat : '1000' } ] ) ;
318
+ . reply ( 200 , { invoices : [ { valueMsat : '1000' } ] } ) ;
317
319
await assert . rejects ( async ( ) => await wallet . listInvoices ( { } ) , / I n v a l i d l i s t i n v o i c e s r e s p o n s e / ) ;
318
320
listInvoicesNock . done ( ) ;
319
321
} ) ;
@@ -503,6 +505,99 @@ describe('Lightning wallets', function () {
503
505
} ) ;
504
506
} ) ;
505
507
508
+ describe ( 'payments' , function ( ) {
509
+ let wallet : LightningWallet ;
510
+ beforeEach ( function ( ) {
511
+ wallet = getLightningWallet (
512
+ new Wallet ( bitgo , basecoin , {
513
+ id : 'walletId' ,
514
+ coin : 'tlnbtc' ,
515
+ subType : 'lightningCustody' ,
516
+ coinSpecific : { keys : [ 'def' , 'ghi' ] } ,
517
+ } )
518
+ ) as LightningWallet ;
519
+ } ) ;
520
+
521
+ it ( 'should get payments' , async function ( ) {
522
+ const payment : PaymentInfo = {
523
+ paymentHash : 'foo' ,
524
+ walletId : wallet . wallet . id ( ) ,
525
+ txRequestId : 'txReqId' ,
526
+ status : 'settled' ,
527
+ invoice : 'tlnfoobar' ,
528
+ destination : 'destination' ,
529
+ feeLimitMsat : 100n ,
530
+ amountMsat : 1000n ,
531
+ createdAt : new Date ( ) ,
532
+ updatedAt : new Date ( ) ,
533
+ } ;
534
+ const query = {
535
+ status : 'settled' ,
536
+ startDate : new Date ( ) ,
537
+ limit : 100n ,
538
+ } as PaymentQuery ;
539
+ const listPaymentsNock = nock ( bgUrl )
540
+ . get ( `/api/v2/wallet/${ wallet . wallet . id ( ) } /lightning/payment` )
541
+ . query ( PaymentQuery . encode ( query ) )
542
+ . reply ( 200 , { payments : [ PaymentInfo . encode ( payment ) ] } ) ;
543
+ const listPaymentsResponse = await wallet . listPayments ( query ) ;
544
+ assert . strictEqual ( listPaymentsResponse . payments . length , 1 ) ;
545
+ assert . deepStrictEqual ( listPaymentsResponse . payments [ 0 ] , payment ) ;
546
+ listPaymentsNock . done ( ) ;
547
+ } ) ;
548
+
549
+ it ( 'should work properly with pagination while listing payments' , async function ( ) {
550
+ const payment1 : PaymentInfo = {
551
+ paymentHash : 'foo1' ,
552
+ walletId : wallet . wallet . id ( ) ,
553
+ txRequestId : 'txReqId1' ,
554
+ status : 'settled' ,
555
+ invoice : 'tlnfoobar1' ,
556
+ destination : 'destination' ,
557
+ feeLimitMsat : 100n ,
558
+ amountMsat : 1000n ,
559
+ createdAt : new Date ( ) ,
560
+ updatedAt : new Date ( ) ,
561
+ } ;
562
+ const payment2 : PaymentInfo = {
563
+ ...payment1 ,
564
+ paymentHash : 'foo2' ,
565
+ txRequestId : 'txReqId2' ,
566
+ invoice : 'tlnfoobar2' ,
567
+ } ;
568
+ const payment3 : PaymentInfo = {
569
+ ...payment1 ,
570
+ paymentHash : 'foo3' ,
571
+ txRequestId : 'txReqId3' ,
572
+ invoice : 'tlnfoobar3' ,
573
+ } ;
574
+ const allPayments = [ PaymentInfo . encode ( payment1 ) , PaymentInfo . encode ( payment2 ) , PaymentInfo . encode ( payment3 ) ] ;
575
+ const query = {
576
+ status : 'settled' ,
577
+ startDate : new Date ( ) ,
578
+ limit : 2n ,
579
+ } as PaymentQuery ;
580
+ const listPaymentsNock = nock ( bgUrl )
581
+ . get ( `/api/v2/wallet/${ wallet . wallet . id ( ) } /lightning/payment` )
582
+ . query ( PaymentQuery . encode ( query ) )
583
+ . reply ( 200 , { payments : allPayments . slice ( 0 , 2 ) , nextBatchPrevId : payment2 . paymentHash } ) ;
584
+ const listPaymentsResponse = await wallet . listPayments ( query ) ;
585
+ assert . strictEqual ( listPaymentsResponse . payments . length , 2 ) ;
586
+ assert . deepStrictEqual ( listPaymentsResponse . payments [ 0 ] , payment1 ) ;
587
+ assert . deepStrictEqual ( listPaymentsResponse . payments [ 1 ] , payment2 ) ;
588
+ assert . strictEqual ( listPaymentsResponse . nextBatchPrevId , payment2 . paymentHash ) ;
589
+ listPaymentsNock . done ( ) ;
590
+ } ) ;
591
+
592
+ it ( 'listPayments should throw error if wp response is invalid' , async function ( ) {
593
+ const listPaymentsNock = nock ( bgUrl )
594
+ . get ( `/api/v2/wallet/${ wallet . wallet . id ( ) } /lightning/payment` )
595
+ . reply ( 200 , { payments : [ { amountMsat : '1000' } ] } ) ;
596
+ await assert . rejects ( async ( ) => await wallet . listPayments ( { } ) , / I n v a l i d p a y m e n t l i s t r e s p o n s e / ) ;
597
+ listPaymentsNock . done ( ) ;
598
+ } ) ;
599
+ } ) ;
600
+
506
601
describe ( 'Get lightning key(s)' , function ( ) {
507
602
const walletData = {
508
603
id : 'fakeid' ,
0 commit comments