Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Signature Redesign e2e tests for each supported signature type #24352

Merged
merged 55 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
2c956d0
refactor: ConfirmFooter data-testid "confirm-footer-button"
digiwand May 1, 2024
4f018dc
test:e2e: signature redesign personal_sign
digiwand May 1, 2024
327e6ba
test:e2e: signature eth_signTypedData
digiwand May 1, 2024
d81f87c
test:refactor: '127.0.0.1:8080' -> DAPP_URL_WITHOUT_SCHEMA
digiwand May 1, 2024
8334bb4
test:refactor require -> import
digiwand May 2, 2024
60571f2
test:fix: require -> import
digiwand May 2, 2024
55fb8a5
test:refactor: snake case -> kebab case filenames
digiwand May 2, 2024
2b51b1f
test:fix: require FixtureBuilder
digiwand May 2, 2024
bd538cc
test:e2e signature redesign deprecate isElementPresent
digiwand May 2, 2024
50f664d
test: signature redesign reorganize imports
digiwand May 2, 2024
bc779a3
test:fix: flaky personalSignVerifyECRecoverResult
digiwand May 2, 2024
364ccc2
test:e2e add signature redesign signTypedDataV3 test
digiwand May 2, 2024
919703d
test:e2e: signature redesign update test phrase
digiwand May 2, 2024
945ce71
refactor: redesign signTypedDataV3 isElementPresent -> findElement
digiwand May 2, 2024
a3b61d6
test:e2e: create signature redesign signTypedDataV4
digiwand May 2, 2024
4892b9c
test:e2e: create signature redesign permit
digiwand May 2, 2024
169befb
refactor: clean whitespaces
digiwand May 2, 2024
5f10110
test: create and use withRedesignConfirmationFixtures
digiwand May 3, 2024
a024071
test: fix whitespace & newlines manually
digiwand May 3, 2024
007839e
test:e2e: add signature redesign reject tests
digiwand May 3, 2024
390be34
fix:test: Signature Redesign footer and page snapshots which include …
digiwand May 3, 2024
4947467
fix:test: rn DAPP_URL_WITHOUT_SCHEMA -> DAPP_HOST_ADDRESS
digiwand May 3, 2024
648de9d
fix:test: update signature design after removing mainnet network fixture
digiwand May 3, 2024
5ceb337
test:e2e:fix: flaky Signature Request rejection tests
digiwand May 3, 2024
62b7b33
Merge branch 'develop' into test-e2e-signature-redesign
digiwand May 7, 2024
f1dcc62
Merge branch 'develop' into test-e2e-signature-redesign
digiwand May 7, 2024
e7a0475
fix: rn preference redesignedConfirmationsEnabled -> redesignedConfir…
digiwand May 7, 2024
84cc1ac
test:e2e:refactor: extract info value assets into separate function
digiwand May 7, 2024
ee29aa8
test:fix: confirm redesign personal-sign reject test
digiwand May 7, 2024
8491ca1
test:e2e: potentially fix flaky test
digiwand May 7, 2024
81a93c1
test:e2e: potentially fix flaky tests 2
digiwand May 7, 2024
02895bd
test:e2e:fix: rm unused const
digiwand May 8, 2024
94e9dc6
test:e2e:refactor: rn confirm-redesign helper-fixture.ts -> herlper.ts
digiwand May 9, 2024
b05d856
test:refactor: use DAPP_HOST_ADDRESS in DAPP_URL
digiwand May 9, 2024
fcffaac
Merge branch 'develop' into test-e2e-signature-redesign
digiwand May 10, 2024
a79c16d
test:e2e:fix: confirm redesign TypeError: windowHandles is not iterable
digiwand May 10, 2024
4e6910d
test:fix: flaky signature redesign w/ waitUntilXWindowHandles
digiwand May 10, 2024
bd82ec6
test:e2e: fix flaky signature redesign w/ switchToNotificationWindow
digiwand May 10, 2024
1693bd6
Merge branch 'develop' into test-e2e-signature-redesign
digiwand May 10, 2024
7360b19
test:fix: flaky test pt.3 use both waitUntilXWindowHandles & switchTo…
digiwand May 10, 2024
216a0a1
test:fix: attempt to fix flaky test with driverOptions: timeOut
digiwand May 10, 2024
238992d
test:e2e:refactor: rn
digiwand May 15, 2024
173290b
test:e2e:fix: confirm redesign scrollable confirmations
digiwand May 15, 2024
51b1f80
test:e2e:refactor: confirm redesign rm unused ganacheServer in reject…
digiwand May 15, 2024
174394e
Merge branch 'develop' into test-e2e-signature-redesign
digiwand May 24, 2024
7bf0b3d
feat: finish merge conflict
digiwand May 24, 2024
a156e5e
fix: CircleCI test-e2e-chrome-confirmation-redesign job (#24684)
digiwand May 24, 2024
a50557f
test:e2e: rm getAttribute asserts for Confirmations scroll helper
digiwand May 24, 2024
22f1bea
Merge branch 'develop' into test-e2e-signature-redesign
digiwand May 27, 2024
7ea5ac6
Merge branch 'develop' into test-e2e-signature-redesign
digiwand May 29, 2024
f53b310
Merge branch 'develop' into test-e2e-signature-redesign
digiwand May 30, 2024
9f6201a
chore: rm console.log
digiwand May 31, 2024
fe81382
Merge branch 'develop' into test-e2e-signature-redesign
digiwand May 31, 2024
f3fd7c8
Merge branch 'develop' into test-e2e-signature-redesign
digiwand Jun 3, 2024
6e183cb
fix: set confirmation e2e circleci retry count to 1
digiwand Jun 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion test/e2e/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,8 @@ const closeSRPReveal = async (driver) => {
});
};

