@avalix/chroma 0.0.11 → 0.0.13

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
@@ -2,7 +2,9 @@
2
2
 
3
3
  End-to-end testing library for Polkadot wallet interactions using Playwright.
4
4
 
5
- > **⚠️ Active Development**: This library is currently under active development. The API may change and breaking changes can occur between versions. Please pin your version and review changelogs carefully when updating.
5
+ ## Documentation
6
+
7
+ We highly recommend you take a look at the [Chroma documentation](https://chroma-docs.up.railway.app/docs) to level up. It's a great resource for learning more about the library. It covers everything from getting started to advanced topics like CI/CD integration and Docker setup.
6
8
 
7
9
  ## Installation
8
10
 
@@ -27,7 +29,7 @@ This will download the wallet extensions (Polkadot JS and Talisman) to `./.chrom
27
29
  ```json
28
30
  {
29
31
  "scripts": {
30
- "prepare": "chroma download-extensions"
32
+ "test:prepare": "chroma download-extensions"
31
33
  }
32
34
  }
33
35
  ```
@@ -36,260 +38,57 @@ This will download the wallet extensions (Polkadot JS and Talisman) to `./.chrom
36
38
 
37
39
  ## Quick Start
38
40
 
39
- ### Basic Usage
40
-
41
41
  ```typescript
42
- import { expect, test } from '@avalix/chroma'
42
+ import { createWalletTest, expect } from '@avalix/chroma'
43
43
 
44
- test('should connect wallet and sign transaction', async ({ page, wallets }) => {
44
+ const test = createWalletTest({
45
+ wallets: [{ type: 'polkadot-js' }]
46
+ })
47
+
48
+ test('connect wallet and sign transaction', async ({ page, wallets }) => {
45
49
  const polkadotJs = wallets['polkadot-js']
46
50
 
47
- // Import a test account
48
51
  await polkadotJs.importMnemonic({
49
52
  seed: 'bottom drive obey lake curtain smoke basket hold race lonely fit walk',
50
53
  name: 'Test Account',
51
54
  password: 'securePassword123'
52
55
  })
53
56
 
54
- // Navigate to your dApp
55
57
  await page.goto('http://localhost:3000')
56
-
57
- // Connect wallet
58
58
  await page.click('button:has-text("Connect Wallet")')
59
59
  await polkadotJs.authorize()
60
60
 
61
- // Perform transaction
62
61
  await page.click('button:has-text("Send Transaction")')
63
62
  await polkadotJs.approveTx({ password: 'securePassword123' })
64
63
 
65
- // Verify transaction success
66
64
  await expect(page.locator('.transaction-success')).toBeVisible()
67
65
  })
68
66
  ```
69
67
 
70
- ### Custom Configuration
71
-
72
- ```typescript
73
- import { createWalletTest, expect } from '@avalix/chroma'
74
-
75
- const customTest = createWalletTest({
76
- wallets: [{ type: 'polkadot-js' }],
77
- headless: false,
78
- slowMo: 100
79
- })
80
-
81
- customTest('test with custom config', async ({ page, wallets }) => {
82
- const polkadotJs = wallets['polkadot-js']
83
-
84
- await polkadotJs.importMnemonic({
85
- seed: 'your seed phrase here...',
86
- name: 'My Test Account'
87
- })
88
- await page.goto('http://localhost:3000')
89
- await polkadotJs.authorize()
90
- })
91
- ```
92
-
93
68
  ### Multiple Wallets
94
69
 
95
- ```typescript
96
- import { createWalletTest, expect } from '@avalix/chroma'
97
-
98
- // Test with multiple wallet extensions
99
- const multiWalletTest = createWalletTest({
100
- wallets: [
101
- { type: 'polkadot-js' },
102
- { type: 'talisman' }
103
- ],
104
- headless: false,
105
- slowMo: 150
106
- })
107
-
108
- multiWalletTest('test with multiple wallets', async ({ page, wallets }) => {
109
- const polkadotJs = wallets['polkadot-js']
110
- const talisman = wallets.talisman
111
-
112
- // Import to Polkadot JS
113
- await polkadotJs.importMnemonic({
114
- seed: 'bottom drive obey lake curtain smoke basket hold race lonely fit walk',
115
- name: 'Alice'
116
- })
117
-
118
- // Import to Talisman using Ethereum private key
119
- await talisman.importEthPrivateKey({
120
- privateKey: '0x...',
121
- name: 'Bob'
122
- })
123
-
124
- await page.goto('http://localhost:3000')
125
-
126
- // Use specific wallet
127
- await polkadotJs.authorize()
128
- await polkadotJs.approveTx()
129
- })
130
- ```
131
-
132
- ## Features
133
-
134
- - 🔐 **Easy Extension Setup**: Simple command to download wallet extensions
135
- - 🧪 **Test Fixtures**: Ready-to-use Playwright fixtures for wallet operations
136
- - 📝 **Account Management**: Import accounts with seed phrases and custom names
137
- - ✅ **Transaction Approval**: Approve transactions with password authentication
138
- - 🔗 **dApp Authorization**: Connect wallet to decentralized applications
139
- - 🔀 **Multi-Wallet Support**: Test with multiple wallet extensions simultaneously
140
- - ⚙️ **Configurable**: Custom extension paths, headless mode, and slow motion settings
141
-
142
- ## API Reference
143
-
144
- ### Core Functions
145
-
146
- #### `test` (Default Test Function)
147
- Pre-configured test function with Polkadot JS extension.
148
-
149
- ```typescript
150
- import { test } from '@avalix/chroma'
151
-
152
- test('my wallet test', async ({ page, wallets }) => {
153
- const polkadotJs = wallets['polkadot-js']
154
-
155
- await polkadotJs.importMnemonic({ seed: '...' })
156
- await polkadotJs.authorize()
157
- })
158
- ```
159
-
160
- #### `createWalletTest(options?: ChromaTestOptions)`
161
- Create a custom test function with specific configuration. Supports single and multi-wallet modes.
162
-
163
70
  ```typescript
164
71
  import { createWalletTest } from '@avalix/chroma'
165
72
 
166
- // Single wallet (default)
167
- const test = createWalletTest()
168
-
169
- // Single wallet with custom config
170
- const customTest = createWalletTest({
171
- wallets: [{ type: 'polkadot-js' }],
172
- headless: false,
173
- slowMo: 150
73
+ const test = createWalletTest({
74
+ wallets: [{ type: 'polkadot-js' }, { type: 'talisman' }]
174
75
  })
175
76
 
176
- // Multiple wallets
177
- const multiTest = createWalletTest({
178
- wallets: [
179
- { type: 'polkadot-js' },
180
- { type: 'talisman' }
181
- ]
182
- })
183
-
184
- // Usage
185
- test('example', async ({ page, wallets }) => {
77
+ test('multi-wallet test', async ({ page, wallets }) => {
186
78
  const polkadotJs = wallets['polkadot-js']
79
+ const talisman = wallets.talisman
187
80
 
188
- await polkadotJs.importMnemonic({ seed: '...' })
189
- await polkadotJs.authorize()
190
- await polkadotJs.approveTx()
191
- })
192
- ```
193
-
194
- ### Test Fixtures
195
-
196
- #### `page`
197
- Playwright page instance with wallet extension(s) loaded.
198
-
199
- #### `wallets`
200
- Typed object containing wallet instances for each configured wallet. Provides full TypeScript autocomplete.
201
-
202
- ```typescript
203
- // Base wallet instance (common methods)
204
- interface BaseWalletInstance {
205
- extensionId: string
206
- importMnemonic: (options: WalletAccount) => Promise<void>
207
- authorize: (options?: { accountName?: string }) => Promise<void>
208
- approveTx: (options?: { password?: string }) => Promise<void>
209
- }
210
-
211
- // Polkadot-JS wallet instance
212
- interface PolkadotJsWalletInstance extends BaseWalletInstance {
213
- type: 'polkadot-js'
214
- }
215
-
216
- // Talisman wallet instance (with additional methods)
217
- interface TalismanWalletInstance extends BaseWalletInstance {
218
- type: 'talisman'
219
- importEthPrivateKey: (options: { privateKey: string, name?: string, password?: string }) => Promise<void>
220
- }
221
-
222
- // Note: Talisman currently does not support importMnemonic - use importEthPrivateKey instead
223
-
224
- // Wallets collection - each wallet has its specific type
225
- interface Wallets {
226
- 'polkadot-js': PolkadotJsWalletInstance
227
- 'talisman': TalismanWalletInstance
228
- }
229
-
230
- interface WalletAccount {
231
- seed: string
232
- name?: string // Default: 'Test Account'
233
- password?: string // Default: 'h3llop0lkadot!'
234
- }
235
- ```
236
-
237
- **Usage:**
238
-
239
- ```typescript
240
- test('example', async ({ page, wallets }) => {
241
- const polkadotJs = wallets['polkadot-js'] // Type: PolkadotJsWalletInstance
242
-
243
- // Import mnemonic (available on all wallets)
244
- await polkadotJs.importMnemonic({
245
- seed: 'bottom drive obey lake curtain smoke basket hold race lonely fit walk',
246
- name: 'Test Account',
247
- password: 'securePassword123'
248
- })
81
+ await polkadotJs.importMnemonic({ seed: '...', name: 'Alice' })
82
+ await talisman.importEthPrivateKey({ privateKey: '0x...', name: 'Bob' })
249
83
 
250
84
  await page.goto('http://localhost:3000')
251
85
  await polkadotJs.authorize()
252
- await polkadotJs.approveTx({ password: 'securePassword123' })
253
- })
254
-
255
- // Talisman-specific features
256
- test('talisman example', async ({ page, wallets }) => {
257
- const talisman = wallets.talisman // Type: TalismanWalletInstance
258
-
259
- // Talisman-specific method: import Ethereum private key
260
- await talisman.importEthPrivateKey({
261
- privateKey: '0x...',
262
- name: 'My Account',
263
- password: 'mypassword'
264
- })
265
-
266
- // Common methods also available
267
- await talisman.authorize({ accountName: 'My Account' })
268
- await talisman.approveTx()
269
86
  })
270
87
  ```
271
88
 
272
- ## Configuration
89
+ ## Supported Wallets & Chains
273
90
 
274
- ### Extension Download
275
- Run the download command to get the required wallet extensions:
276
-
277
- ```bash
278
- npx chroma download-extensions
279
- ```
280
-
281
- Extensions will be downloaded to `./.chroma` directory in your project root. Add this directory to your `.gitignore`:
282
-
283
- ```gitignore
284
- .chroma/
285
- ```
286
-
287
- ### Browser Settings
288
- - **Headless Mode**: Disabled by default for better debugging
289
- - **Slow Motion**: 150ms delay between actions (configurable)
290
- - **Extension Loading**: Automatically loads configured wallet extensions
291
-
292
- ## Supported Chains
91
+ ### Supported Chains
293
92
 
294
93
  | Chain | Status |
295
94
  |-------|--------|
@@ -297,27 +96,27 @@ Extensions will be downloaded to `./.chroma` directory in your project root. Add
297
96
  | Ethereum | ✅ Supported |
298
97
  | Solana | ⏳ Planned |
299
98
 
300
- ## Supported Wallets
99
+ ### Supported Wallets
301
100
 
302
101
  | Wallet | Status | Version |
303
102
  |--------|--------|---------|
304
103
  | Polkadot JS Extension | ✅ Supported | v0.62.6 |
305
104
  | Talisman | ✅ Supported | v3.1.13 |
306
105
  | SubWallet | ⏳ Planned | - |
106
+ | MetaMask | ⏳ Planned | - |
107
+
108
+ ## Features
109
+
110
+ - **Easy Extension Setup** - Download wallet extensions with a single command
111
+ - **Multi-Wallet Support** - Test with multiple wallet extensions simultaneously
112
+ - **TypeScript Support** - Full type safety and autocomplete
113
+ - **VS Code Integration** - Works with [Playwright Test for VS Code](https://marketplace.visualstudio.com/items?itemName=ms-playwright.playwright)
307
114
 
308
115
  ## Requirements
309
116
 
310
117
  - Node.js 24+
311
118
  - @playwright/test ^1.55.0
312
119
 
313
- ## Contributing
314
-
315
- This project is in active development. Currently focusing on:
316
- - Polkadot JS Extension and Talisman support
317
- - Core testing fixtures
318
- - Additional wallet integrations
319
- - Documentation improvements
320
-
321
120
  ## License
322
121
 
323
122
  MIT
package/dist/index.d.mts CHANGED
@@ -9923,38 +9923,45 @@ declare namespace test_d_exports {
9923
9923
  export { BlobReporterOptions, Config, Expect, ExpectMatcherState, ExpectMatcherUtils, Fixtures, FullConfig, FullProject, HtmlReporterOptions, JUnitReporterOptions, JsonReporterOptions, ListReporterOptions, Location, MatcherHintOptions, MatcherReturnType, Metadata, PageAssertionsToHaveScreenshotOptions, PlaywrightTestArgs, PlaywrightTestConfig, PlaywrightTestOptions, PlaywrightTestProject, PlaywrightWorkerArgs, PlaywrightWorkerOptions, Project, ReporterDescription, ScreenshotMode, TestAnnotation, TestDetails, TestDetailsAnnotation, TestFixture, TestInfo, TestInfoError, TestStatus, TestStepInfo, TestType, TraceMode, VideoMode, WorkerFixture, WorkerInfo, _baseTest, test$2 as default, defineConfig, expect$1 as expect, mergeExpects, mergeTests, test$2 as test };
9924
9924
  }
9925
9925
  //#endregion
9926
- //#region src/context-playwright/types.d.ts
9927
- type WalletType = 'polkadot-js' | 'talisman';
9928
- interface WalletAccount {
9929
- seed: string;
9930
- name?: string;
9931
- password?: string;
9932
- }
9933
- interface WalletConfig {
9934
- type: WalletType;
9935
- downloadUrl?: string;
9936
- }
9937
- interface BaseWalletInstance {
9926
+ //#region src/context-playwright/wallet-factory.d.ts
9927
+ declare function createPolkadotJsWallet(extensionId: string, context: BrowserContext): {
9938
9928
  extensionId: string;
9929
+ type: "polkadot-js";
9939
9930
  importMnemonic: (options: WalletAccount) => Promise<void>;
9940
- authorize: (options?: {
9941
- accountName?: string;
9942
- }) => Promise<void>;
9931
+ authorize: () => Promise<void>;
9943
9932
  approveTx: (options?: {
9944
9933
  password?: string;
9945
9934
  }) => Promise<void>;
9946
9935
  rejectTx: () => Promise<void>;
9947
- }
9948
- interface PolkadotJsWalletInstance extends BaseWalletInstance {
9949
- type: 'polkadot-js';
9950
- }
9951
- interface TalismanWalletInstance extends BaseWalletInstance {
9952
- type: 'talisman';
9936
+ };
9937
+ declare function createTalismanWallet(extensionId: string, context: BrowserContext): {
9938
+ extensionId: string;
9939
+ type: "talisman";
9940
+ importPolkadotMnemonic: (options: WalletAccount) => Promise<void>;
9953
9941
  importEthPrivateKey: (options: {
9954
9942
  privateKey: string;
9955
9943
  name?: string;
9956
9944
  password?: string;
9957
9945
  }) => Promise<void>;
9946
+ authorize: (options?: {
9947
+ accountName?: string;
9948
+ }) => Promise<void>;
9949
+ approveTx: () => Promise<void>;
9950
+ rejectTx: () => Promise<void>;
9951
+ };
9952
+ type PolkadotJsWalletInstance = ReturnType<typeof createPolkadotJsWallet>;
9953
+ type TalismanWalletInstance = ReturnType<typeof createTalismanWallet>;
9954
+ //#endregion
9955
+ //#region src/context-playwright/types.d.ts
9956
+ type WalletType = 'polkadot-js' | 'talisman';
9957
+ interface WalletAccount {
9958
+ seed: string;
9959
+ name?: string;
9960
+ password?: string;
9961
+ }
9962
+ interface WalletConfig {
9963
+ type: WalletType;
9964
+ downloadUrl?: string;
9958
9965
  }
9959
9966
  interface WalletTypeMap {
9960
9967
  'polkadot-js': PolkadotJsWalletInstance;