1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 01:39:44 +01:00
metamask-extension/app/scripts/migrations/092.3.test.ts
Brad Decker 64aef2a1c9
split advancedGasFee by network and erase previous options (#20576)
* Split out advanced gas fees by network and delete old values

* use arrow functions in preferences test

* changes

* added back priorityFeeProperCase to en messages

* update types

* remove case change
2023-08-26 17:58:26 -07:00

185 lines
4.4 KiB
TypeScript

import { migrate } from './092.3';
const PREFERENCES_CONTROLLER_MOCK = {
useBlockie: false,
useNonceField: false,
usePhishDetect: true,
dismissSeedBackUpReminder: false,
disabledRpcMethodPreferences: {
eth_sign: false,
},
useMultiAccountBalanceChecker: true,
useTokenDetection: false,
useNftDetection: false,
use4ByteResolution: true,
useCurrencyRateCheck: true,
openSeaEnabled: false,
advancedGasFee: null,
featureFlags: {
showIncomingTransactions: true,
},
knownMethodData: {},
currentLocale: 'EN',
identities: {},
lostIdentities: {},
forgottenPassword: false,
preferences: {
autoLockTimeLimit: undefined,
showFiatInTestnets: false,
showTestNetworks: false,
useNativeCurrencyAsPrimaryCurrency: true,
hideZeroBalanceTokens: false,
},
// ENS decentralized website resolution
ipfsGateway: '',
useAddressBarEnsResolution: true,
infuraBlocked: null,
ledgerTransportType: 'U2F',
snapRegistryList: {},
transactionSecurityCheckEnabled: false,
theme: 'OS',
isLineaMainnetReleased: false,
};
describe('migration #92.3', () => {
it('updates the version metadata', async () => {
const oldStorage = {
meta: { version: 92.2 },
data: {},
};
const newStorage = await migrate(oldStorage);
expect(newStorage.meta).toStrictEqual({ version: 92.3 });
});
it('does nothing if no PreferencesController state', async () => {
const oldData = {
some: 'data',
};
const oldStorage = {
meta: { version: 92.2 },
data: oldData,
};
const newStorage = await migrate(oldStorage);
expect(newStorage.data).toStrictEqual(oldData);
});
it('does nothing if no AppStateController state', async () => {
const oldData = {
some: 'data',
};
const oldStorage = {
meta: { version: 92.2 },
data: oldData,
};
const newStorage = await migrate(oldStorage);
expect(newStorage.data).toStrictEqual(oldData);
});
it('changes advancedGasFee from null to an empty object, and sets hadAdvancedGasFeesSetPriorToMigration92_3 to false', async () => {
const oldData = {
some: 'data',
PreferencesController: {
...PREFERENCES_CONTROLLER_MOCK,
},
AppStateController: {},
};
const oldStorage = {
meta: { version: 92.2 },
data: oldData,
};
const newStorage = await migrate(oldStorage);
expect(newStorage.data).toStrictEqual({
some: oldData.some,
PreferencesController: {
...PREFERENCES_CONTROLLER_MOCK,
advancedGasFee: {},
},
AppStateController: {
hadAdvancedGasFeesSetPriorToMigration92_3: false,
},
});
});
it('changes advancedGasFee from an object of values to an empty object and sets hadAdvancedGasFeesSetPriorToMigration92_3 to true', async () => {
const oldData = {
some: 'data',
PreferencesController: {
...PREFERENCES_CONTROLLER_MOCK,
advancedGasFee: {
priorityFee: '0x1',
maxBaseFee: '0x1',
},
},
AppStateController: {},
};
const oldStorage = {
meta: { version: 92.2 },
data: oldData,
};
const newStorage = await migrate(oldStorage);
expect(newStorage.data).toStrictEqual({
some: oldData.some,
PreferencesController: {
...PREFERENCES_CONTROLLER_MOCK,
advancedGasFee: {},
},
AppStateController: {
hadAdvancedGasFeesSetPriorToMigration92_3: true,
},
});
});
it('does not erase advancedGasFee if it does not contain the expected data prior to this migration', async () => {
const oldData = {
some: 'data',
PreferencesController: {
...PREFERENCES_CONTROLLER_MOCK,
advancedGasFee: {
'0x5': {
priorityFee: '0x1',
maxBaseFee: '0x1',
},
},
},
AppStateController: {},
};
const oldStorage = {
meta: { version: 92.2 },
data: oldData,
};
const newStorage = await migrate(oldStorage);
expect(newStorage.data).toStrictEqual({
some: oldData.some,
PreferencesController: {
...PREFERENCES_CONTROLLER_MOCK,
advancedGasFee: {
'0x5': {
priorityFee: '0x1',
maxBaseFee: '0x1',
},
},
},
AppStateController: {
hadAdvancedGasFeesSetPriorToMigration92_3: false,
},
});
});
});