1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-29 07:16:36 +01:00
metamask-extension/test/e2e/tests/4byte-directory.spec.js
Victor Thomas 2ff289e271
Add Opt-out Settings toggle for 4byte contract method names resolution (#20098)
* Adding 4byte toggle to settings UI and preferences

* Adding 4byte toggle to advanced settings tab

* adding use4ByteResolution privacy logic to getContractMethodData & getMethodDataAsync, removing unused useMethodData hook, adding clearKnownMethodData

* add 4byte setting to onboarding advanced option

* more test changes

* adding e2e for 4byte setting toggle

* test and copy changes, snap updates

* removing 4byte from advanced section

* adding settings constant and fixing refs

* removing clearKnownMethodData, adding flag to selector, test fixes

* e2e refactor, selectors refactor

* adding tests

* Fix jest tests, remove unwanted forceUpdateMetamaskState

* Fix jest tests

* lint:fix

* settingsRefs fixes

---------

Co-authored-by: David Walsh <davidwalsh83@gmail.com>
2023-08-04 13:28:37 -04:00

115 lines
3.8 KiB
JavaScript

const { strict: assert } = require('assert');
const FixtureBuilder = require('../fixture-builder');
const {
withFixtures,
openDapp,
unlockWallet,
largeDelayMs,
veryLargeDelayMs,
WINDOW_TITLES,
} = require('../helpers');
const { SMART_CONTRACTS } = require('../seeder/smart-contracts');
describe('4byte setting', function () {
it('makes a call to 4byte when the setting is on', async function () {
const smartContract = SMART_CONTRACTS.PIGGYBANK;
await withFixtures(
{
dapp: true,
fixtures: new FixtureBuilder()
.withPermissionControllerConnectedToTestDapp()
.build(),
smartContract,
title: this.test.title,
},
async ({ driver, contractRegistry }) => {
const contractAddress = await contractRegistry.getContractAddress(
smartContract,
);
await driver.navigate();
await unlockWallet(driver);
// deploy contract
await openDapp(driver, contractAddress);
// wait for deployed contract, calls and confirms a contract method where ETH is sent
await driver.delay(largeDelayMs);
await driver.clickElement('#depositButton');
await driver.waitForSelector({
css: 'span',
text: 'Deposit initiated',
});
await driver.waitUntilXWindowHandles(3);
await driver.switchToWindowWithTitle(WINDOW_TITLES.Notification);
const actionElement = await driver.waitForSelector({
css: '.confirm-page-container-summary__action__name',
text: 'Deposit',
});
assert.equal(await actionElement.getText(), 'DEPOSIT');
},
);
});
it('does not try to get contract method name from 4byte when the setting is off', async function () {
const smartContract = SMART_CONTRACTS.PIGGYBANK;
await withFixtures(
{
dapp: true,
fixtures: new FixtureBuilder()
.withPermissionControllerConnectedToTestDapp()
.build(),
smartContract,
title: this.test.title,
},
async ({ driver, contractRegistry }) => {
const contractAddress = await contractRegistry.getContractAddress(
smartContract,
);
await driver.navigate();
await unlockWallet(driver);
// goes to the settings screen
await driver.clickElement(
'[data-testid="account-options-menu-button"]',
);
await driver.clickElement({ text: 'Settings', tag: 'div' });
await driver.clickElement({ text: 'Security & privacy', tag: 'div' });
// turns off 4Byte Directory contract method name resolution
await driver.clickElement(
'[data-testid="4byte-resolution-container"] .toggle-button',
);
// deploy contract
await openDapp(driver, contractAddress);
// wait for deployed contract, calls and confirms a contract method where ETH is sent
await driver.findClickableElement('#depositButton');
await driver.clickElement('#depositButton');
await driver.waitForSelector({
css: 'span',
text: 'Deposit initiated',
});
await driver.waitUntilXWindowHandles(3);
await driver.switchToWindowWithTitle(WINDOW_TITLES.Notification);
const contractInteraction = 'Contract interaction';
const actionElement = await driver.waitForSelector({
css: '.confirm-page-container-summary__action__name',
text: contractInteraction,
});
// We add a delay here to wait for any potential UI changes
await driver.delay(veryLargeDelayMs);
// css text-transform: uppercase is applied to the text
assert.equal(
await actionElement.getText(),
contractInteraction.toUpperCase(),
);
},
);
});
});