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
2 changes: 1 addition & 1 deletion .github/workflows/linting-and-unit-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
run: pnpm install --no-frozen-lockfile

- name: Run Linting
run: pnpm run lint
run: pnpm run check:ci

- name: Run unit tests
run: pnpm run tests
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# @tobelabs/chainwright

## 0.10.11

### Patch Changes

- [Linting] - Fix linting that breaks deployment

## 0.10.10

### Patch Changes

- [Solflare] - Close the "What's new" modal popup during onboarding

## 0.10.9

### Patch Changes
Expand Down
8 changes: 4 additions & 4 deletions dist/wallets/phantom/index.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions dist/wallets/solflare/index.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chainwright",
"version": "0.10.9",
"version": "0.10.11",
"description": "Playwright Web3 wallet testing framework for end-to-end dApp automation with MetaMask, Phantom, Solflare, Petra, Meteor, and Keplr",
"type": "module",
"license": "MIT",
Expand Down Expand Up @@ -83,6 +83,8 @@
"setup-wallets": "tsx src/cli/index.ts ./tests/wallet-setup --all -f",
"tests": "vitest --exclude '**/*.spec.ts'",
"lint": "biome check ./src",
"check:types": "tsc",
"check:ci": "pnpm run lint && pnpm run check:types",
"format": "biome format --write ./src",
"tests:e2e:debug": "playwright test --config=tests/playwright.config.ts --debug",
"tests:e2e:ui": "playwright test --config=tests/playwright.config.ts --ui",
Expand Down
7 changes: 3 additions & 4 deletions src/wallets/phantom/actions/onboard.phantom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,13 @@ export default async function onboard({ page, additionalAccounts, ...args }: Onb
}

