Skip to content

Commit f02c1bb

Browse files
abhijit0943joshisakshi
authored andcommitted
unstaking builder test changes
1 parent 6107abc commit f02c1bb

File tree

5 files changed

+39
-24
lines changed

5 files changed

+39
-24
lines changed

modules/abstract-substrate/src/lib/iface.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,14 @@ export interface TxData {
5151
chainName: string;
5252
method?: string;
5353
specName?: string;
54-
amount?: number;
54+
amount?: string;
5555
to?: string;
5656
tip?: number;
5757
eraPeriod?: number;
5858
payee?: string;
5959
keepAlive?: boolean;
60+
netuid?: number;
61+
hotkey?: string;
6062
}
6163

6264
/**

modules/abstract-substrate/src/lib/transaction.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,20 @@ export class Transaction extends BaseTransaction {
168168
} else {
169169
throw new ParseTransactionError(`Serializing unknown Transfer type parameters`);
170170
}
171+
} else if (this.type === TransactionType.StakingDeactivate) {
172+
// fill this up
173+
const txMethod = decodedTx.method.args;
174+
if (utils.isUnstake(txMethod)) {
175+
const keypair = new KeyPair({
176+
pub: Buffer.from(decodeAddress(txMethod.hotkey)).toString('hex'),
177+
});
178+
result.to = keypair.getAddress(this.getAddressFormat());
179+
result.amount = txMethod.amountUnstaked.toString();
180+
result.netuid = txMethod.netuid;
181+
}
182+
} else {
183+
throw new ParseTransactionError(`Serializing unknown Transfer type parameters`);
171184
}
172-
173185
return result;
174186
}
175187

modules/abstract-substrate/src/lib/utils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import bs58 from 'bs58';
1313
import base32 from 'hi-base32';
1414
import nacl from 'tweetnacl';
1515
import { KeyPair } from '.';
16-
import { HexString, Material, TransferAllArgs, TransferArgs, TxMethod } from './iface';
16+
import { HexString, Material, TransferAllArgs, TransferArgs, TxMethod, UnstakeArgs } from './iface';
1717

1818
export class Utils implements BaseUtils {
1919
/** @inheritdoc */
@@ -195,6 +195,9 @@ export class Utils implements BaseUtils {
195195
return (arg as TransferAllArgs).dest?.id !== undefined && (arg as TransferAllArgs).keepAlive !== undefined;
196196
}
197197

