/midnight-cq:dapp-connector-testingfrom midnight-cq
Tests DApp wallet integration via the Midnight DApp Connector API, covering connection lifecycle, ConnectedAPI methods (transfers, balances, submissions), error codes, and wallet discovery.
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-18 — checked against
@midnight-ntwrk/dapp-connector-api4.0.1: all 16 documentedConnectedAPImethods and all 5 error codes (InternalError,InvalidRequest,Rejected,PermissionRejected,Disconnected) are present in the published type definitions; theapiVersion4.0.1 fixture matches the current package.
Write tests for DApp code that integrates with the wallet through the
DApp Connector API — the window.midnight injection, InitialAPI.connect(),
and the ConnectedAPI methods.
| Question | Skill |
|---|---|
| Am I testing my DApp's wallet integration code? | dapp-connector-testing (this skill) |
| Am I building a custom wallet variant or capability? | wallet-testing |
| Am I testing Compact contract logic? | compact-testing |
| Am I testing DApp UI flows end-to-end? | dapp-testing |
Relationship to dapp-testing: This skill covers the API contract between
your DApp and the wallet. dapp-testing covers Playwright E2E and UI flows.
They complement each other — use both.
window.midnightapiVersion validation (semver)connect(networkId) success and failure| Category | Methods |
|---|---|
| Balance queries | getShieldedBalances, getUnshieldedBalances, getDustBalance |
| Address queries | getShieldedAddresses, getUnshieldedAddress, getDustAddress |
| Transaction creation | makeTransfer, makeIntent |
| Transaction balancing | balanceUnsealedTransaction, balanceSealedTransaction |
| Transaction submission | submitTransaction |
| Data signing | signData |
| Configuration | getConfiguration, getConnectionStatus |
| Proving delegation | getProvingProvider |
| Permissions | hintUsage |
The DApp Connector API defines 5 error codes. Your DApp must handle each correctly:
| Error Code | Meaning | DApp Behavior |
|---|---|---|
InternalError | Wallet can't process request | Show error to user |
InvalidRequest | Malformed request from DApp | Fix request, don't retry |
Rejected | User rejected this specific action (transient) | Allow retry |
PermissionRejected | Permission denied for method (permanent per session) | Don't retry, degrade gracefully |
Disconnected | Connection lost | Attempt reconnection |
The critical distinction: Rejected is transient (user said "no" to one
transaction), PermissionRejected is permanent (user doesn't want this DApp
using that method at all). Your tests must verify your DApp handles both
correctly.
Build a configurable test double that implements InitialAPI and ConnectedAPI:
function createWalletStub(config?: Partial<StubConfig>): InitialAPI {
const cfg = { ...defaultConfig, ...config };
return Object.freeze({
rdns: 'com.test.wallet',
name: cfg.name ?? 'Test Wallet',
icon: cfg.icon ?? 'data:image/png;base64,...',
apiVersion: cfg.apiVersion ?? '4.0.1',
connect: async (networkId) => {
if (cfg.connectError) throw createAPIError(cfg.connectError);
return createConnectedStub(cfg);
},
});
}
function createConnectedStub(cfg: StubConfig): ConnectedAPI {
return {
getShieldedBalances: async () => {
if (cfg.errors?.getShieldedBalances) throw createAPIError(cfg.errors.getShieldedBalances);
return cfg.shieldedBalances ?? {};
},
getUnshieldedBalances: async () => cfg.unshieldedBalances ?? {},
getDustBalance: async () => cfg.dustBalance ?? { cap: 0n, balance: 0n },
// ... all other ConnectedAPI methods
submitTransaction: async (tx) => {
if (cfg.errors?.submitTransaction) throw createAPIError(cfg.errors.submitTransaction);
},
};
}
See references/connector-stub-patterns.md for complete implementations.
it('should retry after Rejected', async () => {
let callCount = 0;
const stub = createWalletStub();
const wallet = await stub.connect('undeployed');
// Wrap submitTransaction with a closure so the error
// is evaluated per-call, not at object creation time
const originalSubmit = wallet.submitTransaction.bind(wallet);
wallet.submitTransaction = async (tx) => {
if (callCount++ === 0) throw createAPIError('Rejected');
return originalSubmit(tx);
};
// First call → Rejected, DApp shows "try again"
await expect(wallet.submitTransaction('tx')).rejects.toMatchObject({
code: 'Rejected',
});
// Second call → success
await wallet.submitTransaction('tx');
});
it('should not retry after PermissionRejected', async () => {
const stub = createWalletStub({
errors: { getShieldedBalances: 'PermissionRejected' },
});
// DApp should hide shielded balance UI, not keep calling
});
it('should attempt reconnection after Disconnected', async () => {
const stub = createWalletStub({
connectError: 'Disconnected',
});
// DApp should show reconnecting state
});
See references/error-handling-patterns.md for complete patterns.
Test that your DApp degrades gracefully when the wallet doesn't support certain methods:
it('should work without getProvingProvider', async () => {
const stub = createWalletStub({
errors: { getProvingProvider: 'PermissionRejected' },
});
// DApp should fall back to client-side proving
});
it('should work without hintUsage', async () => {
const stub = createWalletStub({
errors: { hintUsage: 'PermissionRejected' },
});
// DApp should still function, just without pre-prompted permissions
});
The DApp Connector spec requires DApps to sanitize wallet-provided data:
it('should sanitize wallet name to prevent XSS', () => {
const stub = createWalletStub({
name: '<script>alert("xss")</script>',
});
// Render wallet selector UI
// Assert no script execution, name displayed as text
});
it('should render wallet icon in img tag only', () => {
const stub = createWalletStub({
icon: 'data:image/svg+xml,...', // SVG can contain scripts
});
// Assert icon is rendered as <img src="...">, not inline SVG
});
| Anti-Pattern | Why It's Wrong | Fix |
|---|---|---|
| Not testing PermissionRejected separately from Rejected | They require different DApp responses | Write separate tests for each |
| Hard-coding balance values in assertions | Brittle; values change with stub config | Assert on structure and relationships |
| Not testing Disconnected recovery | Users will lose connection | Test reconnection flow |
| Testing only happy-path connect | Real wallets reject connections | Test connect with every error code |
| Skipping hintUsage testing | Wallet may prompt user based on hints | Test that DApp sends hints before method calls |
| Using wallet stub for contract logic testing | Wrong tool; contract logic needs the simulator | Use compact-testing for contract logic |
| Topic | Reference |
|---|---|
| Complete ConnectedAPI stub, factory functions, scenario configurations | references/connector-stub-patterns.md |
| Error code test patterns, progressive enhancement, XSS prevention | references/error-handling-patterns.md |
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
7 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-testingmidnight-cq:dapp-testingThis skill should be used when the user asks to test my dapp, write e2e tests, test wallet connection, playwright midnight, test transaction UI, integration test frontend, end-to-end test, browser test, test UI with contract, write Playwright tests for a Midnight dapp, mock ContractProvider, test wallet disconnect, test confirmation screen, test rejected transaction, test contract state displayed in the UI, test React components with contract simulator, mock wallet in tests, or set up e2e testing. NOT for testing Compact contract logic in isolation — see midnight-cq:compact-testing.npx claudepluginhub midnightntwrk/midnight-expert --plugin midnight-cqOther plugins' skills for the same job