@@ -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' ;
@@ -317,14 +317,18 @@ describe('Staking Wallet Common', function () {
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 ) ;
330+ deleteSignatureShares . notCalled . should . be . true ( ) ;
331+ build . calledOnce . should . be . true ( ) ;
328332
329333 const formattedParams = {
330334 ...fixtures . buildParams ,
@@ -336,6 +340,41 @@ describe('Staking Wallet Common', function () {
336340 const expected = await stakingWallet . wallet . prebuildTransaction ( formattedParams ) ;
337341 const stakingTransaction = await stakingWallet . prebuildSelfManagedStakingTransaction ( transaction ) ;
338342
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 , undefined ) ;
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+ prebuildTransaction . calledOnce . should . be . true ( ) ;
364+ build . calledOnce . should . be . true ( ) ;
365+ if ( transaction . txRequestId ) {
366+ deleteSignatureShares . calledOnceWithExactly ( transaction . txRequestId ) ;
367+ }
368+ const formattedParams = {
369+ ...fixtures . buildParams ,
370+ coin : stakingWallet . coin ,
371+ walletId : stakingWallet . walletId ,
372+ walletType : stakingWallet . wallet . type ( ) ,
373+ preview : true ,
374+ } ;
375+ const expected = await stakingWallet . wallet . prebuildTransaction ( formattedParams ) ;
376+ const stakingTransaction = await stakingWallet . prebuildSelfManagedStakingTransaction ( transaction ) ;
377+
339378 stakingTransaction . should . deepEqual ( expected ) ;
340379 should . exist ( stakingTransaction ) ;
341380 } ) ;
0 commit comments