ic-testkit
ic-testkit is a wrapper around pocket-ic, the core local IC testing runtime this crate builds on. It does not replace pocket-ic; it adds a small, opinionated host-side layer for test suites that want typed Candid calls, install helpers, diagnostics, serialized PocketIC startup, cached baselines, deterministic fake principals, and wasm artifact utilities.
If you need the underlying IC simulator/runtime itself, start with pocket-ic. Use ic-testkit when you want reusable Rust test harness conveniences on top of it.
It is intentionally application-neutral. Bring your own init payloads, method names, readiness checks, fixture graph, and product-specific test policy.
Install
[]
= "0.0.1"
[!WARNING] Do not use - some of this may be hallucinations, our best agents are currently auditing the code.
Quick Start
Use PicSerialGuard when a test owns a PocketIC instance. It serializes PocketIC usage across processes, which helps avoid shared server/resource exhaustion in larger test runs.
use ;
Calling Canisters
Pic wraps common update/query calls with Candid encoding and decoding. The error includes the canister id and method name when PocketIC rejects the call.
use ;
Use the _as variants when the caller matters:
use Principal;
let caller = principal;
let ledger_id = from_text.unwrap;
let balance: u128 = pic
.query_call_as
.unwrap;
Installing Wasm
For one-off tests, install a prebuilt wasm into a fresh PocketIC instance:
use ;
For existing Pic instances, use the lower-level helper:
let canister_id = pic.create_and_install_with_args;
If PocketIC reports install-code rate limiting, retry while advancing PocketIC time between attempts:
use Duration;
let result = pic.retry_install_code_ok;
Artifact Helpers
Build wasm packages into a dedicated target directory:
use ;
let workspace = workspace_root_for;
let target = test_target_dir;
build_wasm_canisters;
assert!;
Check generated .icp artifacts against watched inputs:
let ready = icp_artifact_ready_for_build;
Deterministic Test Identities
Fake gives stable principals and account-like values from numeric seeds:
use Fake;
let alice = principal;
let bob = principal;
let account = account;
assert_ne!;
assert_eq!;
Cached Baselines
For expensive multi-canister setup, CachedPicBaseline can snapshot canisters once and restore them between tests. If the cached PocketIC instance has died, restore_or_rebuild_cached_pic_baseline rebuilds instead of reusing a broken instance.
Use this when setup time dominates the test and the fixture can be restored from PocketIC snapshots. Keep application-specific topology and readiness logic in your own test harness.
What This Adds Over pocket-ic
Pic, a narrow wrapper for the PocketIC operations used by this crate- typed startup errors for common PocketIC launch failures
PicSerialGuardfor cross-process PocketIC serialization- Candid query/update helpers with contextual errors
- generic wasm install helpers and install-code retry helpers
- canister status/log diagnostics
- standalone prebuilt-wasm fixtures
- cached snapshot baselines
- deterministic fake principals and accounts
- wasm path/build/readiness helpers
- watched-input freshness checks for generated
.icpartifacts
Boundaries
This crate does not define application init payloads, endpoint names, role models, readiness polling, canister graph topology, attestation policy, or broad self-test orchestration. Those belong in the application or framework that owns the canisters being tested.
Toolchains
- MSRV: Rust 1.88
- internal build/test lane: Rust 1.95
Local Checks