1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 03:12:42 +02:00

Add e2e tests for queuing multiple transactions (#19411)

This commit is contained in:
Vinicius Stevam 2023-06-22 08:56:44 +01:00 committed by GitHub
parent 7949ec9cd4
commit ed702af8ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,7 +1,13 @@
const { convertToHexValue, withFixtures } = require('../helpers');
const assert = require('assert');
const {
convertToHexValue,
withFixtures,
openDapp,
regularDelayMs,
} = require('../helpers');
const FixtureBuilder = require('../fixture-builder');
describe('Confirm transactions', function () {
describe('Multiple transactions', function () {
const ganacheOptions = {
hardfork: 'london',
accounts: [
@ -12,11 +18,13 @@ describe('Confirm transactions', function () {
},
],
};
it('should be able to confirm multiple transactions', async function () {
it('creates multiple queued transactions, then confirms', async function () {
await withFixtures(
{
dapp: true,
fixtures: new FixtureBuilder()
.withTransactionControllerMultipleTransactions()
.withPermissionControllerConnectedToTestDapp()
.build(),
ganacheOptions,
title: this.test.title,
@ -26,42 +34,58 @@ describe('Confirm transactions', function () {
await driver.fill('#password', 'correct horse battery staple');
await driver.press('#password', driver.Key.ENTER);
// confirm multiple transactions
await driver.waitForSelector({
text: 'Reject 4 transactions',
tag: 'a',
// initiates a transaction from the dapp
await openDapp(driver);
// creates first transaction
await driver.clickElement({
text: 'Send EIP 1559 Transaction',
tag: 'button',
});
await driver.clickElement({ text: 'Confirm', tag: 'button' });
await driver.waitForSelector({
text: 'Reject 3 transactions',
tag: 'a',
await driver.waitUntilXWindowHandles(3);
const windowHandles = await driver.getAllWindowHandles();
const extensionTab = windowHandles[0];
const dApp = windowHandles[1];
const confirmation = windowHandles[2];
await driver.switchToWindow(dApp);
// creates second transaction
await driver.clickElement({
text: 'Send EIP 1559 Transaction',
tag: 'button',
});
await driver.clickElement({ text: 'Confirm', tag: 'button' });
await driver.switchToWindow(confirmation);
// confirms second transaction
await driver.waitForSelector({
text: 'Reject 2 transactions',
tag: 'a',
});
await driver.clickElement({ text: 'Confirm', tag: 'button' });
await driver.waitForElementNotPresent('.loading-overlay__spinner');
// confirms first transaction
await driver.clickElement({ text: 'Confirm', tag: 'button' });
await driver.waitUntilXWindowHandles(2);
await driver.switchToWindow(extensionTab);
await driver.delay(regularDelayMs);
await driver.clickElement('[data-testid="home__activity-tab"]');
await driver.wait(async () => {
const confirmedTxes = await driver.findElements(
'.transaction-list__completed-transactions .transaction-list-item',
);
return confirmedTxes.length === 4;
}, 10000);
const confirmedTxes = await driver.findElements(
'.transaction-list__completed-transactions .transaction-list-item',
);
assert.equal(confirmedTxes.length, 2);
},
);
});
it('should be able to reject multiple transactions', async function () {
it('creates multiple queued transactions, then rejects', async function () {
await withFixtures(
{
dapp: true,
fixtures: new FixtureBuilder()
.withTransactionControllerMultipleTransactions()
.withPermissionControllerConnectedToTestDapp()
.build(),
ganacheOptions,
title: this.test.title,
@ -71,27 +95,50 @@ describe('Confirm transactions', function () {
await driver.fill('#password', 'correct horse battery staple');
await driver.press('#password', driver.Key.ENTER);
// confirm multiple transactions
await driver.waitForSelector({
text: 'Reject 4 transactions',
tag: 'a',
// initiates a transaction from the dapp
await openDapp(driver);
// creates first transaction
await driver.clickElement({
text: 'Send EIP 1559 Transaction',
tag: 'button',
});
await driver.clickElement({ text: 'Reject', tag: 'button' });
await driver.waitForSelector({
text: 'Reject 3 transactions',
tag: 'a',
await driver.waitUntilXWindowHandles(3);
const windowHandles = await driver.getAllWindowHandles();
const extension = windowHandles[0];
const confirmation = windowHandles[2];
await driver.switchToWindowWithTitle('E2E Test Dapp', windowHandles);
// creates second transaction
await driver.clickElement({
text: 'Send EIP 1559 Transaction',
tag: 'button',
});
await driver.clickElement({ text: 'Reject', tag: 'button' });
await driver.switchToWindow(confirmation);
// rejects second transaction
await driver.waitForSelector({
text: 'Reject 2 transactions',
tag: 'a',
});
await driver.clickElement({ text: 'Reject', tag: 'button' });
await driver.waitForElementNotPresent('.loading-overlay__spinner');
// rejects first transaction
await driver.clickElement({ text: 'Reject', tag: 'button' });
await driver.waitForSelector('[data-testid="home__activity-tab"]');
await driver.waitUntilXWindowHandles(2);
await driver.switchToWindow(extension);
await driver.delay(regularDelayMs);
await driver.clickElement('[data-testid="home__activity-tab"]');
const isTransactionListEmpty = await driver.isElementPresentAndVisible(
'.transaction-list__empty-text',
);
assert.equal(isTransactionListEmpty, true);
// should not be present
await driver.assertElementNotPresent(
'.transaction-list__completed-transactions .transaction-list-item',
);
},
);
});