@@ -15,6 +15,7 @@ import {
15
15
getLightningKeychain ,
16
16
getLightningAuthKeychains ,
17
17
updateWalletCoinSpecific ,
18
+ LightningOnchainWithdrawParams ,
18
19
} from '@bitgo/abstract-lightning' ;
19
20
20
21
import { BitGo , common , GenerateLightningWalletOptions , Wallet , Wallets } from '../../../../src' ;
@@ -651,4 +652,96 @@ describe('Lightning wallets', function () {
651
652
assert . strictEqual ( signedRequest . passphrase , undefined , 'passphrase should not exist in request' ) ;
652
653
} ) ;
653
654
} ) ;
655
+ describe ( 'On chain withdrawal' , function ( ) {
656
+ let wallet : LightningWallet ;
657
+ beforeEach ( function ( ) {
658
+ wallet = getLightningWallet (
659
+ new Wallet ( bitgo , basecoin , {
660
+ id : 'walletId' ,
661
+ coin : 'tlnbtc' ,
662
+ subType : 'lightningCustody' ,
663
+ coinSpecific : { keys : [ 'def' , 'ghi' ] } ,
664
+ } )
665
+ ) as LightningWallet ;
666
+ } ) ;
667
+ it ( 'should withdraw on chain' , async function ( ) {
668
+ const params : LightningOnchainWithdrawParams = {
669
+ recipients : [
670
+ {
671
+ amountSat : 500000n ,
672
+ address : 'bcrt1qjq48cqk2u80hewdcndf539m8nnnvt845nl68x7' ,
673
+ } ,
674
+ ] ,
675
+ satsPerVbyte : 15n ,
676
+ } ;
677
+
678
+ const txRequestResponse = {
679
+ txRequestId : 'txReq123' ,
680
+ state : 'pendingDelivery' ,
681
+ } ;
682
+
683
+ const finalPaymentResponse = {
684
+ txRequestId : 'txReq123' ,
685
+ state : 'delivered' ,
686
+ } ;
687
+
688
+ const createTxRequestNock = nock ( bgUrl )
689
+ . post ( `/api/v2/wallet/${ wallet . wallet . id ( ) } /txrequests` )
690
+ . reply ( 200 , txRequestResponse ) ;
691
+
692
+ const sendTxRequestNock = nock ( bgUrl )
693
+ . post ( `/api/v2/wallet/${ wallet . wallet . id ( ) } /txrequests/${ txRequestResponse . txRequestId } /transactions/0/send` )
694
+ . reply ( 200 , finalPaymentResponse ) ;
695
+
696
+ const response = await wallet . withdrawOnchain ( params ) ;
697
+ assert . strictEqual ( response . txRequestId , 'txReq123' ) ;
698
+ assert . strictEqual ( response . txRequestState , 'delivered' ) ;
699
+
700
+ createTxRequestNock . done ( ) ;
701
+ sendTxRequestNock . done ( ) ;
702
+ } ) ;
703
+
704
+ it ( 'should handle pending approval when withdrawing onchain' , async function ( ) {
705
+ const params : LightningOnchainWithdrawParams = {
706
+ recipients : [
707
+ {
708
+ amountSat : 500000n ,
709
+ address : 'bcrt1qjq48cqk2u80hewdcndf539m8nnnvt845nl68x7' ,
710
+ } ,
711
+ ] ,
712
+ satsPerVbyte : 15n ,
713
+ } ;
714
+
715
+ const txRequestResponse = {
716
+ txRequestId : 'txReq123' ,
717
+ state : 'pendingApproval' ,
718
+ pendingApprovalId : 'approval123' ,
719
+ } ;
720
+
721
+ const pendingApprovalData : PendingApprovalData = {
722
+ id : 'approval123' ,
723
+ state : State . PENDING ,
724
+ creator : 'user123' ,
725
+ info : {
726
+ type : Type . TRANSACTION_REQUEST ,
727
+ } ,
728
+ } ;
729
+
730
+ const createTxRequestNock = nock ( bgUrl )
731
+ . post ( `/api/v2/wallet/${ wallet . wallet . id ( ) } /txrequests` )
732
+ . reply ( 200 , txRequestResponse ) ;
733
+
734
+ const getPendingApprovalNock = nock ( bgUrl )
735
+ . get ( `/api/v2/${ coinName } /pendingapprovals/${ txRequestResponse . pendingApprovalId } ` )
736
+ . reply ( 200 , pendingApprovalData ) ;
737
+
738
+ const response = await wallet . withdrawOnchain ( params ) ;
739
+ assert . strictEqual ( response . txRequestId , 'txReq123' ) ;
740
+ assert . strictEqual ( response . txRequestState , 'pendingApproval' ) ;
741
+ assert ( response . pendingApproval ) ;
742
+
743
+ createTxRequestNock . done ( ) ;
744
+ getPendingApprovalNock . done ( ) ;
745
+ } ) ;
746
+ } ) ;
654
747
} ) ;
0 commit comments