Skip to main content

ic_testkit/
lib.rs

1//! Focused `PocketIC` test-harness utilities for Internet Computer canisters.
2//!
3//! Import native `PocketIC` clients and DTOs from `ic_testkit::pocket_ic`.
4//! `pic` adds optional typed Wire calls, extension traits for
5//! installation, diagnostics and snapshots, startup errors, caller-owned
6//! managed-server startup and bounded readiness polling. It does not provide a
7//! simulator wrapper or a host-wide runtime lock.
8//!
9//! Deterministic test principals through [`fake_principal`] are available on
10//! every target. The client and `pic` helpers are native-only.
11
12#[cfg(not(target_arch = "wasm32"))]
13pub mod pocket_ic;
14
15#[cfg(not(target_arch = "wasm32"))]
16pub mod pic;
17
18use ic_platform_types::principal::ExternalPrincipal as Principal;
19
20/// Deterministically derive a test [`Principal`] from `seed`.
21///
22/// Values are derived directly from a numeric seed, making fixtures stable
23/// without embedding textual principal literals.
24#[must_use]
25pub fn fake_principal(seed: u32) -> Principal {
26    let mut buf = [0u8; 29];
27    buf[..4].copy_from_slice(&seed.to_be_bytes());
28
29    Principal::from_slice(&buf)
30}
31
32#[cfg(test)]
33mod tests;