const DAPP_URL = 'http://127.0.0.1:8080';
const DAPP_HOST_ADDRESS = '127.0.0.1:8080';
const DAPP_URL = `http://${DAPP_HOST_ADDRESS}`;
const DAPP_ONE_URL = 'http://127.0.0.1:8081';

const openDapp = async (driver, contract = null, dappURL = DAPP_URL) => {
Expand Down Expand Up @@ -1107,6 +1108,7 @@ async function initBundler(bundlerServer, ganacheServer, usePaymaster) {
}

module.exports = {
DAPP_HOST_ADDRESS,
DAPP_URL,
DAPP_ONE_URL,
TEST_SEED_PHRASE,
Expand Down
24 changes: 24 additions & 0 deletions test/e2e/tests/confirmations/helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {
defaultGanacheOptions,
withFixtures,
} from '../../helpers';
import FixtureBuilder from '../../fixture-builder';

export function withRedesignConfirmationFixtures (title: string = '', testFunction: Function) {
return withFixtures(
{
dapp: true,
fixtures: new FixtureBuilder()
.withPermissionControllerConnectedToTestDapp()
.withPreferencesController({
preferences: {
redesignedConfirmationsEnabled: true,
},
})
.build(),
ganacheOptions: defaultGanacheOptions,
title,
},
testFunction,
);
}
112 changes: 112 additions & 0 deletions test/e2e/tests/confirmations/signatures/permit.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import { strict as assert } from 'assert';
import { Suite } from 'mocha';
import { withRedesignConfirmationFixtures } from '../helper';
import {
DAPP_HOST_ADDRESS,
WINDOW_TITLES,
openDapp,
unlockWallet,
} from '../../../helpers';
import { Ganache } from '../../../seeder/ganache';
import { Driver } from '../../../webdriver/driver';

describe('Confirmation Signature - Permit', function (this: Suite) {
if (!process.env.ENABLE_CONFIRMATION_REDESIGN) { return; }

it('initiates and confirms', async function () {
await withRedesignConfirmationFixtures(
this.test?.fullTitle(),
async ({ driver, ganacheServer }: { driver: Driver, ganacheServer: Ganache }) => {
const addresses = await ganacheServer.getAccounts();
const publicAddress = addresses?.[0] as string;

await unlockWallet(driver);
await openDapp(driver);
await driver.clickElement('#signPermit');
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);

await assertInfoValues(driver);

await driver.clickElement('[data-testid="confirm-footer-button"]');

/**
* TODO: test scroll and fixing scroll
* @see {@link https://github.com/MetaMask/MetaMask-planning/issues/2458}
*/
// test "confirm-footer-button" is disabled and unclickable
//
// await driver.clickElement('.confirm-scroll-to-bottom__button');
// await driver.clickElement('[data-testid="confirm-footer-button"]');

await assertVerifiedResults(driver, publicAddress);
},
);
});

it('initiates and rejects', async function () {
await withRedesignConfirmationFixtures(
this.test?.fullTitle(),
async ({ driver, ganacheServer }: { driver: Driver, ganacheServer: Ganache }) => {
await unlockWallet(driver);
await openDapp(driver);
await driver.clickElement('#signPermit');
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog, { timeout: 20000 });
await driver.clickElement('[data-testid="confirm-footer-cancel-button"]');

await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);

const rejectionResult = await driver.waitForSelector({
css: '#signPermitResult',
text: 'Error: User rejected the request.',
});
assert.ok(rejectionResult);
},
);
});
});

