@@ -32,6 +32,7 @@ describe('Lightning Withdraw Routes', () => {
3232 } ,
3333 ] ,
3434 satsPerVbyte : '15' ,
35+ numBlocks : 3 ,
3536 passphrase : 'password123' ,
3637 } ;
3738
@@ -85,10 +86,11 @@ describe('Lightning Withdraw Routes', () => {
8586 // we decode the amountMsat string to bigint, it should be in bigint format when passed to payInvoice
8687 should ( firstArg ) . have . property ( 'recipients' , decodedRecipients ) ;
8788 should ( firstArg ) . have . property ( 'satsPerVbyte' , BigInt ( inputParams . satsPerVbyte ) ) ;
89+ should ( firstArg ) . have . property ( 'numBlocks' , inputParams . numBlocks ) ;
8890 should ( firstArg ) . have . property ( 'passphrase' , inputParams . passphrase ) ;
8991 } ) ;
9092
91- it ( 'should throw an error if the satsPerVbyte is missing in the request params' , async ( ) => {
93+ it ( 'should not throw an error if the satsPerVbyte and/or numBlocks is missing in the request params' , async ( ) => {
9294 const inputParams = {
9395 recipients : [
9496 {
@@ -99,15 +101,43 @@ describe('Lightning Withdraw Routes', () => {
99101 passphrase : 'password123' ,
100102 } ;
101103
104+ const expectedResponse : LightningOnchainWithdrawResponse = {
105+ txRequestState : 'delivered' ,
106+ txRequestId : '123' ,
107+ withdrawStatus : {
108+ status : 'delivered' ,
109+ txid : 'tx123' ,
110+ } ,
111+ } ;
112+
113+ const onchainWithdrawStub = sinon . stub ( ) . resolves ( expectedResponse ) ;
114+ const mockLightningWallet = {
115+ withdrawOnchain : onchainWithdrawStub ,
116+ } ;
117+
118+ // Mock the module import
119+ const proxyquire = require ( 'proxyquire' ) ;
120+ const lightningWithdrawRoutes = proxyquire ( '../../../src/lightning/lightningWithdrawRoutes' , {
121+ '@bitgo/abstract-lightning' : {
122+ getLightningWallet : ( ) => mockLightningWallet ,
123+ } ,
124+ } ) ;
125+
126+ const walletStub = { } ;
127+ const coinStub = {
128+ wallets : ( ) => ( { get : sinon . stub ( ) . resolves ( walletStub ) } ) ,
129+ } ;
130+ const stubBitgo = sinon . createStubInstance ( BitGo as any , { coin : coinStub } ) ;
131+
102132 const req = mockRequestObject ( {
103133 params : { id : 'testWalletId' , coin } ,
104134 body : inputParams ,
135+ bitgo : stubBitgo ,
105136 } ) ;
106- req . bitgo = bitgo ;
107137
108- await should ( handleLightningWithdraw ( req ) ) . be . rejectedWith (
109- 'Invalid request body for withdrawing on chain lightning balance'
110- ) ;
138+ const result = await lightningWithdrawRoutes . handleLightningWithdraw ( req ) ;
139+
140+ should ( result ) . deepEqual ( expectedResponse ) ;
111141 } ) ;
112142
113143 it ( 'should throw an error if the recipients is missing in the request params' , async ( ) => {
0 commit comments