Skip to content

Commit

Permalink
Revert "Custom gas e2e (#1318)" (#1354)
Browse files Browse the repository at this point in the history
  • Loading branch information
derHowie authored Feb 21, 2024
1 parent e466011 commit 1a2ba4e
Show file tree
Hide file tree
Showing 17 changed files with 240 additions and 541 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,6 @@ jobs:
- uses: geekyeggo/delete-artifact@v2
with:
name: node_modules.tar.gz
- name: Anvil Cleanup
run: yarn anvil:kill
- uses: geekyeggo/delete-artifact@v2
with:
name: screenshots
74 changes: 1 addition & 73 deletions e2e/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import * as fs from 'node:fs';

import { Contract } from '@ethersproject/contracts';
import { getDefaultProvider } from '@ethersproject/providers';
import { ethers } from 'ethers';
import {
Builder,
By,
Expand Down Expand Up @@ -737,84 +736,13 @@ export async function getOnchainBalance(addy: string, contract: string) {
}
}

async function fetchLatestTransactionHash(
provider: ethers.providers.JsonRpcProvider,
): Promise<string | null> {
const latestBlock = await provider.getBlockWithTransactions('latest');
if (latestBlock.transactions.length === 0) return null;
return latestBlock.transactions[latestBlock.transactions.length - 1].hash;
}

async function validateTransactionGasSettings(
transactionHash: string,
provider: ethers.providers.JsonRpcProvider,
expectedMaxPriorityFeePerGasInGwei: number,
expectedBaseFeeInGwei: number,
): Promise<void> {
if (!transactionHash) throw new Error('No transaction hash provided.');
const transaction = await provider.getTransaction(transactionHash);
if (!transaction) throw new Error('Transaction not found.');

const expectedTotalMaxFeePerGasInGwei =
expectedMaxPriorityFeePerGasInGwei + expectedBaseFeeInGwei;
const expectedMaxPriorityFeePerGasWei = ethers.utils.parseUnits(
expectedMaxPriorityFeePerGasInGwei.toString(),
'gwei',
);
const expectedTotalMaxFeePerGasWei = ethers.utils.parseUnits(
expectedTotalMaxFeePerGasInGwei.toString(),
'gwei',
);

const actualMaxPriorityFeePerGas = transaction.maxPriorityFeePerGas;
const actualMaxFeePerGas = transaction.maxFeePerGas;

if (
!actualMaxPriorityFeePerGas ||
!actualMaxFeePerGas ||
!actualMaxPriorityFeePerGas.eq(expectedMaxPriorityFeePerGasWei) ||
!actualMaxFeePerGas.eq(expectedTotalMaxFeePerGasWei)
) {
throw new Error(
`Gas settings mismatch. Expected maxPriorityFeePerGas: ${expectedMaxPriorityFeePerGasInGwei} gwei, expected total maxFeePerGas (Max Base Fee + Miner Tip): ${expectedTotalMaxFeePerGasInGwei} gwei, but got maxPriorityFeePerGas: ${
actualMaxPriorityFeePerGas
? ethers.utils.formatUnits(actualMaxPriorityFeePerGas, 'gwei')
: 'none'
} gwei, maxFeePerGas: ${
actualMaxFeePerGas
? ethers.utils.formatUnits(actualMaxFeePerGas, 'gwei')
: 'none'
} gwei.`,
);
}
}

export async function verifyCustomGasSettings(
maxBaseFee: number,
minerTip: number,
): Promise<void> {
const provider = new ethers.providers.JsonRpcProvider(
'http://127.0.0.1:8545',
);
const transactionHash = await fetchLatestTransactionHash(provider);
if (transactionHash) {
await validateTransactionGasSettings(
transactionHash,
provider,
maxBaseFee,
minerTip,
);
}
}

export async function transactionStatus() {
const provider = getDefaultProvider('http://127.0.0.1:8545');
const blockData = await provider.getBlock('latest');
const txnReceipt = await provider.getTransactionReceipt(
blockData.transactions[blockData.transactions.length - 1],
blockData.transactions[0],
);
const txnStatus = txnReceipt.status === 1 ? 'success' : 'failure';

return txnStatus;
}

Expand Down
10 changes: 0 additions & 10 deletions e2e/serial/optimismTransactions/1_sendFlow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
checkWalletName,
delay,
delayTime,
doNotFindElementByTestId,
executePerformShortcut,
findElementByTestId,
findElementByText,
Expand Down Expand Up @@ -122,15 +121,6 @@ describe('Complete Hardhat Optimism send flow', () => {
expect(Number(valueNum)).toBe(0);
});

it('should not be able to open up either of the gas menu options', async () => {
await doNotFindElementByTestId({ id: 'gas-menu', driver });
await doNotFindElementByTestId({ id: 'custom-gas-menu', driver });
await executePerformShortcut({ driver, key: 'C' });
await doNotFindElementByTestId({ id: 'custom-gas-sheet', driver });
await executePerformShortcut({ driver, key: 'G' });
await doNotFindElementByTestId({ id: 'transaction-speed-title', driver });
});

it('should be able to initiate Optimisim ETH transaction', async () => {
await driver.actions().sendKeys('1').perform();
const value = await findElementByTestId({ id: 'send-input-mask', driver });
Expand Down
94 changes: 1 addition & 93 deletions e2e/serial/send/1_sendFlow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { afterAll, afterEach, beforeAll, beforeEach, expect, it } from 'vitest';

import {
delayTime,
executePerformShortcut,
findElementById,
findElementByIdAndClick,
findElementByTestId,
Expand All @@ -22,7 +21,6 @@ import {
takeScreenshotOnFailure,
transactionStatus,
typeOnTextInput,
verifyCustomGasSettings,
waitAndClick,
} from '../../helpers';
import { TEST_VARIABLES } from '../../walletVariables';
Expand Down Expand Up @@ -208,95 +206,6 @@ it('should be able to click max and switch on send flow', async () => {
await inputMask.sendKeys('0.01');
});

it('should be able to open gas dropdown via shortcut', async () => {
await delayTime('long');
await executePerformShortcut({ driver, key: 'g' });
const txnSpeed1 = await findElementByText(driver, 'Transaction Speed');
expect(txnSpeed1).toBeTruthy();
await executePerformShortcut({ driver, key: 'ESCAPE' });
});

it('should be able to switch gas prices via dropdown on send flow', async () => {
await findElementByTestIdAndClick({ id: 'gas-menu', driver });
const txnSpeed2 = await findElementByText(driver, 'Transaction Speed');
expect(txnSpeed2).toBeTruthy();
await findElementByTextAndClick(driver, 'Urgent');
await delayTime('medium');
const urgent = await findElementByText(driver, 'Urgent');
expect(urgent).toBeTruthy();
});

it('should be able to open custom gas sheet via shortcut', async () => {
await delayTime('long');
await executePerformShortcut({ driver, key: 'c' });
const gasSettings1 = await findElementByText(driver, 'Gas Settings');
expect(gasSettings1).toBeTruthy();
await executePerformShortcut({ driver, key: 'ESCAPE' });
});

it('should be able to open up the custom gas menu on the send flow', async () => {
await findElementByTestIdAndClick({ id: 'custom-gas-menu', driver });
const gasSettings = await findElementByText(driver, 'Gas Settings');
expect(gasSettings).toBeTruthy();
});

it('should be able to open up the explainers on the custom gas menu', async () => {
// explainer 1
await findElementByTestIdAndClick({
id: 'current-base-fee-explainer',
driver,
});
await delayTime('short');
const current = await findElementByText(driver, 'The base fee is');
expect(current).toBeTruthy();
await findElementByTestIdAndClick({ id: 'explainer-action-button', driver });

// explainer 2
await findElementByTestIdAndClick({ id: 'max-base-fee-explainer', driver });
await delayTime('short');
const max = await findElementByText(driver, 'This is the maximum');
expect(max).toBeTruthy();
await findElementByTestIdAndClick({ id: 'explainer-action-button', driver });

// explainer 3
await findElementByTestIdAndClick({
id: 'max-priority-fee-explainer',
driver,
});
await delayTime('short');
const miner = await findElementByText(driver, 'The miner tip goes');
expect(miner).toBeTruthy();
await findElementByTestIdAndClick({ id: 'explainer-action-button', driver });
});

it('should be able to customize gas', async () => {
await delayTime('short');
await executePerformShortcut({ driver, key: 'TAB' });
await executePerformShortcut({ driver, key: 'BACK_SPACE', timesToPress: 5 });
await driver.actions().sendKeys('400').perform();
await delayTime('short');
await executePerformShortcut({ driver, key: 'TAB' });
await executePerformShortcut({ driver, key: 'BACK_SPACE', timesToPress: 5 });
await driver.actions().sendKeys('400').perform();
const baseFeeGweiInputMask = await querySelector(
driver,
"[data-testid='max-base-fee-input'] [data-testid='gwei-input-mask']",
);

expect(await baseFeeGweiInputMask.getAttribute('value')).toContain('400');

const minerTipGweiInputMask = await querySelector(
driver,
"[data-testid='miner-tip-input'] [data-testid='gwei-input-mask']",
);

expect(await minerTipGweiInputMask.getAttribute('value')).toContain('400');
await findElementByTestIdAndClick({ id: 'set-gas-button', driver });

const gasMenu = await findElementByTestId({ id: 'gas-menu', driver });
expect(await gasMenu.getText()).toContain('Custom');
});

it('should be able to go to review on send flow', async () => {
await findElementByTestIdAndClick({ id: 'send-review-button', driver });
});
Expand Down Expand Up @@ -327,8 +236,7 @@ it('should be able to interact with destination menu on review on send flow', as
it('should be able to send transaction on review on send flow', async () => {
await findElementByTestIdAndClick({ id: 'review-confirm-button', driver });
const sendTransaction = await transactionStatus();
expect(sendTransaction).toBe('success');
await verifyCustomGasSettings(400, 400);
expect(await sendTransaction).toBe('success');
});

it('should be able to rename a wallet from the wallet switcher', async () => {
Expand Down
17 changes: 10 additions & 7 deletions e2e/serial/send/2_shortcuts-sendFlow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ let driver: WebDriver;

const browser = process.env.BROWSER || 'chrome';
const os = process.env.OS || 'mac';
const isFirefox = browser === 'firefox';

describe('Complete send flow via shortcuts and keyboard navigation', () => {
beforeAll(async () => {
Expand Down Expand Up @@ -210,12 +211,14 @@ describe('Complete send flow via shortcuts and keyboard navigation', () => {
});

it('should be able to select asset to send from home using keyboard ', async () => {
await executePerformShortcut({ driver, key: 'ESCAPE' });
await executePerformShortcut({ driver, key: 'ARROW_LEFT' });
await executePerformShortcut({ driver, key: 'TAB', timesToPress: 8 });
await executePerformShortcut({ driver, key: 'SPACE' });
await executePerformShortcut({ driver, key: 'ARROW_DOWN' });
await executePerformShortcut({ driver, key: 'ENTER' });
await checkExtensionURL(driver, 'send');
if (!isFirefox) {
await executePerformShortcut({ driver, key: 'ESCAPE' });
await executePerformShortcut({ driver, key: 'ARROW_LEFT' });
await executePerformShortcut({ driver, key: 'TAB', timesToPress: 8 });
await executePerformShortcut({ driver, key: 'SPACE' });
await executePerformShortcut({ driver, key: 'ARROW_DOWN' });
await executePerformShortcut({ driver, key: 'ENTER' });
await checkExtensionURL(driver, 'send');
}
});
});
Loading

0 comments on commit 1a2ba4e

Please sign in to comment.