const { strict: assert } = require('assert'); const { withFixtures, openDapp, DAPP_URL, login, defaultGanacheOptions, } = 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 login(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 expectedPersonalMessage = '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 login(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 driver.findElement({ css: '.request-signature__content__title', text: 'Signature request', }); await driver.findElement({ css: '.request-signature__origin', text: DAPP_URL, }); await driver.findElement({ css: '.request-signature__row-value', text: expectedPersonalMessage, }); await driver.clickElement('[data-testid="page-container-footer-next"]'); await driver.clickElement( '.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, }); }, ); }); });