Skip to content

Commit 4b48c5e

Browse files
feat: Typhon wallet registration | NPG-000 (#657)
# Description Added wallet registration UI automated testing for Typhon Fixes # [654](#654) ## Type of change - [x] New feature (non-breaking change which adds functionality) ## Checklist - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [x] Any dependent changes have been merged and published in downstream modules --------- Co-authored-by: vasapornchaiyakul <[email protected]> Co-authored-by: kukkok3 <[email protected]>
1 parent 5a6d91a commit 4b48c5e

File tree

14 files changed

+1171
-103
lines changed

14 files changed

+1171
-103
lines changed

.github/workflows/nix.yml

Lines changed: 0 additions & 99 deletions
This file was deleted.

.github/workflows/rust.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ jobs:
229229
run: cargo install --force cargo-make
230230

231231
- name: Install refinery
232-
run: cargo install refinery_cli
232+
run: cargo install refinery_cli --version 0.8.7 --locked
233233

234234
- name: Install dependencies
235235
run:

.gitignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,8 @@ tests/tmp/
117117
lefthook.yml
118118
treefmt.toml
119119

120-
# local earthly Environments
121-
local/*
120+
# local earthly environments
121+
local/*
122+
tests/wallet-automation/typhon/usrdatadir/*
123+
tests/wallet-automation/node_modules/*
124+
tests/wallet-automation/typhon/extensions/*

Earthfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ rust-toolchain:
88
# Installs Cargo chef
99
install-chef:
1010
FROM +rust-toolchain
11-
RUN cargo install --debug cargo-chef
11+
RUN cargo install --debug --version 0.1.59 cargo-chef --locked
1212

1313
# Prepares the local cache
1414
prepare-cache:

tests/wallet-automation/Earthfile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
VERSION 0.7
2+
3+
# Define a base target for dependencies
4+
deps:
5+
FROM mcr.microsoft.com/playwright:v1.41.0-jammy
6+
WORKDIR /wallet-automation
7+
8+
# Consolidate RUN commands to reduce layers and ensure cleaner installation
9+
RUN apt-get update && apt-get install -y \
10+
libnss3 libatk-bridge2.0-0 libdrm-dev libxkbcommon-dev libgbm-dev libasound-dev libatspi2.0-0 libxshmfence-dev postgresql-client xvfb python3.11 python3-pip && \
11+
apt-get clean && \
12+
rm -rf /var/lib/apt/lists/*
13+
14+
COPY package.json .
15+
COPY package-lock.json .
16+
17+
RUN npm install
18+
ENV PATH "/wallet-automation/node_modules/.bin:$PATH"
19+
20+
# Define a source target that builds upon deps
21+
src:
22+
FROM +deps
23+
24+
COPY --dir typhon .
25+
COPY playwright.config.ts .
26+
COPY global-setup.ts .
27+
28+
# Define a test target that builds upon deps
29+
test:
30+
FROM +src
31+
RUN xvfb-run -a npx playwright test
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { test } from '@playwright/test';
2+
import * as fs from 'fs/promises';
3+
import * as path from 'path';
4+
5+
const typhonId = 'KFDNIEFADAANBJODLDOHAEDPHAFOFFOH';
6+
const url = `https://clients2.google.com/service/update2/crx?response=redirect&os=win&arch=x64&os_arch=x86_64&nacl_arch=x86-64&prod=chromiumcrx&prodchannel=beta&prodversion=79.0.3945.53&lang=ru&acceptformat=crx3&x=id%3D${typhonId}%26installsource%3Dondemand%26uc`;
7+
const downloadPath = path.resolve(__dirname, 'typhon/extensions');
8+
const unzip = require("unzip-crx-3");
9+
10+
test('downloadFile test', async ({ page }) => {
11+
await fs.mkdir(downloadPath, { recursive: true });
12+
13+
const downloadPromise = new Promise(async (resolve) => {
14+
page.once('download', async (download) => {
15+
const originalFilePath = path.join(downloadPath, download.suggestedFilename());
16+
await download.saveAs(originalFilePath);
17+
console.log(`file has been downloaded to: ${originalFilePath}`);
18+
19+
// new code: rename the downloaded file
20+
const newFilePath = path.join(downloadPath, typhonId);
21+
await fs.rename(originalFilePath, newFilePath);
22+
console.log(`file has been renamed to: ${newFilePath}`);
23+
24+
resolve(newFilePath); // resolve the promise with the new file path
25+
});
26+
});
27+
28+
try {
29+
await page.goto(url, {
30+
waitUntil: 'domcontentloaded',
31+
timeout: 10000
32+
});
33+
} catch (error) {
34+
console.log('navigation caused an exception, likely due to immediate download:', 'directDownload');
35+
}
36+
37+
// wait for the download and rename to complete
38+
const downloadedFilePath = await downloadPromise;
39+
40+
// verify the file exists
41+
try {
42+
await fs.access(downloadedFilePath as string); // type assertion to string
43+
console.log('file verification succeeded, file exists.');
44+
} catch {
45+
console.error('file verification failed, file does not exist.');
46+
throw new Error('downloaded file does not exist.');
47+
}
48+
49+
// Assuming the rest of your setup remains the same...
50+
51+
// Unzip the renamed file
52+
try {
53+
// Create a directory for the unzipped contents if it doesn't exist
54+
const extractPath = path.join(downloadPath, typhonId + "_unzipped");
55+
await fs.mkdir(extractPath, { recursive: true });
56+
57+
// Adjust the unzip call to specify the extraction directory
58+
await unzip(downloadedFilePath, extractPath); // Specify where to unzip
59+
console.log("Successfully unzipped your CRX file to:", extractPath);
60+
} catch (error) {
61+
console.error("Failed to unzip the CRX file:", error.message);
62+
throw new Error('Failed to unzip the CRX file.');
63+
}
64+
});

0 commit comments

Comments
 (0)