async function assertInfoValues(driver: Driver) {
const origin = driver.findElement({ text: DAPP_HOST_ADDRESS });
const contractPetName = driver.findElement({
css: '.name__value',
text: '0xCcCCc...ccccC',
});

const primaryType = driver.findElement({ text: 'Permit' });
const owner = driver.findElement({ css: '.name__name', text: 'Account 1' });
const spender = driver.findElement({ css: '.name__value', text: '0x5B38D...eddC4' });
const value = driver.findElement({ text: '3000' });
const nonce = driver.findElement({ text: '0' });
const deadline = driver.findElement({ text: '50000000000' });

assert.ok(await origin, 'origin');
assert.ok(await contractPetName, 'contractPetName');
assert.ok(await primaryType, 'primaryType');
assert.ok(await owner, 'owner');
assert.ok(await spender, 'spender');
assert.ok(await value, 'value');
assert.ok(await nonce, 'nonce');
assert.ok(await deadline, 'deadline');
}

async function assertVerifiedResults(driver: Driver, publicAddress: string) {
await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);
await driver.clickElement('#signPermitVerify');

const verifyResult = await driver.findElement('#signPermitResult');
const verifyResultR = await driver.findElement('#signPermitResultR');
const verifyResultS = await driver.findElement('#signPermitResultS');
const verifyResultV = await driver.findElement('#signPermitResultV');

await driver.waitForSelector({
css: '#signPermitVerifyResult',
text: publicAddress,
});
const verifyRecoverAddress = await driver.findElement('#signPermitVerifyResult');

assert.equal(await verifyResult.getText(), '0x0a396f89ee073214f7e055e700048abd7b4aba6ecca0352937d6a2ebb7176f2f43c63097ad7597632e34d6a801695702ba603d5872a33ee7d7562fcdb9e816ee1c');
assert.equal(await verifyResultR.getText(), 'r: 0x0a396f89ee073214f7e055e700048abd7b4aba6ecca0352937d6a2ebb7176f2f');
assert.equal(await verifyResultS.getText(), 's: 0x43c63097ad7597632e34d6a801695702ba603d5872a33ee7d7562fcdb9e816ee');
assert.equal(await verifyResultV.getText(), 'v: 28');
assert.equal(await verifyRecoverAddress.getText(), publicAddress);
}
80 changes: 80 additions & 0 deletions test/e2e/tests/confirmations/signatures/personal-sign.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { strict as assert } from 'assert';
import { Suite } from 'mocha';
import { withRedesignConfirmationFixtures } from '../helper';
import {
DAPP_HOST_ADDRESS,
WINDOW_TITLES,
openDapp,
unlockWallet,
} from '../../../helpers';
import { Ganache } from '../../../seeder/ganache';
import { Driver } from '../../../webdriver/driver';

describe('Confirmation Signature - Personal Sign', function (this: Suite) {
if (!process.env.ENABLE_CONFIRMATION_REDESIGN) { return; }

it('initiates and confirms', async function () {
await withRedesignConfirmationFixtures(
this.test?.fullTitle(),
async ({ driver, ganacheServer }: { driver: Driver, ganacheServer: Ganache }) => {
const addresses = await ganacheServer.getAccounts();
const publicAddress = addresses?.[0] as string;

await unlockWallet(driver);
await openDapp(driver);
await driver.clickElement('#personalSign');
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);

await assertInfoValues(driver);

await driver.clickElement('[data-testid="confirm-footer-button"]');
matthewwalsh0 marked this conversation as resolved.
Show resolved Hide resolved

await assertVerifiedPersonalMessage(driver, publicAddress);
}
);
});

it('initiates and rejects', async function () {
await withRedesignConfirmationFixtures(
this.test?.fullTitle(),
async ({ driver, ganacheServer }: { driver: Driver, ganacheServer: Ganache }) => {
await unlockWallet(driver);
await openDapp(driver);
await driver.clickElement('#personalSign');
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog, { timeout: 20000 });
await driver.clickElement('[data-testid="confirm-footer-cancel-button"]');

await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);

const rejectionResult = await driver.waitForSelector({
css: '#personalSign',
text: 'Error: User rejected the request.',
});
assert.ok(rejectionResult);
},
);
});
});

async function assertInfoValues(driver: Driver) {
const origin = driver.findElement({ text: DAPP_HOST_ADDRESS });
const message = driver.findElement({ text: 'Example `personal_sign` message' });

assert.ok(await origin);
assert.ok(await message);
}

