Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version v12.0.4 RC #26427

Merged
merged 4 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [12.0.4]
### Fixed
- Further prevented data persistence errors related to networks ([#26432](https://github.com/MetaMask/metamask-extension/pull/26432))

## [12.0.3]

## [12.0.2]
Expand Down Expand Up @@ -4909,7 +4913,8 @@ Update styles and spacing on the critical error page ([#20350](https://github.c
- Added the ability to restore accounts from seed words.


[Unreleased]: https://github.com/MetaMask/metamask-extension/compare/v12.0.3...HEAD
[Unreleased]: https://github.com/MetaMask/metamask-extension/compare/v12.0.4...HEAD
[12.0.4]: https://github.com/MetaMask/metamask-extension/compare/v12.0.3...v12.0.4
[12.0.3]: https://github.com/MetaMask/metamask-extension/compare/v12.0.2...v12.0.3
[12.0.2]: https://github.com/MetaMask/metamask-extension/compare/v12.0.1...v12.0.2
[12.0.1]: https://github.com/MetaMask/metamask-extension/compare/v12.0.0...v12.0.1
Expand Down
255 changes: 255 additions & 0 deletions app/scripts/migrations/120.5.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,255 @@
import { cloneDeep } from 'lodash';
import { migrate, version } from './120.5';

const oldVersion = 120.4;

describe('migration #120.5', () => {
afterEach(() => {
jest.resetAllMocks();
});

it('updates the version metadata', async () => {
const oldStorage = {
meta: { version: oldVersion },
data: {},
};

const newStorage = await migrate(cloneDeep(oldStorage));

expect(newStorage.meta).toStrictEqual({ version });
});

it('does nothing if SelectedNetworkController state is not set', async () => {
const oldState = {
NetworkController: {
networkConfigurations: {
123: {},
},
},
};

const transformedState = await migrate({
meta: { version: oldVersion },
data: cloneDeep(oldState),
});

expect(transformedState.data).toEqual(oldState);
});

it('deletes the SelectedNetworkController state if it is corrupted', async () => {
const oldState = {
NetworkController: {
networkConfigurations: {
123: {},
},
},
SelectedNetworkController: 'invalid',
};

const transformedState = await migrate({
meta: { version: oldVersion },
data: cloneDeep(oldState),
});

expect(transformedState.data).toEqual({
NetworkController: {
networkConfigurations: {
123: {},
},
},
});
});

it('deletes the SelectedNetworkController state if it is missing the domains state', async () => {
const oldState = {
NetworkController: {
networkConfigurations: {
123: {},
},
},
SelectedNetworkController: {
somethingElse: {},
},
};

const transformedState = await migrate({
meta: { version: oldVersion },
data: cloneDeep(oldState),
});

expect(transformedState.data).toEqual({
NetworkController: {
networkConfigurations: {
123: {},
},
},
});
});

it('deletes the SelectedNetworkController state if the domains state is corrupted', async () => {
const oldState = {
NetworkController: {
networkConfigurations: {
123: {},
},
},
SelectedNetworkController: {
domains: 'invalid',
},
};

const transformedState = await migrate({
meta: { version: oldVersion },
data: cloneDeep(oldState),
});

expect(transformedState.data).toEqual({
NetworkController: {
networkConfigurations: {
123: {},
},
},
});
});

it('deletes the SelectedNetworkController state if NetworkController state is missing', async () => {
const oldState = {
SelectedNetworkController: {
domains: {},
},
};

const transformedState = await migrate({
meta: { version: oldVersion },
data: cloneDeep(oldState),
});

expect(transformedState.data).toEqual({});
});

it('deletes the SelectedNetworkController state if NetworkController state is corrupted', async () => {
const oldState = {
NetworkController: 'invalid',
SelectedNetworkController: {
domains: {},
},
};

const transformedState = await migrate({
meta: { version: oldVersion },
data: cloneDeep(oldState),
});

expect(transformedState.data).toEqual({
NetworkController: 'invalid',
});
});

it('deletes the SelectedNetworkController state if NetworkController has no networkConfigurations', async () => {
const oldState = {
NetworkController: {},
SelectedNetworkController: {
domains: {},
},
};

const transformedState = await migrate({
meta: { version: oldVersion },
data: cloneDeep(oldState),
});

expect(transformedState.data).toEqual({
NetworkController: {},
});
});

it('deletes the SelectedNetworkController state if NetworkController networkConfigurations state is corrupted', async () => {
const oldState = {
NetworkController: { networkConfigurations: 'invalid' },
SelectedNetworkController: {
domains: {},
},
};

const transformedState = await migrate({
meta: { version: oldVersion },
data: cloneDeep(oldState),
});

expect(transformedState.data).toEqual({
NetworkController: { networkConfigurations: 'invalid' },
});
});

it('does nothing if SelectedNetworkController domains state is empty', async () => {
const oldState = {
NetworkController: { networkConfigurations: {} },
SelectedNetworkController: {
domains: {},
},
};

const transformedState = await migrate({
meta: { version: oldVersion },
data: cloneDeep(oldState),
});

expect(transformedState.data).toEqual(oldState);
});

it('does nothing if SelectedNetworkController domains state is valid', async () => {
const oldState = {
NetworkController: {
networkConfigurations: {
123: {},
},
},
SelectedNetworkController: {
domains: {
'example1.test': '123',
'example2.test': 'mainnet',
'example3.test': 'goerli',
'example4.test': 'sepolia',
'example5.test': 'linea-goerli',
'example6.test': 'linea-sepolia',
'example7.test': 'linea-mainnet',
},
},
};

const transformedState = await migrate({
meta: { version: oldVersion },
data: cloneDeep(oldState),
});

expect(transformedState.data).toEqual(oldState);
});

it('deletes the SelectedNetworkController state if an invalid networkConfigurationId is found', async () => {
const oldState = {
NetworkController: {
networkConfigurations: {
123: {},
},
},
SelectedNetworkController: {
domains: {
'domain.test': '456',
},
},
};

const transformedState = await migrate({
meta: { version: oldVersion },
data: cloneDeep(oldState),
});

expect(transformedState.data).toEqual({
NetworkController: {
networkConfigurations: {
123: {},
},
},
});
});
});
Loading