/midnight-cq:wallet-testingfrom midnight-cq
Writes tests for custom wallet implementations built on the Midnight Wallet SDK, covering wallet variants, capabilities, services, and WalletBuilder composition with Effect/Observable state.
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 — wallet SDK npm scope corrected to
@midnightntwrk(no hyphen; commit 9485a0f).ProtocolVersionconfirmed exported by@midnightntwrk/wallet-sdk-abstractions2.1.0 as aBrand.Branded<bigint>with a brand constructor (matching theProtocolVersion(8n)fixture pattern). DeeperWalletBuilder/WalletFacade/capability signatures are cross-referenced frommidnight-wallet:wallet-sdk(its dedicated pass).
Write tests for custom wallet implementations and extensions built on the
Midnight Wallet SDK packages (@midnightntwrk/wallet-sdk-*).
| Question | Skill |
|---|---|
| Am I building a custom wallet variant or capability? | wallet-testing (this skill) |
| Am I integrating with the wallet via the DApp Connector API? | midnight-cq:dapp-connector-testing |
| Am I testing Compact contract logic? | midnight-cq:compact-testing |
| Am I testing DApp UI flows? | midnight-cq:dapp-testing |
| Do I need the Wallet SDK API reference? | midnight-wallet:wallet-sdk |
You are testing code that uses the wallet SDK packages directly:
midnight-cq:dapp-connector-testing)midnight-cq:compact-testing)midnight-cq:dapp-testing)Users write their own code in whatever style they choose. But at the interface boundary, they must interact with SDK types. These boundary interactions are where testing gets tricky:
SDK methods return Effect<A, E> and Either<A, E>. Your test code needs to
unwrap these to make assertions.
import { Effect, Exit, Either } from 'effect';
// Happy path — unwrap Effect to get the value
it('should fetch wallet state', async () => {
const result = await Effect.runPromise(myService.getState());
expect(result.version).toBe(expectedVersion);
});
// Failure path — check that an Effect fails with the right error
it('should fail for invalid seed', async () => {
const exit = await Effect.runPromiseExit(myService.init(invalidSeed));
expect(Exit.isFailure(exit)).toBe(true);
});
// Pure capability — unwrap Either
it('should balance the transaction', () => {
const result = myCapability.balance(state, tx);
expect(Either.isRight(result)).toBe(true);
if (Either.isRight(result)) {
expect(result.right[0].inputs.length).toBeGreaterThan(0);
}
});
See references/effect-boundary-patterns.md for complete patterns.
WalletFacade exposes state(): Observable<FacadeState>. Tests need to
subscribe, wait for specific conditions, and assert on emitted values.
import { firstValueFrom, filter } from 'rxjs';
it('should sync all three wallets', async () => {
const syncedState = await firstValueFrom(
wallet.state().pipe(
filter((s) => s.shielded.progress.isCompleteWithin() &&
s.unshielded.progress.isCompleteWithin() &&
s.dust.progress.isCompleteWithin())
)
);
expect(syncedState.shielded.availableBalances).toBeDefined();
});
See references/observable-testing.md for complete patterns.
ProtocolVersion, WalletSeed, WalletState, and NetworkId are branded types. Use the SDK's constructors — never cast raw values.
import { ProtocolVersion } from '@midnightntwrk/wallet-sdk-abstractions';
const version = ProtocolVersion(8n); // Use the brand constructor
See references/wallet-builder-setup.md for all fixture patterns.
When providing custom capabilities or services to WalletBuilder, your test double must satisfy the interface. A partial implementation will pass TypeScript but crash at runtime.
// Providing a test double for ProvingService
const testProvingService: ProvingServiceEffect<MyTransaction> = {
proveTransaction: (tx) => Effect.succeed(provenTx),
};
See references/wallet-builder-setup.md for interface patterns.
Wire up WalletBuilder with test variants and initial state:
const TestWallet = WalletBuilder
.init()
.withVariant(ProtocolVersion(8n), myV8Builder)
.build();
let wallet: InstanceType<typeof TestWallet>;
beforeEach(async () => {
wallet = await TestWallet.startFirst(TestWallet, initialState);
});
afterEach(async () => {
await wallet.close();
});
See references/wallet-builder-setup.md for complete setup patterns.
| Anti-Pattern | Why It's Wrong | Fix |
|---|---|---|
| Unwrapping Effect with try/catch | Loses typed error information; can't distinguish Effect failure from thrown exception | Use Effect.runPromiseExit + Exit.isFailure |
| Asserting on Observable without waiting | Test races the async emission; passes sometimes, fails sometimes | Use firstValueFrom with filter and a timeout |
Constructing branded types with as casts | Bypasses validation; creates values the SDK would reject | Use the SDK's brand constructors (e.g., ProtocolVersion(8n)) |
| Partial interface implementations | Passes tsc but crashes at runtime when unimplemented method is called | Implement every method in the interface, even if some return dummy values |
| Sharing wallet instances across tests | State bleeds between tests; order-dependent failures | Create fresh wallet in beforeEach, close in afterEach |
| Not cleaning up subscriptions | Observable subscriptions leak; tests hang or interfere with each other | Unsubscribe in afterEach or use firstValueFrom (auto-completes) |
| Topic | Reference |
|---|---|
| Unwrapping Effect/Either, mock Layers, testing Streams | references/effect-boundary-patterns.md |
| WalletBuilder wiring, initial state, branded type fixtures, test doubles | references/wallet-builder-setup.md |
| Observable state testing, subscription cleanup, state transition assertions | references/observable-testing.md |
What SKILL.md sets; muted values are Claude Code's defaults
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.Other plugins' skills for the same job