Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wild-pants-wear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainwright": patch
---

Update README.md and CONTRIBUTING.md
6 changes: 6 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ This repository uses two main long-lived branches:
When contributing:

- Create your feature/fix branch from `dev`.
- Run the changeset script to log your changes. `pnpm run changeset`
- Open pull requests targeting `dev` (not `main`).

## Project Structure
Expand All @@ -42,6 +43,7 @@ When contributing:
- `tests/e2e/`: end-to-end wallet and dapp specs
- `tests/wallet-setup/`: setup files used to build wallet cache
- `scripts/`: helper tooling (including wallet scaffolding)
- `examples/`: Contains wallet setup examples

## Development Commands

Expand All @@ -68,6 +70,10 @@ Use the wallet scaffolder:

- `pnpm run add:wallet`: Specify the wallet name

```bash
pnpm run add:wallet foxtrot
```

Then implement wallet-specific actions/selectors and add/update tests in `tests/e2e` and `tests/wallet-setup`.

## Changesets (Required for User-Facing Changes)
Expand Down
48 changes: 34 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Chainwright is an end-to-end testing toolkit for Web3 dapps built on Playwright.
## Features

- Wallet setup CLI to build reusable extension cache
- Custom wallet extension source.
- Playwright fixtures for wallet + Dapp testing
- Support for multiple wallet profiles per wallet
- Wallet action APIs for onboarding, account switching, transaction confirmation, and more
Expand All @@ -37,7 +38,7 @@ Chainwright is an end-to-end testing toolkit for Web3 dapps built on Playwright.
## Requirements

- Node.js `>=22`
- `@playwright/test@1.60.0` (peer dependency)
- `@playwright/test@1.61.1` (peer dependency)

## Operating Systems
Supports the following operating systems:
Expand Down Expand Up @@ -83,10 +84,11 @@ Create a setup directory (default: `tests/wallet-setup`) and add `*.setup.ts` fi
- `petra.setup.ts`
- `phantom-team-a.setup.ts`

Each file must export `default defineWalletSetup(...)`.
Each file must export `defineWalletSetup(...)`.

Wallet setup examples: [Setup examples link](https://github.com/amaify/chainwright/tree/dev/examples)

```ts
// tests/wallet-setup/metamask.setup.ts
import { defineWalletSetup } from "chainwright/core";
import { Metamask } from "chainwright/metamask";

Expand All @@ -113,7 +115,6 @@ export default defineWalletSetup(
**For Wallets with additional accounts**

```ts
// tests/wallet-setup/metamask.setup.ts
import { defineWalletSetup } from "chainwright/core";
import { Petra } from "chainwright/petra";

Expand Down Expand Up @@ -146,15 +147,14 @@ export default defineWalletSetup(

To support multiple profiles in a single wallet (for example, MetaMask), only setup files from the second profile onward need an explicit, distinct profile name.

`main.setup.ts` can use the default profile, while `main-two.setup.ts` (and any additional setup files) should declare a unique profile name. Then, in any fixture that should use that profile, pass the exact same profileName value.
`main.setup.ts` can use the default profile, while `main-two.setup.ts` (and any additional setup files) should declare a unique profile name. Then, in any fixture that should use that profile, pass the exact `profileName` value.

Example:
- `main.setup.ts`: uses the default profile
- `main-two.setup.ts`: defines `profileName: "profile two"`
- Fixture usage: `metamaskFixture({ profileName: "profile two" })`

```ts
// tests/wallet-setup/main-two.setup.ts
import { defineWalletSetup } from "chainwright/core";
import { Metamask } from "chainwright/metamask";

Expand Down Expand Up @@ -187,12 +187,12 @@ You must ensure that the version of the extension you provide matches the one Ch

These are Chainwright's wallet extensions and their versions:

- **MetaMask**: v13.33.0
- **Petra**: v2.4.8
- **Phantom**: v26.10.0
- **Solflare**: v2.19.1
- **Meteor**: v0.7.0
- **Keplr**: v0.13.39
- **MetaMask**: v13.33.0 [Source](https://github.com/MetaMask/metamask-extension/releases/tag/v13.33.0)
- **Petra**: v2.4.8 [Source](https://github.com/amaify/chainwright/releases/tag/v0.1.0)
- **Phantom**: v26.10.0 [Source](https://github.com/amaify/chainwright/releases/tag/v0.1.0)
- **Solflare**: v2.19.1 [Source](https://github.com/amaify/chainwright/releases/tag/v0.1.0)
- **Meteor**: v0.7.0 [Source](https://github.com/amaify/chainwright/releases/tag/v0.1.0)
- **Keplr**: v0.13.39 [Source](https://github.com/chainapsis/keplr-wallet/releases/tag/v0.13.39)

Example:

Expand Down Expand Up @@ -233,13 +233,32 @@ Run setup with the CLI (Supports **npx**, **bun**, **pnpm**, and **yarn**):
By default, Chainwright looks for `tests/wallet-setup` in your base directory. However, you can specify the directory you want Chainwright to get your setup files from.

```bash

bun chainwright --wallets <Wallets you want to support>

Examples:
# Multiple wallet setup command
bun chainwright --wallets metamask phantom solflare

# Single wallet setup command
bun chainwright --metamask

# Overriding existing wallet cache during setup
bun chainwright --metamask --force

# Overriding multiple existing wallet cache during setup
bun chainwright --wallets metamask phantom petra --force

# NOTE: These command will work with other package managers. npm, pnpm, and yarn.
```

To specify a directory:

```bash
bun chainwright <directory path> <wallet> -f #Optional flag
bun chainwright <directory path> <wallet>

Example:
bun chainwright ./src/e2e/your-tests --metamask
```

Useful flags:
Expand Down Expand Up @@ -289,6 +308,7 @@ test.describe("Example tests", () => {
});
})
```

> [!NOTE]
The wallet fixture will make use of the `default` wallet profile. If you specified a `profile-name` at the point of setting up, make sure to include it in the fixture.

Expand Down Expand Up @@ -450,7 +470,7 @@ defineWalletSetup(password, setupFn, config?)

- `password: string` - wallet unlock password saved in cache metadata
- `setupFn: ({ context, walletPage }) => Promise<void>` - runs onboarding/import flow
- `config?: { profileName?: string; slowMo?: number }` - useful for setting up multiple wallet profiles and running the setup in slow motion `slowMo`.
- `config?: { profileName?: string; slowMo?: number, extensionSource?: {...} }` - useful for setting up multiple wallet profiles, running the setup in slow motion `slowMo` and using a custom extension source.

### `testWithChainwright`

Expand Down