Skip to content

Commit 18caa10

Browse files
committed
fix(sdk-coin-tao): handle subnetId as number
Ticket: WIN-6439
1 parent e6953f2 commit 18caa10

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ export class Utils extends SubstrateUtils {
88
return (networkType === NetworkType.MAINNET ? mainnetMaterial : testnetMaterial) as unknown as Interface.Material;
99
}
1010

11-
getTaoTokenBySubnetId(subnetId: string): Readonly<CoinConfig> {
12-
const tokens = coins.filter((coin) => coin instanceof TaoCoin && coin.subnetId === subnetId).map((coin) => coin);
11+
getTaoTokenBySubnetId(subnetId: string | number): Readonly<CoinConfig> {
12+
const tokens = coins
13+
.filter((coin) => coin instanceof TaoCoin && coin.subnetId === String(subnetId))
14+
.map((coin) => coin);
1315

1416
assert(tokens.length > 0, `No Tao token found for subnetId: ${subnetId}`);
1517
assert(tokens.length === 1, `Multiple Tao tokens found for subnetId: ${subnetId}`);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import utils from '../../src/lib/utils';
2+
3+
describe('Tao utils', function () {
4+
describe('getTaoTokenBySubnetId', function () {
5+
it('should succeed for valid string subnetId', function () {
6+
const token = utils.getTaoTokenBySubnetId('1');
7+
token.name.should.equal('ttao:apex');
8+
});
9+
it('should succeed for valid number subnetId', function () {
10+
const token = utils.getTaoTokenBySubnetId(1);
11+
token.name.should.equal('ttao:apex');
12+
});
13+
it('should fail for invalid subnetId', function () {
14+
(() => utils.getTaoTokenBySubnetId('invalid')).should.throw('No Tao token found for subnetId: invalid');
15+
});
16+
it('should fail for non-existent subnetId', function () {
17+
(() => utils.getTaoTokenBySubnetId(999)).should.throw('No Tao token found for subnetId: 999');
18+
});
19+
it('should fail for undefined subnetId', function () {
20+
// @ts-expect-error testing failure case
21+
(() => utils.getTaoTokenBySubnetId(undefined)).should.throw('No Tao token found for subnetId: undefined');
22+
});
23+
});
24+
});

0 commit comments

Comments
 (0)