1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 01:39:44 +01:00
metamask-extension/test/e2e/tests/eth-sign.spec.js
Niranjana Binoy 0c203d0518
Signature-Request refactor (#19104)
* refactoring signature-request and adding test coverage

* adding storybook and removing the reduntant files:

* adding new components from

* replacing <SiteOrigin/> with <TagUrl/>

* updating review comments from Jyoti and George

* adding the hook

* refactoring in the changes from #18770 MMI PR

* adding new hook for the MMISign changes

* updating lavamoat

* updating lavamoat

* removing a commeted line

* updating the sign check with accountType conditional

* fixing build issues

* updating the review comments on the hooks

* updating signatureRequestHeader

* lint fix

* fixing test failure

* lint fix

* updating review comments

* adding the renamed hook

* updating the origin url

* fixing test failure

* migrating changes from #19184

* updating snapshot

* fixing e2e failure

* fixing e2e failure

* addressing review comments from Joao

* migrating chnages from #19892

* moving shallowEqual inside of mmi build

* migrating changes from #19881

* fixing build failure

* migrating changes from #19949

* migrating changes from #19468

* updating snapshot

* updating snapshot

* updating QA review comments

* fixing full screen height issue from develop

* migrating changes from #20083

* fixing snapshot
2023-07-20 18:51:38 +01:00

193 lines
5.9 KiB
JavaScript

const { strict: assert } = require('assert');
const {
withFixtures,
openDapp,
DAPP_URL,
defaultGanacheOptions,
unlockWallet,
regularDelayMs,
} = require('../helpers');
const FixtureBuilder = require('../fixture-builder');
describe('Eth sign', function () {
it('will detect if eth_sign is disabled', async function () {
await withFixtures(
{
dapp: true,
fixtures: new FixtureBuilder()
.withPermissionControllerConnectedToTestDapp()
.build(),
ganacheOptions: defaultGanacheOptions,
title: this.test.title,
},
async ({ driver }) => {
await driver.navigate();
await unlockWallet(driver);
await openDapp(driver);
await driver.clickElement('#ethSign');
await driver.delay(1000);
const ethSignButton = await driver.findElement('#ethSign');
const exceptionString =
'ERROR: ETH_SIGN HAS BEEN DISABLED. YOU MUST ENABLE IT IN THE ADVANCED SETTINGS';
assert.equal(await ethSignButton.getText(), exceptionString);
},
);
});
it('can initiate and confirm a eth sign', async function () {
const expectedEthSignMessage =
'0x879a053d4800c6354e76c7985a865d2922c82fb5b3f4577b2fe08b998954f2e0';
const expectedEthSignResult =
'"0x816ab6c5d5356548cc4e004ef35a37fdfab916742a2bbeda756cd064c3d3789a6557d41d49549be1de249e1937a8d048996dfcc70d0552111605dc7cc471e8531b"';
await withFixtures(
{
dapp: true,
fixtures: new FixtureBuilder()
.withPreferencesController({
disabledRpcMethodPreferences: {
eth_sign: true,
},
})
.withPermissionControllerConnectedToTestDapp()
.build(),
ganacheOptions: defaultGanacheOptions,
title: this.test.title,
},
async ({ driver }) => {
await driver.navigate();
await unlockWallet(driver);
await openDapp(driver);
await driver.clickElement('#ethSign');
// Wait for Signature request popup
await driver.waitUntilXWindowHandles(3);
let windowHandles = await driver.getAllWindowHandles();
await driver.switchToWindowWithTitle(
'MetaMask Notification',
windowHandles,
);
await verifyAndAssertEthSign(driver, DAPP_URL, expectedEthSignMessage);
await approveEthSign(
driver,
'[data-testid="page-container-footer-next"]',
'.signature-request-warning__footer__sign-button',
);
// Switch to the Dapp
await driver.waitUntilXWindowHandles(2);
windowHandles = await driver.getAllWindowHandles();
await driver.switchToWindowWithTitle('E2E Test Dapp', windowHandles);
// Verify
await driver.findElement({
css: '#ethSignResult',
text: expectedEthSignResult,
});
},
);
});
it('can queue multiple eth sign and confirm', async function () {
const expectedEthSignMessage =
'0x879a053d4800c6354e76c7985a865d2922c82fb5b3f4577b2fe08b998954f2e0';
const expectedEthSignResult =
'"0x816ab6c5d5356548cc4e004ef35a37fdfab916742a2bbeda756cd064c3d3789a6557d41d49549be1de249e1937a8d048996dfcc70d0552111605dc7cc471e8531b"';
await withFixtures(
{
dapp: true,
fixtures: new FixtureBuilder()
.withPreferencesController({
disabledRpcMethodPreferences: {
eth_sign: true,
},
})
.withPermissionControllerConnectedToTestDapp()
.build(),
ganacheOptions: defaultGanacheOptions,
title: this.test.title,
},
async ({ driver }) => {
await driver.navigate();
await driver.fill('#password', 'correct horse battery staple');
await driver.press('#password', driver.Key.ENTER);
await openDapp(driver);
// Create eth sign
await driver.clickElement('#ethSign');
// Wait for Signature request popup
await driver.waitUntilXWindowHandles(3);
let windowHandles = await driver.getAllWindowHandles();
// Switch to Dapp
await driver.switchToWindowWithTitle('E2E Test Dapp', windowHandles);
// Create second eth sign
await driver.clickElement('#ethSign');
await driver.switchToWindowWithTitle(
'MetaMask Notification',
windowHandles,
);
await driver.waitForSelector({
text: 'Reject 2 requests',
tag: 'button',
});
await verifyAndAssertEthSign(driver, DAPP_URL, expectedEthSignMessage);
// Confirm first eth sign
await approveEthSign(
driver,
'[data-testid="page-container-footer-next"]',
'.signature-request-warning__footer__sign-button',
);
// Confirm second eth sign
await approveEthSign(
driver,
'[data-testid="page-container-footer-next"]',
'.signature-request-warning__footer__sign-button',
);
// Switch to the Dapp
await driver.waitUntilXWindowHandles(2);
windowHandles = await driver.getAllWindowHandles();
await driver.switchToWindowWithTitle('E2E Test Dapp', windowHandles);
// Verify last confirmed request
const result = await driver.findElement('#ethSignResult');
assert.equal(await result.getText(), expectedEthSignResult);
},
);
});
});
async function verifyAndAssertEthSign(driver, dappUrl, expectedMessage) {
await driver.findElement({
css: '.request-signature__content__title',
text: 'Signature request',
});
await driver.findElement({
css: '.request-signature__origin',
text: dappUrl,
});
await driver.findElement({
css: '.request-signature__row-value',
text: expectedMessage,
});
}
async function approveEthSign(driver, buttonTestId, signButtonClass) {
await driver.clickElement(buttonTestId);
await driver.clickElement(signButtonClass);
await driver.delay(regularDelayMs);
}