File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff 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 } ` ) ;
Original file line number Diff line number Diff line change 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+ } ) ;
You can’t perform that action at this time.
0 commit comments