Skip to content

Commit 1a2afec

Browse files
authored
Merge pull request #8108 from BitGo/feature-branch
fix(sdk-coin-dot): add check for undefined amount
2 parents a4f8473 + f20e66f commit 1a2afec

2 files changed

Lines changed: 53 additions & 1 deletion

File tree

modules/sdk-coin-dot/src/dot.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ export class Dot extends BaseCoin {
715715
}
716716

717717
// validate amount is same as txBuilder['_amount']
718-
if (txParams.recipients[0].amount !== txBuilder['_amount']) {
718+
if (!txBuilder['_sweepFreeBalance'] && txParams.recipients[0].amount !== txBuilder['_amount']) {
719719
throw new TxIntentMismatchRecipientError(
720720
`Recipient amount ${txParams.recipients[0].amount} does not match transaction amount ${txBuilder['_amount']}`,
721721
reqId,

modules/sdk-coin-dot/test/unit/dot.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,58 @@ describe('DOT:', function () {
774774
'Transaction destination address 5CZh773vKGwKFCYUjGc31AwXCbf7TPkavdeuk2XoujJMjbBD does not match wallet base address 5DxD9nT16GQLrU6aB5pSS5VtxoZbVju3NHUCcawxZyZCTf74'
775775
);
776776
});
777+
778+
it('should verify a transferAll (sweep) transaction with empty txParams', async function () {
779+
const mockedWallet = {
780+
coinSpecific: () => ({
781+
baseAddress: '5Ffp1wJCPu4hzVDTo7XaMLqZSvSadyUQmxWPDw74CBjECSoq',
782+
}),
783+
};
784+
785+
// TransferAll tx (sweep) - uses method 0a04 (balances.transferAll)
786+
const txPrebuild = {
787+
txHex:
788+
'0x900a04009f7b0675db59d19b4bd9c8c72eaabba75a9863d02b30115b8b3c3ca5c20f025401d50121030000009d880f001000000067f9723393ef76214df0118c34bbbd3dbebc8ed46a10973a8c969d48fe7598c9149799bc9602cb5cf201f3425fb8d253b2d4e61fc119dcab3249f307f594754d00',
789+
};
790+
791+
const result = await basecoin.verifyTransaction({
792+
txPrebuild,
793+
txParams: {},
794+
wallet: mockedWallet as any,
795+
verification: {
796+
consolidationToBaseAddress: true,
797+
},
798+
});
799+
assert.strictEqual(result, true);
800+
});
801+
802+
it('should verify a transferAll (sweep) transaction with recipients in txParams', async function () {
803+
const mockedWallet = {
804+
coinSpecific: () => ({
805+
baseAddress: '5Ffp1wJCPu4hzVDTo7XaMLqZSvSadyUQmxWPDw74CBjECSoq',
806+
}),
807+
};
808+
809+
// TransferAll tx (sweep) - _amount is undefined for these transactions
810+
const txPrebuild = {
811+
txHex:
812+
'0x900a04009f7b0675db59d19b4bd9c8c72eaabba75a9863d02b30115b8b3c3ca5c20f025401d50121030000009d880f001000000067f9723393ef76214df0118c34bbbd3dbebc8ed46a10973a8c969d48fe7598c9149799bc9602cb5cf201f3425fb8d253b2d4e61fc119dcab3249f307f594754d00',
813+
};
814+
815+
const txParams = {
816+
recipients: [{ address: '5Ffp1wJCPu4hzVDTo7XaMLqZSvSadyUQmxWPDw74CBjECSoq', amount: '1000000000000' }],
817+
};
818+
819+
const result = await basecoin.verifyTransaction({
820+
txPrebuild,
821+
txParams,
822+
wallet: mockedWallet as any,
823+
verification: {
824+
consolidationToBaseAddress: true,
825+
},
826+
});
827+
assert.strictEqual(result, true);
828+
});
777829
});
778830

779831
describe('isWalletAddress', () => {

0 commit comments

Comments
 (0)