From 1672019f1b9827206a90b06c1663d4cea30315c9 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 23 May 2024 15:36:31 -0500 Subject: [PATCH] fix up e2e tests --- .../tests/metrics/signature-approved.spec.js | 50 ------ test/e2e/tests/signature/eth-sign.spec.js | 145 +----------------- 2 files changed, 1 insertion(+), 194 deletions(-) diff --git a/test/e2e/tests/metrics/signature-approved.spec.js b/test/e2e/tests/metrics/signature-approved.spec.js index a175f049ee61..68fc2a4ae110 100644 --- a/test/e2e/tests/metrics/signature-approved.spec.js +++ b/test/e2e/tests/metrics/signature-approved.spec.js @@ -238,54 +238,4 @@ describe('Signature Approved Event @no-mmi', function () { }, ); }); - it('Successfully tracked for eth_sign', async function () { - await withFixtures( - { - dapp: true, - fixtures: new FixtureBuilder() - .withPermissionControllerConnectedToTestDapp() - .withMetaMetricsController({ - metaMetricsId: 'fake-metrics-id', - participateInMetaMetrics: true, - }) - .build(), - defaultGanacheOptions, - title: this.test.fullTitle(), - testSpecificMock: mockSegment, - }, - async ({ driver, mockedEndpoint: mockedEndpoints }) => { - await unlockWallet(driver); - await openDapp(driver); - - // creates a sign typed data signature request - await driver.clickElement('#ethSign'); - await switchToNotificationWindow(driver); - await driver.delay(regularDelayMs); - await driver.clickElement('[data-testid="page-container-footer-next"]'); - await driver.clickElement( - '[data-testid="signature-warning-sign-button"]', - ); - const events = await getEventPayloads(driver, mockedEndpoints); - assert.deepStrictEqual(events[0].properties, { - account_type: 'MetaMask', - signature_type: 'eth_sign', - category: 'inpage_provider', - locale: 'en', - chain_id: '0x539', - environment_type: 'background', - security_alert_reason: 'NotApplicable', - security_alert_response: 'NotApplicable', - }); - assert.deepStrictEqual(events[1].properties, { - account_type: 'MetaMask', - signature_type: 'eth_sign', - category: 'inpage_provider', - locale: 'en', - chain_id: '0x539', - environment_type: 'background', - security_alert_response: 'NotApplicable', - }); - }, - ); - }); }); diff --git a/test/e2e/tests/signature/eth-sign.spec.js b/test/e2e/tests/signature/eth-sign.spec.js index 42e50a840671..f1d8c4cefd66 100644 --- a/test/e2e/tests/signature/eth-sign.spec.js +++ b/test/e2e/tests/signature/eth-sign.spec.js @@ -2,11 +2,8 @@ const { strict: assert } = require('assert'); const { withFixtures, openDapp, - DAPP_URL, defaultGanacheOptions, unlockWallet, - regularDelayMs, - WINDOW_TITLES, } = require('../../helpers'); const FixtureBuilder = require('../../fixture-builder'); @@ -31,149 +28,9 @@ describe('Eth sign', function () { const ethSignButton = await driver.findElement('#ethSign'); const exceptionString = 'ERROR: ETH_SIGN HAS BEEN DISABLED. YOU MUST ENABLE IT IN THE ADVANCED SETTINGS'; + // TODO the error should be different now... 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() - .withPermissionControllerConnectedToTestDapp() - .build(), - ganacheOptions: defaultGanacheOptions, - title: this.test.fullTitle(), - }, - async ({ driver }) => { - 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( - WINDOW_TITLES.Dialog, - windowHandles, - ); - - await verifyAndAssertEthSign(driver, DAPP_URL, expectedEthSignMessage); - - await approveEthSign( - driver, - '[data-testid="page-container-footer-next"]', - '[data-testid="signature-warning-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() - .withPermissionControllerConnectedToTestDapp() - .build(), - ganacheOptions: defaultGanacheOptions, - title: this.test.fullTitle(), - }, - async ({ driver }) => { - await unlockWallet(driver); - - 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( - WINDOW_TITLES.Dialog, - 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"]', - '[data-testid="signature-warning-sign-button"]', - ); - - // Confirm second eth sign - await approveEthSign( - driver, - '[data-testid="page-container-footer-next"]', - '[data-testid="signature-warning-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); -}