w3wallets 0.2.1 → 0.3.0
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 +18 -37
- package/dist/index.d.mts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +44 -18
- package/dist/index.mjs +44 -18
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -32,52 +32,33 @@ The unzipped files should be stored in the `.w3wallets/<wallet-name>` directory.
|
|
|
32
32
|
|
|
33
33
|
#### 2. Wrap your fixture `withWallets`
|
|
34
34
|
|
|
35
|
+
Install needed wallets into the chromium using `withWallets`.
|
|
36
|
+
|
|
35
37
|
```ts
|
|
38
|
+
// your-fixture.ts
|
|
39
|
+
import { withWallets } from "w3wallets";
|
|
36
40
|
import { test as base } from "@playwright/test";
|
|
37
|
-
import { withWallets } from "../src/withWallets";
|
|
38
|
-
|
|
39
|
-
// Specify one or many wallets that should be installed in the browser
|
|
40
|
-
const test = withWallets(base, "backpack", "polkadotJS");
|
|
41
41
|
|
|
42
|
-
test
|
|
43
|
-
|
|
44
|
-
"4wDJd9Ds5ueTdS95ReAZGSBVkjMcNKbgZk47xcmqzpUJjCt7VoB2Cs7hqwXWRnopzXqE4mCP6BEDHCYrFttEcBw2";
|
|
45
|
-
|
|
46
|
-
await backpack.onboard("Eclipse", privateKey);
|
|
42
|
+
export const test = withWallets(base, 'backpack', 'polkadotJS').extend<BaseFixture>({
|
|
43
|
+
magic: (_, use) => use(42),
|
|
47
44
|
});
|
|
48
|
-
```
|
|
49
45
|
|
|
50
|
-
|
|
46
|
+
type BaseFixture = {
|
|
47
|
+
magic: number;
|
|
48
|
+
};
|
|
51
49
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
0. Create the `.env` using `.env.example` as a reference.
|
|
55
|
-
1. Install dependencies
|
|
56
|
-
|
|
57
|
-
```sh
|
|
58
|
-
yarn
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
2. Install Chrome browser
|
|
62
|
-
|
|
63
|
-
```sh
|
|
64
|
-
npx playwright install chromium
|
|
50
|
+
export { expect } from "@playwright/test";
|
|
65
51
|
```
|
|
66
52
|
|
|
67
|
-
3.
|
|
53
|
+
#### 3. Use the installed wallets in tests
|
|
68
54
|
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
4. Start UI
|
|
74
|
-
|
|
75
|
-
```sh
|
|
76
|
-
yarn start:ui
|
|
77
|
-
```
|
|
55
|
+
```ts
|
|
56
|
+
import { test } from "./your-fixture";
|
|
78
57
|
|
|
79
|
-
|
|
58
|
+
test("Can use wallet", async ({ page, backpack }) => {
|
|
59
|
+
const privateKey =
|
|
60
|
+
"4wDJd9Ds5ueTdS95ReAZGSBVkjMcNKbgZk47xcmqzpUJjCt7VoB2Cs7hqwXWRnopzXqE4mCP6BEDHCYrFttEcBw2";
|
|
80
61
|
|
|
81
|
-
|
|
82
|
-
|
|
62
|
+
await backpack.onboard("Eclipse", privateKey);
|
|
63
|
+
});
|
|
83
64
|
```
|
package/dist/index.d.mts
CHANGED
|
@@ -21,14 +21,23 @@ declare abstract class Wallet implements IWallet {
|
|
|
21
21
|
|
|
22
22
|
declare class Backpack extends Wallet {
|
|
23
23
|
private defaultPassword;
|
|
24
|
+
private currentAccountId;
|
|
25
|
+
private maxAccountId;
|
|
24
26
|
gotoOnboardPage(): Promise<void>;
|
|
25
27
|
onboard(network: BackPackNetwork, privateKey: string): Promise<void>;
|
|
28
|
+
addAccount(network: BackPackNetwork, privateKey: string): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Switch account
|
|
31
|
+
* @param id The first added account has id 1, the second – 2, and so on
|
|
32
|
+
*/
|
|
33
|
+
switchAccount(id: number): Promise<void>;
|
|
26
34
|
unlock(): Promise<void>;
|
|
27
|
-
goToSettings(accountName?: string): Promise<void>;
|
|
28
35
|
setRPC(network: BackPackNetwork, rpc: string): Promise<void>;
|
|
29
36
|
ignoreAndProceed(): Promise<void>;
|
|
30
37
|
approve(): Promise<void>;
|
|
31
38
|
deny(): Promise<void>;
|
|
39
|
+
private _clickOnAccount;
|
|
40
|
+
private _importAccount;
|
|
32
41
|
}
|
|
33
42
|
|
|
34
43
|
declare class PolkadotJS extends Wallet {
|
package/dist/index.d.ts
CHANGED
|
@@ -21,14 +21,23 @@ declare abstract class Wallet implements IWallet {
|
|
|
21
21
|
|
|
22
22
|
declare class Backpack extends Wallet {
|
|
23
23
|
private defaultPassword;
|
|
24
|
+
private currentAccountId;
|
|
25
|
+
private maxAccountId;
|
|
24
26
|
gotoOnboardPage(): Promise<void>;
|
|
25
27
|
onboard(network: BackPackNetwork, privateKey: string): Promise<void>;
|
|
28
|
+
addAccount(network: BackPackNetwork, privateKey: string): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Switch account
|
|
31
|
+
* @param id The first added account has id 1, the second – 2, and so on
|
|
32
|
+
*/
|
|
33
|
+
switchAccount(id: number): Promise<void>;
|
|
26
34
|
unlock(): Promise<void>;
|
|
27
|
-
goToSettings(accountName?: string): Promise<void>;
|
|
28
35
|
setRPC(network: BackPackNetwork, rpc: string): Promise<void>;
|
|
29
36
|
ignoreAndProceed(): Promise<void>;
|
|
30
37
|
approve(): Promise<void>;
|
|
31
38
|
deny(): Promise<void>;
|
|
39
|
+
private _clickOnAccount;
|
|
40
|
+
private _importAccount;
|
|
32
41
|
}
|
|
33
42
|
|
|
34
43
|
declare class PolkadotJS extends Wallet {
|
package/dist/index.js
CHANGED
|
@@ -58,6 +58,8 @@ var Wallet = class {
|
|
|
58
58
|
// src/backpack/backpack.ts
|
|
59
59
|
var Backpack = class extends Wallet {
|
|
60
60
|
defaultPassword = "11111111";
|
|
61
|
+
currentAccountId = 0;
|
|
62
|
+
maxAccountId = 0;
|
|
61
63
|
async gotoOnboardPage() {
|
|
62
64
|
await this.page.goto(
|
|
63
65
|
`chrome-extension://${this.extensionId}/options.html?onboarding=true`
|
|
@@ -65,28 +67,34 @@ var Backpack = class extends Wallet {
|
|
|
65
67
|
await (0, import_test.expect)(this.page.getByText("Welcome to Backpack")).toBeVisible();
|
|
66
68
|
}
|
|
67
69
|
async onboard(network, privateKey) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
await this.page.
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
await this.
|
|
70
|
+
this.currentAccountId++;
|
|
71
|
+
this.maxAccountId++;
|
|
72
|
+
return this._importAccount(network, privateKey, true);
|
|
73
|
+
}
|
|
74
|
+
async addAccount(network, privateKey) {
|
|
75
|
+
this.maxAccountId++;
|
|
76
|
+
this.currentAccountId = this.maxAccountId;
|
|
77
|
+
await this.page.goto(
|
|
78
|
+
`chrome-extension://${this.extensionId}/options.html?add-user-account=true`
|
|
79
|
+
);
|
|
80
|
+
await this._importAccount(network, privateKey, false);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Switch account
|
|
84
|
+
* @param id The first added account has id 1, the second – 2, and so on
|
|
85
|
+
*/
|
|
86
|
+
async switchAccount(id) {
|
|
87
|
+
await this.page.getByRole("button", { name: `A${this.currentAccountId}` }).click();
|
|
88
|
+
await this.page.getByRole("button", { name: `Account ${id}` }).click();
|
|
89
|
+
this.currentAccountId = id;
|
|
79
90
|
}
|
|
80
91
|
async unlock() {
|
|
81
92
|
await this.page.getByPlaceholder("Password").fill(this.defaultPassword);
|
|
82
93
|
await this.page.getByRole("button", { name: "Unlock" }).click();
|
|
83
94
|
}
|
|
84
|
-
async goToSettings(accountName) {
|
|
85
|
-
await this.page.getByRole("button", { name: accountName ?? "A1" }).click();
|
|
86
|
-
await this.page.getByRole("button", { name: "Settings" }).click();
|
|
87
|
-
}
|
|
88
95
|
async setRPC(network, rpc) {
|
|
89
|
-
await this.
|
|
96
|
+
await this._clickOnAccount();
|
|
97
|
+
await this.page.getByRole("button", { name: "Settings" }).click();
|
|
90
98
|
await this.page.getByRole("button", { name: network }).click();
|
|
91
99
|
await this.page.getByRole("button", { name: "RPC Connection" }).click();
|
|
92
100
|
await this.page.getByRole("button", { name: "Custom" }).click();
|
|
@@ -98,10 +106,28 @@ var Backpack = class extends Wallet {
|
|
|
98
106
|
await ignoreButton.click();
|
|
99
107
|
}
|
|
100
108
|
async approve() {
|
|
101
|
-
await this.page.getByText("Approve").click();
|
|
109
|
+
await this.page.getByText("Approve", { exact: true }).click();
|
|
102
110
|
}
|
|
103
111
|
async deny() {
|
|
104
|
-
await this.page.getByText("Deny").click();
|
|
112
|
+
await this.page.getByText("Deny", { exact: true }).click();
|
|
113
|
+
}
|
|
114
|
+
async _clickOnAccount() {
|
|
115
|
+
return this.page.getByRole("button", { name: `A${this.currentAccountId}`, exact: true }).click();
|
|
116
|
+
}
|
|
117
|
+
async _importAccount(network, privateKey, isOnboard) {
|
|
118
|
+
await this.page.getByRole("button", { name: "Import wallet" }).click();
|
|
119
|
+
await this.page.getByRole("button", { name: network }).click();
|
|
120
|
+
await this.page.getByRole("button", { name: "Import private key" }).click();
|
|
121
|
+
await this.page.getByPlaceholder("Enter private key").fill(privateKey);
|
|
122
|
+
await this.page.getByRole("button", { name: "Import" }).click();
|
|
123
|
+
if (isOnboard) {
|
|
124
|
+
await this.page.getByPlaceholder("Password", { exact: true }).fill(this.defaultPassword);
|
|
125
|
+
await this.page.getByPlaceholder("Confirm Password").fill(this.defaultPassword);
|
|
126
|
+
await this.page.getByRole("checkbox").click();
|
|
127
|
+
await this.page.getByRole("button", { name: "Next" }).click();
|
|
128
|
+
}
|
|
129
|
+
await (0, import_test.expect)(this.page.getByText("You're all good!")).toBeVisible();
|
|
130
|
+
await this.page.goto(`chrome-extension://${this.extensionId}/popup.html`);
|
|
105
131
|
}
|
|
106
132
|
};
|
|
107
133
|
|
package/dist/index.mjs
CHANGED
|
@@ -24,6 +24,8 @@ var Wallet = class {
|
|
|
24
24
|
// src/backpack/backpack.ts
|
|
25
25
|
var Backpack = class extends Wallet {
|
|
26
26
|
defaultPassword = "11111111";
|
|
27
|
+
currentAccountId = 0;
|
|
28
|
+
maxAccountId = 0;
|
|
27
29
|
async gotoOnboardPage() {
|
|
28
30
|
await this.page.goto(
|
|
29
31
|
`chrome-extension://${this.extensionId}/options.html?onboarding=true`
|
|
@@ -31,28 +33,34 @@ var Backpack = class extends Wallet {
|
|
|
31
33
|
await expect(this.page.getByText("Welcome to Backpack")).toBeVisible();
|
|
32
34
|
}
|
|
33
35
|
async onboard(network, privateKey) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
await this.page.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
await this.
|
|
36
|
+
this.currentAccountId++;
|
|
37
|
+
this.maxAccountId++;
|
|
38
|
+
return this._importAccount(network, privateKey, true);
|
|
39
|
+
}
|
|
40
|
+
async addAccount(network, privateKey) {
|
|
41
|
+
this.maxAccountId++;
|
|
42
|
+
this.currentAccountId = this.maxAccountId;
|
|
43
|
+
await this.page.goto(
|
|
44
|
+
`chrome-extension://${this.extensionId}/options.html?add-user-account=true`
|
|
45
|
+
);
|
|
46
|
+
await this._importAccount(network, privateKey, false);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Switch account
|
|
50
|
+
* @param id The first added account has id 1, the second – 2, and so on
|
|
51
|
+
*/
|
|
52
|
+
async switchAccount(id) {
|
|
53
|
+
await this.page.getByRole("button", { name: `A${this.currentAccountId}` }).click();
|
|
54
|
+
await this.page.getByRole("button", { name: `Account ${id}` }).click();
|
|
55
|
+
this.currentAccountId = id;
|
|
45
56
|
}
|
|
46
57
|
async unlock() {
|
|
47
58
|
await this.page.getByPlaceholder("Password").fill(this.defaultPassword);
|
|
48
59
|
await this.page.getByRole("button", { name: "Unlock" }).click();
|
|
49
60
|
}
|
|
50
|
-
async goToSettings(accountName) {
|
|
51
|
-
await this.page.getByRole("button", { name: accountName ?? "A1" }).click();
|
|
52
|
-
await this.page.getByRole("button", { name: "Settings" }).click();
|
|
53
|
-
}
|
|
54
61
|
async setRPC(network, rpc) {
|
|
55
|
-
await this.
|
|
62
|
+
await this._clickOnAccount();
|
|
63
|
+
await this.page.getByRole("button", { name: "Settings" }).click();
|
|
56
64
|
await this.page.getByRole("button", { name: network }).click();
|
|
57
65
|
await this.page.getByRole("button", { name: "RPC Connection" }).click();
|
|
58
66
|
await this.page.getByRole("button", { name: "Custom" }).click();
|
|
@@ -64,10 +72,28 @@ var Backpack = class extends Wallet {
|
|
|
64
72
|
await ignoreButton.click();
|
|
65
73
|
}
|
|
66
74
|
async approve() {
|
|
67
|
-
await this.page.getByText("Approve").click();
|
|
75
|
+
await this.page.getByText("Approve", { exact: true }).click();
|
|
68
76
|
}
|
|
69
77
|
async deny() {
|
|
70
|
-
await this.page.getByText("Deny").click();
|
|
78
|
+
await this.page.getByText("Deny", { exact: true }).click();
|
|
79
|
+
}
|
|
80
|
+
async _clickOnAccount() {
|
|
81
|
+
return this.page.getByRole("button", { name: `A${this.currentAccountId}`, exact: true }).click();
|
|
82
|
+
}
|
|
83
|
+
async _importAccount(network, privateKey, isOnboard) {
|
|
84
|
+
await this.page.getByRole("button", { name: "Import wallet" }).click();
|
|
85
|
+
await this.page.getByRole("button", { name: network }).click();
|
|
86
|
+
await this.page.getByRole("button", { name: "Import private key" }).click();
|
|
87
|
+
await this.page.getByPlaceholder("Enter private key").fill(privateKey);
|
|
88
|
+
await this.page.getByRole("button", { name: "Import" }).click();
|
|
89
|
+
if (isOnboard) {
|
|
90
|
+
await this.page.getByPlaceholder("Password", { exact: true }).fill(this.defaultPassword);
|
|
91
|
+
await this.page.getByPlaceholder("Confirm Password").fill(this.defaultPassword);
|
|
92
|
+
await this.page.getByRole("checkbox").click();
|
|
93
|
+
await this.page.getByRole("button", { name: "Next" }).click();
|
|
94
|
+
}
|
|
95
|
+
await expect(this.page.getByText("You're all good!")).toBeVisible();
|
|
96
|
+
await this.page.goto(`chrome-extension://${this.extensionId}/popup.html`);
|
|
71
97
|
}
|
|
72
98
|
};
|
|
73
99
|
|