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
6 changes: 4 additions & 2 deletions modules/sdk-coin-tao/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ export class Utils extends SubstrateUtils {
return (networkType === NetworkType.MAINNET ? mainnetMaterial : testnetMaterial) as unknown as Interface.Material;
}

getTaoTokenBySubnetId(subnetId: string): Readonly<CoinConfig> {
const tokens = coins.filter((coin) => coin instanceof TaoCoin && coin.subnetId === subnetId).map((coin) => coin);
getTaoTokenBySubnetId(subnetId: string | number): Readonly<CoinConfig> {
const tokens = coins
.filter((coin) => coin instanceof TaoCoin && coin.subnetId === String(subnetId))
.map((coin) => coin);

assert(tokens.length > 0, `No Tao token found for subnetId: ${subnetId}`);
assert(tokens.length === 1, `Multiple Tao tokens found for subnetId: ${subnetId}`);
Expand Down
24 changes: 24 additions & 0 deletions modules/sdk-coin-tao/test/unit/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import utils from '../../src/lib/utils';

describe('Tao utils', function () {
describe('getTaoTokenBySubnetId', function () {
it('should succeed for valid string subnetId', function () {
const token = utils.getTaoTokenBySubnetId('1');
token.name.should.equal('ttao:apex');
});
it('should succeed for valid number subnetId', function () {
const token = utils.getTaoTokenBySubnetId(1);
token.name.should.equal('ttao:apex');
});
it('should fail for invalid subnetId', function () {
(() => utils.getTaoTokenBySubnetId('invalid')).should.throw('No Tao token found for subnetId: invalid');
});
it('should fail for non-existent subnetId', function () {
(() => utils.getTaoTokenBySubnetId(999)).should.throw('No Tao token found for subnetId: 999');
});
it('should fail for undefined subnetId', function () {
// @ts-expect-error testing failure case
(() => utils.getTaoTokenBySubnetId(undefined)).should.throw('No Tao token found for subnetId: undefined');
});
});
});