/midnight-cq:dapp-testingfrom midnight-cq
Writes Playwright E2E and Vitest integration tests for Midnight dApps, including wallet connection, transaction flows, and contract state UI. Use for UI-with-contract testing, not for contract logic.
Ships in midnight-cq. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Last verified: 2026-09-17 — simulator import corrected to
@openzeppelin/[email protected](verified on npm to exportcreateSimulator).
"If you're testing contract logic, use
midnight-cq:compact-testing. If you're testing that the UI correctly calls contracts and displays results, you're here."
Every Midnight DApp has three testing layers. Use the right tool at each layer — do not collapse them.
┌────────────────────────────────────────────────────────────┐
│ Layer 3 – E2E Tests │
│ Tool: Playwright (always headless) │
│ Scope: Full browser flows — wallet connect, submit tx, │
│ confirmation screen, error modals │
├────────────────────────────────────────────────────────────┤
│ Layer 2 – Integration Tests │
│ Tool: Vitest │
│ Scope: Frontend components + contract simulator │
│ ContractProvider mocked to wrap simulator │
├────────────────────────────────────────────────────────────┤
│ Layer 1 – Unit Tests │
│ Tool: Vitest (contracts via midnight-cq:compact-testing) │
│ Scope: Contract logic in isolation; pure TypeScript │
│ utilities; component logic without DOM │
└────────────────────────────────────────────────────────────┘
Layer 1 is covered by midnight-cq:compact-testing. This skill starts at Layer 2.
| Question | Answer |
|---|---|
| Does the test call a Compact circuit directly? | Use midnight-cq:compact-testing |
| Does the test verify UI renders correct contract state? | You are here |
| Does the test simulate a user clicking through a flow? | You are here (E2E) |
| Does the test check a pure utility function? | Plain Vitest, no skill needed |
The Midnight SDK's ContractProvider bridges frontend components and the
blockchain. In integration tests, swap it for a mock that wraps the contract
simulator instead of hitting a live network.
// tests/integration/setup.ts
import { createSimulator } from '@openzeppelin/compact-simulator';
import { MyContractSimulator } from '../simulators/MyContractSimulator';
export function createMockContractProvider() {
const simulator = new MyContractSimulator(/* initial args */);
return {
// Mirror the real ContractProvider interface
callCircuit: vi.fn(async (circuit: string, args: unknown[]) => {
const fn = (simulator.circuits.impure as Record<string, (...a: unknown[]) => unknown>)[circuit];
if (!fn) throw new Error(`Unknown circuit: ${circuit}`);
return fn(...args);
}),
queryState: vi.fn(async () => simulator.getPublicState()),
};
}
// tests/integration/MyComponent.test.ts
import { render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { ContractContext } from '../../src/context/ContractContext';
import { createMockContractProvider } from './setup';
import { MyComponent } from '../../src/components/MyComponent';
describe('MyComponent — integration', () => {
let provider: ReturnType<typeof createMockContractProvider>;
beforeEach(() => {
provider = createMockContractProvider();
});
it('displays contract state after mount', async () => {
render(
<ContractContext.Provider value={provider}>
<MyComponent />
</ContractContext.Provider>,
);
await waitFor(() =>
expect(screen.getByTestId('contract-value')).toHaveTextContent('42'),
);
});
it('calls callCircuit on button click', async () => {
render(
<ContractContext.Provider value={provider}>
<MyComponent />
</ContractContext.Provider>,
);
await userEvent.click(screen.getByRole('button', { name: /submit/i }));
expect(provider.callCircuit).toHaveBeenCalledOnce();
});
});
headless: false must never appear in
committed test code or CI configuration.page.locator() directly
inside test blocks.tests/e2e/.tests/
e2e/
pages/
WalletPage.ts # Page object: wallet connect/disconnect
TransactionPage.ts # Page object: tx submission + confirmation
ErrorPage.ts # Page object: error state helpers
wallet-connection.spec.ts
transaction-flow.spec.ts
error-states.spec.ts
integration/
... # Vitest integration tests (Layer 2)
playwright.config.ts
// playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({
testDir: './tests/e2e',
use: {
headless: true, // always — never change this
baseURL: 'http://localhost:3000',
},
webServer: {
command: 'npm run dev',
url: 'http://localhost:3000',
reuseExistingServer: !process.env.CI,
},
});
// tests/e2e/pages/WalletPage.ts
import { type Page, type Locator } from '@playwright/test';
export class WalletPage {
readonly connectButton: Locator;
readonly disconnectButton: Locator;
readonly walletAddress: Locator;
constructor(private page: Page) {
this.connectButton = page.getByRole('button', { name: /connect wallet/i });
this.disconnectButton = page.getByRole('button', { name: /disconnect/i });
this.walletAddress = page.getByTestId('wallet-address');
}
async connect() {
await this.connectButton.click();
// Handle wallet extension popup if present
await this.page.waitForSelector('[data-testid="wallet-address"]');
}
async disconnect() {
await this.disconnectButton.click();
await this.connectButton.waitFor();
}
}
Follow the same pattern for TransactionPage and ErrorPage: locators in
the constructor, multi-step flows in named methods.
| Scenario | Layer | Notes |
|---|---|---|
| Wallet connects successfully | E2E | Assert address displayed |
| Wallet disconnects | E2E | Assert connect button returns |
| Transaction submission flow | E2E | Pending → confirmed state |
| Confirmation UI shown | E2E | Check confirmation banner/hash |
| Transaction rejected by user | E2E | Assert rejection error message |
| Network error during submission | E2E | Assert error modal, retry option |
| Contract state displayed on mount | Integration | Provider mock returns simulator state |
| State updates after transaction | Integration | callCircuit → re-query → UI refresh |
| Error state from bad contract call | Integration | Provider throws → UI shows error |
When a real browser wallet extension is unavailable in CI, inject a stub via
page.addInitScript() before any app code runs. The stub must match the real
DApp Connector API shape: window.midnight is a record keyed by the wallet's
rdns, each value an InitialAPI ({ rdns, name, icon, apiVersion, connect(networkId) })
whose connect() resolves to a ConnectedAPI — see
references/playwright-patterns.md for the full fixture pattern.
test.beforeEach(async ({ page }) => {
await page.addInitScript(() => {
(window as any).midnight = {
'com.test.wallet': {
rdns: 'com.test.wallet',
name: 'MockWallet',
icon: 'data:image/png;base64,iVBORw0KGgo=',
apiVersion: '4.0.1',
connect: async (_networkId: string) => ({
getShieldedAddresses: async () => ({
shieldedAddress: 'mn_shield-addr_test',
shieldedCoinPublicKey: '0'.repeat(64),
shieldedEncryptionPublicKey: '0'.repeat(64),
}),
getUnshieldedAddress: async () => ({ unshieldedAddress: 'mn_addr_test' }),
submitTransaction: async (_tx: string) => {},
getConnectionStatus: async () => ({ status: 'connected', networkId: _networkId }),
}),
},
};
});
});
Blockchain state transitions are async. Always use waitFor or Playwright's
built-in auto-waiting rather than asserting on immediately-resolved values:
// GOOD — waits up to 30 s for confirmation banner
await expect(txPage.confirmationBanner).toBeVisible({ timeout: 30_000 });
// BAD — races the async state update
expect(await page.locator('[data-testid="tx-confirmed"]').count()).toBe(1);
| Reference | Contents |
|---|---|
references/playwright-patterns.md | Page objects, wallet mocking, async blockchain assertions |
references/integration-testing.md | Simulator in frontend tests, ContractProvider mocking |
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
midnight, dapp-testing, e2e, playwright, vitest, integration-testing
npx claudepluginhub midnightntwrk/midnight-expert --plugin midnight-cq7 skills in this plugin
/compact-testingmidnight-cq:compact-testingThis skill should be used when the user asks to write Compact contract tests, test a contract with the simulator, set up createSimulator, mock contract patterns, override witnesses in tests, write unit tests for Compact circuits, set up Vitest for a Compact project, test access control or error cases, use describe.each or it.each for parameterized tests, check invariants with afterEach, property-based testing with fast-check, or ZK commitment testing./dapp-connector-testingmidnight-cq:dapp-connector-testingThis skill should be used when the user asks to test DApp Connector API integration, test wallet connection, test makeTransfer, test balanceTransaction, test submitTransaction, mock ConnectedAPI, stub wallet for tests, test wallet errors, test PermissionRejected, test Disconnected handling, test progressive enhancement, write wallet integration tests, test DApp Connector error codes, test wallet discovery, test window.midnight, test apiVersion, test signData, or test DApp Connector security./ledger-testingmidnight-cq:ledger-testingThis skill should be used when the user asks to write ledger tests, test transaction construction, test proof staging, test ZswapLocalState, test DustLocalState, test cost model, test coinCommitment, test ledger-v8, test onchain-runtime, or test well-formedness. Also triggered by requests to write tests for code that uses @midnight-ntwrk/ledger-v8 or @midnight-ntwrk/onchain-runtime directly, test proof staging lifecycle, test token type functions, test crypto fixtures, test serialization round-trips for ledger types, test fee estimation, test SyntheticCost, or test coinNullifier./quality-checkmidnight-cq:quality-checkThis skill should be used when the user asks to run linting, check code quality, run tests, or needs help with "why is biome failing", "fix lint errors", "CI is failing", "type check errors", "biome error", "vitest failing", "tsc error", "playwright failing", or "e2e tests failing". Also triggered by requests to interpret Biome output, fix tsc errors in Midnight projects, debug vitest failures with simulator stack traces, run the full pre-push suite, or understand why compact compile is failing./quality-initmidnight-cq:quality-initThis skill should be used when the user asks to set up linting, add code quality tooling, configure biome, init project quality, initialize code quality, add CI workflows, add GitHub Actions, set up git hooks, add pre-commit hooks, add testing, add Vitest, add Playwright, or configure formatter for a Midnight Network project./wallet-testingmidnight-cq:wallet-testingThis skill should be used when the user asks to write wallet tests, test my wallet variant, test my capability, test my wallet service, test WalletBuilder, write wallet SDK tests, test Effect code, test Observable state, mock wallet services, test wallet state management, wallet test fixtures, wallet test setup, or Vitest wallet. Also triggered by requests to write tests for custom wallet implementations or compose wallets with WalletBuilder.Other plugins' skills for the same job