@@ -2,7 +2,7 @@ import * as nock from 'nock';
22import * as should from 'should' ;
33import fixtures from '../../fixtures/staking/stakingWallet' ;
44
5- import { Enterprise , Environments , StakingRequest , StakingWallet , Wallet } from '@bitgo/sdk-core' ;
5+ import { Enterprise , Environments , StakingRequest , StakingWallet , TssUtils , Wallet } from '@bitgo/sdk-core' ;
66import { TestBitGo } from '@bitgo/sdk-test' ;
77import { BitGo } from '../../../../src' ;
88import * as sinon from 'sinon' ;
@@ -309,32 +309,73 @@ describe('Staking Wallet Common', function () {
309309
310310 describe ( 'prebuildSelfManagedStakingTransaction' , function ( ) {
311311 it ( 'should prebuild self-managed staking transaction' , async function ( ) {
312- const transaction = fixtures . transaction ( 'READY' , fixtures . buildParams ) ;
312+ const transaction = fixtures . transaction ( 'READY' , fixtures . buildParams , false ) ;
313313 nock ( microservicesUri )
314314 . get (
315315 `/api/staking/v1/${ stakingWallet . coin } /wallets/${ stakingWallet . walletId } /requests/${ transaction . stakingRequestId } /transactions/${ transaction . id } `
316316 )
317317 . query ( { expandBuildParams : true } )
318318 . reply ( 200 , transaction ) ;
319319
320+ const deleteSignatureShares = sandbox . stub ( TssUtils . prototype , 'deleteSignatureShares' ) ;
320321 const prebuildTransaction = sandbox . stub ( Wallet . prototype , 'prebuildTransaction' ) ;
322+ const build = sandbox . stub ( StakingWallet . prototype , 'build' ) ;
321323 const txPrebuild = {
322324 walletId : stakingWallet . walletId ,
323325 txHex : 'hex' ,
324326 buildParams : transaction . buildParams ,
325327 } ;
326328 prebuildTransaction . resolves ( txPrebuild ) ;
327329 prebuildTransaction . calledOnceWithExactly ( transaction . buildParams ) ;
328-
329330 const formattedParams = {
330331 ...fixtures . buildParams ,
331332 coin : stakingWallet . coin ,
332333 walletId : stakingWallet . walletId ,
333334 walletType : stakingWallet . wallet . type ( ) ,
334335 preview : true ,
335336 } ;
337+ const stakingTransaction = await stakingWallet . prebuildSelfManagedStakingTransaction ( transaction ) ;
338+ sandbox . assert . calledOnce ( prebuildTransaction ) ;
339+ sandbox . assert . notCalled ( build ) ;
340+ sandbox . assert . notCalled ( deleteSignatureShares ) ;
341+
336342 const expected = await stakingWallet . wallet . prebuildTransaction ( formattedParams ) ;
343+ stakingTransaction . should . deepEqual ( expected ) ;
344+ should . exist ( stakingTransaction ) ;
345+ } ) ;
346+ it ( 'should prebuild self-managed staking transaction - no build params' , async function ( ) {
347+ const transaction = fixtures . transaction ( 'READY' , undefined , true ) ;
348+ nock ( microservicesUri )
349+ . get (
350+ `/api/staking/v1/${ stakingWallet . coin } /wallets/${ stakingWallet . walletId } /requests/${ transaction . stakingRequestId } /transactions/${ transaction . id } `
351+ )
352+ . query ( { expandBuildParams : true } )
353+ . reply ( 200 , transaction ) ;
354+
355+ const deleteSignatureShares = sandbox . stub ( TssUtils . prototype , 'deleteSignatureShares' ) ;
356+ const prebuildTransaction = sandbox . stub ( Wallet . prototype , 'prebuildTransaction' ) ;
357+ const build = sandbox . stub ( StakingWallet . prototype , 'build' ) ;
358+ const txPrebuild = {
359+ walletId : stakingWallet . walletId ,
360+ txHex : 'hex' ,
361+ } ;
362+ prebuildTransaction . resolves ( txPrebuild ) ;
363+ if ( transaction . txRequestId ) {
364+ deleteSignatureShares . calledOnceWithExactly ( transaction . txRequestId ) ;
365+ }
366+ const formattedParams = {
367+ ...fixtures . buildParams ,
368+ coin : stakingWallet . coin ,
369+ walletId : stakingWallet . walletId ,
370+ walletType : stakingWallet . wallet . type ( ) ,
371+ preview : true ,
372+ } ;
337373 const stakingTransaction = await stakingWallet . prebuildSelfManagedStakingTransaction ( transaction ) ;
374+ sandbox . assert . calledOnce ( prebuildTransaction ) ;
375+ sandbox . assert . notCalled ( build ) ;
376+ sandbox . assert . calledOnce ( deleteSignatureShares ) ;
377+
378+ const expected = await stakingWallet . wallet . prebuildTransaction ( formattedParams ) ;
338379
339380 stakingTransaction . should . deepEqual ( expected ) ;
340381 should . exist ( stakingTransaction ) ;
0 commit comments