Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feat/multi-chain
Browse files Browse the repository at this point in the history
  • Loading branch information
superical committed Jan 7, 2022
2 parents 508820b + 81c0230 commit e9d0b4e
Show file tree
Hide file tree
Showing 14 changed files with 255 additions and 143 deletions.
3 changes: 2 additions & 1 deletion integration/local/endorse-owner.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import expect from "expect-puppeteer";
import { confirmTransaction } from "./utils.mjs";

export const endorseOwner = async (metamask, browser) => {
// force process to exit if any assertion fail
Expand Down Expand Up @@ -31,7 +32,7 @@ export const endorseOwner = async (metamask, browser) => {
await page.click("[data-testid='endorseBtn']");

await page.waitFor(1500);
await metamask.confirmTransaction();
await confirmTransaction(metamask);
await page.bringToFront();
await page.waitFor(1500);

Expand Down
6 changes: 4 additions & 2 deletions integration/local/metamask-init.mjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import puppeteer from "puppeteer";
import dappeteer from "dappeteer";
import dappeteer from "@chainsafe/dappeteer";

export const metamaskInit = async () => {
try {
const browser = await dappeteer.launch(puppeteer, {
metamaskVersion: "v10.1.1", // latest version looks like don't even assume default networks, need to manual add them
args: ["--no-sandbox"],
executablePath: process.env.PUPPETEER_EXEC_PATH,
headless: false, // must be false, so can test with metamask extension
defaultViewport: null,
// slowMo: 5,
});
const version = await browser.version();
const metamask = await dappeteer.getMetamask(browser, {
const metamask = await dappeteer.setupMetamask(browser, {
seed: "indicate swing place chair flight used hammer soon photo region volume shuffle",
});

Expand Down
3 changes: 2 additions & 1 deletion integration/local/nominate-owner-accept.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import expect from "expect-puppeteer";
import { confirmTransaction } from "./utils.mjs";

export const nominateOwnerAccept = async (metamask, browser) => {
// force process to exit if any assertion fail
Expand All @@ -25,7 +26,7 @@ export const nominateOwnerAccept = async (metamask, browser) => {
await page.click("[data-testid='endorseTransferBtn']");

await page.waitFor(1500);
await metamask.confirmTransaction();
await confirmTransaction(metamask);
await page.bringToFront();
await page.waitFor(1500);

Expand Down
3 changes: 2 additions & 1 deletion integration/local/nominate-owner.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import expect from "expect-puppeteer";
import { confirmTransaction } from "./utils.mjs";

export const nominateOwner = async (metamask, browser) => {
// force process to exit if any assertion fail
Expand Down Expand Up @@ -27,7 +28,7 @@ export const nominateOwner = async (metamask, browser) => {
await page.click("[data-testid='nominationBtn']");

await page.waitFor(1500);
await metamask.confirmTransaction();
await confirmTransaction(metamask);
await page.bringToFront();
await page.waitFor(1500);

Expand Down
3 changes: 2 additions & 1 deletion integration/local/surrender-accept.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import expect from "expect-puppeteer";
import { confirmTransaction } from "./utils.mjs";

export const surrenderAccept = async (metamask, browser) => {
// force process to exit if any assertion fail
Expand All @@ -23,7 +24,7 @@ export const surrenderAccept = async (metamask, browser) => {
await page.click("[data-testid='acceptSurrenderBtn']");

await page.waitFor(1500);
await metamask.confirmTransaction();
await confirmTransaction(metamask);
await page.bringToFront();
await page.waitFor(1500);

Expand Down
3 changes: 2 additions & 1 deletion integration/local/surrender-reject.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import expect from "expect-puppeteer";
import { confirmTransaction } from "./utils.mjs";

export const surrenderReject = async (metamask, browser) => {
// force process to exit if any assertion fail
Expand Down Expand Up @@ -27,7 +28,7 @@ export const surrenderReject = async (metamask, browser) => {
await page.click("[data-testid='confirmActionBtn']");

await page.waitFor(1500);
await metamask.confirmTransaction();
await confirmTransaction(metamask);
await page.bringToFront();
await page.waitFor(1500);

Expand Down
3 changes: 2 additions & 1 deletion integration/local/surrender.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import expect from "expect-puppeteer";
import { confirmTransaction } from "./utils.mjs";

export const surrender = async (metamask, browser) => {
// force process to exit if any assertion fail
Expand All @@ -23,7 +24,7 @@ export const surrender = async (metamask, browser) => {
await page.click("[data-testid='surrenderBtn']");

await page.waitFor(1500);
await metamask.confirmTransaction();
await confirmTransaction(metamask);
await page.bringToFront();
await page.waitFor(1500);

Expand Down
9 changes: 5 additions & 4 deletions integration/local/transfer-holder.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import expect from "expect-puppeteer";
import { confirmTransaction, approveAllAccounts } from "./utils.mjs";

export const transferHolder = async (metamask, browser) => {
// force process to exit if any assertion fail
Expand All @@ -12,10 +13,10 @@ export const transferHolder = async (metamask, browser) => {
await page.waitForSelector("[data-testid='connectToWallet']", { visible: true });
await page.click("[data-testid='connectToWallet']");

// START - approve application once, subsequent tests no longer need
await metamask.approve({ allAccounts: true });
// START - approve application once after connect to wallet, subsequent tests no longer need
await approveAllAccounts(metamask);
await page.bringToFront();
// END - approve application once, subsequent tests no longer need
// END - approve application once after connect to wallet, subsequent tests no longer need

await page.waitFor(1500); // after connect, need to wait awhile
await page.waitForSelector("[data-testid='manageAssetDropdown']", { visible: true });
Expand All @@ -32,7 +33,7 @@ export const transferHolder = async (metamask, browser) => {
await page.click("[data-testid='transferBtn']");

await page.waitFor(1500); // switch between metamask / page tab, need to wait awhile
await metamask.confirmTransaction();
await confirmTransaction(metamask);
await page.bringToFront();
await page.waitFor(1500); // switch between metamask / page tab, need to wait awhile

Expand Down
41 changes: 41 additions & 0 deletions integration/local/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// ChainSafe/dappeteer's metamask methods mostly doesn't not work out of box, fml

// manually dismiss banner!
// news popup keeps re-appearing AFTER some metamask actions
// clue (dasanra's fork) -> https://github.com/dasanra/dappeteer/commit/3656360e4f891a3e7d1e80e77a40b2cfb83af2c8
export const checkAndCloseNewsPopOver = async (metamask) => {
await metamask.page.waitFor(1000);
const isPopOverOpen = await metamask.page.evaluate(() => {
return document.querySelector(".whats-new-popup__popover") !== null;
});

if (isPopOverOpen) {
const closePopOverButton = await metamask.page.waitForSelector(".popover-header__button");
await closePopOverButton.click();
}
await metamask.page.waitFor(1000);
};

// https://github.com/ChainSafe/dappeteer/issues/67
export const confirmTransaction = async (metamask) => {
await metamask.confirmTransaction();
await metamask.page.waitForSelector(".btn-primary:not([disabled])", { visible: true });
await metamask.page.click(".btn-primary:not([disabled])");
await checkAndCloseNewsPopOver(metamask);
};

// manually approve all accounts!
// https://github.com/ChainSafe/dappeteer/blob/master/src/metamask/approve.ts
export const approveAllAccounts = async (metamask) => {
await metamask.page.bringToFront();
await metamask.page.reload();

const checkbox = await metamask.page.waitForSelector(".permissions-connect-choose-account__header-check-box");
await checkbox.click();

const button = await metamask.page.waitForSelector("button.button.btn-primary");
await button.click();

const connectButton = await metamask.page.waitForSelector("button.button.btn-primary");
await connectButton.click();
};
Loading

0 comments on commit e9d0b4e

Please sign in to comment.