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
10 changes: 5 additions & 5 deletions modules/sdk-coin-tao/src/lib/moveStakeBuilder.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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 })
Expand Down Expand Up @@ -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 })
Expand All @@ -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');
});
Expand Down Expand Up @@ -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 })
Expand Down Expand Up @@ -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 })
Expand Down Expand Up @@ -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');

Expand All @@ -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');

Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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');

Expand Down Expand Up @@ -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 });
});
});

Expand All @@ -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')
);
});
Expand All @@ -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 })
Expand All @@ -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 })
Expand Down