Skip to content

Commit

Permalink
fix up e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adonesky1 committed Jun 25, 2024
1 parent bc4c056 commit 1672019
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 194 deletions.
50 changes: 0 additions & 50 deletions test/e2e/tests/metrics/signature-approved.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});
},
);
});
});
145 changes: 1 addition & 144 deletions test/e2e/tests/signature/eth-sign.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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);
}

0 comments on commit 1672019

Please sign in to comment.