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

Enable ppom by default #22246

Merged
merged 15 commits into from
Dec 14, 2023
2 changes: 1 addition & 1 deletion app/scripts/controllers/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default class PreferencesController {
useRequestQueue: false,
openSeaEnabled: false,
///: BEGIN:ONLY_INCLUDE_IF(blockaid)
securityAlertsEnabled: false,
securityAlertsEnabled: true,
///: END:ONLY_INCLUDE_IF
///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
addSnapAccountEnabled: false,
Expand Down
30 changes: 30 additions & 0 deletions app/scripts/migrations/106.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { cloneDeep } from 'lodash';

export const version = 106;

/**
* This migration set preference securityAlertsEnabled to true.
*
* @param originalVersionedData - Versioned MetaMask extension state, exactly what we persist to dist.
*/
export async function migrate(originalVersionedData) {
const versionedData = cloneDeep(originalVersionedData);
versionedData.meta.version = version;
const state = versionedData.data;
const newState = transformState(state);
versionedData.data = newState;
return versionedData;
}

function transformState(state) {
const PreferencesController = state?.PreferencesController || {};

return {
...state,
PreferencesController: {
...PreferencesController,
securityAlertsEnabled:
PreferencesController.transactionSecurityCheckEnabled !== true,
},
};
}
135 changes: 135 additions & 0 deletions app/scripts/migrations/106.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import { migrate } from './106';

describe('migration #106', () => {
it('should update the version metadata', async () => {
const oldStorage = {
meta: {
version: 105,
},
data: {},
};

const newStorage = await migrate(oldStorage);
expect(newStorage.meta).toStrictEqual({
version: 106,
});
});

it('should set securityAlertsEnabled to true in PreferencesController', async () => {
const oldStorage = {
meta: {
version: 105,
},
data: {
PreferencesController: {
securityAlertsEnabled: false,
},
},
};

const newStorage = await migrate(oldStorage);
expect(newStorage).toStrictEqual({
meta: {
version: 106,
},
data: {
PreferencesController: {
securityAlertsEnabled: true,
},
},
});
});

it('should not set securityAlertsEnabled to true in PreferencesController if transactionSecurityCheckEnabled is set to true', async () => {
const oldStorage = {
meta: {
version: 105,
},
data: {
PreferencesController: {
securityAlertsEnabled: false,
transactionSecurityCheckEnabled: true,
},
},
};

const newStorage = await migrate(oldStorage);
expect(newStorage).toStrictEqual({
meta: {
version: 106,
},
data: {
PreferencesController: {
securityAlertsEnabled: false,
transactionSecurityCheckEnabled: true,
},
},
});
});

it('should preserve other PreferencesController state', async () => {
const oldStorage = {
meta: {
version: 105,
},
data: {
PreferencesController: {
currentLocale: 'en',
dismissSeedBackUpReminder: false,
ipfsGateway: 'dweb.link',
securityAlertsEnabled: false,
openSeaEnabled: false,
useTokenDetection: false,
},
},
};

const newStorage = await migrate(oldStorage);
expect(newStorage).toStrictEqual({
meta: {
version: 106,
},
data: {
PreferencesController: {
currentLocale: 'en',
dismissSeedBackUpReminder: false,
ipfsGateway: 'dweb.link',
securityAlertsEnabled: true,
openSeaEnabled: false,
useTokenDetection: false,
},
},
});
});

it('should not change state in controllers other than PreferencesController', async () => {
const oldStorage = {
meta: {
version: 105,
},
data: {
PreferencesController: {
securityAlertsEnabled: false,
},
data: {
FooController: { a: 'b' },
},
},
};

const newStorage = await migrate(oldStorage);
expect(newStorage).toStrictEqual({
meta: {
version: 106,
},
data: {
PreferencesController: {
securityAlertsEnabled: true,
},
data: {
FooController: { a: 'b' },
},
},
});
});
});
1 change: 1 addition & 0 deletions app/scripts/migrations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ const migrations = [
require('./103'),
require('./104'),
require('./105'),
require('./106'),
];

export default migrations;
15 changes: 8 additions & 7 deletions test/e2e/tests/ppom-toggle-settings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ describe('PPOM Settings @no-mmi', function () {
async ({ driver }) => {
await unlockWallet(driver);

await driver.clickElement(
'[data-testid="account-options-menu-button"]',
);

await driver.clickElement({ text: 'Settings', tag: 'div' });
await driver.clickElement({ text: 'Experimental', tag: 'div' });
await driver.clickElement('label.toggle-button');

await openDapp(driver);
await driver.clickElement('#maliciousPermit');
const windowHandles = await getWindowHandles(driver, 3);
Expand Down Expand Up @@ -51,13 +59,6 @@ describe('PPOM Settings @no-mmi', function () {
await driver.navigate();
await unlockWallet(driver);

await driver.clickElement(
'[data-testid="account-options-menu-button"]',
);

await driver.clickElement({ text: 'Settings', tag: 'div' });
await driver.clickElement({ text: 'Experimental', tag: 'div' });

await driver.clickElement(
'[data-testid="settings-toggle-security-alert-blockaid"] .toggle-button > div',
);
Expand Down
Loading