async function assertVerifiedPersonalMessage(driver: Driver, publicAddress: string) {
await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);
await driver.clickElement('#personalSignVerify');

const verifySigUtil = await driver.findElement('#personalSignVerifySigUtilResult');
await driver.waitForSelector({
css: '#personalSignVerifyECRecoverResult',
text: publicAddress,
});
const verifyECRecover = await driver.findElement('#personalSignVerifyECRecoverResult');

assert.equal(await verifySigUtil.getText(), publicAddress);
assert.equal(await verifyECRecover.getText(), publicAddress);
}
105 changes: 105 additions & 0 deletions test/e2e/tests/confirmations/signatures/sign-typed-data-v3.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { strict as assert } from 'assert';
import { Suite } from 'mocha';
import { withRedesignConfirmationFixtures } from '../helper';
import {
DAPP_HOST_ADDRESS,
WINDOW_TITLES,
openDapp,
unlockWallet,
} from '../../../helpers';
import { Ganache } from '../../../seeder/ganache';
import { Driver } from '../../../webdriver/driver';

describe('Confirmation Signature - Sign Typed Data V3', function (this: Suite) {
if (!process.env.ENABLE_CONFIRMATION_REDESIGN) { return; }

it('initiates and confirms', async function () {
await withRedesignConfirmationFixtures(
this.test?.fullTitle(),
async ({ driver, ganacheServer }: { driver: Driver, ganacheServer: Ganache }) => {
const addresses = await ganacheServer.getAccounts();
const publicAddress = addresses?.[0] as string;

await unlockWallet(driver);
await openDapp(driver);
await driver.clickElement('#signTypedDataV3');
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog, { timeout: 20000 });

await assertInfoValues(driver);

await driver.clickElement('[data-testid="confirm-footer-button"]');

/**
* TODO: test scroll and fixing scroll
* @see {@link https://github.com/MetaMask/MetaMask-planning/issues/2458}
*/
// test "confirm-footer-button" is disabled and unclickable
//
// await driver.clickElement('.confirm-scroll-to-bottom__button');
// await driver.clickElement('[data-testid="confirm-footer-button"]');

await assertVerifiedResults(driver, publicAddress);
},
);
});

it('initiates and rejects', async function () {
await withRedesignConfirmationFixtures(
this.test?.fullTitle(),
async ({ driver, ganacheServer }: { driver: Driver, ganacheServer: Ganache }) => {
await unlockWallet(driver);
await openDapp(driver);
await driver.clickElement('#signTypedDataV3');
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
await driver.clickElement('[data-testid="confirm-footer-cancel-button"]');

await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);

const rejectionResult = await driver.waitForSelector({
css: '#signTypedDataV3Result',
text: 'Error: User rejected the request.',
});
assert.ok(rejectionResult);
},
);
});
});

async function assertInfoValues(driver: Driver) {
const origin = driver.findElement({ text: DAPP_HOST_ADDRESS });
const contractPetName = driver.findElement({
css: '.name__value',
text: '0xCcCCc...ccccC',
});

const primaryType = driver.findElement({ text: 'Mail' });
const fromName = driver.findElement({ text: 'Cow' });
const fromAddress = driver.findElement({ css: '.name__value', text: '0xCD2a3...DD826' });
const toName = driver.findElement({ text: 'Bob' });
const toAddress = driver.findElement({ css: '.name__value', text: '0xbBbBB...bBBbB' });
const contents = driver.findElement({ text: 'Hello, Bob!' });

assert.ok(await origin, 'origin');
assert.ok(await contractPetName, 'contractPetName');
assert.ok(await primaryType, 'primaryType');
assert.ok(await fromName, 'fromName');
assert.ok(await fromAddress, 'fromAddress');
assert.ok(await toName, 'toName');
assert.ok(await toAddress, 'toAddress');
assert.ok(await contents, 'contents');
}

async function assertVerifiedResults(driver: Driver, publicAddress: string) {
await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);
await driver.clickElement('#signTypedDataV3Verify');

const verifyResult = await driver.findElement('#signTypedDataV3Result');
await driver.waitForSelector({
css: '#signTypedDataV3VerifyResult',
text: publicAddress,
});
const verifyRecoverAddress = await driver.findElement('#signTypedDataV3VerifyResult');

assert.equal(await verifyResult.getText(), '0x0a22f7796a2a70c8dc918e7e6eb8452c8f2999d1a1eb5ad714473d36270a40d6724472e5609948c778a07216bd082b60b6f6853d6354c731fd8ccdd3a2f4af261b');
assert.equal(await verifyRecoverAddress.getText(), publicAddress);
}