diff --git a/app/scripts/migrations/120.2.test.ts b/app/scripts/migrations/120.2.test.ts index 860ac7a1816a..9910fab17dfb 100644 --- a/app/scripts/migrations/120.2.test.ts +++ b/app/scripts/migrations/120.2.test.ts @@ -291,6 +291,39 @@ describe('migration #120.2', () => { ); }); + it('does nothing if obsolete properties and providerConfig are not set', async () => { + const oldState = { + NetworkController: { + selectedNetworkClientId: 'example', + }, + }; + + const transformedState = await migrate({ + meta: { version: oldVersion }, + data: cloneDeep(oldState), + }); + + expect(transformedState.data).toEqual(oldState); + }); + + it('does nothing if obsolete properties are not set and providerConfig is set to undefined', async () => { + const oldState = { + NetworkController: { + // This should be impossible because `undefined` cannot be returned from persisted state, + // it's not valid JSON. But a bug in migration 14 ends up setting this to `undefined`. + providerConfig: undefined, + selectedNetworkClientId: 'example', + }, + }; + + const transformedState = await migrate({ + meta: { version: oldVersion }, + data: cloneDeep(oldState), + }); + + expect(transformedState.data).toEqual(oldState); + }); + it('does nothing if obsolete properties and providerConfig id are not set', async () => { const oldState = { NetworkController: { diff --git a/app/scripts/migrations/120.2.ts b/app/scripts/migrations/120.2.ts index e598c7fa5d4e..4b32de9026c0 100644 --- a/app/scripts/migrations/120.2.ts +++ b/app/scripts/migrations/120.2.ts @@ -105,7 +105,12 @@ function removeObsoleteNetworkControllerState( const networkControllerState = state.NetworkController; // Check for invalid `providerConfig.id`, and remove if found - if (hasProperty(networkControllerState, 'providerConfig')) { + if ( + hasProperty(networkControllerState, 'providerConfig') && + // This should be impossible because `undefined` cannot be returned from persisted state, + // it's not valid JSON. But a bug in migration 14 ends up setting this to `undefined`. + networkControllerState.providerConfig !== undefined + ) { if (!isObject(networkControllerState.providerConfig)) { global.sentry?.captureException?.( new Error(