Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions modules/bitgo/test/v2/unit/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1786,6 +1786,28 @@ describe('V2 Wallet:', function () {
txPrebuild.recipients[0].amount.should.equal('1000000000000000');
});

it('should pass isTestTransaction parameter through for multisig wallets', async function () {
const recipients = [
{
address: 'aaa',
amount: '1000',
},
];
const isTestTransaction = true;
const path = `/api/v2/${wallet.coin()}/wallet/${wallet.id()}/tx/build`;
const response = nock(bgUrl)
.post(path, _.matches({ recipients, isTestTransaction })) // use _.matches to do a partial match on request body object instead of strict matching
.reply(200);
try {
await wallet.prebuildTransaction({ recipients, isTestTransaction });
} catch (e) {
// the prebuildTransaction method will probably throw an exception for not having all of the correct nocks
// we only care about /tx/build and whether isTestTransaction is an allowed parameter
}

response.isDone().should.be.true();
});

it('should pass unspent reservation parameter through when building transactions', async function () {
const reservation = {
expireTime: '2029-08-12',
Expand Down Expand Up @@ -2362,6 +2384,50 @@ describe('V2 Wallet:', function () {
});
});

it('should build a transfer transaction with isTestTransaction flag', async function () {
const recipients = [
{
address: '6DadkZcx9JZgeQUDbHh12cmqCpaqehmVxv6sGy49jrah',
amount: '1000',
},
];

const prebuildTxWithIntent = sandbox.stub(TssUtils.prototype, 'prebuildTxWithIntent');
prebuildTxWithIntent.resolves(txRequest);

const txPrebuild = await tssSolWallet.prebuildTransaction({
reqId,
recipients,
type: 'transfer',
isTestTransaction: true,
});

// Verify isTestTransaction is passed to prebuildTxWithIntent
sinon.assert.calledOnce(prebuildTxWithIntent);
const callArgs = prebuildTxWithIntent.getCall(0).args[0];
callArgs.should.have.property('isTestTransaction', true);
callArgs.should.have.property('intentType', 'payment');
callArgs.should.have.property('recipients');
should.exist(callArgs.recipients);
callArgs.recipients!.should.deepEqual(recipients);

txPrebuild.should.deepEqual({
walletId: tssSolWallet.id(),
wallet: tssSolWallet,
txRequestId: 'id',
txHex: 'ababcdcd',
buildParams: {
recipients,
type: 'transfer',
isTestTransaction: true,
},
feeInfo: {
fee: 5000,
feeString: '5000',
},
});
});

it('should build an enable token transaction', async function () {
const recipients = [];
const tokenName = 'tcoin:tokenName';
Expand Down Expand Up @@ -3909,6 +3975,35 @@ describe('V2 Wallet:', function () {
setRequestTracerSpy.restore();
});

it('should pass isTestTransaction through sendMany to prebuildAndSignTransaction', async function () {
const signedTransaction = {
txRequestId: 'txRequestId',
};

const sendManyInputWithTestFlag = {
...sendManyInput,
type: 'transfer',
isTestTransaction: true,
};

const prebuildAndSignTransaction = sandbox.stub(tssSolWallet, 'prebuildAndSignTransaction');
prebuildAndSignTransaction.resolves(signedTransaction);

const sendTxRequest = sandbox.stub(TssUtils.prototype, 'sendTxRequest');
sendTxRequest.resolves('sendTxResponse');

const sendMany = await tssSolWallet.sendMany(sendManyInputWithTestFlag);

// Verify prebuildAndSignTransaction was called with isTestTransaction
sinon.assert.calledOnce(prebuildAndSignTransaction);
const callArgs = prebuildAndSignTransaction.getCall(0).args[0];
should.exist(callArgs);
callArgs!.should.have.property('isTestTransaction', true);
callArgs!.should.have.property('type', 'transfer');

sendMany.should.deepEqual('sendTxResponse');
});

it('should return transfer from sendMany for apiVersion=full', async function () {
const wallet = new Wallet(bitgo, tsol, {
...walletData,
Expand Down
1 change: 1 addition & 0 deletions modules/sdk-core/src/bitgo/utils/mpcUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ export abstract class MpcUtils {
nonce: params.nonce,
recipients: intentRecipients,
tokenName: params.tokenName,
isTestTransaction: params.isTestTransaction,
};

if (baseCoin.getFamily() === 'eth' || baseCoin.getFamily() === 'polygon' || baseCoin.getFamily() === 'bsc') {
Expand Down
2 changes: 2 additions & 0 deletions modules/sdk-core/src/bitgo/utils/tss/baseTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ export interface PrebuildTransactionWithIntentOptions extends IntentOptionsBase
abi?: any;
};
txRequestId?: string;
isTestTransaction?: boolean;
}
export interface IntentRecipient {
address: {
Expand Down Expand Up @@ -338,6 +339,7 @@ export interface PopulatedIntent extends PopulatedIntentBase {
*/
aptosCustomTransactionParams?: aptosCustomTransactionParams;
txRequestId?: string;
isTestTransaction?: boolean;
}

export type TxRequestState =
Expand Down
1 change: 1 addition & 0 deletions modules/sdk-core/src/bitgo/wallet/BuildParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export const BuildParams = t.exact(
solVersionedTransactionData: t.unknown,
// Aptos custom transaction parameters for smart contract calls
aptosCustomTransactionParams: t.unknown,
isTestTransaction: t.unknown,
}),
])
);
Expand Down
1 change: 1 addition & 0 deletions modules/sdk-core/src/bitgo/wallet/iWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ export interface PrebuildTransactionOptions {
abi?: any;
};
txRequestId?: string;
isTestTransaction?: boolean;
}

export interface PrebuildAndSignTransactionOptions extends PrebuildTransactionOptions, WalletSignTransactionOptions {
Expand Down
1 change: 1 addition & 0 deletions modules/sdk-core/src/bitgo/wallet/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3434,6 +3434,7 @@ export class Wallet implements IWallet {
custodianTransactionId: params.custodianTransactionId,
unspents: params.unspents,
senderAddress: params.senderAddress,
isTestTransaction: params.isTestTransaction,
},
apiVersion,
params.preview
Expand Down