/defi-ui-testing:defi-ui-mock-connectorfrom defi-ui-testing
This skill should be used when implementing DeFi UI E2E with Playwright, Anvil, and Wagmi mock connector — window._setupAccount, fixtures, error features, without MetaMask extension.
Ships in defi-ui-testing. 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.
None: SKILL.md is the whole skill.
Wallet-agnostic E2E: no browser extension. Based on patterns from rombrom.com.
features// src/wagmi.ts
import { createClient, http, isAddress } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { createConfig } from 'wagmi'
import { injected, mock, type MockParameters } from 'wagmi/connectors'
import { foundry, mainnet } from 'wagmi/chains'
const chains = [mainnet, foundry] as const
export const config = createConfig({
chains,
client: ({ chain }) => createClient({ chain, transport: http() }),
connectors: [injected()],
ssr: true,
})
export function createMockConfig(
addressOrPkey: `0x${string}`,
features?: MockParameters['features']
) {
const account = isAddress(addressOrPkey)
? addressOrPkey
: privateKeyToAccount(addressOrPkey)
const address = typeof account === 'string' ? account : account.address
return createConfig({
chains,
connectors: [mock({ accounts: [address], features })],
client: ({ chain }) =>
createClient({
account: typeof account === 'string' ? undefined : account,
chain,
transport: http(),
}),
ssr: true,
})
}
window (test-only hook)Keep Wagmi config in React state so tests can hot-swap:
// root layout / App providers
const [wagmiConfig, setWagmiConfig] = useState(config)
const _setupAccount = useCallback(
(...args: Parameters<typeof createMockConfig>) => {
setWagmiConfig(createMockConfig(...args))
},
[]
)
if (typeof window !== 'undefined') {
// Optionally gate: if (import.meta.env.MODE !== 'production')
;(window as any)._setupAccount = _setupAccount
}
return (
<WagmiProvider config={wagmiConfig} key={wagmiConfig} /* remount if needed */>
{children}
</WagmiProvider>
)
Declare:
declare global {
interface Window {
_setupAccount: typeof createMockConfig
}
}
// tests/fixtures/wallet.ts
import { test as base, type Page } from '@playwright/test'
import { privateKeyToAccount } from 'viem/accounts'
import type { MockParameters } from 'wagmi/connectors'
const ACCOUNT_PKEYS = {
alice: '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',
bob: '0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d',
} as const
export class WalletFixture {
address?: `0x${string}`
constructor(private page: Page) {}
async connect(
name: keyof typeof ACCOUNT_PKEYS,
features?: MockParameters['features']
) {
const pkey = ACCOUNT_PKEYS[name]
this.address = privateKeyToAccount(pkey).address
await this.page.waitForFunction(() => (window as any)._setupAccount)
await this.page.evaluate(
([key, feats]) => (window as any)._setupAccount(key, feats),
[pkey, features] as const
)
await this.page.getByRole('button', { name: /Mock Connector/i }).click()
}
}
export const test = base.extend<{ wallet: WalletFixture }>({
wallet: async ({ page }, use) => {
await use(new WalletFixture(page))
},
})
import { expect, test } from './fixtures'
import { UserRejectedRequestError } from 'viem'
test('connect alice', async ({ page, wallet }) => {
await page.goto('/')
await wallet.connect('alice')
await expect(page.getByText(`Connected: ${wallet.address}`)).toBeVisible()
})
test('user rejects connect', async ({ page, wallet }) => {
await page.goto('/')
const [error] = await Promise.all([
page.waitForEvent('pageerror'),
wallet.connect('alice', {
connectError: new UserRejectedRequestError(new Error('user rejected')),
}),
])
expect(error.name).toBe('UserRejectedRequestError')
})
fullyParallel: false,
webServer: [
{ command: 'anvil', url: 'http://127.0.0.1:8545', reuseExistingServer: !process.env.CI },
{ command: 'npm run dev', url: 'http://127.0.0.1:3000', reuseExistingServer: !process.env.CI },
],
window._setupAccount behind non-production envhttps://github.com/re-nft/blockchain-web-app-e2e-testing-remix-wagmi
What SKILL.md sets; muted values are Claude Code's defaults
5 skills in this plugin
/defi-ui-anvil-fixturesThis skill should be used when building Anvil-backed Playwright fixtures for DeFi UI tests — snapshots, time travel, mining, impersonation, and multi-account chain helpers./defi-ui-synpress-metamaskThis skill should be used when implementing DeFi UI E2E with Synpress, Playwright, MetaMask, and Hardhat/Anvil — wallet setup cache, connect, approve, deposit/borrow/liquidate flows./defi-ui-testing-overviewThis skill should be used when planning or implementing DeFi UI E2E tests — choosing between Wagmi mock connector vs Synpress MetaMask, stack layout with Anvil, and test strategy for dApps.Other plugins' skills for the same job
defi-ui-testing@cyotee is listed by cyotee/cyotee-claude-plugins — review the source before installing
npx claudepluginhub cyotee/cyotee-claude-plugins --plugin defi-ui-testing