w3wallets 0.0.2 → 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 ADDED
@@ -0,0 +1,46 @@
1
+ # w3wallets
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
+
6
+ Web3 wallets for Playwright.
7
+
8
+ > [!IMPORTANT]
9
+ > This is Alpha!
10
+
11
+ This library provides methods for interacting with Web3 wallets using Playwright.
12
+
13
+ ```sh
14
+ npm install -D w3wallets
15
+ ```
16
+
17
+ ## Getting Started
18
+
19
+ Only the `Backpack` wallet is supported at this point.
20
+
21
+ #### 1. Download Backpack
22
+
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
28
+ npx w3wallets
29
+ ``` -->
30
+
31
+ #### 2. Wrap your fixture `withWallets`
32
+
33
+ ```ts
34
+ import { test as base } from "@playwright/test";
35
+ import { withWallets } from "../src/withWallets";
36
+
37
+ const test = withWallets(base, { backpack: true });
38
+
39
+ test("has title", async ({ page, backpack }) => {
40
+ await page.goto("https://playwright.dev/");
41
+
42
+ await backpack.onboard(
43
+ "4wDJd9Ds5ueTdS95ReAZGSBVkjMcNKbgZk47xcmqzpUJjCt7VoB2Cs7hqwXWRnopzXqE4mCP6BEDHCYrFttEcBw2",
44
+ );
45
+ });
46
+ ```
package/dist/index.d.mts CHANGED
@@ -1,11 +1,29 @@
1
1
  import * as playwright_test from 'playwright/test';
2
- import { test, BrowserContext } from '@playwright/test';
2
+ import { Page, test, BrowserContext } from '@playwright/test';
3
+
4
+ type BackPackNetwork = "Eclipse";
5
+
6
+ declare class Backpack {
7
+ private page;
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>;
18
+ }
3
19
 
4
20
  type Config = {
5
21
  backpack: boolean;
6
22
  };
7
- declare function withExtensions(test: typeof test, config: Config): playwright_test.TestType<playwright_test.PlaywrightTestArgs & playwright_test.PlaywrightTestOptions & {
23
+ declare function withWallets(test: typeof test, config: Config): playwright_test.TestType<playwright_test.PlaywrightTestArgs & playwright_test.PlaywrightTestOptions & {
8
24
  context: BrowserContext;
25
+ backpack: Backpack;
26
+ extensionId: string;
9
27
  }, playwright_test.PlaywrightWorkerArgs & playwright_test.PlaywrightWorkerOptions>;
10
28
 
11
- export { withExtensions };
29
+ export { withWallets as withExtensions };
package/dist/index.d.ts CHANGED
@@ -1,11 +1,29 @@
1
1
  import * as playwright_test from 'playwright/test';
2
- import { test, BrowserContext } from '@playwright/test';
2
+ import { Page, test, BrowserContext } from '@playwright/test';
3
+
4
+ type BackPackNetwork = "Eclipse";
5
+
6
+ declare class Backpack {
7
+ private page;
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>;
18
+ }
3
19
 
4
20
  type Config = {
5
21
  backpack: boolean;
6
22
  };
7
- declare function withExtensions(test: typeof test, config: Config): playwright_test.TestType<playwright_test.PlaywrightTestArgs & playwright_test.PlaywrightTestOptions & {
23
+ declare function withWallets(test: typeof test, config: Config): playwright_test.TestType<playwright_test.PlaywrightTestArgs & playwright_test.PlaywrightTestOptions & {
8
24
  context: BrowserContext;
25
+ backpack: Backpack;
26
+ extensionId: string;
9
27
  }, playwright_test.PlaywrightWorkerArgs & playwright_test.PlaywrightWorkerOptions>;
10
28
 
11
- export { withExtensions };
29
+ export { withWallets as withExtensions };
package/dist/index.js CHANGED
@@ -30,26 +30,92 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
- withExtensions: () => withExtensions
33
+ withExtensions: () => withWallets
34
34
  });
35
35
  module.exports = __toCommonJS(index_exports);
36
36
 
37
- // src/withExtension.ts
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");
42
- function withExtensions(test, config) {
41
+ var import_test3 = require("@playwright/test");
42
+
43
+ // src/backpack/backpack.ts
44
+ var import_test = require("@playwright/test");
45
+ var Backpack = class {
46
+ constructor(page, extensionId) {
47
+ this.page = page;
48
+ this.extensionId = extensionId;
49
+ }
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();
55
+ await this.page.getByPlaceholder("Enter private key").fill(privateKey);
56
+ await this.page.getByRole("button", { name: "Import" }).click();
57
+ await this.page.getByPlaceholder("Password", { exact: true }).fill(this.defaultPassword);
58
+ await this.page.getByPlaceholder("Confirm Password").fill(this.defaultPassword);
59
+ await this.page.getByRole("checkbox").click();
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();
89
+ }
90
+ };
91
+
92
+ // src/withWallets.ts
93
+ function withWallets(test, config) {
43
94
  const backpack = import_path.default.join(process.cwd(), "extensions", "backpack");
44
95
  return test.extend({
45
- context: async ({}, use) => {
46
- const userDataDir = import_path.default.join(process.cwd(), ".tmp-user-data");
96
+ backpack: async ({ context, extensionId }, use) => {
97
+ const page = context.pages()[0];
98
+ if (!page) throw Error("No pages in context");
99
+ const backpack2 = new Backpack(page, extensionId);
100
+ await page.goto(
101
+ `chrome-extension://${extensionId}/options.html?onboarding=true`
102
+ );
103
+ await use(backpack2);
104
+ },
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 });
47
113
  const backpackDownloaded = import_fs.default.existsSync(
48
114
  import_path.default.join(backpack, "manifest.json")
49
115
  );
