1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
metamask-extension/app/scripts/migrations/093.test.ts
Mark Stacey a7a086537b
Force an update of the phishing warning configuration (#20381)
The "last fetched" state for the `PhishingController` has been deleted
to force an immediate full update of the phishing configuration state.
We're doing this because the state was cleared in v10.34.2 because the
format of that state had changed.

This has been implemented in migration 92. The previous migration 92
has been renamed to 93 because it won't be included until a future
release. We need the migrations to remain sequential, and this will
save us from having to resolve a complex conflict when releasing this.
2023-08-03 13:12:21 -02:30

114 lines
2.7 KiB
TypeScript

import { InfuraNetworkType, NetworkType } from '@metamask/controller-utils';
import { migrate, version } from './093';
const PREVIOUS_VERSION = version - 1;
describe('migration #93', () => {
it('should update the version metadata', async () => {
const oldStorage = {
meta: {
version: PREVIOUS_VERSION,
},
data: {},
};
const newStorage = await migrate(oldStorage);
expect(newStorage.meta).toStrictEqual({
version,
});
});
it('should return state unaltered if there is no network controller state', async () => {
const oldData = {
other: 'data',
};
const oldStorage = {
meta: {
version: PREVIOUS_VERSION,
},
data: oldData,
};
const newStorage = await migrate(oldStorage);
expect(newStorage.data).toStrictEqual(oldData);
});
it('should return state unaltered if there is no network controller providerConfig state', async () => {
const oldData = {
other: 'data',
NetworkController: {
networkConfigurations: {
id1: {
foo: 'bar',
},
},
},
};
const oldStorage = {
meta: {
version: PREVIOUS_VERSION,
},
data: oldData,
};
const newStorage = await migrate(oldStorage);
expect(newStorage.data).toStrictEqual(oldData);
});
it('should return state unaltered if there is already a ticker in the providerConfig state', async () => {
const oldData = {
other: 'data',
NetworkController: {
providerConfig: {
ticker: 'GoerliETH',
type: InfuraNetworkType.goerli,
chainId: '5',
nickname: 'Goerli Testnet',
id: 'goerli',
},
},
};
const oldStorage = {
meta: {
version: PREVIOUS_VERSION,
},
data: oldData,
};
const newStorage = await migrate(oldStorage);
expect(newStorage.data).toStrictEqual(oldData);
});
it('should update the provider config to have a ticker set to "ETH" if none is currently present', async () => {
const oldData = {
other: 'data',
NetworkController: {
providerConfig: {
type: NetworkType.rpc,
chainId: '0x9292',
nickname: 'Funky Town Chain',
},
},
};
const oldStorage = {
meta: {
version: PREVIOUS_VERSION,
},
data: oldData,
};
const newStorage = await migrate(oldStorage);
expect(newStorage.data).toStrictEqual({
other: 'data',
NetworkController: {
providerConfig: {
type: NetworkType.rpc,
chainId: '0x9292',
nickname: 'Funky Town Chain',
ticker: 'ETH',
},
},
});
});
});