Skip to content

Commit

Permalink
BX-1080 - Add op Sends to testing (#1048)
Browse files Browse the repository at this point in the history
  • Loading branch information
BrodyHughes authored Oct 18, 2023
1 parent dcc5c08 commit 0a1959a
Show file tree
Hide file tree
Showing 25 changed files with 426 additions and 71 deletions.
35 changes: 34 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,39 @@ jobs:
- name: Fail if any tests failed
if: steps.ChromeE2ESend.outcome == 'failure'
run: exit 1
chrome-optimism-e2e-send:
runs-on: send-runner-bx
timeout-minutes: 25
needs: [build]
env:
DISPLAY: :0
VITEST_SEGFAULT_RETRY: 3
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/chromeTestsSetup
with:
gh-access-token: ${{ secrets.DOTENV_GITHUB_ACCESS_TOKEN }}
- name: Run Optimism e2e send (Chrome)
id: ChromeOpE2ESend
continue-on-error: true
uses: nick-fields/retry@v2
with:
timeout_minutes: 25
max_attempts: 2
command: |
export BROWSER=chrome
export OS=linux
export CHROMIUM_BIN=$(find chrome -type f -name 'chrome')
yarn vitest:send:optimism --retry=5
- name: Upload deps artifacts
if: steps.ChromeOpE2ESend.outcome == 'failure'
uses: actions/upload-artifact@v3
with:
name: screenshots
path: screenshots/
- name: Fail if any tests failed
if: steps.ChromeOpE2ESend.outcome == 'failure'
run: exit 1
chrome-e2e-dappInteractions:
runs-on: dapp-interactions-runner-bx
timeout-minutes: 25
Expand Down Expand Up @@ -457,7 +490,7 @@ jobs:
run: yarn typecheck
cleanup:
runs-on: ubuntu-latest
needs: [firefox-e2e-parallel, firefox-e2e-send, firefox-e2e-dappInteractions, chrome-e2e-parallel, chrome-e2e-swap, chrome-e2e-send, chrome-e2e-dappInteractions, unit-tests, ci-checks]
needs: [firefox-e2e-parallel, firefox-e2e-send, firefox-e2e-dappInteractions, chrome-e2e-parallel, chrome-e2e-swap, chrome-e2e-send, chrome-e2e-dappInteractions, chrome-optimism-e2e-send, unit-tests, ci-checks]
steps:
- uses: geekyeggo/delete-artifact@v2
with:
Expand Down
11 changes: 4 additions & 7 deletions e2e/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -687,13 +687,10 @@ export async function getOnchainBalance(addy: string, contract: string) {
export async function transactionStatus() {
const provider = getDefaultProvider('http://127.0.0.1:8545');
const blockData = await provider.getBlock('latest');
const txn = await provider.getTransaction(blockData.transactions[0]);
const txnData = txn.wait();

// transactionResponse.wait.status returns '1' if txn is successful
// it returns '0' if the txn is a failure
const txnStatus = (await txnData).status === 1 ? 'success' : 'failure';

const txnReceipt = await provider.getTransactionReceipt(
blockData.transactions[0],
);
const txnStatus = txnReceipt.status === 1 ? 'success' : 'failure';
return txnStatus;
}

Expand Down
144 changes: 144 additions & 0 deletions e2e/serial/optimismTransactions/1_sendFlow.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import 'chromedriver';
import 'geckodriver';
import { WebDriver } from 'selenium-webdriver';
import {
afterAll,
afterEach,
beforeAll,
beforeEach,
describe,
expect,
it,
} from 'vitest';

import {
checkExtensionURL,
checkWalletName,
delay,
delayTime,
executePerformShortcut,
findElementByTestId,
findElementByText,
getExtensionIdByName,
getRootUrl,
goToPopup,
importWalletFlowUsingKeyboardNavigation,
initDriverWithOptions,
navigateToElementWithTestId,
takeScreenshotOnFailure,
transactionStatus,
} from '../../helpers';
import { TEST_VARIABLES } from '../../walletVariables';

let rootURL = getRootUrl();
let driver: WebDriver;

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

describe('Complete Hardhat Optimism send flow', () => {
beforeAll(async () => {
driver = await initDriverWithOptions({
browser,
os,
});
const extensionId = await getExtensionIdByName(driver, 'Rainbow');
if (!extensionId) throw new Error('Extension not found');
rootURL += extensionId;
});

beforeEach<{ driver: WebDriver }>(async (context) => {
context.driver = driver;
});

afterEach<{ driver: WebDriver }>(async (context) => {
await takeScreenshotOnFailure(context);
});

afterAll(() => driver.quit());

it('should be able import a wallet via pk', async () => {
await importWalletFlowUsingKeyboardNavigation(
driver,
rootURL,
TEST_VARIABLES.SEED_WALLET.PK,
);
});

it('should display account name', async () => {
await checkWalletName(driver, rootURL, TEST_VARIABLES.SEED_WALLET.ADDRESS);
});

it('should be able to go to setings', async () => {
await goToPopup(driver, rootURL);
await executePerformShortcut({ driver, key: 'DECIMAL' });
await executePerformShortcut({ driver, key: 'ARROW_DOWN' });
await executePerformShortcut({ driver, key: 'ENTER' });
await checkExtensionURL(driver, 'settings');
});

it('should be able to connect to hardhat Optimism', async () => {
await navigateToElementWithTestId({
driver,
testId: 'connect-to-hardhat-op',
});
const button = await findElementByText(
driver,
'Disconnect from Hardhat Optimism',
);
expect(button).toBeTruthy();
await executePerformShortcut({ driver, key: 'ESCAPE' });
});

it('should be able to navigate to send', async () => {
await executePerformShortcut({ driver, key: 's' });
await checkExtensionURL(driver, 'send');
});

it('should be able to nav to send field and type in address', async () => {
await executePerformShortcut({ driver, key: 'TAB', timesToPress: 2 });
await driver
.actions()
.sendKeys('0x9126914f62314402cC3f098becfaa7c2Bc23a55C')
.perform();
const shortenedAddress = await findElementByText(driver, '0x9126…a55C');
expect(shortenedAddress).toBeTruthy();
});

it('should be able to select asset to send with keyboard', async () => {
await navigateToElementWithTestId({
driver,
testId: 'asset-name-eth_10',
});
await delayTime('long');
const tokenInput = await findElementByTestId({
id: 'input-wrapper-dropdown-token-input',
driver,
});
expect(await tokenInput.getText()).toContain('Ethereum');
const value = await findElementByTestId({ id: 'send-input-mask', driver });
const valueNum = await value.getAttribute('value');
expect(Number(valueNum)).toBe(0);
});

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 });
const valueNum = await value.getAttribute('value');
expect(Number(valueNum)).toBe(1);
await navigateToElementWithTestId({ driver, testId: 'send-review-button' });
const reviewText = await findElementByText(driver, 'Review & Send');
expect(reviewText).toBeTruthy();
await delayTime('medium');
await navigateToElementWithTestId({ driver, testId: 'L2-check-1' });
await navigateToElementWithTestId({ driver, testId: 'L2-check-2' });
await navigateToElementWithTestId({
driver,
testId: 'review-confirm-button',
});
await delayTime('very-long');
const sendTransaction = await transactionStatus();
expect(sendTransaction).toBe('success');
await delay(10000);
});
});
2 changes: 0 additions & 2 deletions e2e/serial/send/2_shortcuts-sendFlow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ describe('Complete send flow via shortcuts and keyboard navigation', () => {
});
const placeholderBeforeContent =
await placeholderBefore.getAttribute('placeholder');
console.log(placeholderBeforeContent);
expect(placeholderBeforeContent).toContain('ETH');
await executePerformShortcut({ driver, key: 'TAB', timesToPress: 2 });
await executePerformShortcut({ driver, key: 'ENTER' });
Expand All @@ -184,7 +183,6 @@ describe('Complete send flow via shortcuts and keyboard navigation', () => {
driver,
});
const placeholderContent = await placeholder.getAttribute('placeholder');
console.log(placeholderContent);
expect(placeholderContent).toContain('USD');
});

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
"// Build and zip": "",
"bundle": "yarn build && yarn zip",
"// Runs tests": "",
"anvil": "ALCHEMY_API_KEY=$(grep ALCHEMY_API_KEY .env | cut -d '=' -f2) && anvil --fork-url https://eth-mainnet.alchemyapi.io/v2/$ALCHEMY_API_KEY",
"anvil": "ETH_MAINNET_RPC=$(grep ETH_MAINNET_RPC .env | cut -d '=' -f2) && anvil --fork-url $ETH_MAINNET_RPC",
"anvil:optimism": "OPTIMISM_MAINNET_RPC=$(grep OPTIMISM_MAINNET_RPC .env | cut -d '=' -f2) && anvil --fork-url $OPTIMISM_MAINNET_RPC",
"anvil:kill": "lsof -i :8545|tail -n +2|awk '{print $2}'|xargs -r kill -s SIGINT",
"test": "./scripts/unit-tests.sh",
"test:watch": "yarn anvil & vitest --watch",
Expand All @@ -60,6 +61,7 @@
"vitest:serial": "./scripts/e2e-serial-tests.sh",
"vitest:swap": "./scripts/e2e-serial-tests.sh 'swap'",
"vitest:send": "./scripts/e2e-serial-tests.sh 'send'",
"vitest:send:optimism": "./scripts/e2e-op-serial-tests.sh 'optimismTransactions'",
"vitest:dappInteractions": "./scripts/e2e-serial-tests.sh 'dappInteractions'",
"e2e:mac:chrome": "BROWSER=chrome OS=mac yarn vitest:parallel && yarn vitest:serial",
"e2e:mac:brave": "BROWSER=brave OS=mac yarn vitest:parallel && yarn vitest:serial",
Expand Down
29 changes: 29 additions & 0 deletions scripts/e2e-op-serial-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash
ANVIL_PORT=8545

