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
35 changes: 1 addition & 34 deletions modules/sdk-coin-dot/src/dot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -651,45 +651,12 @@ export class Dot extends BaseCoin {
}

async verifyTransaction(params: VerifyTransactionOptions): Promise<boolean> {
const { txPrebuild, txParams } = params;
if (!txParams) {
throw new Error('missing txParams');
}

if (!txPrebuild) {
throw new Error('missing txPrebuild');
}

if (!txPrebuild.txHex) {
throw new Error('missing txHex in txPrebuild');
}

if (!txParams.recipients || txParams.recipients.length === 0) {
throw new Error('missing recipients in txParams');
}

const factory = this.getBuilder();
const txBuilder = factory.from(txPrebuild.txHex) as any;

const { txParams } = params;
if (Array.isArray(txParams.recipients) && txParams.recipients.length > 1) {
throw new Error(
`${this.getChain()} doesn't support sending to more than 1 destination address within a single transaction. Try again, using only a single recipient.`
);
}

// validate recipient is same as txBuilder._to
if (txParams.recipients[0].address !== txBuilder._to) {
throw new Error(
`Recipient address ${txParams.recipients[0].address} does not match transaction destination address ${txBuilder._to}`
);
}

// and amount is same as txBuilder._amount
if (txParams.recipients[0].amount !== txBuilder._amount) {
throw new Error(
`Recipient amount ${txParams.recipients[0].amount} does not match transaction amount ${txBuilder._amount}`
);
}
return true;
}

Expand Down
59 changes: 1 addition & 58 deletions modules/sdk-coin-dot/test/unit/dot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -664,69 +664,12 @@ describe('DOT:', function () {
walletPassphrase: 'fakeWalletPassphrase',
};

const txPrebuild = {
txHex:
'0xa80a0300161b969b6b53ef81225feea3882284c778cd4a406d23215fcf492e83f75d42960b00204aa9d101eb600400000065900f001000000067f9723393ef76214df0118c34bbbd3dbebc8ed46a10973a8c969d48fe7598c9a7b7420ee3e4fe2b88da0fc42b30897e18d56d8b56a1934211d9de730cf96de300',
};

await basecoin
.verifyTransaction({ txPrebuild, txParams })
.verifyTransaction({ txParams })
.should.be.rejectedWith(
`tdot doesn't support sending to more than 1 destination address within a single transaction. Try again, using only a single recipient.`
);
});

it('should reject a txPrebuild with more than invalid amount', async function () {
const wallet = new Wallet(bitgo, basecoin, {});
const txParams = {
recipients: [{ amount: '20000000000', address: '5CZh773vKGwKFCYUjGc31AwXCbf7TPkavdeuk2XoujJMjbBD' }],
wallet: wallet,
walletPassphrase: 'fakeWalletPassphrase',
};
const txPrebuild = {
txHex:
'0xa80a0300161b969b6b53ef81225feea3882284c778cd4a406d23215fcf492e83f75d42960b00204aa9d101eb600400000065900f001000000067f9723393ef76214df0118c34bbbd3dbebc8ed46a10973a8c969d48fe7598c9a7b7420ee3e4fe2b88da0fc42b30897e18d56d8b56a1934211d9de730cf96de300',
};

await basecoin
.verifyTransaction({ txPrebuild, txParams })
.should.be.rejectedWith(`Recipient amount 20000000000 does not match transaction amount 2000000000000`);
});

it('should reject a txPrebuild with more than invalid recipient', async function () {
const wallet = new Wallet(bitgo, basecoin, {});
const txParams = {
recipients: [{ amount: '2000000000000', address: '5CZh773vKGwKFCUjGc31AwXCbf7TPkavduk2XoujJMjbBD' }],
wallet: wallet,
walletPassphrase: 'fakeWalletPassphrase',
};
const txPrebuild = {
txHex:
'0xa80a0300161b969b6b53ef81225feea3882284c778cd4a406d23215fcf492e83f75d42960b00204aa9d101eb600400000065900f001000000067f9723393ef76214df0118c34bbbd3dbebc8ed46a10973a8c969d48fe7598c9a7b7420ee3e4fe2b88da0fc42b30897e18d56d8b56a1934211d9de730cf96de300',
};

await basecoin
.verifyTransaction({ txPrebuild, txParams })
.should.be.rejectedWith(
`Recipient address 5CZh773vKGwKFCUjGc31AwXCbf7TPkavduk2XoujJMjbBD does not match transaction destination address 5CZh773vKGwKFCYUjGc31AwXCbf7TPkavdeuk2XoujJMjbBD`
);
});

it('should accept a txPrebuild with more than valid recipient and amount', async function () {
const wallet = new Wallet(bitgo, basecoin, {});
const txParams = {
recipients: [{ amount: '2000000000000', address: '5CZh773vKGwKFCYUjGc31AwXCbf7TPkavdeuk2XoujJMjbBD' }],
wallet: wallet,
walletPassphrase: 'fakeWalletPassphrase',
};
const txPrebuild = {
txHex:
'0xa80a0300161b969b6b53ef81225feea3882284c778cd4a406d23215fcf492e83f75d42960b00204aa9d101eb600400000065900f001000000067f9723393ef76214df0118c34bbbd3dbebc8ed46a10973a8c969d48fe7598c9a7b7420ee3e4fe2b88da0fc42b30897e18d56d8b56a1934211d9de730cf96de300',
};

const result = await basecoin.verifyTransaction({ txPrebuild, txParams });
assert.strictEqual(result, true);
});
});

describe('isWalletAddress', () => {
Expand Down