From 4a918756c18512a57e81dc55d8a58f250ee638b5 Mon Sep 17 00:00:00 2001 From: raksha-r7 Date: Tue, 16 Sep 2025 11:21:16 +0530 Subject: [PATCH] fix: resolve type annotation error in TransactionBuilderFactory Ticket: SC-3131 --- .../sdk-coin-tao/src/lib/moveStakeBuilder.ts | 10 ++-- .../src/lib/transactionBuilderFactory.ts | 2 +- .../transactionBuilder/moveStakeBuilder.ts | 60 ++++++++++--------- 3 files changed, 37 insertions(+), 35 deletions(-) diff --git a/modules/sdk-coin-tao/src/lib/moveStakeBuilder.ts b/modules/sdk-coin-tao/src/lib/moveStakeBuilder.ts index 03c0cede32..138fa1ef38 100644 --- a/modules/sdk-coin-tao/src/lib/moveStakeBuilder.ts +++ b/modules/sdk-coin-tao/src/lib/moveStakeBuilder.ts @@ -1,5 +1,5 @@ import { Interface, Schema, Transaction, TransactionBuilder } from '@bitgo/abstract-substrate'; -import { InvalidTransactionError, TransactionType } from '@bitgo/sdk-core'; +import { InvalidTransactionError, TransactionType, BaseAddress } from '@bitgo/sdk-core'; import { BaseCoin as CoinConfig } from '@bitgo/statics'; import { DecodedSignedTx, DecodedSigningPayload, defineMethod, UnsignedTransaction } from '@substrate/txwrapper-core'; import BigNumber from 'bignumber.js'; @@ -58,7 +58,7 @@ export class MoveStakeBuilder extends TransactionBuilder { * @param {string} address of origin hotkey * @returns {MoveStakeBuilder} This builder. */ - originHotkey(address: string): this { + originHotkey({ address }: BaseAddress): this { this.validateAddress({ address }); this._originHotkey = address; return this; @@ -69,7 +69,7 @@ export class MoveStakeBuilder extends TransactionBuilder { * @param {string} address of destination hotkey * @returns {MoveStakeBuilder} This builder. */ - destinationHotkey(address: string): this { + destinationHotkey({ address }: BaseAddress): this { this.validateAddress({ address }); this._destinationHotkey = address; return this; @@ -107,8 +107,8 @@ export class MoveStakeBuilder extends TransactionBuilder { const tx = super.fromImplementation(rawTransaction); const txMethod = this._method.args as Interface.MoveStakeArgs; this.amount(txMethod.alphaAmount); - this.originHotkey(txMethod.originHotkey); - this.destinationHotkey(txMethod.destinationHotkey); + this.originHotkey({ address: txMethod.originHotkey }); + this.destinationHotkey({ address: txMethod.destinationHotkey }); this.originNetuid(txMethod.originNetuid); this.destinationNetuid(txMethod.destinationNetuid); return tx; diff --git a/modules/sdk-coin-tao/src/lib/transactionBuilderFactory.ts b/modules/sdk-coin-tao/src/lib/transactionBuilderFactory.ts index f0af01ce34..476a4fb1ee 100644 --- a/modules/sdk-coin-tao/src/lib/transactionBuilderFactory.ts +++ b/modules/sdk-coin-tao/src/lib/transactionBuilderFactory.ts @@ -33,7 +33,7 @@ export class TransactionBuilderFactory extends BaseTransactionBuilderFactory { return new TokenTransferBuilder(this._coinConfig).material(this._material); } - getMoveStakeBuilder(): TransactionBuilder { + getMoveStakeBuilder(): MoveStakeBuilder { return new MoveStakeBuilder(this._coinConfig).material(this._material); } diff --git a/modules/sdk-coin-tao/test/unit/transactionBuilder/moveStakeBuilder.ts b/modules/sdk-coin-tao/test/unit/transactionBuilder/moveStakeBuilder.ts index 668e156c1c..3feedc8184 100644 --- a/modules/sdk-coin-tao/test/unit/transactionBuilder/moveStakeBuilder.ts +++ b/modules/sdk-coin-tao/test/unit/transactionBuilder/moveStakeBuilder.ts @@ -43,15 +43,17 @@ describe('Tao Move Stake Builder', function () { it('should validate addresses', function () { const spyValidateAddress = spy(builder, 'validateAddress'); assert.throws( - () => builder.originHotkey('abc'), + () => builder.originHotkey({ address: 'abc' }), (e: Error) => e.message === `The address 'abc' is not a well-formed dot address` ); assert.throws( - () => builder.destinationHotkey('abc'), + () => builder.destinationHotkey({ address: 'abc' }), (e: Error) => e.message === `The address 'abc' is not a well-formed dot address` ); - should.doesNotThrow(() => builder.originHotkey('5FCPTnjevGqAuTttetBy4a24Ej3pH9fiQ8fmvP1ZkrVsLUoT')); - should.doesNotThrow(() => builder.destinationHotkey('5Ffp1wJCPu4hzVDTo7XaMLqZSvSadyUQmxWPDw74CBjECSoq')); + should.doesNotThrow(() => builder.originHotkey({ address: '5FCPTnjevGqAuTttetBy4a24Ej3pH9fiQ8fmvP1ZkrVsLUoT' })); + should.doesNotThrow(() => + builder.destinationHotkey({ address: '5Ffp1wJCPu4hzVDTo7XaMLqZSvSadyUQmxWPDw74CBjECSoq' }) + ); SinonAssert.callCount(spyValidateAddress, 4); }); @@ -61,8 +63,8 @@ describe('Tao Move Stake Builder', function () { it('should build a move stake transaction', async function () { builder .amount('9007199254740995') - .originHotkey('5FCPTnjevGqAuTttetBy4a24Ej3pH9fiQ8fmvP1ZkrVsLUoT') - .destinationHotkey('5Ffp1wJCPu4hzVDTo7XaMLqZSvSadyUQmxWPDw74CBjECSoq') + .originHotkey({ address: '5FCPTnjevGqAuTttetBy4a24Ej3pH9fiQ8fmvP1ZkrVsLUoT' }) + .destinationHotkey({ address: '5Ffp1wJCPu4hzVDTo7XaMLqZSvSadyUQmxWPDw74CBjECSoq' }) .originNetuid('1') .destinationNetuid('1') .sender({ address: sender.address }) @@ -136,8 +138,8 @@ describe('Tao Move Stake Builder', function () { it('should build transaction with different netuids', async function () { builder .amount('1000000000000') - .originHotkey('5FCPTnjevGqAuTttetBy4a24Ej3pH9fiQ8fmvP1ZkrVsLUoT') - .destinationHotkey('5Ffp1wJCPu4hzVDTo7XaMLqZSvSadyUQmxWPDw74CBjECSoq') + .originHotkey({ address: '5FCPTnjevGqAuTttetBy4a24Ej3pH9fiQ8fmvP1ZkrVsLUoT' }) + .destinationHotkey({ address: '5Ffp1wJCPu4hzVDTo7XaMLqZSvSadyUQmxWPDw74CBjECSoq' }) .originNetuid('1') .destinationNetuid('2') .sender({ address: sender.address }) @@ -163,8 +165,8 @@ describe('Tao Move Stake Builder', function () { should.doesNotThrow(() => { builder .amount('1000000000000') - .originHotkey('5FCPTnjevGqAuTttetBy4a24Ej3pH9fiQ8fmvP1ZkrVsLUoT') - .destinationHotkey('5Ffp1wJCPu4hzVDTo7XaMLqZSvSadyUQmxWPDw74CBjECSoq') + .originHotkey({ address: '5FCPTnjevGqAuTttetBy4a24Ej3pH9fiQ8fmvP1ZkrVsLUoT' }) + .destinationHotkey({ address: '5Ffp1wJCPu4hzVDTo7XaMLqZSvSadyUQmxWPDw74CBjECSoq' }) .originNetuid('1') .destinationNetuid('1'); }); @@ -231,8 +233,8 @@ describe('Tao Move Stake Builder', function () { it('should build a signed move stake transaction with TSS signature', async function () { builder .amount('9007199254740995') - .originHotkey('5FCPTnjevGqAuTttetBy4a24Ej3pH9fiQ8fmvP1ZkrVsLUoT') - .destinationHotkey('5Ffp1wJCPu4hzVDTo7XaMLqZSvSadyUQmxWPDw74CBjECSoq') + .originHotkey({ address: '5FCPTnjevGqAuTttetBy4a24Ej3pH9fiQ8fmvP1ZkrVsLUoT' }) + .destinationHotkey({ address: '5Ffp1wJCPu4hzVDTo7XaMLqZSvSadyUQmxWPDw74CBjECSoq' }) .originNetuid('1') .destinationNetuid('1') .sender({ address: sender.address }) @@ -265,8 +267,8 @@ describe('Tao Move Stake Builder', function () { it('should build an unsigned move stake transaction', async function () { builder .amount('50000000') - .originHotkey('5FCPTnjevGqAuTttetBy4a24Ej3pH9fiQ8fmvP1ZkrVsLUoT') - .destinationHotkey('5Ffp1wJCPu4hzVDTo7XaMLqZSvSadyUQmxWPDw74CBjECSoq') + .originHotkey({ address: '5FCPTnjevGqAuTttetBy4a24Ej3pH9fiQ8fmvP1ZkrVsLUoT' }) + .destinationHotkey({ address: '5Ffp1wJCPu4hzVDTo7XaMLqZSvSadyUQmxWPDw74CBjECSoq' }) .originNetuid('1') .destinationNetuid('2') .sender({ address: sender.address }) @@ -300,7 +302,7 @@ describe('Tao Move Stake Builder', function () { it('should throw error for missing origin hotkey', function () { builder .amount('1000000000000') - .destinationHotkey('5Ffp1wJCPu4hzVDTo7XaMLqZSvSadyUQmxWPDw74CBjECSoq') + .destinationHotkey({ address: '5Ffp1wJCPu4hzVDTo7XaMLqZSvSadyUQmxWPDw74CBjECSoq' }) .originNetuid('1') .destinationNetuid('1'); @@ -313,7 +315,7 @@ describe('Tao Move Stake Builder', function () { it('should throw error for missing destination hotkey', function () { builder .amount('1000000000000') - .originHotkey('5FCPTnjevGqAuTttetBy4a24Ej3pH9fiQ8fmvP1ZkrVsLUoT') + .originHotkey({ address: '5FCPTnjevGqAuTttetBy4a24Ej3pH9fiQ8fmvP1ZkrVsLUoT' }) .originNetuid('1') .destinationNetuid('1'); @@ -326,8 +328,8 @@ describe('Tao Move Stake Builder', function () { it('should throw error for missing origin netuid', function () { builder .amount('1000000000000') - .originHotkey('5FCPTnjevGqAuTttetBy4a24Ej3pH9fiQ8fmvP1ZkrVsLUoT') - .destinationHotkey('5Ffp1wJCPu4hzVDTo7XaMLqZSvSadyUQmxWPDw74CBjECSoq') + .originHotkey({ address: '5FCPTnjevGqAuTttetBy4a24Ej3pH9fiQ8fmvP1ZkrVsLUoT' }) + .destinationHotkey({ address: '5Ffp1wJCPu4hzVDTo7XaMLqZSvSadyUQmxWPDw74CBjECSoq' }) .destinationNetuid('1'); assert.throws( @@ -339,8 +341,8 @@ describe('Tao Move Stake Builder', function () { it('should throw error for missing destination netuid', function () { builder .amount('1000000000000') - .originHotkey('5FCPTnjevGqAuTttetBy4a24Ej3pH9fiQ8fmvP1ZkrVsLUoT') - .destinationHotkey('5Ffp1wJCPu4hzVDTo7XaMLqZSvSadyUQmxWPDw74CBjECSoq') + .originHotkey({ address: '5FCPTnjevGqAuTttetBy4a24Ej3pH9fiQ8fmvP1ZkrVsLUoT' }) + .destinationHotkey({ address: '5Ffp1wJCPu4hzVDTo7XaMLqZSvSadyUQmxWPDw74CBjECSoq' }) .originNetuid('1'); assert.throws( @@ -351,8 +353,8 @@ describe('Tao Move Stake Builder', function () { it('should throw error for missing amount', function () { builder - .originHotkey('5FCPTnjevGqAuTttetBy4a24Ej3pH9fiQ8fmvP1ZkrVsLUoT') - .destinationHotkey('5Ffp1wJCPu4hzVDTo7XaMLqZSvSadyUQmxWPDw74CBjECSoq') + .originHotkey({ address: '5FCPTnjevGqAuTttetBy4a24Ej3pH9fiQ8fmvP1ZkrVsLUoT' }) + .destinationHotkey({ address: '5Ffp1wJCPu4hzVDTo7XaMLqZSvSadyUQmxWPDw74CBjECSoq' }) .originNetuid('1') .destinationNetuid('1'); @@ -402,7 +404,7 @@ describe('Tao Move Stake Builder', function () { it('should handle same origin and destination hotkeys', function () { const sameAddress = '5FCPTnjevGqAuTttetBy4a24Ej3pH9fiQ8fmvP1ZkrVsLUoT'; should.doesNotThrow(() => { - builder.originHotkey(sameAddress).destinationHotkey(sameAddress); + builder.originHotkey({ address: sameAddress }).destinationHotkey({ address: sameAddress }); }); }); @@ -422,11 +424,11 @@ describe('Tao Move Stake Builder', function () { invalidAddresses.forEach((address) => { assert.throws( - () => builder.originHotkey(address), + () => builder.originHotkey({ address }), (e: Error) => e.message.includes('is not a well-formed dot address') ); assert.throws( - () => builder.destinationHotkey(address), + () => builder.destinationHotkey({ address }), (e: Error) => e.message.includes('is not a well-formed dot address') ); }); @@ -453,8 +455,8 @@ describe('Tao Move Stake Builder', function () { it('should provide correct explanation with different subnet tokens', async function () { builder .amount('1000000000000') - .originHotkey('5FCPTnjevGqAuTttetBy4a24Ej3pH9fiQ8fmvP1ZkrVsLUoT') - .destinationHotkey('5Ffp1wJCPu4hzVDTo7XaMLqZSvSadyUQmxWPDw74CBjECSoq') + .originHotkey({ address: '5FCPTnjevGqAuTttetBy4a24Ej3pH9fiQ8fmvP1ZkrVsLUoT' }) + .destinationHotkey({ address: '5Ffp1wJCPu4hzVDTo7XaMLqZSvSadyUQmxWPDw74CBjECSoq' }) .originNetuid('1') .destinationNetuid('2') .sender({ address: sender.address }) @@ -479,8 +481,8 @@ describe('Tao Move Stake Builder', function () { it('should handle explanation with zero tip', async function () { builder .amount('500000000') - .originHotkey('5FCPTnjevGqAuTttetBy4a24Ej3pH9fiQ8fmvP1ZkrVsLUoT') - .destinationHotkey('5Ffp1wJCPu4hzVDTo7XaMLqZSvSadyUQmxWPDw74CBjECSoq') + .originHotkey({ address: '5FCPTnjevGqAuTttetBy4a24Ej3pH9fiQ8fmvP1ZkrVsLUoT' }) + .destinationHotkey({ address: '5Ffp1wJCPu4hzVDTo7XaMLqZSvSadyUQmxWPDw74CBjECSoq' }) .originNetuid('1') .destinationNetuid('1') .sender({ address: sender.address })