2022-02-04 16:39:48 +01:00
|
|
|
const { strict: assert } = require('assert');
|
2023-05-05 15:56:08 +02:00
|
|
|
const {
|
|
|
|
withFixtures,
|
|
|
|
openDapp,
|
|
|
|
DAPP_URL,
|
2023-06-15 14:13:54 +02:00
|
|
|
defaultGanacheOptions,
|
2023-06-20 12:17:08 +02:00
|
|
|
unlockWallet,
|
2023-06-28 09:21:02 +02:00
|
|
|
regularDelayMs,
|
2023-05-05 15:56:08 +02:00
|
|
|
} = require('../helpers');
|
2022-10-28 10:42:12 +02:00
|
|
|
const FixtureBuilder = require('../fixture-builder');
|
2022-02-04 16:39:48 +01:00
|
|
|
|
|
|
|
describe('Eth sign', function () {
|
2023-02-06 17:47:50 +01:00
|
|
|
it('will detect if eth_sign is disabled', async function () {
|
|
|
|
await withFixtures(
|
|
|
|
{
|
|
|
|
dapp: true,
|
|
|
|
fixtures: new FixtureBuilder()
|
|
|
|
.withPermissionControllerConnectedToTestDapp()
|
|
|
|
.build(),
|
2023-06-15 14:13:54 +02:00
|
|
|
ganacheOptions: defaultGanacheOptions,
|
2023-02-06 17:47:50 +01:00
|
|
|
title: this.test.title,
|
|
|
|
},
|
|
|
|
async ({ driver }) => {
|
|
|
|
await driver.navigate();
|
2023-06-20 12:17:08 +02:00
|
|
|
await unlockWallet(driver);
|
2023-02-06 17:47:50 +01:00
|
|
|
|
2023-05-05 15:56:08 +02:00
|
|
|
await openDapp(driver);
|
2023-02-06 17:47:50 +01:00
|
|
|
await driver.clickElement('#ethSign');
|
|
|
|
|
2023-03-23 18:01:51 +01:00
|
|
|
await driver.delay(1000);
|
2023-02-06 17:47:50 +01:00
|
|
|
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);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2022-02-04 16:39:48 +01:00
|
|
|
it('can initiate and confirm a eth sign', async function () {
|
2023-06-28 09:21:02 +02:00
|
|
|
const expectedEthSignMessage =
|
2022-02-04 16:39:48 +01:00
|
|
|
'0x879a053d4800c6354e76c7985a865d2922c82fb5b3f4577b2fe08b998954f2e0';
|
|
|
|
const expectedEthSignResult =
|
|
|
|
'"0x816ab6c5d5356548cc4e004ef35a37fdfab916742a2bbeda756cd064c3d3789a6557d41d49549be1de249e1937a8d048996dfcc70d0552111605dc7cc471e8531b"';
|
|
|
|
await withFixtures(
|
|
|
|
{
|
|
|
|
dapp: true,
|
2022-10-28 10:42:12 +02:00
|
|
|
fixtures: new FixtureBuilder()
|
2023-02-06 17:47:50 +01:00
|
|
|
.withPreferencesController({
|
|
|
|
disabledRpcMethodPreferences: {
|
|
|
|
eth_sign: true,
|
|
|
|
},
|
|
|
|
})
|
2022-10-28 10:42:12 +02:00
|
|
|
.withPermissionControllerConnectedToTestDapp()
|
|
|
|
.build(),
|
2023-06-15 14:13:54 +02:00
|
|
|
ganacheOptions: defaultGanacheOptions,
|
2022-02-04 16:39:48 +01:00
|
|
|
title: this.test.title,
|
|
|
|
},
|
|
|
|
async ({ driver }) => {
|
|
|
|
await driver.navigate();
|
2023-06-20 12:17:08 +02:00
|
|
|
await unlockWallet(driver);
|
2022-02-04 16:39:48 +01:00
|
|
|
|
2023-05-05 15:56:08 +02:00
|
|
|
await openDapp(driver);
|
2022-02-04 16:39:48 +01:00
|
|
|
await driver.clickElement('#ethSign');
|
|
|
|
|
2023-02-06 17:47:50 +01:00
|
|
|
// Wait for Signature request popup
|
2022-02-04 16:39:48 +01:00
|
|
|
await driver.waitUntilXWindowHandles(3);
|
|
|
|
let windowHandles = await driver.getAllWindowHandles();
|
|
|
|
await driver.switchToWindowWithTitle(
|
|
|
|
'MetaMask Notification',
|
|
|
|
windowHandles,
|
|
|
|
);
|
|
|
|
|
2023-06-28 09:21:02 +02:00
|
|
|
await verifyAndAssertEthSign(driver, DAPP_URL, expectedEthSignMessage);
|
2023-06-15 14:13:54 +02:00
|
|
|
|
2023-06-28 09:21:02 +02:00
|
|
|
await approveEthSign(
|
|
|
|
driver,
|
|
|
|
'[data-testid="page-container-footer-next"]',
|
2022-11-30 16:34:50 +01:00
|
|
|
'.signature-request-warning__footer__sign-button',
|
|
|
|
);
|
2022-02-04 16:39:48 +01:00
|
|
|
// Switch to the Dapp
|
|
|
|
await driver.waitUntilXWindowHandles(2);
|
|
|
|
windowHandles = await driver.getAllWindowHandles();
|
|
|
|
await driver.switchToWindowWithTitle('E2E Test Dapp', windowHandles);
|
|
|
|
|
|
|
|
// Verify
|
2023-06-15 14:13:54 +02:00
|
|
|
await driver.findElement({
|
|
|
|
css: '#ethSignResult',
|
|
|
|
text: expectedEthSignResult,
|
|
|
|
});
|
2022-02-04 16:39:48 +01:00
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
2023-06-28 09:21:02 +02:00
|
|
|
|
|
|
|
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',
|
2023-07-20 19:51:38 +02:00
|
|
|
tag: 'button',
|
2023-06-28 09:21:02 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
2022-02-04 16:39:48 +01:00
|
|
|
});
|
2023-06-28 09:21:02 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|