w3wallets 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # w3wallets
2
2
 
3
+ ![License](https://img.shields.io/badge/License-MIT-yellow.svg)
4
+ [![npm version](https://img.shields.io/npm/v/w3wallets.svg)](https://img.shields.io/npm/v/w3wallets.svg)
5
+
3
6
  Web3 wallets for Playwright.
4
7
 
5
8
  > [!IMPORTANT]
@@ -15,11 +18,15 @@ npm install -D w3wallets
15
18
 
16
19
  Only the `Backpack` wallet is supported at this point.
17
20
 
18
- #### 1. Download wallets
21
+ #### 1. Download Backpack
19
22
 
20
- ```sh
23
+ Currently, you need to download the extension manually. You can use [Chrome extension source viewer](https://chromewebstore.google.com/detail/chrome-extension-source-v/jifpbeccnghkjeaalbbjmodiffmgedin).
24
+
25
+ Put the unzipped files to the root of your Playwright project `extensions/backpack`.
26
+
27
+ <!-- ```sh
21
28
  npx w3wallets
22
- ```
29
+ ``` -->
23
30
 
24
31
  #### 2. Wrap your fixture `withWallets`
25
32
 
package/dist/index.d.mts CHANGED
@@ -1,10 +1,20 @@
1
1
  import * as playwright_test from 'playwright/test';
2
2
  import { Page, test, BrowserContext } from '@playwright/test';
3
3
 
4
+ type BackPackNetwork = "Eclipse";
5
+
4
6
  declare class Backpack {
5
7
  private page;
6
- constructor(page: Page);
7
- onboard(privateKey: string): Promise<void>;
8
+ private extensionId;
9
+ private defaultPassword;
10
+ constructor(page: Page, extensionId: string);
11
+ onboard(network: BackPackNetwork, privateKey: string): Promise<void>;
12
+ unlock(): Promise<void>;
13
+ goToSettings(accountName?: string): Promise<void>;
14
+ setRPC(network: BackPackNetwork, rpc: string): Promise<void>;
15
+ ignoreAndProceed(): Promise<void>;
16
+ approve(): Promise<void>;
17
+ deny(): Promise<void>;
8
18
  }
9
19
 
10
20
  type Config = {
package/dist/index.d.ts CHANGED
@@ -1,10 +1,20 @@
1
1
  import * as playwright_test from 'playwright/test';
2
2
  import { Page, test, BrowserContext } from '@playwright/test';
3
3
 
4
+ type BackPackNetwork = "Eclipse";
5
+
4
6
  declare class Backpack {
5
7
  private page;
6
- constructor(page: Page);
7
- onboard(privateKey: string): Promise<void>;
8
+ private extensionId;
9
+ private defaultPassword;
10
+ constructor(page: Page, extensionId: string);
11
+ onboard(network: BackPackNetwork, privateKey: string): Promise<void>;
12
+ unlock(): Promise<void>;
13
+ goToSettings(accountName?: string): Promise<void>;
14
+ setRPC(network: BackPackNetwork, rpc: string): Promise<void>;
15
+ ignoreAndProceed(): Promise<void>;
16
+ approve(): Promise<void>;
17
+ deny(): Promise<void>;
8
18
  }
9
19
 
10
20
  type Config = {
package/dist/index.js CHANGED
@@ -37,24 +37,55 @@ module.exports = __toCommonJS(index_exports);
37
37
  // src/withWallets.ts
38
38
  var import_path = __toESM(require("path"));
39
39
  var import_fs = __toESM(require("fs"));
40
- var import_test = require("@playwright/test");
41
40
  var import_test2 = require("@playwright/test");
41
+ var import_test3 = require("@playwright/test");
42
42
 
43
- // src/backpack/index.ts
43
+ // src/backpack/backpack.ts
44
+ var import_test = require("@playwright/test");
44
45
  var Backpack = class {
45
- constructor(page) {
46
+ constructor(page, extensionId) {
46
47
  this.page = page;
48
+ this.extensionId = extensionId;
47
49
  }
48
- async onboard(privateKey) {
49
- await this.page.getByRole("button", { name: "I already have a wallet" }).click();
50
- await this.page.getByRole("button", { name: "Show advanced options" }).click();
51
- await this.page.getByRole("button", { name: "Import with private key" }).click();
50
+ defaultPassword = "11111111";
51
+ async onboard(network, privateKey) {
52
+ await this.page.getByRole("button", { name: "Import wallet" }).click();
53
+ await this.page.getByRole("button", { name: network }).click();
54
+ await this.page.getByRole("button", { name: "Import private key" }).click();
52
55
  await this.page.getByPlaceholder("Enter private key").fill(privateKey);
53
56
  await this.page.getByRole("button", { name: "Import" }).click();
54
- await this.page.getByPlaceholder("Password", { exact: true }).fill("11111111");
55
- await this.page.getByPlaceholder("Confirm Password").fill("11111111");
57
+ await this.page.getByPlaceholder("Password", { exact: true }).fill(this.defaultPassword);
58
+ await this.page.getByPlaceholder("Confirm Password").fill(this.defaultPassword);
56
59
  await this.page.getByRole("checkbox").click();
57
60
  await this.page.getByRole("button", { name: "Next" }).click();
61
+ await (0, import_test.expect)(this.page.getByText("You're all good!")).toBeVisible();
62
+ await this.page.goto(`chrome-extension://${this.extensionId}/popup.html`);
63
+ }
64
+ async unlock() {
65
+ await this.page.getByPlaceholder("Password").fill(this.defaultPassword);
66
+ await this.page.getByRole("button", { name: "Unlock" }).click();
67
+ }
68
+ async goToSettings(accountName) {
69
+ await this.page.getByRole("button", { name: accountName ?? "A1" }).click();
70
+ await this.page.getByRole("button", { name: "Settings" }).click();
71
+ }
72
+ async setRPC(network, rpc) {
73
+ await this.goToSettings();
74
+ await this.page.getByRole("button", { name: network }).click();
75
+ await this.page.getByRole("button", { name: "RPC Connection" }).click();
76
+ await this.page.getByRole("button", { name: "Custom" }).click();
77
+ await this.page.getByPlaceholder("RPC URL").fill(rpc);
78
+ await this.page.keyboard.press("Enter");
79
+ }
80
+ async ignoreAndProceed() {
81
+ const ignoreButton = this.page.getByText("Ignore and proceed anyway.");
82
+ await ignoreButton.click();
83
+ }
84
+ async approve() {
85
+ await this.page.getByText("Approve").click();
86
+ }
87
+ async deny() {
88
+ await this.page.getByText("Deny").click();
58
89
  }
59
90
  };
60
91
 
@@ -65,20 +96,26 @@ function withWallets(test, config) {
65
96
  backpack: async ({ context, extensionId }, use) => {
66
97
  const page = context.pages()[0];
67
98
  if (!page) throw Error("No pages in context");
68
- const backpack2 = new Backpack(page);
99
+ const backpack2 = new Backpack(page, extensionId);
69
100
  await page.goto(
70
101
  `chrome-extension://${extensionId}/options.html?onboarding=true`
71
102
  );
72
103
  await use(backpack2);
73
104
  },
74
- context: async ({}, use) => {
75
- const userDataDir = import_path.default.join(process.cwd(), ".tmp-user-data");
105
+ context: async ({}, use, testInfo) => {
106
+ const userDataDir = import_path.default.join(
107
+ process.cwd(),
108
+ ".w3wallets",
109
+ testInfo.testId
110
+ );
111
+ if (import_fs.default.existsSync(userDataDir))
112
+ import_fs.default.rmSync(userDataDir, { recursive: true });
76
113
  const backpackDownloaded = import_fs.default.existsSync(
77
114
  import_path.default.join(backpack, "manifest.json")
78
115
  );
79
116
  if (!backpackDownloaded)
80
117
  throw Error("Cannot find Backpack. download it `npx w3wallets`");
81
- const context = await import_test2.chromium.launchPersistentContext(userDataDir, {
118
+ const context = await import_test3.chromium.launchPersistentContext(userDataDir, {
82
119
  headless: false,
83
120
  args: [
84
121
  `--disable-extensions-except=${backpack}`,
package/dist/index.mjs CHANGED
@@ -4,21 +4,52 @@ import fs from "fs";
4
4
  import "@playwright/test";
5
5
  import { chromium } from "@playwright/test";
6
6
 
7
- // src/backpack/index.ts
7
+ // src/backpack/backpack.ts
8
+ import { expect } from "@playwright/test";
8
9
  var Backpack = class {
9
- constructor(page) {
10
+ constructor(page, extensionId) {
10
11
  this.page = page;
12
+ this.extensionId = extensionId;
11
13
  }
12
- async onboard(privateKey) {
13
- await this.page.getByRole("button", { name: "I already have a wallet" }).click();
14
- await this.page.getByRole("button", { name: "Show advanced options" }).click();
15
- await this.page.getByRole("button", { name: "Import with private key" }).click();
14
+ defaultPassword = "11111111";
15
+ async onboard(network, privateKey) {
16
+ await this.page.getByRole("button", { name: "Import wallet" }).click();
17
+ await this.page.getByRole("button", { name: network }).click();
18
+ await this.page.getByRole("button", { name: "Import private key" }).click();
16
19
  await this.page.getByPlaceholder("Enter private key").fill(privateKey);
17
20
  await this.page.getByRole("button", { name: "Import" }).click();
18
- await this.page.getByPlaceholder("Password", { exact: true }).fill("11111111");
19
- await this.page.getByPlaceholder("Confirm Password").fill("11111111");
21
+ await this.page.getByPlaceholder("Password", { exact: true }).fill(this.defaultPassword);
22
+ await this.page.getByPlaceholder("Confirm Password").fill(this.defaultPassword);
20
23
  await this.page.getByRole("checkbox").click();
21
24
  await this.page.getByRole("button", { name: "Next" }).click();
25
+ await expect(this.page.getByText("You're all good!")).toBeVisible();
26
+ await this.page.goto(`chrome-extension://${this.extensionId}/popup.html`);
27
+ }
28
+ async unlock() {
29
+ await this.page.getByPlaceholder("Password").fill(this.defaultPassword);
30
+ await this.page.getByRole("button", { name: "Unlock" }).click();
31
+ }
32
+ async goToSettings(accountName) {
33
+ await this.page.getByRole("button", { name: accountName ?? "A1" }).click();
34
+ await this.page.getByRole("button", { name: "Settings" }).click();
35
+ }
36
+ async setRPC(network, rpc) {
37
+ await this.goToSettings();
38
+ await this.page.getByRole("button", { name: network }).click();
39
+ await this.page.getByRole("button", { name: "RPC Connection" }).click();
40
+ await this.page.getByRole("button", { name: "Custom" }).click();
41
+ await this.page.getByPlaceholder("RPC URL").fill(rpc);
42
+ await this.page.keyboard.press("Enter");
43
+ }
44
+ async ignoreAndProceed() {
45
+ const ignoreButton = this.page.getByText("Ignore and proceed anyway.");
46
+ await ignoreButton.click();
47
+ }
48
+ async approve() {
49
+ await this.page.getByText("Approve").click();
50
+ }
51
+ async deny() {
52
+ await this.page.getByText("Deny").click();
22
53
  }
23
54
  };
24
55
 
@@ -29,14 +60,20 @@ function withWallets(test, config) {
29
60
  backpack: async ({ context, extensionId }, use) => {
30
61
  const page = context.pages()[0];
31
62
  if (!page) throw Error("No pages in context");
32
- const backpack2 = new Backpack(page);
63
+ const backpack2 = new Backpack(page, extensionId);
33
64
  await page.goto(
34
65
  `chrome-extension://${extensionId}/options.html?onboarding=true`
35
66
  );
36
67
  await use(backpack2);
37
68
  },
38
- context: async ({}, use) => {
39
- const userDataDir = path.join(process.cwd(), ".tmp-user-data");
69
+ context: async ({}, use, testInfo) => {
70
+ const userDataDir = path.join(
71
+ process.cwd(),
72
+ ".w3wallets",
73
+ testInfo.testId
74
+ );
75
+ if (fs.existsSync(userDataDir))
76
+ fs.rmSync(userDataDir, { recursive: true });
40
77
  const backpackDownloaded = fs.existsSync(
41
78
  path.join(backpack, "manifest.json")
42
79
  );
package/package.json CHANGED
@@ -1,10 +1,18 @@
1
1
  {
2
2
  "name": "w3wallets",
3
3
  "description": "browser wallets for playwright",
4
- "version": "0.0.3",
4
+ "version": "0.0.4",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
- "author": "Max Andreev <maxick20@gmail.com>",
7
+ "homepage": "https://github.com/Maksandre/w3wallets",
8
+ "bugs": {
9
+ "url": "https://github.com/Maksandre/w3wallets/issues"
10
+ },
11
+ "author": "Max Andreev",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/Maksandre/w3wallets.git"
15
+ },
8
16
  "license": "MIT",
9
17
  "publishConfig": {
10
18
  "access": "public"