Skip to content
This repository has been archived by the owner on Oct 15, 2023. It is now read-only.

Commit

Permalink
Merge pull request #50 from jayden-sudo/develop
Browse files Browse the repository at this point in the history
chore: added op-goerli testcase
  • Loading branch information
exrobbie authored Sep 6, 2023
2 parents a605e69 + 0f440a5 commit 775d929
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 58 deletions.
10 changes: 9 additions & 1 deletion .env.test.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@
# global config
PRIVATEKEY: "<you EOA privateKey>"

CHAINLIST: "arbitrum-goerli,optimism-goerli,goerli"

# RPC config, key = rpc-lowercase(network name in UI)
rpc-arbitrum-goerli: "https://goerli-rollup.arbitrum.io/rpc"
maxfee-arbitrum-goerli: 0.0001
activatewallet-arbitrum-goerli: true

rpc-optimism-goerli: "https://optimism-goerli.publicnode.com"
maxfee-optimism-goerli: 0.001
activatewallet-optimism-goerli: true

rpc-goerli: "https://ethereum-goerli.publicnode.com"
maxfee-goerli: 0.001
maxfee-goerli: 0.001
activatewallet-goerli: false
36 changes: 25 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
name: ci

on:
push:
branches: ["feature/ui"]
branches: ["develop"]

jobs:
UnitTest:
timeout-minutes: 20
Expand All @@ -11,6 +13,18 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

# base64 < .env
- name: Create .env file
run: |
echo "${{ secrets.ENV_BUILD }}" | base64 -d > .env
ls -la .env
# base64 < .env.test
- name: Create .env.test file
run: |
echo "${{ secrets.ENV_TEST }}" | base64 -d > .env.test
ls -la .env.test
- name: Install Node.js
uses: actions/setup-node@v3
with:
Expand All @@ -36,15 +50,7 @@ jobs:
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install --frozen-lockfile

# base64 < .env
- name: Create .env file
run: echo "${{ secrets.ENV_BUILD }}" | base64 -d > .env

# base64 < .env.test
- name: Create .env.test file
run: echo "${{ secrets.ENV_TEST }}" | base64 -d > .env.test
run: pnpm install

- name: Install Playwright Browsers
run: pnpm exec playwright install chromium --with-deps
Expand All @@ -55,7 +61,7 @@ jobs:

- name: Run UI:Test
run: xvfb-run npx playwright test
timeout-minutes: 10
timeout-minutes: 20

- uses: actions/upload-artifact@v3
if: always()
Expand All @@ -79,7 +85,15 @@ jobs:
retention-days: 30

- uses: actions/upload-artifact@v3
if: success()
with:
name: dist
path: dist/
retention-days: 30