if (additionalAccounts && additionalAccounts.length > 0) {
let cancelled = false;
const isCancelled = () => cancelled;
const autoCloseController = new AbortController();

autoClosePhantomNotification(newPage, isCancelled).catch((error) => console.error({ error }));
autoClosePhantomNotification(newPage, autoCloseController.signal).catch((error) => console.error({ error }));

for (const { accountName, chain, privateKey } of additionalAccounts) {
await addAccount({ page: newPage, privateKey, accountName, chain });
cancelled = true;
autoCloseController.abort();
Comment on lines +202 to +208

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Abort the notification runner in a finally block.

A failed account, rename, or network action skips abort(), leaving the runner polling until page teardown.

  • src/wallets/phantom/actions/onboard.phantom.ts#L202-L208: wrap the additional-account flow in try/finally and abort in finally.
  • src/wallets/solflare/actions/onboard.solflare.ts#L46-L64: wrap the post-runner onboarding work in try/finally and abort in finally.
📍 Affects 2 files
  • src/wallets/phantom/actions/onboard.phantom.ts#L202-L208 (this comment)
  • src/wallets/solflare/actions/onboard.solflare.ts#L46-L64
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/wallets/phantom/actions/onboard.phantom.ts` around lines 202 - 208,
Ensure the notification runners are always stopped by moving abort calls into
finally blocks: in src/wallets/phantom/actions/onboard.phantom.ts lines 202-208,
wrap the additional-account flow around autoClosePhantomNotification in
try/finally and abort autoCloseController in finally; apply the same try/finally
cleanup to the post-runner onboarding work in
src/wallets/solflare/actions/onboard.solflare.ts lines 46-64, aborting its
controller in finally.

}

await switchAccount(newPage, args.accountName);
Expand Down
7 changes: 3 additions & 4 deletions src/wallets/phantom/phantom-fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,12 @@ export const phantomFixture = ({ slowMo = 0, profileName }: WalletProfileFixture
},
autoCloseNotification: [
async ({ context: _ }, use) => {
let cancelled = false;
const isCancelled = () => cancelled;
const runner = autoClosePhantomNotification(_phantomPage, isCancelled);
const autoCloseController = new AbortController();
const runner = autoClosePhantomNotification(_phantomPage, autoCloseController.signal);

await use(undefined);

cancelled = true;
autoCloseController.abort();
await runner.catch((error) => {
console.error(`Auto close notification error: ${(error as Error).message}`);
});
Expand Down
7 changes: 3 additions & 4 deletions src/wallets/phantom/phantom-worker-scope-fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@ export const phantomWorkerScopeFixture = ({ slowMo, profileName }: WalletProfile
],
autoCloseNotification: [
async ({ workerScopeContents }, use) => {
let cancelled = false;
const isCancelled = () => cancelled;
const runner = autoClosePhantomNotification(workerScopeContents.walletPage, isCancelled);
const autoCloseController = new AbortController();
const runner = autoClosePhantomNotification(workerScopeContents.walletPage, autoCloseController.signal);

await use(undefined);

cancelled = true;
autoCloseController.abort();
await runner.catch((error) => {
console.error(`Auto close notification error: ${(error as Error).message}`);
});
Expand Down
18 changes: 4 additions & 14 deletions src/wallets/phantom/utils.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
import type { Page } from "@playwright/test";
import { sleep } from "@/utils/sleep";

export async function autoClosePhantomNotification(page: Page, isCancelled: () => boolean) {
export async function autoClosePhantomNotification(page: Page, signal: AbortSignal) {
const INTERVAL = 300;
let IS_POLLING_COMPLETE = false;

while (!isCancelled()) {
const _isCancelled = isCancelled();

// Check if notification is closed
// If it's closed or cancelled, there's no need to check again
if (_isCancelled || IS_POLLING_COMPLETE || page.isClosed()) break;

while (!signal.aborted && !page.isClosed()) {
try {
const notificationPopupBackButton = page.locator("div[id='modal']").locator("div > svg").first();
const isNotificationButtonVisible = await notificationPopupBackButton.isVisible().catch(() => false);

if (isNotificationButtonVisible) {
await notificationPopupBackButton.click();
IS_POLLING_COMPLETE = true;
return;
Comment on lines 12 to +14

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Re-check cancellation immediately before clicking.

An abort can occur while isVisible() is awaited. The current iteration can then click a notification after fixture teardown or onboarding cancellation.

  • src/wallets/phantom/utils.ts#L12-L14: include !signal.aborted and !page.isClosed() in the click condition.
  • src/wallets/solflare/utils.ts#L17-L19: include !signal.aborted and !page.isClosed() in the click condition.
📍 Affects 2 files
  • src/wallets/phantom/utils.ts#L12-L14 (this comment)
  • src/wallets/solflare/utils.ts#L17-L19
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/wallets/phantom/utils.ts` around lines 12 - 14, In the click conditions
of the notification back-button flows, re-check both cancellation and page state
immediately before clicking: update src/wallets/phantom/utils.ts lines 12-14 and
src/wallets/solflare/utils.ts lines 17-19 to require !signal.aborted and
!page.isClosed() alongside visibility before invoking the click.

}
} catch (error) {
if (page.isClosed()) break;
console.error("[autoClosePhantomNotification]: ", error);
if (page.isClosed()) return;
}

// Check if polling is complete
if (_isCancelled || IS_POLLING_COMPLETE || page.isClosed()) break;

