Skip to content

Commit

Permalink
Add undefined providerConfig check
Browse files Browse the repository at this point in the history
  • Loading branch information
Gudahtt committed Aug 2, 2024
1 parent a44bf3d commit 27d6dcc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
33 changes: 33 additions & 0 deletions app/scripts/migrations/120.2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
7 changes: 6 additions & 1 deletion app/scripts/migrations/120.2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 27d6dcc

Please sign in to comment.