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

fix: Fix migration 120.3 error caused by invalid state #26485

Merged
merged 2 commits into from
Aug 19, 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
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { cloneDeep } from 'lodash';
import { migrate, version } from './120.3';
import { migrate, version } from './120.6';

const sentryCaptureExceptionMock = jest.fn();

global.sentry = {
captureException: sentryCaptureExceptionMock,
};

const oldVersion = 120.2;
const oldVersion = 120.5;

describe('migration #120.3', () => {
describe('migration #120.6', () => {
afterEach(() => {
jest.resetAllMocks();
});
Expand Down Expand Up @@ -72,7 +72,7 @@ describe('migration #120.3', () => {
expect(newStorage.data).toStrictEqual(oldStorageDataClone);
});

it('reports error and returns state unchanged if transactions property is invalid', async () => {
it('removes transactions property if it is invalid', async () => {
const oldStorage = {
meta: { version: oldVersion },
data: {
Expand All @@ -82,14 +82,13 @@ describe('migration #120.3', () => {
},
},
};
const oldStorageDataClone = cloneDeep(oldStorage.data);

const newStorage = await migrate(oldStorage);

expect(sentryCaptureExceptionMock).toHaveBeenCalledWith(
`Migration ${version}: Invalid TransactionController transactions state of type 'string'`,
);
expect(newStorage.data).toStrictEqual(oldStorageDataClone);
expect(newStorage.data).toStrictEqual({
PreferencesController: {},
TransactionController: {},
});
});

it('reports error and returns state unchanged if there is an invalid transaction', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type VersionedData = {
data: Record<string, unknown>;
};

export const version = 120.3;
export const version = 120.6;

const MAX_TRANSACTION_HISTORY_LENGTH = 100;

Expand Down Expand Up @@ -52,9 +52,12 @@ function transformState(state: Record<string, unknown>): void {
);
return;
} else if (!Array.isArray(transactionControllerState.transactions)) {
global.sentry?.captureException(
`Migration ${version}: Invalid TransactionController transactions state of type '${typeof transactionControllerState.transactions}'`,
log.error(
new Error(
`Migration ${version}: Invalid TransactionController transactions state of type '${typeof transactionControllerState.transactions}'`,
),
);
delete transactionControllerState.transactions;
return;
}

Expand Down
3 changes: 2 additions & 1 deletion app/scripts/migrations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,10 @@ const migrations = [
require('./120'),
require('./120.1'),
require('./120.2'),
require('./120.3'),
// require('./120.3'), Renamed to 120.6, do not re-use this number
require('./120.4'),
require('./120.5'),
require('./120.6'),
require('./121'),
require('./122'),
require('./123'),
Expand Down
Loading