2023-08-03 17:42:21 +02:00
|
|
|
import { InfuraNetworkType, NetworkType } from '@metamask/controller-utils';
|
|
|
|
import { migrate, version } from './093';
|
|
|
|
|
2023-08-17 13:34:30 +02:00
|
|
|
const PREVIOUS_VERSION = 92.1;
|
2023-08-03 17:42:21 +02:00
|
|
|
|
2023-08-16 21:26:20 +02:00
|
|
|
const sentryCaptureExceptionMock = jest.fn();
|
|
|
|
|
|
|
|
global.sentry = {
|
|
|
|
startSession: jest.fn(),
|
|
|
|
endSession: jest.fn(),
|
|
|
|
toggleSession: jest.fn(),
|
|
|
|
captureException: sentryCaptureExceptionMock,
|
|
|
|
};
|
|
|
|
|
2023-08-03 17:42:21 +02:00
|
|
|
describe('migration #93', () => {
|
2023-08-16 21:26:20 +02:00
|
|
|
afterEach(() => {
|
|
|
|
jest.resetAllMocks();
|
|
|
|
});
|
|
|
|
|
2023-08-03 17:42:21 +02:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
2023-08-16 21:26:20 +02:00
|
|
|
it('should capture an exception if there is no network controller state', async () => {
|
|
|
|
const oldData = {
|
|
|
|
other: 'data',
|
|
|
|
};
|
|
|
|
const oldStorage = {
|
|
|
|
meta: {
|
|
|
|
version: PREVIOUS_VERSION,
|
|
|
|
},
|
|
|
|
data: oldData,
|
|
|
|
};
|
|
|
|
|
|
|
|
await migrate(oldStorage);
|
|
|
|
|
|
|
|
expect(sentryCaptureExceptionMock).toHaveBeenCalledTimes(1);
|
|
|
|
expect(sentryCaptureExceptionMock).toHaveBeenCalledWith(
|
|
|
|
new Error(`typeof state.NetworkController is undefined`),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2023-08-03 17:42:21 +02:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
2023-08-16 21:26:20 +02:00
|
|
|
it('should capture an exception 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,
|
|
|
|
};
|
|
|
|
|
|
|
|
await migrate(oldStorage);
|
|
|
|
|
|
|
|
expect(sentryCaptureExceptionMock).toHaveBeenCalledTimes(1);
|
|
|
|
expect(sentryCaptureExceptionMock).toHaveBeenCalledWith(
|
|
|
|
new Error(`typeof state.NetworkController.providerConfig is undefined`),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2023-08-03 17:42:21 +02:00
|
|
|
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',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|