- uses: actions/upload-artifact@v3
if: failure()
with:
name: dist(failure)
path: dist/
retention-days: 1
1 change: 0 additions & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export default defineConfig({
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 1 : 0,
/* Opt out of parallel tests on CI. */
workers: 1,
Expand Down
36 changes: 8 additions & 28 deletions tests/activateWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@ export async function activate(
debugger;
throw new Error("popupPage is undefined");
}
for (let index = 0; index < pages.length; index++) {
const page = pages[index];
if (page.url() === "about:blank") {
await page.close();
break;
}
}

await popupPage.getByRole("button", { name: "I Understand" }).click();
await popupPage.getByText("Create New Wallet").click();
Expand Down Expand Up @@ -66,36 +59,23 @@ export async function activate(
await popupPage.getByPlaceholder("Enter amount").fill(threshold.toString());
await popupPage.getByRole("button", { name: "Continue" }).click();

await popupPage.getByRole("button", { name: "Store On-chain" }).click();
await popupPage.getByRole("button", { name: "Store Onchain" }).click();
await popupPage.getByRole("button", { name: "Continue" }).click();
await popupPage.getByRole("button", { name: "Yes" }).click();
// await popupPage.getByRole('button', { name: 'Activate Wallet' }).click();
await popupPage.goto(`chrome-extension://${extensionId}/popup.html`);

const chainNames = await UIKit.listChainNames(popupPage);
console.log("chainNames", chainNames);
const supportedChainNames = ["Arbitrum Goerli", "Goerli"];
if (
chainNames.length !== supportedChainNames.length ||
chainNames[0] !== supportedChainNames[0] ||
chainNames[1] !== supportedChainNames[1]
) {
throw new Error(`chainNames not match!`);
}
let walletAddress = "";
{
// Arbitrum Goerli
const chainName = supportedChainNames[0];
await UIKit.chooseChain(popupPage, chainName);
walletAddress = await UIKit.activateWallet(popupPage, chainName, screenshotDir, options);
//await UIKit.sendToken(popupPage, "0xb9d3eF27DDBAD4D361A412dc419EBB3A7Ee586c5", "MAX");
for (let index = 0; index < chainNames.length; index++) {
const chainName = chainNames[index];
if (Config.activateWallet(chainName)) {
await UIKit.chooseChain(popupPage, chainName);
walletAddress = await UIKit.activateWallet(popupPage, chainName, screenshotDir, options);
//await UIKit.sendToken(popupPage, "0xb9d3eF27DDBAD4D361A412dc419EBB3A7Ee586c5", "MAX");
}
}
// {
// // Goerli
// const chainName = supportedChainNames[1];
// await UIKit.chooseChain(popupPage, chainName);
// await UIKit.activateWallet(popupPage, chainName, screenshotDir);
// }

return {
walletAddress: [walletAddress],
Expand Down
25 changes: 19 additions & 6 deletions tests/ci.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,28 @@ if (fs.existsSync(SHARING_FILE)) {
fs.unlinkSync(SHARING_FILE);
}

{
const testEnvFile = path.join(__dirname, "..", ".env.test");
if (!fs.existsSync(testEnvFile)) {
throw new Error("Please create .env.test file");
}
const testEnvContent = fs.readFileSync(testEnvFile, "utf-8");
if (!testEnvContent.includes("PRIVATEKEY")) {
console.log("testEnvFile", testEnvFile);
console.log("testEnvContent", testEnvContent);
throw new Error("Please set PRIVATEKEY in .env.test file");
}
}

const metamaskChromeDir = path.join(archiveDir, "chrome");
if (!fs.existsSync(metamaskChromeDir)) {
// curl -o metamask.zip https://raw.githubusercontent.com/jayden-sudo/archive/main/metamask.zip && unzip metamask.zip -d ./metamask
console.log("download metamask");
execSync(
`curl -o ${path.join(
`git clone -b metamask https://github.com/jayden-sudo/archive.git ${path.join(
archiveDir,
"metamask.zip",
)} https://raw.githubusercontent.com/jayden-sudo/archive/main/metamask.zip && unzip ${path.join(
archiveDir,
"metamask.zip",
)} -d ${archiveDir}`,
"archive",
)} && unzip ${path.join(archiveDir, "archive", "metamask.zip")} -d ${archiveDir}`,
);
console.log("download metamask done");
}
Expand All @@ -57,6 +67,9 @@ test.describe("CI", () => {
console.log("Activate Wallet done");
});
test("Recovery Wallet", async ({ context, extensionId }) => {
if (process.env.CI) {
test.skip(true);
}
test.setTimeout(1000 * 60 * 5);
console.log("Recovery Wallet start");
const page = (await context.pages())[0];
Expand Down
15 changes: 5 additions & 10 deletions tests/recoveryWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@ export async function recovery(
debugger;
throw new Error("popupPage is undefined");
}
for (let index = 0; index < pages.length; index++) {
const page = pages[index];
if (page.url() === "about:blank") {
await page.close();
break;
}
}

await MetaMask.init(context);
await MetaMask.importPrivateKey(context, guardians[0]);
Expand Down Expand Up @@ -63,7 +56,7 @@ export async function recovery(
await popupPage.getByPlaceholder("Confirm password").fill("111111111");
await popupPage.getByRole("button", { name: "Continue" }).click();
await popupPage.getByRole("button", { name: "Next" }).click();
await popupPage.waitForTimeout(500);
await popupPage.waitForTimeout(1000);
const qr_img_bound = await popupPage
.locator("div")
.filter({ hasText: /^Copy to Clickboard$/ })
Expand Down Expand Up @@ -148,7 +141,7 @@ export async function recovery(
await popupPage.waitForTimeout(1000 * 5);
// Recovery in progress
let text = await popupPage.innerText("body");
if (text.includes("Goerli\nRecovered")) {
if (text.includes("Goerli Wallet(s)\nRecovered")) {
recoveryStatus = true;
break;
}
Expand All @@ -157,9 +150,11 @@ export async function recovery(
});
await popupPage.waitForTimeout(500);
text = await popupPage.innerText("body");
if (text.includes("Goerli\nRecovered")) {
if (text.includes("Goerli Wallet(s)\nRecovered")) {
recoveryStatus = true;
break;
} else {
console.log(text);
}
}
if (!recoveryStatus) {
Expand Down
19 changes: 18 additions & 1 deletion tests/utils/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import dotenv from "dotenv";
dotenv.config({ path: ".env.test" });

export class Config {
static privateKey(): string {
const _privateKey = process.env.PRIVATEKEY;
Expand Down Expand Up @@ -42,4 +41,22 @@ export class Config {
}
return maxFeeNumber;
}

static getChainList(): string {
const envName = `CHAINLIST`;
const chainList = process.env[envName];
if (!chainList) {
throw new Error(`${envName} is not defined in .env.test file`);
}
return chainList;
}

static activateWallet(netWorkName: string): boolean {
const envName = `activatewallet-${Config.networkName(netWorkName)}`;
const activate = process.env[envName];
if (!activate) {
throw new Error(`${envName} is not defined in .env.test file`);
}
return activate === "true";
}
}

0 comments on commit 775d929

Please sign in to comment.