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
2 changes: 1 addition & 1 deletion modules/bitgo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"webpack-dev": "cross-env NODE_ENV=development webpack",
"webpack-prod": "NODE_OPTIONS=--max-old-space-size=4096 cross-env NODE_ENV=production webpack",
"test": "npm run coverage",
"unit-test": "mocha 'test/v2/unit/**/*.ts' 'test/unit/**/*.ts'",
"unit-test": "NODE_OPTIONS=--max-old-space-size=8192 mocha 'test/v2/unit/**/*.ts' 'test/unit/**/*.ts'",
"coverage": "nyc -- npm run unit-test",
"integration-test": "nyc -- mocha \"test/v2/integration/**/*.ts\"",
"browser-test": "karma start karma.conf.js",
Expand Down
205 changes: 204 additions & 1 deletion modules/bitgo/test/v2/unit/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5672,7 +5672,7 @@ describe('V2 Wallet:', function () {
solInstructions: [],
recipients: testRecipients,
})
.should.be.rejectedWith(`'solInstructions' is a required parameter for customTx intent`);
.should.be.rejectedWith(`'solInstructions' or 'solVersionedTransactionData' is required for customTx intent`);
});

it('should support solInstruction for cold wallets', async function () {
Expand Down Expand Up @@ -5710,6 +5710,209 @@ describe('V2 Wallet:', function () {
});
});
});