50
116
  if (!backpackDownloaded)
51
117
  throw Error("Cannot find Backpack. download it `npx w3wallets`");
52
- const context = await import_test2.chromium.launchPersistentContext(userDataDir, {
118
+ const context = await import_test3.chromium.launchPersistentContext(userDataDir, {
53
119
  headless: false,
54
120
  args: [
55
121
  `--disable-extensions-except=${backpack}`,
@@ -58,6 +124,13 @@ function withExtensions(test, config) {
58
124
  });
59
125
  await use(context);
60
126
  await context.close();
127
+ },
128
+ extensionId: async ({ context }, use) => {
129
+ let [background] = context.serviceWorkers();
130
+ if (!background) background = await context.waitForEvent("serviceworker");
131
+ const extensionId = background.url().split("/")[2];
132
+ if (!extensionId) throw Error("No extension id");
133
+ await use(extensionId);
61
134
  }
62
135
  });
63
136
  }
package/dist/index.mjs CHANGED
@@ -1,13 +1,79 @@
1
- // src/withExtension.ts
1
+ // src/withWallets.ts
2
2
  import path from "path";
3
3
  import fs from "fs";
4
4
  import "@playwright/test";
5
5
  import { chromium } from "@playwright/test";
6
- function withExtensions(test, config) {
6
+
7
+ // src/backpack/backpack.ts
8
+ import { expect } from "@playwright/test";
9
+ var Backpack = class {
10
+ constructor(page, extensionId) {
11
+ this.page = page;
12
+ this.extensionId = extensionId;
13
+ }
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();
19
+ await this.page.getByPlaceholder("Enter private key").fill(privateKey);
20
+ await this.page.getByRole("button", { name: "Import" }).click();
21
+ await this.page.getByPlaceholder("Password", { exact: true }).fill(this.defaultPassword);
22
+ await this.page.getByPlaceholder("Confirm Password").fill(this.defaultPassword);
23
+ await this.page.getByRole("checkbox").click();
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();
53
+ }
54
+ };
55
+
56
+ // src/withWallets.ts
57
+ function withWallets(test, config) {
7
58
  const backpack = path.join(process.cwd(), "extensions", "backpack");
8
59
  return test.extend({
9
- context: async ({}, use) => {
10
- const userDataDir = path.join(process.cwd(), ".tmp-user-data");
60
+ backpack: async ({ context, extensionId }, use) => {
61
+ const page = context.pages()[0];
62
+ if (!page) throw Error("No pages in context");
63
+ const backpack2 = new Backpack(page, extensionId);
64
+ await page.goto(
65
+ `chrome-extension://${extensionId}/options.html?onboarding=true`
66
+ );
67
+ await use(backpack2);
68
+ },
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 });
11
77
  const backpackDownloaded = fs.existsSync(
12
78
  path.join(backpack, "manifest.json")
13
79
  );
@@ -22,9 +88,16 @@ function withExtensions(test, config) {
22
88
  });
23
89
  await use(context);
24
90
  await context.close();
91
+ },
92
+ extensionId: async ({ context }, use) => {
93
+ let [background] = context.serviceWorkers();
94
+ if (!background) background = await context.waitForEvent("serviceworker");
95
+ const extensionId = background.url().split("/")[2];
96
+ if (!extensionId) throw Error("No extension id");
97
+ await use(extensionId);
25
98
  }
26
99
  });
27
100
  }
28
101
  export {
29
- withExtensions
102
+ withWallets as withExtensions
30
103
  };
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.2",
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"