Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: flaky BTC e2e tests #26082

Merged
merged 6 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions test/e2e/accounts/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,14 @@ export async function createBtcAccount(driver: Driver) {
text: messages.addNewBitcoinAccount.message,
tag: 'button',
});
await driver.clickElementAndWaitToDisappear({
text: 'Create',
tag: 'button',
});
await driver.clickElementAndWaitToDisappear(
{
text: 'Create',
tag: 'button',
},
// Longer timeout than usual, this reduces the flakiness
// around Bitcoin account creation (mainly required for
// Firefox)
5000,
danroc marked this conversation as resolved.
Show resolved Hide resolved
montelaidev marked this conversation as resolved.
Show resolved Hide resolved
);
}
3 changes: 3 additions & 0 deletions test/e2e/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ export const VERIFYING_PAYMASTER = '0xbdbDEc38ed168331b1F7004cc9e5392A2272C1D7';

/* Default ganache ETH balance in decimal when first login */
export const DEFAULT_GANACHE_ETH_BALANCE_DEC = '25';

/* Default BTC address created using test SRP */
export const DEFAULT_BTC_ACCOUNT = 'bc1qg6whd6pc0cguh6gpp3ewujm53hv32ta9hdp252';
25 changes: 4 additions & 21 deletions test/e2e/flask/btc/btc-account-overview.spec.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,12 @@
import { strict as assert } from 'assert';
import { Suite } from 'mocha';
import {
withFixtures,
defaultGanacheOptions,
unlockWallet,
} from '../../helpers';
import { Driver } from '../../webdriver/driver';
import FixtureBuilder from '../../fixture-builder';
import { createBtcAccount } from '../../accounts/common';
import { withBtcAccountSnap } from './common-btc';

