diff --git a/modules/sdk-coin-tao/src/lib/utils.ts b/modules/sdk-coin-tao/src/lib/utils.ts index 1f85d04953..8a0b702a19 100644 --- a/modules/sdk-coin-tao/src/lib/utils.ts +++ b/modules/sdk-coin-tao/src/lib/utils.ts @@ -8,8 +8,10 @@ export class Utils extends SubstrateUtils { return (networkType === NetworkType.MAINNET ? mainnetMaterial : testnetMaterial) as unknown as Interface.Material; } - getTaoTokenBySubnetId(subnetId: string): Readonly { - const tokens = coins.filter((coin) => coin instanceof TaoCoin && coin.subnetId === subnetId).map((coin) => coin); + getTaoTokenBySubnetId(subnetId: string | number): Readonly { + 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}`); diff --git a/modules/sdk-coin-tao/test/unit/util.ts b/modules/sdk-coin-tao/test/unit/util.ts new file mode 100644 index 0000000000..2a3329c4ad --- /dev/null +++ b/modules/sdk-coin-tao/test/unit/util.ts @@ -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'); + }); + }); +});