@@ -58,7 +58,7 @@ describe('CosmosWallet', () => {
5858 expect ( mockClient . enable ) . toHaveBeenCalledWith ( 'cosmoshub-4' ) ;
5959 } ) ;
6060
61- it ( 'should suggest a chain if connection fails with a specific error ' , async ( ) => {
61+ it ( 'should suggest a chain if connection fails with not "Request rejected" ' , async ( ) => {
6262 const mockClient = {
6363 enable : jest . fn ( ) . mockRejectedValue ( new Error ( 'some error' ) ) ,
6464 experimentalSuggestChain : jest . fn ( ) ,
@@ -67,10 +67,23 @@ describe('CosmosWallet', () => {
6767
6868 ( chainRegistryChainToKeplr as jest . Mock ) . mockReturnValue ( { chainId : 'cosmoshub-4' } ) ;
6969
70- await expect ( wallet . connect ( 'cosmoshub-4' ) ) . rejects . toThrow ( 'some error' ) ;
70+ await wallet . connect ( 'cosmoshub-4' ) ;
71+
7172 expect ( mockClient . experimentalSuggestChain ) . toHaveBeenCalledWith ( { chainId : 'cosmoshub-4' } ) ;
7273 } ) ;
7374
75+ it ( 'should not suggest a chain if connection fails with "Request rejected"' , async ( ) => {
76+ const mockClient = {
77+ enable : jest . fn ( ) . mockRejectedValue ( new Error ( 'Request rejected' ) ) ,
78+ experimentalSuggestChain : jest . fn ( ) ,
79+ } ;
80+ wallet . client = mockClient ;
81+
82+ await expect ( wallet . connect ( 'cosmoshub-4' ) ) . rejects . toThrow ( 'Request rejected' ) ;
83+
84+ expect ( mockClient . experimentalSuggestChain ) . not . toHaveBeenCalled ( ) ;
85+ } )
86+
7487 it ( 'should disconnect from a chain' , async ( ) => {
7588 const mockClient = { disable : jest . fn ( ) } ;
7689 wallet . client = mockClient ;
@@ -116,4 +129,14 @@ describe('CosmosWallet', () => {
116129 expect ( chainRegistryChainToKeplr ) . toHaveBeenCalledWith ( cosmosChain , [ cosmosAssetList ] ) ;
117130 expect ( mockClient . experimentalSuggestChain ) . toHaveBeenCalledWith ( { chainId : 'cosmoshub-4' } ) ;
118131 } ) ;
132+
133+ it ( 'should throw an error if adding a suggested chain fails' , async ( ) => {
134+ const mockClient = { experimentalSuggestChain : jest . fn ( ) . mockRejectedValue ( new Error ( 'suggestion error' ) ) } ;
135+ wallet . client = mockClient ;
136+ wallet . chainMap . set ( 'cosmoshub-4' , cosmosChain ) ;
137+
138+ ( chainRegistryChainToKeplr as jest . Mock ) . mockReturnValue ( { chainId : 'cosmoshub-4' } ) ;
139+
140+ await expect ( wallet . addSuggestChain ( 'cosmoshub-4' ) ) . rejects . toThrow ( 'suggestion error' ) ;
141+ } ) ;
119142} ) ;
0 commit comments