@@ -52,6 +52,13 @@ const unrecognisedChainError = {
5252 } ,
5353} ;
5454
55+ const anotherUnrecognisedChainError = {
56+ error : {
57+ message : 'Provider error' ,
58+ code : 4902 ,
59+ } ,
60+ } ;
61+
5562jest . mock ( '../api/http' , ( ) => ( {
5663 // eslint-disable-next-line @typescript-eslint/naming-convention
5764 HttpClient : jest . fn ( ) . mockImplementation ( ( ) => ( {
@@ -342,6 +349,54 @@ describe('network functions', () => {
342349 ] ) ;
343350 } ) ;
344351
352+ it ( 'should request the user to add a new network when anotherUnrecognisedChainError is received' , async ( ) => {
353+ ( WrappedBrowserProvider as unknown as jest . Mock )
354+ . mockReturnValueOnce ( {
355+ send : jest
356+ . fn ( )
357+ . mockRejectedValueOnce ( anotherUnrecognisedChainError )
358+ . mockResolvedValueOnce ( { } ) ,
359+ ethereumProvider : {
360+ isMetaMask : true ,
361+ } ,
362+ getNetwork : jest . fn ( ) . mockResolvedValue ( zkevmNetworkInfo ) ,
363+ } )
364+ . mockReturnValueOnce ( {
365+ send : jest . fn ( ) . mockResolvedValueOnce ( { } ) ,
366+ ethereumProvider : {
367+ isMetaMask : true ,
368+ } ,
369+ getNetwork : jest . fn ( ) . mockResolvedValue ( zkevmNetworkInfo ) ,
370+ } ) ;
371+ const { provider } = await createProvider ( WalletProviderName . METAMASK ) ;
372+
373+ await switchWalletNetwork (
374+ testCheckoutConfiguration ,
375+ provider ,
376+ ChainId . IMTBL_ZKEVM_TESTNET ,
377+ ) ;
378+
379+ expect ( provider . send ) . toHaveBeenCalledWith ( WalletAction . ADD_NETWORK , [
380+ {
381+ chainId : testCheckoutConfiguration . networkMap . get (
382+ ChainId . IMTBL_ZKEVM_TESTNET ,
383+ ) ?. chainIdHex ,
384+ chainName : testCheckoutConfiguration . networkMap . get (
385+ ChainId . IMTBL_ZKEVM_TESTNET ,
386+ ) ?. chainName ,
387+ rpcUrls : testCheckoutConfiguration . networkMap . get (
388+ ChainId . IMTBL_ZKEVM_TESTNET ,
389+ ) ?. rpcUrls ,
390+ nativeCurrency : testCheckoutConfiguration . networkMap . get (
391+ ChainId . IMTBL_ZKEVM_TESTNET ,
392+ ) ?. nativeCurrency ,
393+ blockExplorerUrls : testCheckoutConfiguration . networkMap . get (
394+ ChainId . IMTBL_ZKEVM_TESTNET ,
395+ ) ?. blockExplorerUrls ,
396+ } ,
397+ ] ) ;
398+ } ) ;
399+
345400 it ( 'should throw an error when switch network is called with a passport provider' , async ( ) => {
346401 try {
347402 await switchWalletNetwork (
0 commit comments