Skip to content

Commit 2889586

Browse files
committed
refactor(sdk-coin-ada): ignore fee address outputs for consolidation tranactions
Ticket: WIN-8861
1 parent 55aef4f commit 2889586

2 files changed

Lines changed: 80 additions & 1 deletion

File tree

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ export interface TransactionPrebuild {
4747
txHex: string;
4848
}
4949

50+
export interface AdaTxInfo {
51+
feeAddress?: string;
52+
}
53+
5054
export interface ExplainTransactionOptions {
5155
txPrebuild: TransactionPrebuild;
5256
}
@@ -145,9 +149,10 @@ export class Ada extends BaseCoin {
145149
}
146150
} else if (verification?.consolidationToBaseAddress) {
147151
const baseAddress = wallet.coinSpecific()?.baseAddress || wallet.coinSpecific()?.rootAddress;
152+
const feeAddress = (txPrebuild.txInfo as AdaTxInfo)?.feeAddress;
148153

149154
for (const output of explainedTx.outputs) {
150-
if (output.address !== baseAddress) {
155+
if (output.address !== baseAddress && output.address !== feeAddress) {
151156
throw new Error('tx outputs does not match with expected address');
152157
}
153158
}

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

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,80 @@ describe('ADA', function () {
322322
}
323323
});
324324

325+
it('should verify a valid sponsored consolidation transaction', async () => {
326+
const consolidationTx = {
327+
txRequestId: '1b5c79c5-ab7c-4f47-912b-de6a95fb0779',
328+
walletId: '64fa31a94db65a0007c9691b',
329+
txHex:
330+
'84a40082825820227f65d20ac6e49602d79c623c51911ead824235e01eb2a1e7e33a72f0747cbb00825820227f65d20ac6e49602d79c623c51911ead824235e01eb2a1e7e33a72f0747cbb0201828258390022098270a5c19c9fb706dce0e7e4566b234ec5f0010623cd63f198ad22098270a5c19c9fb706dce0e7e4566b234ec5f0010623cd63f198ad1a0098968082581d60cf90f9fb02c88bad3c5294d90587458c4f160a2db26ba8af3da255b11a05d42fb8021a0002a491031a06d8c048a0f5f6',
331+
feeInfo: {
332+
fee: 165545,
333+
feeString: '165545',
334+
},
335+
txInfo: {
336+
minerFee: '165545',
337+
spendAmount: '999834455',
338+
spendAmounts: [
339+
{
340+
coinName: 'tada',
341+
amountString: '999834455',
342+
},
343+
],
344+
payGoFee: '0',
345+
outputs: [
346+
{
347+
address:
348+
'addr_test1qprqrlqpdtpctqy3d56jp0rkkevjnq2kqzrn356842f3gt6xq87qz6krskqfzmf4yz78ddje9xq4vqy88rf5025nzshsjdmg2s',
349+
value: 999834455,
350+
wallet: '64fa31a94db65a0007c9691b',
351+
wallets: ['64fa31a94db65a0007c9691b'],
352+
enterprise: '62cc59b727443a0007089033',
353+
enterprises: ['62cc59b727443a0007089033'],
354+
valueString: '999834455',
355+
coinName: 'tada',
356+
walletType: 'hot',
357+
walletTypes: ['hot'],
358+
},
359+
],
360+
inputs: [
361+
{
362+
value: 1000000000,
363+
address:
364+
'addr_test1qqlzxfl7tlgp999x4a7334pchycpkk72pykrsr3mryl3yj6xq87qz6krskqfzmf4yz78ddje9xq4vqy88rf5025nzshsvpgl8w',
365+
valueString: '1000000000',
366+
},
367+
],
368+
type: '0',
369+
feeAddress: 'addr_test1vr8ep70mqtyghtfu222djpv8gkxy79s29kexh2908k39tvge02d5j',
370+
},
371+
consolidateId: '68b9fc18558006aab53785615fea7c28',
372+
coin: 'tada',
373+
};
374+
375+
const mockedWallet = {
376+
coinSpecific: () => {
377+
return {
378+
rootAddress:
379+
'addr_test1qq3qnqns5hqee8ahqmwwpely2e4jxnk97qqsvg7dv0ce3tfzpxp8pfwpnj0mwpkuurn7g4ntyd8vtuqpqc3u6cl3nzksvggu82',
380+
};
381+
},
382+
};
383+
384+
try {
385+
const isVerified = await basecoin.verifyTransaction({
386+
txParams: {},
387+
txPrebuild: consolidationTx,
388+
wallet: mockedWallet,
389+
verification: {
390+
consolidationToBaseAddress: true,
391+
},
392+
});
393+
isVerified.should.equal(true);
394+
} catch (e) {
395+
assert.fail('Transaction should pass verification');
396+
}
397+
});
398+
325399
it('should fail to sign a spoofed consolidation transaction', async function () {
326400
// Set up wallet data
327401
const walletData = {

0 commit comments

Comments
 (0)