@@ -15,9 +15,9 @@ describe('POST /api/:coin/wallet/:walletId/sendmany', () => {
1515 let agent : request . SuperAgentTest ;
1616 const enclavedExpressUrl = 'http://enclaved.invalid' ;
1717 const bitgoApiUrl = Environments . test . uri ;
18- const coin = 'tbtc' ;
1918 const accessToken = 'test-token' ;
2019 const walletId = 'test-wallet-id' ;
20+ const coin = 'tbtc' ;
2121
2222 before ( ( ) => {
2323 nock . disableNetConnect ( ) ;
@@ -49,6 +49,7 @@ describe('POST /api/:coin/wallet/:walletId/sendmany', () => {
4949 } ) ;
5050
5151 describe ( 'SendMany Multisig:' , ( ) => {
52+ const coin = 'tbtc' ;
5253 it ( 'should send many transactions by calling the enclaved express service' , async ( ) => {
5354 // Mock wallet get request
5455 const walletGetNock = nock ( bitgoApiUrl )
@@ -226,7 +227,27 @@ describe('POST /api/:coin/wallet/:walletId/sendmany', () => {
226227 } ) ;
227228
228229 describe ( 'SendMany TSS EDDSA:' , ( ) => {
230+ const coin = 'tsol' ;
229231 it ( 'should send many transactions using EDDSA TSS signing' , async ( ) => {
232+ const mockTxRequest = {
233+ txRequestId : 'test-tx-request-id' ,
234+ state : 'signed' ,
235+ apiVersion : 'full' ,
236+ pendingApprovalId : 'test-pending-approval-id' ,
237+ transactions : [
238+ {
239+ unsignedTx : {
240+ derivationPath : 'm/0' ,
241+ signableHex : 'testMessage' ,
242+ } ,
243+ signedTx : {
244+ id : 'test-tx-id' ,
245+ tx : 'signed-transaction' ,
246+ } ,
247+ } ,
248+ ] ,
249+ } ;
250+
230251 // Mock wallet get request for TSS wallet
231252 const walletGetNock = nock ( bitgoApiUrl )
232253 . get ( `/api/v2/${ coin } /wallet/${ walletId } ` )
@@ -262,34 +283,28 @@ describe('POST /api/:coin/wallet/:walletId/sendmany', () => {
262283 walletId,
263284 } ) ;
264285
265- const verifyStub = sinon . stub ( Coin . Btc . prototype , 'verifyTransaction' ) . resolves ( true ) ;
286+ const verifyStub = sinon . stub ( Coin . Tsol . prototype , 'verifyTransaction' ) . resolves ( true ) ;
266287
267288 // Mock multisigType to return 'tss'
268289 const multisigTypeStub = sinon . stub ( Wallet . prototype , 'multisigType' ) . returns ( 'tss' ) ;
269290
270- // Mock getMPCAlgorithm to return 'eddsa'
271- const getMPCAlgorithmStub = sinon
272- . stub ( Coin . Btc . prototype , 'getMPCAlgorithm' )
273- . returns ( 'eddsa' ) ;
274-
275291 // Mock handleEddsaSigning
276292 const handleEddsaSigningStub = sinon . stub ( ) . resolves ( {
277- txRequestId : 'test-tx-request-id' ,
278- state : 'signed' ,
279- apiVersion : 'full' ,
280- transactions : [
281- {
282- signedTx : {
283- id : 'test-tx-id' ,
284- tx : 'signed-transaction' ,
285- } ,
286- } ,
287- ] ,
293+ ...mockTxRequest ,
288294 } ) ;
289295
290- // Import and stub the handleEddsaSigning function
296+ // Import and stub the signAndSendTxRequests function
291297 sinon . stub ( eddsa , 'handleEddsaSigning' ) . callsFake ( handleEddsaSigningStub ) ;
292298
299+ // Mock getTxRequest call
300+ const getTxRequestNock = nock ( bitgoApiUrl )
301+ . get ( `/api/v2/wallet/${ walletId } /txrequests` )
302+ . query ( { txRequestIds : 'test-tx-request-id' , latest : true } )
303+ . matchHeader ( 'any' , ( ) => true )
304+ . reply ( 200 , {
305+ txRequests : [ mockTxRequest ] ,
306+ } ) ;
307+
293308 const response = await agent
294309 . post ( `/api/${ coin } /wallet/${ walletId } /sendMany` )
295310 . set ( 'Authorization' , `Bearer ${ accessToken } ` )
@@ -317,13 +332,14 @@ describe('POST /api/:coin/wallet/:walletId/sendmany', () => {
317332 keychainGetNock . done ( ) ;
318333 sinon . assert . calledOnce ( prebuildStub ) ;
319334 sinon . assert . calledOnce ( verifyStub ) ;
320- sinon . assert . calledTwice ( multisigTypeStub ) ;
321- sinon . assert . calledOnce ( getMPCAlgorithmStub ) ;
335+ sinon . assert . calledThrice ( multisigTypeStub ) ;
322336 sinon . assert . calledOnce ( handleEddsaSigningStub ) ;
337+ getTxRequestNock . done ( ) ;
323338 } ) ;
324339 } ) ;
325340
326341 describe ( 'SendMany TSS ECDSA:' , ( ) => {
342+ const coin = 'hteth' ;
327343 it ( 'should send many transactions using ECDSA TSS signing' , async ( ) => {
328344 // Mock wallet get request for TSS wallet
329345 const walletGetNock = nock ( bitgoApiUrl )
@@ -349,45 +365,35 @@ describe('POST /api/:coin/wallet/:walletId/sendmany', () => {
349365 type : 'tss' ,
350366 } ) ;
351367
352- const prebuildStub = sinon . stub ( Wallet . prototype , 'prebuildTransaction' ) . resolves ( {
353- txRequestId : 'test-tx-request-id' ,
354- txHex : 'prebuilt-tx-hex' ,
355- txInfo : {
356- nP2SHInputs : 1 ,
357- nSegwitInputs : 0 ,
358- nOutputs : 2 ,
368+ const sendManyStub = sinon . stub ( Wallet . prototype , 'sendMany' ) . resolves ( {
369+ txRequest : {
370+ txRequestId : 'test-tx-request-id' ,
371+ state : 'signed' ,
372+ apiVersion : 'full' ,
373+ pendingApprovalId : 'test-pending-approval-id' ,
374+ transactions : [
375+ {
376+ state : 'signed' ,
377+ unsignedTx : {
378+ derivationPath : 'm/0' ,
379+ signableHex : 'testMessage' ,
380+ serializedTxHex : 'testSerializedTxHex' ,
381+ } ,
382+ signatureShares : [ ] ,
383+ signedTx : {
384+ id : 'test-tx-id' ,
385+ tx : 'signed-transaction' ,
386+ } ,
387+ } ,
388+ ] ,
359389 } ,
360- walletId,
390+ txid : 'test-tx-id' ,
391+ tx : 'signed-transaction' ,
361392 } ) ;
362393
363- const verifyStub = sinon . stub ( Coin . Btc . prototype , 'verifyTransaction' ) . resolves ( true ) ;
364-
365394 // Mock multisigType to return 'tss'
366395 const multisigTypeStub = sinon . stub ( Wallet . prototype , 'multisigType' ) . returns ( 'tss' ) ;
367396
368- // Mock getMPCAlgorithm to return 'ecdsa'
369- const getMPCAlgorithmStub = sinon
370- . stub ( Coin . Btc . prototype , 'getMPCAlgorithm' )
371- . returns ( 'ecdsa' ) ;
372-
373- // Mock handleEcdsaSigning
374- const handleEcdsaMPCv2Signing = sinon . stub ( ) . resolves ( {
375- txRequestId : 'test-tx-request-id' ,
376- state : 'signed' ,
377- apiVersion : 'full' ,
378- transactions : [
379- {
380- signedTx : {
381- id : 'test-tx-id' ,
382- tx : 'signed-transaction' ,
383- } ,
384- } ,
385- ] ,
386- } ) ;
387-
388- // Import and stub the handleEcdsaSigning function
389- sinon . stub ( ecdsa , 'handleEcdsaMPCv2Signing' ) . callsFake ( handleEcdsaMPCv2Signing ) ;
390-
391397 const response = await agent
392398 . post ( `/api/${ coin } /wallet/${ walletId } /sendMany` )
393399 . set ( 'Authorization' , `Bearer ${ accessToken } ` )
@@ -413,11 +419,8 @@ describe('POST /api/:coin/wallet/:walletId/sendmany', () => {
413419
414420 walletGetNock . done ( ) ;
415421 keychainGetNock . done ( ) ;
416- sinon . assert . calledOnce ( prebuildStub ) ;
417- sinon . assert . calledOnce ( verifyStub ) ;
418- sinon . assert . calledTwice ( multisigTypeStub ) ;
419- sinon . assert . calledOnce ( getMPCAlgorithmStub ) ;
420- sinon . assert . calledOnce ( handleEcdsaMPCv2Signing ) ;
422+ sinon . assert . calledOnce ( sendManyStub ) ;
423+ sinon . assert . calledOnce ( multisigTypeStub ) ;
421424 } ) ;
422425
423426 it ( 'should fail when backup key is used for ECDSA TSS signing' , async ( ) => {
@@ -445,19 +448,17 @@ describe('POST /api/:coin/wallet/:walletId/sendmany', () => {
445448 type : 'tss' ,
446449 } ) ;
447450
448- const prebuildStub = sinon . stub ( Wallet . prototype , 'prebuildTransaction' ) . resolves ( {
449- txRequestId : 'test-tx-request-id' ,
450- txHex : 'prebuilt-tx-hex' ,
451- txInfo : {
452- nP2SHInputs : 1 ,
453- nSegwitInputs : 0 ,
454- nOutputs : 2 ,
451+ const sendManyStub = sinon . stub ( Wallet . prototype , 'sendMany' ) . resolves ( {
452+ txRequest : {
453+ txRequestId : 'test-tx-request-id' ,
454+ state : 'signed' ,
455+ apiVersion : 'full' ,
456+ pendingApprovalId : 'test-pending-approval-id' ,
455457 } ,
456- walletId,
458+ txid : 'test-tx-id' ,
459+ tx : 'signed-transaction' ,
457460 } ) ;
458461
459- const verifyStub = sinon . stub ( Coin . Btc . prototype , 'verifyTransaction' ) . resolves ( true ) ;
460-
461462 // Mock multisigType to return 'tss'
462463 const multisigTypeStub = sinon . stub ( Wallet . prototype , 'multisigType' ) . returns ( 'tss' ) ;
463464
@@ -480,9 +481,8 @@ describe('POST /api/:coin/wallet/:walletId/sendmany', () => {
480481
481482 walletGetNock . done ( ) ;
482483 keychainGetNock . done ( ) ;
483- sinon . assert . calledOnce ( prebuildStub ) ;
484- sinon . assert . calledOnce ( verifyStub ) ;
485- sinon . assert . calledTwice ( multisigTypeStub ) ;
484+ sinon . assert . notCalled ( sendManyStub ) ;
485+ sinon . assert . calledOnce ( multisigTypeStub ) ;
486486 } ) ;
487487 } ) ;
488488
0 commit comments