File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -266,4 +266,30 @@ describe('Migration #90 - Replace BSC Network RPC URL', () => {
266
266
. networkConfigurationsByChainId [ BSC_CHAIN_ID ] . rpcEndpoints [ 0 ] . url ,
267
267
) . toBe ( NEW_RPC_URL ) ;
268
268
} ) ;
269
+
270
+ it ( 'should capture exception when NetworkController structure is invalid' , async ( ) => {
271
+ const oldState = merge (
272
+ { } ,
273
+ {
274
+ engine : {
275
+ backgroundState : {
276
+ NetworkController : {
277
+ // Valid object but missing networkConfigurationsByChainId
278
+ selectedNetworkClientId : 'mainnet' ,
279
+ networksMetadata : { } ,
280
+ // networkConfigurationsByChainId is intentionally missing
281
+ } ,
282
+ } ,
283
+ } ,
284
+ } ,
285
+ ) ;
286
+
287
+ const newState = await migrate ( oldState ) ;
288
+
289
+ expect ( newState ) . toStrictEqual ( oldState ) ;
290
+ expect ( mockedCaptureException ) . toHaveBeenCalledWith ( expect . any ( Error ) ) ;
291
+ expect ( mockedCaptureException . mock . calls [ 0 ] [ 0 ] . message ) . toBe (
292
+ 'Migration 90: NetworkController or networkConfigurationsByChainId not found in expected state structure. Skipping BSC RPC endpoint migration.' ,
293
+ ) ;
294
+ } ) ;
269
295
} ) ;
Original file line number Diff line number Diff line change 1
1
import { hasProperty , isObject } from '@metamask/utils' ;
2
2
import { ensureValidState } from './util' ;
3
3
import Logger from '../../util/Logger' ;
4
+ import { captureException } from '@sentry/react-native' ;
4
5
import { RpcEndpointType } from '@metamask/network-controller' ;
5
6
import {
6
7
allowedInfuraHosts ,
@@ -123,6 +124,12 @@ export default function migrate(state: unknown) {
123
124
}
124
125
}
125
126
}
127
+ } else {
128
+ captureException (
129
+ new Error (
130
+ 'Migration 90: NetworkController or networkConfigurationsByChainId not found in expected state structure. Skipping BSC RPC endpoint migration.' ,
131
+ ) ,
132
+ ) ;
126
133
}
127
134
128
135
return state ;
You can’t perform that action at this time.
0 commit comments