198+
isUnstake(arg: TxMethod['args']): arg is UnstakeArgs {
199+
return (arg as UnstakeArgs).hotkey !== undefined && (arg as UnstakeArgs).netuid !== undefined;
200+
}
198201
/**
199202
* extracts and returns the signature in hex format given a raw signed transaction
200203
*

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

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

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

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('Tao Unstake Builder', function () {
1212
beforeEach(function () {
1313
const config = buildTestConfig();
1414
const material = utils.getMaterial(config.network.type);
15-
// console.log('Material:', material);
15+
//console.log('Material:', material);
1616
builder = new UnstakeBuilder(config).material(material);
1717
});
1818
describe('setter validation', function () {
@@ -38,14 +38,14 @@ describe('Tao Unstake Builder', function () {
3838
.sequenceId({ name: 'Nonce', keyword: 'nonce', value: 200 })
3939
.fee({ amount: 0, type: 'tip' })
4040
.addSignature({ pub: sender.publicKey }, Buffer.from(mockTssSignature, 'hex'));
41-
41+
// console.log('Builder after setting properties:', builder);
4242
const tx = await builder.build();
43-
// console.log('Transaction built:', tx);
43+
// console.log('Transaction built:', tx);
4444
const txJson = tx.toJson();
45-
console.log('Transaction JSON:', JSON.stringify(txJson, null, 2));
46-
should.deepEqual(txJson.amount, 50000000000000);
47-
should.deepEqual(txJson.hotkey, '5H56KVtb3sSMxuhFsH51iFi1gei7tnBQjpVmj6hu9tK7CBDR');
48-
should.deepEqual(txJson.netuid, 0);
45+
// console.log('Transaction JSON:', JSON.stringify(txJson, null, 2));
46+
should.deepEqual(txJson.amount, '50000000000000');
47+
should.deepEqual(txJson.to, '5H56KVtb3sSMxuhFsH51iFi1gei7tnBQjpVmj6hu9tK7CBDR');
48+
should.deepEqual(txJson.netuid, '0');
4949
should.deepEqual(txJson.sender, sender.address);
5050
should.deepEqual(txJson.blockNumber, 3933);
5151
should.deepEqual(txJson.referenceBlock, referenceBlock);
@@ -67,14 +67,12 @@ describe('Tao Unstake Builder', function () {
6767
.referenceBlock(referenceBlock)
6868
.sequenceId({ name: 'Nonce', keyword: 'nonce', value: 200 })
6969
.fee({ amount: 0, type: 'tip' });
70-
// console.log('Builder after setting properties:', builder);
7170
console.log('Building transaction...');
7271
const tx = await builder.build();
7372
const txJson = tx.toJson();
74-
// console.log('Transaction JSON:', JSON.stringify(txJson, null, 2));
75-
should.deepEqual(txJson.amount, 50000000000000);
76-
should.deepEqual(txJson.hotkey, '5H56KVtb3sSMxuhFsH51iFi1gei7tnBQjpVmj6hu9tK7CBDR');
77-
should.deepEqual(txJson.netuid, 0);
73+
should.deepEqual(txJson.amount, '50000000000000');
74+
should.deepEqual(txJson.to, '5H56KVtb3sSMxuhFsH51iFi1gei7tnBQjpVmj6hu9tK7CBDR');
75+
should.deepEqual(txJson.netuid, '0');
7876
should.deepEqual(txJson.sender, sender.address);
7977
should.deepEqual(txJson.blockNumber, 3933);
8078
should.deepEqual(txJson.referenceBlock, referenceBlock);
@@ -88,12 +86,12 @@ describe('Tao Unstake Builder', function () {
8886
});
8987
it('should build from raw signed tx', async function () {
9088
builder.from(rawTx.unstake.signed);
91-
builder.validity({ firstValid: 3933, maxDuration: 64 }).referenceBlock(referenceBlock);
89+
// builder.validity({ firstValid: 3933, maxDuration: 64 }).referenceBlock(referenceBlock);
9290
const tx = await builder.build();
9391
const txJson = tx.toJson();
94-
should.deepEqual(txJson.amount, 50000000000000);
95-
should.deepEqual(txJson.hotkey, '5H56KVtb3sSMxuhFsH51iFi1gei7tnBQjpVmj6hu9tK7CBDR');
96-
should.deepEqual(txJson.netuid, 0);
92+
should.deepEqual(txJson.amount, '50000000000000');
93+
should.deepEqual(txJson.to, '5H56KVtb3sSMxuhFsH51iFi1gei7tnBQjpVmj6hu9tK7CBDR');
94+
should.deepEqual(txJson.netuid, '0');
9795
should.deepEqual(txJson.sender, '5F1mFBGhm7FrSKftDxzFPN8U1BqHKSAxEDhTV2Yx5JhCe2Nk');
9896
should.deepEqual(txJson.blockNumber, 3933);
9997
should.deepEqual(txJson.referenceBlock, referenceBlock);
@@ -114,9 +112,9 @@ describe('Tao Unstake Builder', function () {
114112
.addSignature({ pub: sender.publicKey }, Buffer.from(mockTssSignature, 'hex'));
115113
const tx = await builder.build();
116114
const txJson = tx.toJson();
117-
should.deepEqual(txJson.amount, 50000000000000);
118-
should.deepEqual(txJson.hotkey, '5H56KVtb3sSMxuhFsH51iFi1gei7tnBQjpVmj6hu9tK7CBDR');
119-
should.deepEqual(txJson.netuid, 0);
115+
should.deepEqual(txJson.amount, '50000000000000');
116+
should.deepEqual(txJson.to, '5H56KVtb3sSMxuhFsH51iFi1gei7tnBQjpVmj6hu9tK7CBDR');
117+
should.deepEqual(txJson.netuid, '0');
120118
should.deepEqual(txJson.sender, '5F1mFBGhm7FrSKftDxzFPN8U1BqHKSAxEDhTV2Yx5JhCe2Nk');
121119
should.deepEqual(txJson.blockNumber, 3933);
122120
should.deepEqual(txJson.referenceBlock, referenceBlock);

0 commit comments

Comments
 (0)