Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

feat: support MetamaMask v10.25.X #281

Merged
merged 5 commits into from
Feb 13, 2023
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
3 changes: 2 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { getDappateerPath } from "./helpers/utils";

export const EXAMPLE_WEBSITE = "http://example.org";

export const RECOMMENDED_METAMASK_VERSION = "v10.24.2";
export const RECOMMENDED_METAMASK_VERSION = "v10.25.0";

export const DEFAULT_METAMASK_USERDATA = path.join(
getDappateerPath(),
"userData/chrome-mm"
);

export const DEFAULT_FLASK_USERDATA = path.join(
getDappateerPath(),
"userData/chrome-flask"
Expand Down
19 changes: 19 additions & 0 deletions src/helpers/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,25 @@ export const clickOnSettingsSwitch = async (
await button.click();
};

type Section =
| "General"
| "Advanced"
| "Contacts"
| "Snaps"
| "Security & privacy"
| "Alerts"
| "Networks"
| "Experimental"
| "About";
export const openSettingsScreen = async (
page: DappeteerPage,
section: Section = "General"
): Promise<void> => {
await profileDropdownClick(page);
await clickOnElement(page, "Settings");
await clickOnElement(page, section);
};

export const openNetworkDropdown = async (
page: DappeteerPage
): Promise<void> => {
Expand Down
16 changes: 13 additions & 3 deletions src/helpers/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,19 @@ export const getElementByContent = (

export const getElementByTestId = (
page: DappeteerPage,
testId: string
testId: string,
options: {
visible?: boolean;
detached?: boolean;
hidden?: boolean;
timeout?: number;
} = {}
): Promise<DappeteerElementHandle | null> =>
page.waitForSelector(`[data-testid="${testId}"]`);
page.waitForSelector(`[data-testid="${testId}"]`, {
timeout: 20000,
visible: true,
...options,
});

export const getInputByLabel = (
page: DappeteerPage,
Expand Down Expand Up @@ -91,7 +101,7 @@ export const getButton = async (
}
): Promise<DappeteerElementHandle> => {
return await Promise.race([
getElementByTestId(page, text),
getElementByTestId(page, text, options),
getElementByContent(page, text, "button", options),
]);
};
37 changes: 19 additions & 18 deletions src/metamask/confirmTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TransactionOptions } from "..";
import {
clickOnButton,
getElementByContent,
getElementByTestId,
retry,
typeOnInputField,
waitForOverlay,
Expand All @@ -10,8 +10,6 @@ import { DappeteerPage } from "../page";

import { GetSingedIn } from "./index";

const MIN_GAS = 21000;

export const confirmTransaction =
(page: DappeteerPage, getSingedIn: GetSingedIn) =>
async (options?: TransactionOptions): Promise<void> => {
Expand All @@ -25,41 +23,44 @@ export const confirmTransaction =
await page.bringToFront();
await page.reload();
await waitForOverlay(page);
await getElementByContent(page, "Edit", "button", {
await getElementByTestId(page, "edit-gas-fee-button", {
timeout: 500,
visible: false,
});
}, 15);

if (options) {
await clickOnButton(page, "Edit");
await clickOnButton(page, "Edit suggested gas fee");
await clickOnButton(page, "edit-gas-fee-button");
await clickOnButton(page, "edit-gas-fee-item-custom");
//non EIP1559 networks don't have priority fee. TODO: run separate Ganache with older hardfork to test this
let priority = false;
if (options.priority) {
priority = await typeOnInputField(
if (options.priority)
await typeOnInputField(
page,
"Max priority fee",
"Priority Fee", // priority-fee-input
String(options.priority),
true,
true,
true
);
}
if (options.gasLimit && options.gasLimit >= MIN_GAS)
if (options.gas)
await typeOnInputField(
page,
"Gas Limit",
String(options.gasLimit),
"Max base fee", // base-fee-input
String(options.priority),
true,
true,
true
);
if (options.gas && options.gasLimit >= MIN_GAS)
if (options.gasLimit) {
await clickOnButton(page, "advanced-gas-fee-edit");
await typeOnInputField(
page,
priority ? "Max fee" : "Gas Limit",
String(options.gasLimit),
"Gas limit", // gas-limit-input
String(options.priority),
true,
true,
true
);
}

await clickOnButton(page, "Save");
}
Expand Down
9 changes: 9 additions & 0 deletions src/setup/setupActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
clickOnNavigationButton,
clickOnSettingsSwitch,
openNetworkDropdown,
openSettingsScreen,
typeOnInputField,
waitForOverlay,
} from "../helpers";
Expand All @@ -19,6 +20,14 @@ export async function showTestNets(metaMaskPage: DappeteerPage): Promise<void> {
await clickOnLogo(metaMaskPage);
}

export async function enableEthSign(
metaMaskPage: DappeteerPage
): Promise<void> {
await openSettingsScreen(metaMaskPage, "Advanced");
await clickOnSettingsSwitch(metaMaskPage, "Toggle eth_sign requests");
await clickOnLogo(metaMaskPage);
}

export async function acceptTheRisks(
metaMaskPage: DappeteerPage
): Promise<void> {
Expand Down
3 changes: 3 additions & 0 deletions src/setup/setupMetaMask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
closeNewModal,
closePortfolioTooltip,
closeWhatsNewModal,
enableEthSign,
importAccount,
showTestNets,
} from "./setupActions";
Expand All @@ -25,6 +26,7 @@ const defaultMetaMaskSteps: Step<MetaMaskOptions>[] = [
importAccount,
closeNewModal,
showTestNets,
enableEthSign,
closeWhatsNewModal,
closeWhatsNewModal,
];
Expand All @@ -33,6 +35,7 @@ const flaskMetaMaskSteps: Step<MetaMaskOptions>[] = [
acceptTheRisks,
importAccount,
showTestNets,
enableEthSign,
closePortfolioTooltip,
closeWhatsNewModal,
closeWhatsNewModal,
Expand Down
8 changes: 0 additions & 8 deletions test/basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,21 +124,13 @@ describe("basic interactions", function () {
});

it("should not add network", async function (this: TestContext) {
if (this.browser.isMetaMaskFlask()) {
this.skip();
}

const addNetworkPromise = testPage.evaluate(addNetwork);
await metaMask.rejectAddNetwork();
const res = await addNetworkPromise;
expect(res).to.equal(false);
});

it("should add network and switch", async function (this: TestContext) {
if (this.browser.isMetaMaskFlask()) {
this.skip();
}

const addNetworkPromise = testPage.evaluate(addNetwork);
await metaMask.acceptAddNetwork();
const res = await addNetworkPromise;
Expand Down