1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
metamask-extension/test/e2e/tests/edit-gas-fee.spec.js
Peter Yinusa 0b4532ec1b
E2e test fixtures (#16061)
* remove state.json files

* move file

* Update Readme

* Create fixture builder

* load test fixture

* remove redundant method

* update snap tests

* update stats tests

* update extension tests

* update extension tests

* Update fixture data

* snap test dapp connection

* Update fixture data

* add onboarding fixture

* use onboarding fixture

* reuse import account vault

* remove unnecessary use of class

* use fixture builder in new tests

* switch to function

* update default fixture

* update default fixture

* update test

* update 1559 test fixttures

* update 1559 test fixtures

* update 1559 test fixtures

* dismiss 3box whats new

* remove redundant code

* move docs

* remove unused code

* token detection

* use default timeout

* remove redundant code

* Update fixture builder

hide `Protect your funds` dialog
remove browser environment
remove default network details
hide dismiss seed backup reminder
recursively merges fixture data

* add token to tokencontroller

* remove network details

* add missing identities to preference controller

* remove duplicate properties

* update bip-32 to use fixturebuilder

* alphabetise snap permissions

* update get snaps to use fixturebuilder

* Update test-snap-bip-32.spec.js

wait for window

* add popular network state

* update test

* lint
2022-10-28 09:42:12 +01:00

273 lines
9.3 KiB
JavaScript

const { strict: assert } = require('assert');
const {
convertToHexValue,
getWindowHandles,
withFixtures,
} = require('../helpers');
const FixtureBuilder = require('../fixture-builder');
describe('Editing Confirm Transaction', function () {
it('allows selecting high, medium, low gas estimates on edit gas fee popover', async function () {
const ganacheOptions = {
hardfork: 'london',
accounts: [
{
secretKey:
'0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC',
balance: convertToHexValue(25000000000000000000),
},
],
};
await withFixtures(
{
fixtures: new FixtureBuilder()
.withPreferencesController({
eip1559V2Enabled: true,
})
.withTransactionControllerTypeTwoTransaction()
.build(),
ganacheOptions,
title: this.test.title,
},
async ({ driver }) => {
await driver.navigate();
await driver.fill('#password', 'correct horse battery staple');
await driver.press('#password', driver.Key.ENTER);
const transactionAmounts = await driver.findElements(
'.currency-display-component__text',
);
const transactionAmount = transactionAmounts[0];
assert.equal(await transactionAmount.getText(), '1');
// update estimates to high
await driver.clickElement('[data-testid="edit-gas-fee-button"]');
await driver.waitForSelector({
text: 'sec',
tag: 'span',
});
await driver.clickElement('[data-testid="edit-gas-fee-item-high"]');
await driver.waitForSelector({ text: '🦍' });
await driver.waitForSelector({
text: 'Aggressive',
});
// update estimates to medium
await driver.clickElement('[data-testid="edit-gas-fee-button"]');
await driver.clickElement('[data-testid="edit-gas-fee-item-medium"]');
await driver.waitForSelector({ text: '🦊' });
await driver.waitForSelector({
text: 'Market',
});
// update estimates to low
await driver.clickElement('[data-testid="edit-gas-fee-button"]');
await driver.clickElement('[data-testid="edit-gas-fee-item-low"]');
await driver.waitForSelector({ text: '🐢' });
await driver.waitForSelector({
text: 'Low',
});
await driver.waitForSelector('[data-testid="low-gas-fee-alert"]');
// confirms the transaction
await driver.clickElement({ text: 'Confirm', tag: 'button' });
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 === 1;
}, 10000);
const txValues = await driver.findElements(
'.transaction-list-item__primary-currency',
);
assert.equal(txValues.length, 1);
assert.ok(/-1\s*ETH/u.test(await txValues[0].getText()));
},
);
});
it('allows accessing advance gas fee popover from edit gas fee popover', async function () {
const ganacheOptions = {
hardfork: 'london',
accounts: [
{
secretKey:
'0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC',
balance: convertToHexValue(25000000000000000000),
},
],
};
await withFixtures(
{
fixtures: new FixtureBuilder()
.withPreferencesController({
eip1559V2Enabled: true,
})
.withTransactionControllerTypeTwoTransaction()
.build(),
ganacheOptions,
title: this.test.title,
},
async ({ driver }) => {
await driver.navigate();
await driver.fill('#password', 'correct horse battery staple');
await driver.press('#password', driver.Key.ENTER);
const transactionAmounts = await driver.findElements(
'.currency-display-component__text',
);
const transactionAmount = transactionAmounts[0];
assert.equal(await transactionAmount.getText(), '1');
// update estimates to high
await driver.clickElement('[data-testid="edit-gas-fee-button"]');
await driver.waitForSelector({
text: 'sec',
tag: 'span',
});
await driver.clickElement('[data-testid="edit-gas-fee-item-custom"]');
// enter max fee
await driver.fill('[data-testid="base-fee-input"]', '8.5');
// enter priority fee
await driver.fill('[data-testid="priority-fee-input"]', '8.5');
// save default values
await driver.clickElement('input[type="checkbox"]');
// edit gas limit
await driver.clickElement('[data-testid="advanced-gas-fee-edit"]');
await driver.fill('[data-testid="gas-limit-input"]', '100000');
// Submit gas fee changes
await driver.clickElement({ text: 'Save', tag: 'button' });
// has correct updated value on the confirm screen the transaction
await driver.waitForSelector({
css: '.transaction-detail-item:nth-of-type(1) h6:nth-of-type(2)',
text: '0.00085 ETH',
});
await driver.waitForSelector({
css: '.transaction-detail-item:nth-of-type(2) h6:nth-of-type(2)',
text: '1.00085 ETH',
});
// confirms the transaction
await driver.clickElement({ text: 'Confirm', tag: 'button' });
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 === 1;
}, 10000);
const txValues = await driver.findElements(
'.transaction-list-item__primary-currency',
);
assert.equal(txValues.length, 1);
assert.ok(/-1\s*ETH/u.test(await txValues[0].getText()));
},
);
});
it('should use dapp suggested estimates for transaction coming from dapp', async function () {
const ganacheOptions = {
hardfork: 'london',
accounts: [
{
secretKey:
'0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC',
balance: convertToHexValue(25000000000000000000),
},
],
};
await withFixtures(
{
fixtures: new FixtureBuilder()
.withPermissionControllerConnectedToTestDapp()
.withPreferencesController({
eip1559V2Enabled: true,
})
.build(),
ganacheOptions,
title: this.test.title,
dapp: true,
},
async ({ driver }) => {
await driver.navigate();
// login to extension
await driver.fill('#password', 'correct horse battery staple');
await driver.press('#password', driver.Key.ENTER);
// open dapp and connect
await driver.openNewPage('http://127.0.0.1:8080/');
await driver.clickElement({
text: 'Send EIP 1559 Transaction',
tag: 'button',
});
// check transaction in extension popup
const windowHandles = await getWindowHandles(driver, 3);
await driver.switchToWindow(windowHandles.popup);
await driver.waitForSelector({ text: '🌐' });
await driver.waitForSelector({
text: 'Site suggested',
});
await driver.clickElement('[data-testid="edit-gas-fee-button"]');
await driver.waitForSelector({
text: 'sec',
tag: 'span',
});
await driver.clickElement(
'[data-testid="edit-gas-fee-item-dappSuggested"]',
);
const transactionAmounts = await driver.findElements(
'.currency-display-component__text',
);
const transactionAmount = transactionAmounts[0];
assert.equal(await transactionAmount.getText(), '0');
// has correct updated value on the confirm screen the transaction
const editedTransactionAmounts = await driver.findElements(
'.transaction-detail-item__row .transaction-detail-item__detail-values .currency-display-component__text:last-of-type',
);
const editedTransactionAmount = editedTransactionAmounts[0];
assert.equal(await editedTransactionAmount.getText(), '0.00021');
const editedTransactionFee = editedTransactionAmounts[1];
assert.equal(await editedTransactionFee.getText(), '0.00021');
// confirms the transaction
await driver.clickElement({ text: 'Confirm', tag: 'button' });
// transaction should correct values in activity tab
await driver.switchToWindow(windowHandles.extension);
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 === 1;
}, 10000);
const txValues = await driver.findElements(
'.transaction-list-item__primary-currency',
);
assert.equal(txValues.length, 1);
assert.ok(/-0\s*ETH/u.test(await txValues[0].getText()));
},
);
});
});