@@ -821,6 +821,48 @@ describe('CoinMap', function () {
821821 coinMap . has ( coin . name ) . should . be . false ( ) ;
822822 coinMap . has ( newCoin . name ) . should . be . true ( ) ;
823823 } ) ;
824+
825+ describe ( 'coinNameFromChainId' , function ( ) {
826+ it ( 'should return coin name from legacy hardcoded mappings' , ( ) => {
827+ // Test backward compatibility with existing hardcoded mappings
828+ const ethCoinName = coins . coinNameFromChainId ( 1 ) ;
829+ should ( ethCoinName ) . not . be . undefined ( ) ;
830+ ethCoinName ! . should . equal ( 'eth' ) ;
831+ const polygonCoinName = coins . coinNameFromChainId ( 137 ) ;
832+ should ( polygonCoinName ) . not . be . undefined ( ) ;
833+ polygonCoinName ! . should . equal ( 'polygon' ) ;
834+ const arbethCoinName = coins . coinNameFromChainId ( 42161 ) ;
835+ should ( arbethCoinName ) . not . be . undefined ( ) ;
836+ arbethCoinName ! . should . equal ( 'arbeth' ) ;
837+ const baseethCoinName = coins . coinNameFromChainId ( 8453 ) ;
838+ should ( baseethCoinName ) . not . be . undefined ( ) ;
839+ baseethCoinName ! . should . equal ( 'baseeth' ) ;
840+ } ) ;
841+
842+ it ( 'should return coin name from dynamic lookup when not in legacy map' , ( ) => {
843+ // Test dynamic lookup for coins defined in networks.ts but not in legacy map
844+ // tdogeos is not present in legacy map but has chainId 6281971 in networks.ts
845+ const coinName = coins . coinNameFromChainId ( 6281971 ) ;
846+ should ( coinName ) . not . be . undefined ( ) ;
847+ coinName ! . should . equal ( 'tdogeos' ) ;
848+
849+ // Verify the coin exists and has the correct chainId
850+ const coin = coins . get ( coinName ! ) ;
851+ const network = coin . network as EthereumNetwork ;
852+ network . chainId . should . equal ( 6281971 ) ;
853+ } ) ;
854+
855+ it ( 'should return undefined for non-existent chainId' , ( ) => {
856+ const result = coins . coinNameFromChainId ( 999999 ) ;
857+ should ( result ) . be . undefined ( ) ;
858+ } ) ;
859+
860+ it ( 'should prioritize legacy mappings over dynamic lookup' , ( ) => {
861+ const ethCoinName = coins . coinNameFromChainId ( 1 ) ;
862+ should ( ethCoinName ) . not . be . undefined ( ) ;
863+ ethCoinName ! . should . equal ( 'eth' ) ;
864+ } ) ;
865+ } ) ;
824866} ) ;
825867
826868coins . forEach ( ( coin , coinName ) => {
@@ -1295,7 +1337,8 @@ describe('create token map using config details', () => {
12951337 token ?. family . should . eql ( coin . family ) ;
12961338 token ?. decimalPlaces . should . eql ( coin . decimalPlaces ) ;
12971339 if ( token instanceof EthLikeErc20Token ) {
1298- ( token as EthLikeErc20Token ) . tokenContractAddress . should . eql ( coin ?. contractAddress ) ;
1340+ const erc20Coin = coin as Erc20Coin ;
1341+ ( token as EthLikeErc20Token ) . tokenContractAddress . should . eql ( erc20Coin . contractAddress ) ;
12991342 }
13001343 }
13011344 } ) ;
0 commit comments