describe('BTC Account - Overview', function (this: Suite) {
it('has portfolio button enabled for BTC accounts', async function () {
await withFixtures(
{
fixtures: new FixtureBuilder()
.withPreferencesControllerAndFeatureFlag({
bitcoinSupportEnabled: true,
})
.build(),
ganacheOptions: defaultGanacheOptions,
title: this.test?.fullTitle(),
},
async ({ driver }: { driver: Driver }) => {
await unlockWallet(driver);
await createBtcAccount(driver);
await withBtcAccountSnap(
{ title: this.test?.fullTitle() },
async (driver) => {
await driver.findElement({
css: '[data-testid="account-menu-icon"]',
text: 'Bitcoin Account',
Expand Down
29 changes: 5 additions & 24 deletions test/e2e/flask/btc/btc-dapp-connection.spec.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,12 @@
import { Suite } from 'mocha';
import {
withFixtures,
defaultGanacheOptions,
unlockWallet,
openDapp,
WINDOW_TITLES,
} from '../../helpers';
import { Driver } from '../../webdriver/driver';
import FixtureBuilder from '../../fixture-builder';
import { createBtcAccount } from '../../accounts/common';
import { openDapp, WINDOW_TITLES } from '../../helpers';
import { withBtcAccountSnap } from './common-btc';

describe('BTC Account - Dapp Connection', function (this: Suite) {
it('cannot connect to dapps', async function () {
await withFixtures(
{
dapp: true,
fixtures: new FixtureBuilder()
.withPreferencesControllerAndFeatureFlag({
bitcoinSupportEnabled: true,
})
.build(),
ganacheOptions: defaultGanacheOptions,
title: this.test?.fullTitle(),
},
async ({ driver }: { driver: Driver }) => {
await unlockWallet(driver);
await createBtcAccount(driver);
await withBtcAccountSnap(
{ title: this.test?.fullTitle() },
async (driver) => {
await openDapp(driver);
await driver.clickElement('#connectButton');
await driver.waitUntilXWindowHandles(3);
Expand Down
59 changes: 59 additions & 0 deletions test/e2e/flask/btc/common-btc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Mockttp } from 'mockttp';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: But we could have just named it common.ts since it's already in test/e2e/flask/btc/ folder!

import FixtureBuilder from '../../fixture-builder';
import { withFixtures, unlockWallet } from '../../helpers';
import { DEFAULT_BTC_ACCOUNT } from '../../constants';
import { Driver } from '../../webdriver/driver';
import { createBtcAccount } from '../../accounts/common';

const GENERATE_MOCK_BTC_BALANCE_CALL = (
address: string = DEFAULT_BTC_ACCOUNT,
): { data: { [address: string]: number } } => {
return {
data: {
[address]: 9999,
},
};
};

export async function mockBtcBalanceQuote(
mockServer: Mockttp,
address: string = DEFAULT_BTC_ACCOUNT,
) {
return [
await mockServer
.forGet(/https:\/\/api\.blockchair\.com\/bitcoin\/addresses\/balances/u)
.withQuery({
addresses: address,
})
.thenCallback(() => ({
statusCode: 200,
json: GENERATE_MOCK_BTC_BALANCE_CALL(address),
})),
];
}

export async function withBtcAccountSnap(
{
title,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: We could have use the whole test object here instead, so we could have computed the title only once here, rather than having it every calls to withBtcAccountSnap

bitcoinSupportEnabled,
}: { title?: string; bitcoinSupportEnabled?: boolean },
test: (driver: Driver) => Promise<void>,
) {
await withFixtures(
{
fixtures: new FixtureBuilder()
.withPreferencesControllerAndFeatureFlag({
bitcoinSupportEnabled: bitcoinSupportEnabled ?? true,
})
.build(),
title,
dapp: true,
testSpecificMock: mockBtcBalanceQuote,
},
async ({ driver }: { driver: Driver }) => {
await unlockWallet(driver);
await createBtcAccount(driver);
await test(driver);
},
);
}
86 changes: 16 additions & 70 deletions test/e2e/flask/btc/create-btc-account.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,22 @@ import { strict as assert } from 'assert';
import { Suite } from 'mocha';
import messages from '../../../../app/_locales/en/messages.json';

import FixtureBuilder from '../../fixture-builder';
import {
WALLET_PASSWORD,
completeSRPRevealQuiz,
defaultGanacheOptions,
getSelectedAccountAddress,
openSRPRevealQuiz,
removeSelectedAccount,
tapAndHoldToRevealSRP,
unlockWallet,
withFixtures,
} from '../../helpers';
import { Driver } from '../../webdriver/driver';
import { createBtcAccount } from '../../accounts/common';
import { withBtcAccountSnap } from './common-btc';

describe('Create BTC Account', function (this: Suite) {
it('create BTC account from the menu', async function () {
await withFixtures(
{
fixtures: new FixtureBuilder()
.withPreferencesControllerAndFeatureFlag({
bitcoinSupportEnabled: true,
})
.build(),
ganacheOptions: defaultGanacheOptions,
title: this.test?.fullTitle(),
},
async ({ driver }: { driver: Driver }) => {
await unlockWallet(driver);
await createBtcAccount(driver);
await withBtcAccountSnap(
{ title: this.test?.fullTitle() },
async (driver) => {
await driver.findElement({
css: '[data-testid="account-menu-icon"]',
text: 'Bitcoin Account',
Expand All @@ -41,19 +27,9 @@ describe('Create BTC Account', function (this: Suite) {
});

it('cannot create multiple BTC accounts', async function () {
await withFixtures(
{
fixtures: new FixtureBuilder()
.withPreferencesControllerAndFeatureFlag({
bitcoinSupportEnabled: true,
})
.build(),
ganacheOptions: defaultGanacheOptions,
title: this.test?.fullTitle(),
},
async ({ driver }: { driver: Driver }) => {
await unlockWallet(driver);
await createBtcAccount(driver);
await withBtcAccountSnap(
{ title: this.test?.fullTitle() },
async (driver) => {
await driver.delay(500);
await driver.clickElement('[data-testid="account-menu-icon"]');
await driver.clickElement(
Expand All @@ -80,19 +56,9 @@ describe('Create BTC Account', function (this: Suite) {
});

it('can cancel the removal of BTC account', async function () {
await withFixtures(
{
fixtures: new FixtureBuilder()
.withPreferencesControllerAndFeatureFlag({
bitcoinSupportEnabled: true,
})
.build(),
ganacheOptions: defaultGanacheOptions,
title: this.test?.fullTitle(),
},
async ({ driver }: { driver: Driver }) => {
await unlockWallet(driver);
await createBtcAccount(driver);
await withBtcAccountSnap(
{ title: this.test?.fullTitle() },
async (driver) => {
await driver.findElement({
css: '[data-testid="account-menu-icon"]',
text: 'Bitcoin Account',
Expand Down Expand Up @@ -121,19 +87,9 @@ describe('Create BTC Account', function (this: Suite) {
});

it('can recreate BTC account after deleting it', async function () {
await withFixtures(
{
fixtures: new FixtureBuilder()
.withPreferencesControllerAndFeatureFlag({
bitcoinSupportEnabled: true,
})
.build(),
ganacheOptions: defaultGanacheOptions,
title: this.test?.fullTitle(),
},
async ({ driver }: { driver: Driver }) => {
await unlockWallet(driver);
await createBtcAccount(driver);
await withBtcAccountSnap(
{ title: this.test?.fullTitle() },
async (driver) => {
await driver.findElement({
css: '[data-testid="account-menu-icon"]',
text: 'Bitcoin Account',
Expand All @@ -156,19 +112,9 @@ describe('Create BTC Account', function (this: Suite) {
});

it('can recreate BTC account after restoring wallet with SRP', async function () {
await withFixtures(
{
fixtures: new FixtureBuilder()
.withPreferencesControllerAndFeatureFlag({
bitcoinSupportEnabled: true,
})
.build(),
ganacheOptions: defaultGanacheOptions,
title: this.test?.fullTitle(),
},
async ({ driver }: { driver: Driver }) => {
await unlockWallet(driver);
await createBtcAccount(driver);
await withBtcAccountSnap(
{ title: this.test?.fullTitle() },
async (driver) => {
await driver.findElement({
css: '[data-testid="account-menu-icon"]',
text: 'Bitcoin Account',
Expand Down