Skip to content

Commit 95d3b2d

Browse files
authored
Merge pull request #5085 from BitGo/SC-498
2 parents d9c6b06 + 92c8c9d commit 95d3b2d

File tree

3 files changed

+61
-8
lines changed

3 files changed

+61
-8
lines changed

modules/bitgo/test/v2/fixtures/staking/stakingWallet.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ export default {
2020
transactions: transactions,
2121
};
2222
},
23-
transaction: function (status: string, buildParams?: PrebuildTransactionOptions): StakingTransaction {
23+
transaction: function (
24+
status: string,
25+
buildParams?: PrebuildTransactionOptions,
26+
setTxRequestId = true
27+
): StakingTransaction {
2428
const transaction: StakingTransaction = {
2529
id: '00566722-daef-40eb-b0ac-fa5402bbfe72',
2630
stakingRequestId: '8638284a-dab2-46b9-b07f-21109a6e7220',
@@ -32,11 +36,13 @@ export default {
3236
amount: '1234',
3337
pendingApprovalId: 'd99e3ae1-d2a6-4f57-87b6-d04c24854739',
3438
transferId: 'e4b482b0-54d5-474b-bb2b-c56ce8516b5e',
35-
txRequestId: this.txRequestId,
3639
};
3740
if (buildParams) {
3841
transaction.buildParams = buildParams;
3942
}
43+
if (setTxRequestId) {
44+
transaction.txRequestId = this.txRequestId;
45+
}
4046
return transaction;
4147
},
4248
buildParams: {

modules/bitgo/test/v2/unit/staking/stakingWalletCommon.ts

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as nock from 'nock';
22
import * as should from 'should';
33
import 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';
66
import { TestBitGo } from '@bitgo/sdk-test';
77
import { BitGo } from '../../../../src';
88
import * 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);

modules/sdk-core/src/bitgo/staking/stakingWallet.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,19 +218,25 @@ export class StakingWallet implements IStakingWallet {
218218

219219
/**
220220
* Create prebuilt staking transaction.
221+
*
222+
* for transactions with tx request id (TSS transactions), we need to delete signature shares before creating prebuild transaction
223+
* we only need to get transaction build params if they exist to pre build
224+
*
221225
* @param transaction
222226
*/
223227
async prebuildSelfManagedStakingTransaction(transaction: StakingTransaction): Promise<PrebuildTransactionResult> {
224-
const builtStakingTransaction = await this.build(transaction);
225-
const buildParams = builtStakingTransaction.transaction.buildParams;
228+
if (transaction.txRequestId) {
229+
await this.tssUtil.deleteSignatureShares(transaction.txRequestId);
230+
}
231+
const buildParams = (await this.expandBuildParams(transaction)).buildParams;
226232
const formattedParams = {
227233
...buildParams,
228234
coin: this.coin,
229235
walletId: this.walletId,
230236
walletType: this.wallet.type(),
231237
preview: true,
232238
};
233-
return await this.wallet.prebuildTransaction(formattedParams);
239+
return await (await this.getWalletForBuildingAndSigning()).prebuildTransaction(formattedParams);
234240
}
235241

236242
/**

0 commit comments

Comments
 (0)