describe('prebuildTransaction with solVersionedTransactionData type', function () {
function getTestVersionedTransactionData() {
return {
versionedInstructions: [
{
programIdIndex: 10,
accountKeyIndexes: [0, 1, 2],
data: '0102030405',
},
{
programIdIndex: 11,
accountKeyIndexes: [0, 3, 4, 5],
data: '060708090a',
},
],
addressLookupTables: [
{
accountKey: '2sk6bVhjN53hz7sqE72eqHvhPfSc1snZzsJR6yA5hF7j',
writableIndexes: [0, 1],
readonlyIndexes: [2, 3],
},
],
staticAccountKeys: [
'5hr5fisPi6DXNuuRpm5XUbzpiEnmdyxXuBDTwzwZj5Pe',
'2sk6bVhjN53hz7sqE72eqHvhPfSc1snZzsJR6yA5hF7j',
'11111111111111111111111111111111',
],
messageHeader: {
numRequiredSignatures: 1,
numReadonlySignedAccounts: 0,
numReadonlyUnsignedAccounts: 1,
},
};
}

it('should call prebuildTxWithIntent with correct parameters for versioned transaction', async function () {
const testVersionedTransactionData = getTestVersionedTransactionData();
const prebuildTxWithIntent = sandbox.stub(TssUtils.prototype, 'prebuildTxWithIntent');
prebuildTxWithIntent.resolves(txRequest);
prebuildTxWithIntent.calledOnceWithExactly({
reqId,
intentType: 'customTx',
solVersionedTransactionData: testVersionedTransactionData,
recipients: testRecipients,
});

const txPrebuild = await tssSolWallet.prebuildTransaction({
reqId,
type: 'customTx',
solVersionedTransactionData: testVersionedTransactionData,
recipients: testRecipients,
});

txPrebuild.should.deepEqual({
walletId: tssSolWallet.id(),
wallet: tssSolWallet,
txRequestId: 'id',
txHex: 'ababcdcd',
buildParams: {
type: 'customTx',
solVersionedTransactionData: testVersionedTransactionData,
recipients: testRecipients,
},
feeInfo: {
fee: 5000,
feeString: '5000',
},
});
});

it('should handle solVersionedTransactionData with empty recipients', async function () {
const testVersionedTransactionData = getTestVersionedTransactionData();
const prebuildTxWithIntent = sandbox.stub(TssUtils.prototype, 'prebuildTxWithIntent');
prebuildTxWithIntent.resolves(txRequest);
prebuildTxWithIntent.calledOnceWithExactly({
reqId,
intentType: 'customTx',
solVersionedTransactionData: testVersionedTransactionData,
recipients: [],
});

const txPrebuild = await tssSolWallet.prebuildTransaction({
reqId,
type: 'customTx',
solVersionedTransactionData: testVersionedTransactionData,
});

txPrebuild.should.deepEqual({
walletId: tssSolWallet.id(),
wallet: tssSolWallet,
txRequestId: 'id',
txHex: 'ababcdcd',
buildParams: {
type: 'customTx',
solVersionedTransactionData: testVersionedTransactionData,
},
feeInfo: {
fee: 5000,
feeString: '5000',
},
});
});

it('should handle solVersionedTransactionData with memo parameter', async function () {
const testVersionedTransactionData = getTestVersionedTransactionData();
const prebuildTxWithIntent = sandbox.stub(TssUtils.prototype, 'prebuildTxWithIntent');
prebuildTxWithIntent.resolves(txRequest);
prebuildTxWithIntent.calledOnceWithExactly({
reqId,
intentType: 'customTx',
solVersionedTransactionData: testVersionedTransactionData,
recipients: testRecipients,
memo: {
type: 'type',
value: 'test memo',
},
});

const txPrebuild = await tssSolWallet.prebuildTransaction({
reqId,
type: 'customTx',
solVersionedTransactionData: testVersionedTransactionData,
recipients: testRecipients,
memo: {
type: 'type',
value: 'test memo',
},
});

txPrebuild.should.deepEqual({
walletId: tssSolWallet.id(),
wallet: tssSolWallet,
txRequestId: 'id',
txHex: 'ababcdcd',
buildParams: {
type: 'customTx',
solVersionedTransactionData: testVersionedTransactionData,
recipients: testRecipients,
memo: {
type: 'type',
value: 'test memo',
},
},
feeInfo: {
fee: 5000,
feeString: '5000',
},
});
});

it('should handle solVersionedTransactionData with pending approval ID', async function () {
const testVersionedTransactionData = getTestVersionedTransactionData();
const prebuildTxWithIntent = sandbox.stub(TssUtils.prototype, 'prebuildTxWithIntent');
prebuildTxWithIntent.resolves({ ...txRequest, state: 'pendingApproval', pendingApprovalId: 'some-id' });
prebuildTxWithIntent.calledOnceWithExactly({
reqId,
intentType: 'customTx',
solVersionedTransactionData: testVersionedTransactionData,
recipients: testRecipients,
});

const txPrebuild = await custodialTssSolWallet.prebuildTransaction({
reqId,
type: 'customTx',
solVersionedTransactionData: testVersionedTransactionData,
recipients: testRecipients,
});

txPrebuild.should.deepEqual({
walletId: custodialTssSolWallet.id(),
wallet: custodialTssSolWallet,
txRequestId: 'id',
txHex: 'ababcdcd',
pendingApprovalId: 'some-id',
buildParams: {
type: 'customTx',
solVersionedTransactionData: testVersionedTransactionData,
recipients: testRecipients,
},
feeInfo: {
fee: 5000,
feeString: '5000',
},
});
});

it('should throw error for empty versionedInstructions array', async function () {
await tssSolWallet
.prebuildTransaction({
reqId,
type: 'customTx',
solVersionedTransactionData: {
versionedInstructions: [],
addressLookupTables: [],
staticAccountKeys: ['test'],
messageHeader: { numRequiredSignatures: 1, numReadonlySignedAccounts: 0, numReadonlyUnsignedAccounts: 0 },
},
recipients: testRecipients,
})
.should.be.rejectedWith(`'solInstructions' or 'solVersionedTransactionData' is required for customTx intent`);
});
});
});

describe('Aptos Custom transaction Flow', function () {
Expand Down
1 change: 1 addition & 0 deletions modules/sdk-coin-sol/src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export enum InstructionBuilderTypes {
MintTo = 'MintTo',
Burn = 'Burn',
CustomInstruction = 'CustomInstruction',
VersionedCustomInstruction = 'VersionedCustomInstruction',
Approve = 'Approve',
WithdrawStake = 'WithdrawStake',
}
Expand Down
Loading