Skip to content

Commit ddbdb42

Browse files
fix(sdk-coin-tao): fix _outputs accumulation and case-insensitive verify
Two correctness bugs identified by post-commit review: 1. ClaimRootTransaction.loadInputsAndOutputs() used push() without resetting _outputs/_ inputs first. The base TransactionBuilder calls loadInputsAndOutputs() on every build(), so repeated build() calls accumulated duplicate entries in _outputs. Fixed by resetting both arrays at the top of the method before delegating to super and before any push — consistent with how the base Transaction class handles Send/Staking paths via assignment. 2. Tao.verifyTransaction() compared txParams.type with the string literal 'StakingClaim' using strict equality. WalletPlatform delivers intentType as lowercase ('stakingclaim'), causing the bypass to be skipped and execution to fall through to super.verifyTransaction() which accesses _to/_amount (absent on ClaimRootBuilder) and throws 'missing recipients in txParams' for a valid claim transaction. Fixed with toLowerCase() comparison. Also strengthen tests: add case-insensitive lowercase test for verifyTransaction and assert explanation.fee.fee value (tip=0 fallback). Ticket: SI-1171 Session-Id: ab70e181-1628-4e73-9662-8ef3fe0426ba Task-Id: 091af7ce-ed42-4177-9ee0-2231917f41fa
1 parent 8056f08 commit ddbdb42

4 files changed

Lines changed: 15 additions & 1 deletion

File tree

modules/sdk-coin-tao/src/lib/claimRootTransaction.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ export class ClaimRootTransaction extends SubstrateTransaction {
3030
return;
3131
}
3232

33+
this._outputs = [];
34+
this._inputs = [];
35+
3336
super.loadInputsAndOutputs();
3437

3538
const decodedTx = decode(this._substrateTransaction, {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ export class Tao extends SubstrateCoin {
5959
/** @inheritDoc */
6060
async verifyTransaction(params: VerifyTransactionOptions): Promise<boolean> {
6161
// claimRootWithHotkey carries no transfer recipient — skip recipient validation.
62-
if (params.txParams?.type === 'StakingClaim') {
62+
// Compare case-insensitively: WalletPlatform may deliver intentType as lowercase.
63+
if (params.txParams?.type?.toLowerCase() === 'stakingclaim') {
6364
return true;
6465
}
6566
return super.verifyTransaction(params);

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,14 @@ describe('Tao:', function () {
573573
result.should.be.true();
574574
});
575575

576+
it('should return true for lowercase stakingclaim type (WalletPlatform intentType)', async function () {
577+
const result = await baseCoin.verifyTransaction({
578+
txPrebuild: { txHex: claimSignedHex },
579+
txParams: { type: 'stakingclaim' },
580+
});
581+
result.should.be.true();
582+
});
583+
576584
it('should return true for transfer tx with no recipients provided', async function () {
577585
const result = await baseCoin.verifyTransaction({
578586
txPrebuild: { txHex: rawTx.transfer.signed },

modules/sdk-coin-tao/test/unit/transactionBuilder/claimRootBuilder.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ describe('Tao ClaimRoot Builder', function () {
151151
explanation.outputAmount.should.equal('0');
152152
explanation.changeAmount.should.equal('0');
153153
explanation.fee.type.should.equal('tip');
154+
// tip=0 is falsy → || '0' fallback fires; assert the fee value is correct
155+
explanation.fee.fee.should.equal('0');
154156
explanation.outputs.length.should.equal(1);
155157
explanation.outputs[0].address.should.equal(hotkey);
156158
explanation.outputs[0].amount.should.equal('0');

0 commit comments

Comments
 (0)