# Launch anvil in the bg
yarn anvil:kill
yarn anvil:optimism --chain-id 1338 &
echo "Launching Anvil..."

# Give it some time to boot
interval=5
until nc -z localhost $ANVIL_PORT; do
sleep $interval
interval=$((interval * 2))
done
echo "Anvil Launched..."

# Run the tests and store the result
echo "Running Tests..."
yarn vitest e2e/serial/$1 --config ./e2e/serial/vitest.config.ts --reporter=verbose

# Store exit code
TEST_RESULT=$?

# kill anvil
echo "Cleaning Up..."
yarn anvil:kill

# return the result of the tests
exit "$TEST_RESULT"
1 change: 1 addition & 0 deletions src/core/keychain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ export const sendTransaction = async (
if (typeof txPayload.from === 'undefined') {
throw new Error('Missing from address');
}

const signer = await keychainManager.getSigner(txPayload.from as Address);
const wallet = signer.connect(provider);
let response = await wallet.sendTransaction(txPayload);
Expand Down
1 change: 1 addition & 0 deletions src/core/references/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export const NATIVE_ASSETS_PER_CHAIN: Record<ChainId, AddressOrEth> = {
[ChainId.bsc]: BSC_BNB_ADDRESS as Address,
[ChainId.bscTestnet]: BSC_BNB_ADDRESS as Address,
[ChainId.optimism]: ETH_OPTIMISM_ADDRESS as Address,
[ChainId.hardhatOptimism]: ETH_OPTIMISM_ADDRESS as Address,
[ChainId.optimismGoerli]: ETH_OPTIMISM_ADDRESS as Address,
[ChainId.base]: ETH_BASE_ADDRESS as Address,
[ChainId.baseGoerli]: ETH_BASE_ADDRESS as Address,
Expand Down
Loading

0 comments on commit 0a1959a

Please sign in to comment.