await sleep(INTERVAL);
}
}
7 changes: 7 additions & 0 deletions src/wallets/solflare/actions/onboard.solflare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Page } from "@playwright/test";
import { getWalletPasswordFromCache } from "@/utils/wallets/get-wallet-password-from-cache";
import { onboardingSelectors } from "../selectors/onboard-selectors.solflare";
import type { OnboardingArgs } from "../types";
import { autoCloseSolflareNotification } from "../utils";
import { addAccount } from "./add-account.solflare";
import { renameAccount } from "./rename-account.solflare";
import { switchNetwork } from "./switch-network.solflare";
Expand Down Expand Up @@ -42,6 +43,10 @@ export async function onboard({ page, recoveryPhrase, network, walletName, addit
const IAgreeButton = page.getByTestId(onboardingSelectors.IAgreeButton);
await IAgreeButton.click();

const autoCloseController = new AbortController();

autoCloseSolflareNotification(page, autoCloseController.signal).catch((error) => console.error({ error }));

if (walletName) {
// "Main Wallet" is the default wallet name for the fist wallet in Solflare.
await renameAccount({ page, currentAccountName: "Main Wallet", newAccountName: walletName });
Expand All @@ -56,5 +61,7 @@ export async function onboard({ page, recoveryPhrase, network, walletName, addit
}
}

autoCloseController.abort();

console.info(styleText("greenBright", "✨ Solflare onboarding completed successfully", { validateStream: false }));
}
7 changes: 3 additions & 4 deletions src/wallets/solflare/solflare-fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,12 @@ export const solflareFixture = ({ slowMo = 0, profileName }: WalletProfileFixtur
},
autoCloseNotification: [
async ({ context: _ }, use) => {
let cancelled = false;
const isCancelled = () => cancelled;
const runner = autoCloseSolflareNotification(_solflarePage, isCancelled);
const autoCloseController = new AbortController();
const runner = autoCloseSolflareNotification(_solflarePage, autoCloseController.signal);

await use(undefined);

cancelled = true;
autoCloseController.abort();
await runner.catch((error) => {
console.error(`Auto close notification error: ${(error as Error).message}`);
});
Expand Down
10 changes: 6 additions & 4 deletions src/wallets/solflare/solflare-worker-scope-fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ export const solflareWorkerScopeFixture = ({ slowMo, profileName }: WalletProfil
],
autoCloseNotification: [
async ({ workerScopeContents }, use) => {
let cancelled = false;
const isCancelled = () => cancelled;
const runner = autoCloseSolflareNotification(workerScopeContents.walletPage, isCancelled);
const autoCloseController = new AbortController();
const runner = autoCloseSolflareNotification(
workerScopeContents.walletPage,
autoCloseController.signal,
);

await use(undefined);

cancelled = true;
autoCloseController.abort();
await runner.catch((error) => {
console.error(`Auto close notification error: ${(error as Error).message}`);
});
Expand Down
15 changes: 3 additions & 12 deletions src/wallets/solflare/utils.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import type { Page } from "@playwright/test";
import { sleep } from "@/utils/sleep";

export async function autoCloseSolflareNotification(page: Page, isCancelled: () => boolean) {
export async function autoCloseSolflareNotification(page: Page, signal: AbortSignal) {
const INTERVAL = 150;
let IS_POLLING_COMPLETE = false;

while (!isCancelled()) {
const _isCancelled = isCancelled();

// Check if notification is closed
// If it's closed or cancelled, there's no need to check again
if (_isCancelled || IS_POLLING_COMPLETE || page.isClosed()) break;

while (!signal.aborted && !page.isClosed()) {
try {
const notificationPopupCloseButton = page
.locator("div[role='dialog']")
Expand All @@ -23,14 +16,12 @@ export async function autoCloseSolflareNotification(page: Page, isCancelled: ()

if (isNotificationPopupCloseButtonVisisble) {
await notificationPopupCloseButton.click();
IS_POLLING_COMPLETE = true;
return;
}
} catch (error) {
console.error("[autoCloseSolflareNotification]: ", error);
}

if (_isCancelled || IS_POLLING_COMPLETE || page.isClosed()) break;

await sleep(INTERVAL);
}
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
"@/tests/*": ["./tests/*"]
}
},
"include": ["**/*.ts", "**/*.tsx"],
"include": ["src/**/*.ts", "tests/**/*.ts", "environment.d.ts"],

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Keep executable TypeScript entry points in the type-check scope.

check:types now excludes scripts/add-wallet.ts, even though it is an exposed project script. A broken script can therefore pass CI and fail only when invoked; include scripts/**/*.ts or document why it is intentionally excluded.

Proposed fix
-    "include": ["src/**/*.ts", "tests/**/*.ts", "environment.d.ts"],
+    "include": ["src/**/*.ts", "tests/**/*.ts", "scripts/**/*.ts", "environment.d.ts"],
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"include": ["src/**/*.ts", "tests/**/*.ts", "environment.d.ts"],
"include": ["src/**/*.ts", "tests/**/*.ts", "scripts/**/*.ts", "environment.d.ts"],
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tsconfig.json` at line 26, Update the TypeScript include configuration in
tsconfig.json to cover executable entry points under scripts/**/*.ts, ensuring
scripts such as add-wallet.ts are checked by check:types alongside the existing
source and test patterns.

"exclude": ["node_modules", "docs"]
}