Skip to content

Commit 838a76d

Browse files
Merge pull request #7449 from BitGo/sandra/cs-6339
feat(sdk-api): pass isTestTransaction parameter to TSS transfer txrequests API and Multisig sendMany API
2 parents 997afbb + 1e1253d commit 838a76d

File tree

6 files changed

+101
-0
lines changed

6 files changed

+101
-0
lines changed

modules/bitgo/test/v2/unit/wallet.ts

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,6 +1787,28 @@ describe('V2 Wallet:', function () {
17871787
txPrebuild.recipients[0].amount.should.equal('1000000000000000');
17881788
});
17891789

1790+
it('should pass isTestTransaction parameter through for multisig wallets', async function () {
1791+
const recipients = [
1792+
{
1793+
address: 'aaa',
1794+
amount: '1000',
1795+
},
1796+
];
1797+
const isTestTransaction = true;
1798+
const path = `/api/v2/${wallet.coin()}/wallet/${wallet.id()}/tx/build`;
1799+
const response = nock(bgUrl)
1800+
.post(path, _.matches({ recipients, isTestTransaction })) // use _.matches to do a partial match on request body object instead of strict matching
1801+
.reply(200);
1802+
try {
1803+
await wallet.prebuildTransaction({ recipients, isTestTransaction });
1804+
} catch (e) {
1805+
// the prebuildTransaction method will probably throw an exception for not having all of the correct nocks
1806+
// we only care about /tx/build and whether isTestTransaction is an allowed parameter
1807+
}
1808+
1809+
response.isDone().should.be.true();
1810+
});
1811+
17901812
it('should pass unspent reservation parameter through when building transactions', async function () {
17911813
const reservation = {
17921814
expireTime: '2029-08-12',
@@ -2377,6 +2399,50 @@ describe('V2 Wallet:', function () {
23772399
});
23782400
});
23792401

2402+
it('should build a transfer transaction with isTestTransaction flag', async function () {
2403+
const recipients = [
2404+
{
2405+
address: '6DadkZcx9JZgeQUDbHh12cmqCpaqehmVxv6sGy49jrah',
2406+
amount: '1000',
2407+
},
2408+
];
2409+
2410+
const prebuildTxWithIntent = sandbox.stub(TssUtils.prototype, 'prebuildTxWithIntent');
2411+
prebuildTxWithIntent.resolves(txRequest);
2412+
2413+
const txPrebuild = await tssSolWallet.prebuildTransaction({
2414+
reqId,
2415+
recipients,
2416+
type: 'transfer',
2417+
isTestTransaction: true,
2418+
});
2419+
2420+
// Verify isTestTransaction is passed to prebuildTxWithIntent
2421+
sinon.assert.calledOnce(prebuildTxWithIntent);
2422+
const callArgs = prebuildTxWithIntent.getCall(0).args[0];
2423+
callArgs.should.have.property('isTestTransaction', true);
2424+
callArgs.should.have.property('intentType', 'payment');
2425+
callArgs.should.have.property('recipients');
2426+
should.exist(callArgs.recipients);
2427+
callArgs.recipients!.should.deepEqual(recipients);
2428+
2429+
txPrebuild.should.deepEqual({
2430+
walletId: tssSolWallet.id(),
2431+
wallet: tssSolWallet,
2432+
txRequestId: 'id',
2433+
txHex: 'ababcdcd',
2434+
buildParams: {
2435+
recipients,
2436+
type: 'transfer',
2437+
isTestTransaction: true,
2438+
},
2439+
feeInfo: {
2440+
fee: 5000,
2441+
feeString: '5000',
2442+
},
2443+
});
2444+
});
2445+
23802446
it('should build an enable token transaction', async function () {
23812447
const recipients = [];
23822448
const tokenName = 'tcoin:tokenName';
@@ -3965,6 +4031,35 @@ describe('V2 Wallet:', function () {
39654031
setRequestTracerSpy.restore();
39664032
});
39674033

4034+
it('should pass isTestTransaction through sendMany to prebuildAndSignTransaction', async function () {
4035+
const signedTransaction = {
4036+
txRequestId: 'txRequestId',
4037+
};
4038+
4039+
const sendManyInputWithTestFlag = {
4040+
...sendManyInput,
4041+
type: 'transfer',
4042+
isTestTransaction: true,
4043+
};
4044+
4045+
const prebuildAndSignTransaction = sandbox.stub(tssSolWallet, 'prebuildAndSignTransaction');
4046+
prebuildAndSignTransaction.resolves(signedTransaction);
4047+
4048+
const sendTxRequest = sandbox.stub(TssUtils.prototype, 'sendTxRequest');
4049+
sendTxRequest.resolves('sendTxResponse');
4050+
4051+
const sendMany = await tssSolWallet.sendMany(sendManyInputWithTestFlag);
4052+
4053+
// Verify prebuildAndSignTransaction was called with isTestTransaction
4054+
sinon.assert.calledOnce(prebuildAndSignTransaction);
4055+
const callArgs = prebuildAndSignTransaction.getCall(0).args[0];
4056+
should.exist(callArgs);
4057+
callArgs!.should.have.property('isTestTransaction', true);
4058+
callArgs!.should.have.property('type', 'transfer');
4059+
4060+
sendMany.should.deepEqual('sendTxResponse');
4061+
});
4062+
39684063
it('should return transfer from sendMany for apiVersion=full', async function () {
39694064
const wallet = new Wallet(bitgo, tsol, {
39704065
...walletData,

modules/sdk-core/src/bitgo/utils/mpcUtils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ export abstract class MpcUtils {
188188
nonce: params.nonce,
189189
recipients: intentRecipients,
190190
tokenName: params.tokenName,
191+
isTestTransaction: params.isTestTransaction,
191192
};
192193

193194
if (baseCoin.getFamily() === 'eth' || baseCoin.getFamily() === 'polygon' || baseCoin.getFamily() === 'bsc') {

modules/sdk-core/src/bitgo/utils/tss/baseTypes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ export interface PrebuildTransactionWithIntentOptions extends IntentOptionsBase
269269
abi?: any;
270270
};
271271
txRequestId?: string;
272+
isTestTransaction?: boolean;
272273
}
273274
export interface IntentRecipient {
274275
address: {
@@ -338,6 +339,7 @@ export interface PopulatedIntent extends PopulatedIntentBase {
338339
*/
339340
aptosCustomTransactionParams?: aptosCustomTransactionParams;
340341
txRequestId?: string;
342+
isTestTransaction?: boolean;
341343
}
342344

343345
export type TxRequestState =

modules/sdk-core/src/bitgo/wallet/BuildParams.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ export const BuildParams = t.exact(
116116
solVersionedTransactionData: t.unknown,
117117
// Aptos custom transaction parameters for smart contract calls
118118
aptosCustomTransactionParams: t.unknown,
119+
isTestTransaction: t.unknown,
119120
}),
120121
])
121122
);

modules/sdk-core/src/bitgo/wallet/iWallet.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ export interface PrebuildTransactionOptions {
217217
abi?: any;
218218
};
219219
txRequestId?: string;
220+
isTestTransaction?: boolean;
220221
}
221222

222223
export interface PrebuildAndSignTransactionOptions extends PrebuildTransactionOptions, WalletSignTransactionOptions {

modules/sdk-core/src/bitgo/wallet/wallet.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3434,6 +3434,7 @@ export class Wallet implements IWallet {
34343434
custodianTransactionId: params.custodianTransactionId,
34353435
unspents: params.unspents,
34363436
senderAddress: params.senderAddress,
3437+
isTestTransaction: params.isTestTransaction,
34373438
},
34383439
apiVersion,
34393440
params.preview

0 commit comments

Comments
 (0)