1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-25 11:28:51 +01:00

Change migration 78 version to 79, 79 to 80 and 80 to 78 (so that the… (#17980)

* Change migration 78 version to 79, 79 to 80 and 80 to 78 (so that the new 78 can be picked into an RC)

* Update migration imports
This commit is contained in:
Dan J Miller 2023-03-06 05:36:01 -08:00 committed by GitHub
parent f5e2183a7f
commit a5dcc60697
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 304 additions and 304 deletions

View File

@ -1,173 +1,108 @@
import migration78 from './078';
import { migrate, version } from './078';
describe('migration #78', () => {
it('should update the version metadata', async () => {
it('updates the version metadata', async () => {
const oldStorage = {
meta: {
version: 77,
},
data: {},
};
const newStorage = await migration78.migrate(oldStorage);
const newStorage = await migrate(oldStorage);
expect(newStorage.meta).toStrictEqual({
version: 78,
version,
});
});
it('should remove the "collectiblesDetectionNoticeDismissed"', async () => {
it('does not change the state if the phishing controller state does not exist', async () => {
const oldStorage = {
meta: {
version: 77,
},
data: { test: '123' },
};
const newStorage = await migrate(oldStorage);
expect(newStorage.data).toStrictEqual(oldStorage.data);
});
const nonObjects = [undefined, null, 'test', 1, ['test']];
for (const invalidState of nonObjects) {
it(`does not change the state if the phishing controller state is ${invalidState}`, async () => {
const oldStorage = {
meta: {
version: 77,
},
data: { PhishingController: invalidState },
};
const newStorage = await migrate(oldStorage);
expect(newStorage.data).toStrictEqual(oldStorage.data);
});
}
it('does not change the state if the phishing controller state does not include "phishing" or "lastFetched" properties', async () => {
const oldStorage = {
meta: {
version: 77,
},
data: { PhishingController: { test: '123' } },
};
const newStorage = await migrate(oldStorage);
expect(newStorage.data).toStrictEqual(oldStorage.data);
});
it('deletes the "phishing" property', async () => {
const oldStorage = {
meta: {
version: 77,
},
data: { PhishingController: { test: '123', phishing: [] } },
};
const newStorage = await migrate(oldStorage);
expect(newStorage.data).toStrictEqual({
PhishingController: { test: '123' },
});
});
it('deletes the "lastFetched" property', async () => {
const oldStorage = {
meta: {
version: 77,
},
data: { PhishingController: { test: '123', lastFetched: 100 } },
};
const newStorage = await migrate(oldStorage);
expect(newStorage.data).toStrictEqual({
PhishingController: { test: '123' },
});
});
it('deletes the "phishing" and "lastFetched" properties', async () => {
const oldStorage = {
meta: {
version: 77,
},
data: {
AppStateController: {
collectiblesDetectionNoticeDismissed: false,
bar: 'baz',
},
PhishingController: { test: '123', lastFetched: 100, phishing: [] },
},
};
const newStorage = await migration78.migrate(oldStorage);
expect(newStorage).toStrictEqual({
meta: {
version: 78,
},
data: {
AppStateController: {
bar: 'baz',
},
},
});
});
const newStorage = await migrate(oldStorage);
it('should remove the "collectiblesDropdownState"', async () => {
const oldStorage = {
meta: {
version: 77,
},
data: {
metamask: {
isInitialized: true,
isUnlocked: true,
isAccountMenuOpen: false,
identities: {
'0x00000': {
address: '0x00000',
lastSelected: 1675966229118,
name: 'Account 1',
},
'0x00001': {
address: '0x00001',
name: 'Account 2',
},
},
collectiblesDropdownState: {},
qrHardware: {},
},
},
};
const newStorage = await migration78.migrate(oldStorage);
expect(newStorage).toStrictEqual({
meta: {
version: 78,
},
data: {
metamask: {
isInitialized: true,
isUnlocked: true,
isAccountMenuOpen: false,
identities: {
'0x00000': {
address: '0x00000',
lastSelected: 1675966229118,
name: 'Account 1',
},
'0x00001': {
address: '0x00001',
name: 'Account 2',
},
},
qrHardware: {},
},
},
});
});
it('should make no changes if "collectiblesDetectionNoticeDismissed" never existed', async () => {
const oldStorage = {
meta: {
version: 77,
},
data: {
AppStateController: {
bar: 'baz',
},
},
};
const newStorage = await migration78.migrate(oldStorage);
expect(newStorage).toStrictEqual({
meta: {
version: 78,
},
data: {
AppStateController: {
bar: 'baz',
},
},
});
});
it('should make no changes if "collectiblesDropdownState" never existed', async () => {
const oldStorage = {
meta: {
version: 77,
},
data: {
metamask: {
isInitialized: true,
isUnlocked: true,
isAccountMenuOpen: false,
identities: {
'0x00000': {
address: '0x00000',
lastSelected: 1675966229118,
name: 'Account 1',
},
'0x00001': {
address: '0x00001',
name: 'Account 2',
},
},
qrHardware: {},
},
},
};
const newStorage = await migration78.migrate(oldStorage);
expect(newStorage).toStrictEqual({
meta: {
version: 78,
},
data: {
metamask: {
isInitialized: true,
isUnlocked: true,
isAccountMenuOpen: false,
identities: {
'0x00000': {
address: '0x00000',
lastSelected: 1675966229118,
name: 'Account 1',
},
'0x00001': {
address: '0x00001',
name: 'Account 2',
},
},
qrHardware: {},
},
},
expect(newStorage.data).toStrictEqual({
PhishingController: { test: '123' },
});
});
});

View File

@ -1,7 +1,7 @@
import { cloneDeep } from 'lodash';
import { hasProperty, isObject } from '@metamask/utils';
export const version = 80;
export const version = 78;
/**
* The`@metamask/phishing-controller` state was updated in v2.0.0.

View File

@ -3,8 +3,7 @@ import { cloneDeep } from 'lodash';
const version = 79;
/**
* The portfolio tooltip has been moved to a button on the home screen so
* this property is no longer needed in state
* Remove collectiblesDropdownState and collectiblesDetectionNoticeDismissed:.
*/
export default {
version,
@ -19,9 +18,14 @@ export default {
};
function transformState(state) {
if (state?.metamask?.showPortfolioTooltip !== undefined) {
delete state.metamask.showPortfolioTooltip;
if (
state?.AppStateController?.collectiblesDetectionNoticeDismissed !==
undefined
) {
delete state.AppStateController.collectiblesDetectionNoticeDismissed;
}
if (state?.metamask?.collectiblesDropdownState !== undefined) {
delete state.metamask.collectiblesDropdownState;
}
return state;
}

View File

@ -14,7 +14,33 @@ describe('migration #79', () => {
});
});
it('should remove the "showPortfolioToolip" property', async () => {
it('should remove the "collectiblesDetectionNoticeDismissed"', async () => {
const oldStorage = {
meta: {
version: 78,
},
data: {
AppStateController: {
collectiblesDetectionNoticeDismissed: false,
bar: 'baz',
},
},
};
const newStorage = await migration79.migrate(oldStorage);
expect(newStorage).toStrictEqual({
meta: {
version: 79,
},
data: {
AppStateController: {
bar: 'baz',
},
},
});
});
it('should remove the "collectiblesDropdownState"', async () => {
const oldStorage = {
meta: {
version: 78,
@ -35,19 +61,7 @@ describe('migration #79', () => {
name: 'Account 2',
},
},
unapprovedTxs: {},
frequentRpcList: [],
addressBook: {},
popupGasPollTokens: [],
notificationGasPollTokens: [],
fullScreenGasPollTokens: [],
recoveryPhraseReminderHasBeenShown: false,
recoveryPhraseReminderLastShown: 1675966206345,
outdatedBrowserWarningLastShown: 1675966206345,
showTestnetMessageInDropdown: true,
showPortfolioTooltip: false,
showBetaHeader: false,
trezorModel: null,
collectiblesDropdownState: {},
qrHardware: {},
},
},
@ -74,25 +88,37 @@ describe('migration #79', () => {
name: 'Account 2',
},
},
unapprovedTxs: {},
frequentRpcList: [],
addressBook: {},
popupGasPollTokens: [],
notificationGasPollTokens: [],
fullScreenGasPollTokens: [],
recoveryPhraseReminderHasBeenShown: false,
recoveryPhraseReminderLastShown: 1675966206345,
outdatedBrowserWarningLastShown: 1675966206345,
showTestnetMessageInDropdown: true,
showBetaHeader: false,
trezorModel: null,
qrHardware: {},
},
},
});
});
it('should make no changes if "showPortfolioToolip" never existed', async () => {
it('should make no changes if "collectiblesDetectionNoticeDismissed" never existed', async () => {
const oldStorage = {
meta: {
version: 78,
},
data: {
AppStateController: {
bar: 'baz',
},
},
};
const newStorage = await migration79.migrate(oldStorage);
expect(newStorage).toStrictEqual({
meta: {
version: 79,
},
data: {
AppStateController: {
bar: 'baz',
},
},
});
});
it('should make no changes if "collectiblesDropdownState" never existed', async () => {
const oldStorage = {
meta: {
version: 78,
@ -113,18 +139,6 @@ describe('migration #79', () => {
name: 'Account 2',
},
},
unapprovedTxs: {},
frequentRpcList: [],
addressBook: {},
popupGasPollTokens: [],
notificationGasPollTokens: [],
fullScreenGasPollTokens: [],
recoveryPhraseReminderHasBeenShown: false,
recoveryPhraseReminderLastShown: 1675966206345,
outdatedBrowserWarningLastShown: 1675966206345,
showTestnetMessageInDropdown: true,
showBetaHeader: false,
trezorModel: null,
qrHardware: {},
},
},
@ -151,18 +165,6 @@ describe('migration #79', () => {
name: 'Account 2',
},
},
unapprovedTxs: {},
frequentRpcList: [],
addressBook: {},
popupGasPollTokens: [],
notificationGasPollTokens: [],
fullScreenGasPollTokens: [],
recoveryPhraseReminderHasBeenShown: false,
recoveryPhraseReminderLastShown: 1675966206345,
outdatedBrowserWarningLastShown: 1675966206345,
showTestnetMessageInDropdown: true,
showBetaHeader: false,
trezorModel: null,
qrHardware: {},
},
},

View File

@ -1,9 +1,10 @@
import { cloneDeep } from 'lodash';
const version = 78;
const version = 80;
/**
* Remove collectiblesDropdownState and collectiblesDetectionNoticeDismissed:.
* The portfolio tooltip has been moved to a button on the home screen so
* this property is no longer needed in state
*/
export default {
version,
@ -18,14 +19,9 @@ export default {
};
function transformState(state) {
if (
state?.AppStateController?.collectiblesDetectionNoticeDismissed !==
undefined
) {
delete state.AppStateController.collectiblesDetectionNoticeDismissed;
}
if (state?.metamask?.collectiblesDropdownState !== undefined) {
delete state.metamask.collectiblesDropdownState;
if (state?.metamask?.showPortfolioTooltip !== undefined) {
delete state.metamask.showPortfolioTooltip;
}
return state;
}

View File

@ -1,108 +1,171 @@
import { migrate, version } from './080';
import migration80 from './080';
describe('migration #80', () => {
it('updates the version metadata', async () => {
it('should update the version metadata', async () => {
const oldStorage = {
meta: {
version: 79,
version: 80,
},
data: {},
};
const newStorage = await migrate(oldStorage);
const newStorage = await migration80.migrate(oldStorage);
expect(newStorage.meta).toStrictEqual({
version,
version: 80,
});
});
it('does not change the state if the phishing controller state does not exist', async () => {
it('should remove the "showPortfolioToolip" property', async () => {
const oldStorage = {
meta: {
version: 79,
},
data: { test: '123' },
};
const newStorage = await migrate(oldStorage);
expect(newStorage.data).toStrictEqual(oldStorage.data);
});
const nonObjects = [undefined, null, 'test', 1, ['test']];
for (const invalidState of nonObjects) {
it(`does not change the state if the phishing controller state is ${invalidState}`, async () => {
const oldStorage = {
meta: {
version: 79,
},
data: { PhishingController: invalidState },
};
const newStorage = await migrate(oldStorage);
expect(newStorage.data).toStrictEqual(oldStorage.data);
});
}
it('does not change the state if the phishing controller state does not include "phishing" or "lastFetched" properties', async () => {
const oldStorage = {
meta: {
version: 79,
},
data: { PhishingController: { test: '123' } },
};
const newStorage = await migrate(oldStorage);
expect(newStorage.data).toStrictEqual(oldStorage.data);
});
it('deletes the "phishing" property', async () => {
const oldStorage = {
meta: {
version: 79,
},
data: { PhishingController: { test: '123', phishing: [] } },
};
const newStorage = await migrate(oldStorage);
expect(newStorage.data).toStrictEqual({
PhishingController: { test: '123' },
});
});
it('deletes the "lastFetched" property', async () => {
const oldStorage = {
meta: {
version: 79,
},
data: { PhishingController: { test: '123', lastFetched: 100 } },
};
const newStorage = await migrate(oldStorage);
expect(newStorage.data).toStrictEqual({
PhishingController: { test: '123' },
});
});
it('deletes the "phishing" and "lastFetched" properties', async () => {
const oldStorage = {
meta: {
version: 79,
version: 80,
},
data: {
PhishingController: { test: '123', lastFetched: 100, phishing: [] },
metamask: {
isInitialized: true,
isUnlocked: true,
isAccountMenuOpen: false,
identities: {
'0x00000': {
address: '0x00000',
lastSelected: 1675966229118,
name: 'Account 1',
},
'0x00001': {
address: '0x00001',
name: 'Account 2',
},
},
unapprovedTxs: {},
frequentRpcList: [],
addressBook: {},
popupGasPollTokens: [],
notificationGasPollTokens: [],
fullScreenGasPollTokens: [],
recoveryPhraseReminderHasBeenShown: false,
recoveryPhraseReminderLastShown: 1675966206345,
outdatedBrowserWarningLastShown: 1675966206345,
showTestnetMessageInDropdown: true,
showPortfolioTooltip: false,
showBetaHeader: false,
trezorModel: null,
qrHardware: {},
},
},
};
const newStorage = await migrate(oldStorage);
const newStorage = await migration80.migrate(oldStorage);
expect(newStorage).toStrictEqual({
meta: {
version: 80,
},
data: {
metamask: {
isInitialized: true,
isUnlocked: true,
isAccountMenuOpen: false,
identities: {
'0x00000': {
address: '0x00000',
lastSelected: 1675966229118,
name: 'Account 1',
},
'0x00001': {
address: '0x00001',
name: 'Account 2',
},
},
unapprovedTxs: {},
frequentRpcList: [],
addressBook: {},
popupGasPollTokens: [],
notificationGasPollTokens: [],
fullScreenGasPollTokens: [],
recoveryPhraseReminderHasBeenShown: false,
recoveryPhraseReminderLastShown: 1675966206345,
outdatedBrowserWarningLastShown: 1675966206345,
showTestnetMessageInDropdown: true,
showBetaHeader: false,
trezorModel: null,
qrHardware: {},
},
},
});
});
expect(newStorage.data).toStrictEqual({
PhishingController: { test: '123' },
it('should make no changes if "showPortfolioToolip" never existed', async () => {
const oldStorage = {
meta: {
version: 80,
},
data: {
metamask: {
isInitialized: true,
isUnlocked: true,
isAccountMenuOpen: false,
identities: {
'0x00000': {
address: '0x00000',
lastSelected: 1675966229118,
name: 'Account 1',
},
'0x00001': {
address: '0x00001',
name: 'Account 2',
},
},
unapprovedTxs: {},
frequentRpcList: [],
addressBook: {},
popupGasPollTokens: [],
notificationGasPollTokens: [],
fullScreenGasPollTokens: [],
recoveryPhraseReminderHasBeenShown: false,
recoveryPhraseReminderLastShown: 1675966206345,
outdatedBrowserWarningLastShown: 1675966206345,
showTestnetMessageInDropdown: true,
showBetaHeader: false,
trezorModel: null,
qrHardware: {},
},
},
};
const newStorage = await migration80.migrate(oldStorage);
expect(newStorage).toStrictEqual({
meta: {
version: 80,
},
data: {
metamask: {
isInitialized: true,
isUnlocked: true,
isAccountMenuOpen: false,
identities: {
'0x00000': {
address: '0x00000',
lastSelected: 1675966229118,
name: 'Account 1',
},
'0x00001': {
address: '0x00001',
name: 'Account 2',
},
},
unapprovedTxs: {},
frequentRpcList: [],
addressBook: {},
popupGasPollTokens: [],
notificationGasPollTokens: [],
fullScreenGasPollTokens: [],
recoveryPhraseReminderHasBeenShown: false,
recoveryPhraseReminderLastShown: 1675966206345,
outdatedBrowserWarningLastShown: 1675966206345,
showTestnetMessageInDropdown: true,
showBetaHeader: false,
trezorModel: null,
qrHardware: {},
},
},
});
});
});

View File

@ -81,9 +81,9 @@ import m074 from './074';
import m075 from './075';
import m076 from './076';
import m077 from './077';
import m078 from './078';
import * as m078 from './078';
import m079 from './079';
import * as m080 from './080';
import m080 from './080';
const migrations = [
m002,