Skip to content

Commit

Permalink
feat: Migrate remaining e2e tests to redesigned confirmations
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronfigueiredo committed Nov 29, 2024
1 parent cbb57a1 commit cf512ad
Show file tree
Hide file tree
Showing 17 changed files with 4,573 additions and 2,367 deletions.
247 changes: 154 additions & 93 deletions test/e2e/json-rpc/eth_sendTransaction.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,105 +11,166 @@ const FixtureBuilder = require('../fixture-builder');
describe('eth_sendTransaction', function () {
const expectedHash =
'0x855951a65dcf5949dc54beb032adfb604c52a0a548a0f616799d6873a9521470';
it('confirms a new transaction', async function () {
await withFixtures(
{
dapp: true,
fixtures: new FixtureBuilder()
.withPermissionControllerConnectedToTestDapp()
.build(),
ganacheOptions: generateGanacheOptions({ hardfork: 'london' }),
title: this.test.fullTitle(),
},
async ({ driver }) => {
await unlockWallet(driver);

// eth_sendTransaction
await driver.openNewPage(`http://127.0.0.1:8080`);
const request = JSON.stringify({
jsonrpc: '2.0',
method: 'eth_sendTransaction',
params: [
{
to: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
from: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
value: '0x0',
maxPriorityFeePerGas: '0x3b9aca00',
maxFeePerGas: '0x2540be400',
},
],
id: 0,
});
await driver.executeScript(
`window.transactionHash = window.ethereum.request(${request})`,
);
describe('Old confirmation screens', function () {
it('rejects a new transaction', async function () {
await withFixtures(
{
dapp: true,
fixtures: new FixtureBuilder()
.withPermissionControllerConnectedToTestDapp()
.build(),
ganacheOptions: generateGanacheOptions({ hardfork: 'london' }),
title: this.test.fullTitle(),
},
async ({ driver }) => {
await unlockWallet(driver);

// confirm transaction in mm popup
await driver.waitUntilXWindowHandles(3);
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
await driver.clickElement({ text: 'Confirm', tag: 'button' });
await driver.switchToWindowWithTitle('E2E Test Dapp');
const actualHash = await driver.executeScript(
`return window.transactionHash;`,
);
assert.equal(actualHash, expectedHash);
},
);
await tempToggleSettingRedesignedTransactionConfirmations(driver);

// eth_sendTransaction
await driver.openNewPage(`http://127.0.0.1:8080`);
const request = JSON.stringify({
jsonrpc: '2.0',
method: 'eth_sendTransaction',
params: [
{
to: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
from: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
value: '0x0',
maxPriorityFeePerGas: '0x3b9aca00',
maxFeePerGas: '0x2540be400',
},
],
id: 0,
});
await driver.executeScript(
`window.transactionHash = window.ethereum.request(${request})`,
);

// reject transaction in mm popup
await driver.waitUntilXWindowHandles(3);
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
await driver.clickElement({ text: 'Reject', tag: 'button' });
await driver.switchToWindowWithTitle('E2E Test Dapp');
const result = await driver
.executeScript(`return window.transactionHash;`)
.then((data) => {
return data;
})
.catch((err) => {
return err;
});
assert.ok(
result.message.includes(
'MetaMask Tx Signature: User denied transaction signature.',
),
);
},
);
});
});
it('rejects a new transaction', async function () {
await withFixtures(
{
dapp: true,
fixtures: new FixtureBuilder()
.withPermissionControllerConnectedToTestDapp()
.build(),
ganacheOptions: generateGanacheOptions({ hardfork: 'london' }),
title: this.test.fullTitle(),
},
async ({ driver }) => {
await unlockWallet(driver);

await tempToggleSettingRedesignedTransactionConfirmations(driver);
describe('Redesigned confirmation screens', function () {
it('confirms a new transaction', async function () {
await withFixtures(
{
dapp: true,
fixtures: new FixtureBuilder()
.withPermissionControllerConnectedToTestDapp()
.build(),
ganacheOptions: generateGanacheOptions({ hardfork: 'london' }),
title: this.test.fullTitle(),
},
async ({ driver }) => {
await unlockWallet(driver);

// eth_sendTransaction
await driver.openNewPage(`http://127.0.0.1:8080`);
const request = JSON.stringify({
jsonrpc: '2.0',
method: 'eth_sendTransaction',
params: [
{
to: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
from: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
value: '0x0',
maxPriorityFeePerGas: '0x3b9aca00',
maxFeePerGas: '0x2540be400',
},
],
id: 0,
});
await driver.executeScript(
`window.transactionHash = window.ethereum.request(${request})`,
);
// eth_sendTransaction
await driver.openNewPage(`http://127.0.0.1:8080`);
const request = JSON.stringify({
jsonrpc: '2.0',
method: 'eth_sendTransaction',
params: [
{
to: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
from: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
value: '0x0',
maxPriorityFeePerGas: '0x3b9aca00',
maxFeePerGas: '0x2540be400',
},
],
id: 0,
});
await driver.executeScript(
`window.transactionHash = window.ethereum.request(${request})`,
);

// reject transaction in mm popup
await driver.waitUntilXWindowHandles(3);
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
await driver.clickElement({ text: 'Reject', tag: 'button' });
await driver.switchToWindowWithTitle('E2E Test Dapp');
const result = await driver
.executeScript(`return window.transactionHash;`)
.then((data) => {
return data;
})
.catch((err) => {
return err;
// confirm transaction in mm popup
await driver.waitUntilXWindowHandles(3);
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
await driver.clickElement({ text: 'Confirm', tag: 'button' });
await driver.switchToWindowWithTitle('E2E Test Dapp');
const actualHash = await driver.executeScript(
`return window.transactionHash;`,
);
assert.equal(actualHash, expectedHash);
},
);
});

it('rejects a new transaction', async function () {
await withFixtures(
{
dapp: true,
fixtures: new FixtureBuilder()
.withPermissionControllerConnectedToTestDapp()
.build(),
ganacheOptions: generateGanacheOptions({ hardfork: 'london' }),
title: this.test.fullTitle(),
},
async ({ driver }) => {
await unlockWallet(driver);

// eth_sendTransaction
await driver.openNewPage(`http://127.0.0.1:8080`);
const request = JSON.stringify({
jsonrpc: '2.0',
method: 'eth_sendTransaction',
params: [
{
to: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
from: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
value: '0x0',
maxPriorityFeePerGas: '0x3b9aca00',
maxFeePerGas: '0x2540be400',
},
],
id: 0,
});
assert.ok(
result.message.includes(
'MetaMask Tx Signature: User denied transaction signature.',
),
);
},
);
await driver.executeScript(
`window.transactionHash = window.ethereum.request(${request})`,
);

// reject transaction in mm popup
await driver.waitUntilXWindowHandles(3);
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
await driver.clickElement({ text: 'Cancel', tag: 'button' });
await driver.switchToWindowWithTitle('E2E Test Dapp');
const result = await driver
.executeScript(`return window.transactionHash;`)
.then((data) => {
return data;
})
.catch((err) => {
return err;
});
assert.ok(
result.message.includes(
'MetaMask Tx Signature: User denied transaction signature.',
),
);
},
);
});
});
});
36 changes: 36 additions & 0 deletions test/e2e/page-objects/flows/send-transaction.flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,42 @@ export const sendRedesignedTransactionToAddress = async ({
await transactionConfirmationPage.clickFooterConfirmButton();
};

/**
* This function initiates the steps required to send a transaction from the homepage to final confirmation.
*
* @param params - An object containing the parameters.
* @param params.driver - The webdriver instance.
* @param params.recipientAccount - The recipient account.
* @param params.amount - The amount of the asset to be sent in the transaction.
*/
export const sendRedesignedTransactionToAccount = async ({
driver,
recipientAccount,
amount,
}: {
driver: Driver;
recipientAccount: string;
amount: string;
}): Promise<void> => {
console.log(
`Start flow to send amount ${amount} to recipient account ${recipientAccount} on home screen`,
);
// click send button on homepage to start flow
const homePage = new HomePage(driver);
await homePage.startSendFlow();

// user should land on send token screen to fill recipient and amount
const sendToPage = new SendTokenPage(driver);
await sendToPage.check_pageIsLoaded();
await sendToPage.selectRecipientAccount(recipientAccount);
await sendToPage.fillAmount(amount);
await sendToPage.goToNextScreen();

// confirm transaction when user lands on confirm transaction screen
const transactionConfirmationPage = new TransactionConfirmation(driver);
await transactionConfirmationPage.clickFooterConfirmButton();
};

/**
* This function initiates the steps required to send a transaction from the homepage to final confirmation.
*
Expand Down
33 changes: 33 additions & 0 deletions test/e2e/page-objects/pages/confirmations/redesign/confirmation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ class Confirmation {
text: 'Alert',
};

private nextPageButton: RawLocator;

private previousPageButton: RawLocator;

private navigationTitle: RawLocator;

constructor(driver: Driver) {
this.driver = driver;

Expand All @@ -28,6 +34,10 @@ class Confirmation {
this.headerAccountDetailsButton =
'[data-testid="header-info__account-details-button"]';
this.footerCancelButton = '[data-testid="confirm-footer-cancel-button"]';
this.nextPageButton = '[data-testid="confirm-nav__next-confirmation"]';
this.previousPageButton =
'[data-testid="confirm-nav__previous-confirmation"]';
this.navigationTitle = '[data-testid="confirm-page-nav-position"]';
}

async clickScrollToBottomButton() {
Expand Down Expand Up @@ -58,6 +68,29 @@ class Confirmation {
async clickInlineAlert() {
await this.driver.clickElement(this.inlineAlertButton);
}

async clickNextPage(): Promise<void> {
await this.driver.clickElement(this.nextPageButton);
}

async clickPreviousPage(): Promise<void> {
await this.driver.clickElement(this.previousPageButton);
}

async check_pageNumbers(
currentPage: number,
totalPages: number,
): Promise<void> {
try {
await this.driver.findElement({
css: this.navigationTitle,
text: `${currentPage} of ${totalPages}`,
});
} catch (e) {
console.log('Timeout while waiting for navigation page numbers', e);
throw e;
}
}
}

export default Confirmation;
Loading

0 comments on commit cf512ad

Please sign in to comment.