@@ -40,6 +40,21 @@ jest.mock('./permissions', () => ({
40
40
} ) ,
41
41
} ) ) ;
42
42
43
+ export const createMockNetworkConfiguration = (
44
+ override ?: Partial < NetworkConfiguration > ,
45
+ ) : NetworkConfiguration => {
46
+ return {
47
+ chainId : CHAIN_IDS . SEPOLIA ,
48
+ blockExplorerUrls : [ ] ,
49
+ defaultRpcEndpointIndex : 0 ,
50
+ name : 'Mock Network' ,
51
+ nativeCurrency : 'MOCK TOKEN' ,
52
+ rpcEndpoints : [ ] ,
53
+ defaultBlockExplorerUrlIndex : 0 ,
54
+ ...override ,
55
+ } ;
56
+ } ;
57
+
43
58
const mockAccount = {
44
59
address : '0x758b8178a9A4B7206d1f648c4a77C515Cbac7001' ,
45
60
id : 'mock-id' ,
@@ -210,6 +225,20 @@ describe('MMIController', function () {
210
225
InfuraNetworkType [ 'sepolia' ] ,
211
226
) ;
212
227
228
+ controllerMessenger . registerActionHandler (
229
+ 'NetworkController:getNetworkClientById' ,
230
+ jest . fn ( ) . mockReturnValue ( {
231
+ configuration : {
232
+ chainId : CHAIN_IDS . SEPOLIA ,
233
+ }
234
+ } ) ,
235
+ ) ;
236
+
237
+ controllerMessenger . registerActionHandler (
238
+ 'NetworkController:getNetworkConfigurationByChainId' ,
239
+ jest . fn ( ) . mockReturnValue ( createMockNetworkConfiguration ( ) ) ,
240
+ ) ;
241
+
213
242
const mmiControllerMessenger = controllerMessenger . getRestricted ( {
214
243
name : 'MMIController' ,
215
244
allowedActions : [
@@ -219,7 +248,9 @@ describe('MMIController', function () {
219
248
'AccountsController:getSelectedAccount' ,
220
249
'AccountsController:setSelectedAccount' ,
221
250
'NetworkController:getState' ,
222
- 'NetworkController:setActiveNetwork'
251
+ 'NetworkController:setActiveNetwork' ,
252
+ 'NetworkController:getNetworkClientById' ,
253
+ 'NetworkController:getNetworkConfigurationByChainId'
223
254
] ,
224
255
} ) ;
225
256
@@ -508,9 +539,7 @@ describe('MMIController', function () {
508
539
CUSTODIAN_TYPES [ 'CUSTODIAN-TYPE' ] = {
509
540
keyringClass : { type : 'mock-keyring-class' } ,
510
541
} ;
511
- mmiController . messagingSystem . call = jest
512
- . fn ( )
513
- . mockReturnValue ( { address : '0x1' } ) ;
542
+ jest . spyOn ( ControllerMessenger . prototype , 'call' ) . mockReturnValue ( { address : '0x1' } ) ;
514
543
mmiController . custodyController . getCustodyTypeByAddress = jest
515
544
. fn ( )
516
545
. mockReturnValue ( 'custodian-type' ) ;
@@ -837,7 +866,7 @@ describe('MMIController', function () {
837
866
'0x1' ,
838
867
) ;
839
868
840
- expect ( selectedAccountSpy ) . toHaveBeenCalledTimes ( 1 ) ;
869
+ expect ( selectedAccountSpy ) . toHaveBeenCalledTimes ( 4 ) ;
841
870
const selectedAccount = accountsController . getSelectedAccount ( ) ;
842
871
expect ( selectedAccount . id ) . toBe ( mockAccount . id ) ;
843
872
} ) ;
0 commit comments