mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-23 02:10:12 +01:00
ec7e7fdf6d
* Fix fallback gas estimation Our fallback gas estimation was failing due to a bug in the `@metamask/controller-utils` package. This was causing gas estimation to fail completely on certain networks (those not supported by our gas estimation APIs and non EIP-1559 compatibile), and it was causing the fallback gas estimation operation (in case our API was down) to fail across all networks. Fixes https://github.com/MetaMask/metamask-extension/issues/19735 * Add e2e tests E2E tests have been added to capture gas estimation. Cases are added for our API, for the fallback estimate, and for non-EIP-1559 estimates. As part of this work, the legacy gas API had to be disabled. This was being used in e2e tests but was dead code in production. It needed to be disabled to ensure the code under test was reachable. * Fix gas API referenced in e2e test * Update unit test snapshots
172 lines
5.2 KiB
JavaScript
172 lines
5.2 KiB
JavaScript
const {
|
|
convertToHexValue,
|
|
withFixtures,
|
|
logInWithBalanceValidation,
|
|
} = require('../helpers');
|
|
const FixtureBuilder = require('../fixture-builder');
|
|
|
|
describe('Gas estimates generated by MetaMask', function () {
|
|
const baseGanacheOptions = {
|
|
accounts: [
|
|
{
|
|
secretKey:
|
|
'0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC',
|
|
balance: convertToHexValue(25000000000000000000),
|
|
},
|
|
],
|
|
};
|
|
const preLondonGanacheOptions = {
|
|
...baseGanacheOptions,
|
|
hardfork: 'berlin',
|
|
};
|
|
const postLondonGanacheOptions = {
|
|
...baseGanacheOptions,
|
|
hardfork: 'london',
|
|
};
|
|
|
|
describe('Send on a network that is EIP-1559 compatible', function () {
|
|
it('show expected gas defaults', async function () {
|
|
await withFixtures(
|
|
{
|
|
fixtures: new FixtureBuilder().build(),
|
|
ganacheOptions: postLondonGanacheOptions,
|
|
title: this.test.title,
|
|
},
|
|
async ({ driver, ganacheServer }) => {
|
|
await driver.navigate();
|
|
await logInWithBalanceValidation(driver, ganacheServer);
|
|
|
|
await driver.clickElement('[data-testid="eth-overview-send"]');
|
|
|
|
await driver.fill(
|
|
'input[placeholder="Enter public address (0x) or ENS name"]',
|
|
'0x2f318C334780961FB129D2a6c30D0763d9a5C970',
|
|
);
|
|
|
|
await driver.fill('.unit-input__input', '1');
|
|
|
|
// Check that the gas estimation is what we expect
|
|
await driver.findElement({
|
|
cass: '[data-testid="confirm-gas-display"]',
|
|
text: '0.00043983',
|
|
});
|
|
},
|
|
);
|
|
});
|
|
|
|
it('show expected gas defaults when API is down', async function () {
|
|
await withFixtures(
|
|
{
|
|
fixtures: new FixtureBuilder().build(),
|
|
ganacheOptions: postLondonGanacheOptions,
|
|
testSpecificMock: (mockServer) => {
|
|
mockServer
|
|
.forGet(
|
|
'https://gas-api.metaswap.codefi.network/networks/1337/suggestedGasFees',
|
|
)
|
|
.thenCallback(() => {
|
|
return {
|
|
json: {
|
|
error: 'cannot get gas prices for chain id 1337',
|
|
},
|
|
statusCode: 503,
|
|
};
|
|
});
|
|
},
|
|
title: this.test.title,
|
|
},
|
|
async ({ driver, ganacheServer }) => {
|
|
await driver.navigate();
|
|
await logInWithBalanceValidation(driver, ganacheServer);
|
|
|
|
await driver.clickElement('[data-testid="eth-overview-send"]');
|
|
|
|
await driver.fill(
|
|
'input[placeholder="Enter public address (0x) or ENS name"]',
|
|
'0x2f318C334780961FB129D2a6c30D0763d9a5C970',
|
|
);
|
|
|
|
await driver.fill('.unit-input__input', '1');
|
|
|
|
// Check that the gas estimation is what we expect
|
|
await driver.findElement({
|
|
cass: '[data-testid="confirm-gas-display"]',
|
|
text: '0.00043983',
|
|
});
|
|
},
|
|
);
|
|
});
|
|
|
|
it('show expected gas defaults when the network is not supported', async function () {
|
|
await withFixtures(
|
|
{
|
|
fixtures: new FixtureBuilder().build(),
|
|
ganacheOptions: postLondonGanacheOptions,
|
|
testSpecificMock: (mockServer) => {
|
|
mockServer
|
|
.forGet(
|
|
'https://gas-api.metaswap.codefi.network/networks/1337/suggestedGasFees',
|
|
)
|
|
.thenCallback(() => {
|
|
return {
|
|
statusCode: 422,
|
|
};
|
|
});
|
|
},
|
|
title: this.test.title,
|
|
},
|
|
async ({ driver, ganacheServer }) => {
|
|
await driver.navigate();
|
|
await logInWithBalanceValidation(driver, ganacheServer);
|
|
|
|
await driver.clickElement('[data-testid="eth-overview-send"]');
|
|
|
|
await driver.fill(
|
|
'input[placeholder="Enter public address (0x) or ENS name"]',
|
|
'0x2f318C334780961FB129D2a6c30D0763d9a5C970',
|
|
);
|
|
|
|
await driver.fill('.unit-input__input', '1');
|
|
|
|
// Check that the gas estimation is what we expect
|
|
await driver.findElement({
|
|
cass: '[data-testid="confirm-gas-display"]',
|
|
text: '0.00043983',
|
|
});
|
|
},
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('Send on a network that is not EIP-1559 compatible', function () {
|
|
it('show expected gas defaults', async function () {
|
|
await withFixtures(
|
|
{
|
|
fixtures: new FixtureBuilder().build(),
|
|
ganacheOptions: preLondonGanacheOptions,
|
|
title: this.test.title,
|
|
},
|
|
async ({ driver, ganacheServer }) => {
|
|
await driver.navigate();
|
|
await logInWithBalanceValidation(driver, ganacheServer);
|
|
|
|
await driver.clickElement('[data-testid="eth-overview-send"]');
|
|
|
|
await driver.fill(
|
|
'input[placeholder="Enter public address (0x) or ENS name"]',
|
|
'0x2f318C334780961FB129D2a6c30D0763d9a5C970',
|
|
);
|
|
|
|
await driver.fill('.unit-input__input', '1');
|
|
|
|
// Check that the gas estimation is what we expect
|
|
await driver.findElement({
|
|
cass: '[data-testid="confirm-gas-display"]',
|
|
text: '0.000042',
|
|
});
|
|
},
|
|
);
|
|
});
|
|
});
|
|
});
|