Skip to main content

Pic

Struct Pic 

Source
pub struct Pic { /* private fields */ }
Expand description

Pic Thin wrapper around a PocketIC instance.

This type intentionally exposes only a minimal API surface; callers should use pic() to obtain an instance and then perform installs/calls. Callers must hold a PicSerialGuard for the full Pic lifetime.

Implementations§

Source§

impl Pic

Source

pub fn update_call<T, A>( &self, canister_id: Principal, method: &str, args: A, ) -> Result<T, PicCallError>

Generic update call helper (serializes args + decodes result).

Source

pub fn update_call_or_panic<T, A>( &self, canister_id: Principal, method: &str, args: A, ) -> T

Generic update call helper that panics on transport or Candid codec failure.

This does not unwrap application-level results. For example, update_call_or_panic::<Result<T, E>, _>(...) returns Result<T, E>.

Source

pub fn update_call_as<T, A>( &self, canister_id: Principal, caller: Principal, method: &str, args: A, ) -> Result<T, PicCallError>

Generic update call helper with an explicit caller principal.

Source

pub fn update_call_as_or_panic<T, A>( &self, canister_id: Principal, caller: Principal, method: &str, args: A, ) -> T

Generic update call helper with an explicit caller principal that panics on transport or Candid codec failure.

This does not unwrap application-level results. For example, update_call_as_or_panic::<Result<T, E>, _>(...) returns Result<T, E>.

Source

pub fn query_call<T, A>( &self, canister_id: Principal, method: &str, args: A, ) -> Result<T, PicCallError>

Generic query call helper.

Source

pub fn query_call_or_panic<T, A>( &self, canister_id: Principal, method: &str, args: A, ) -> T

Generic query call helper that panics on transport or Candid codec failure.

This does not unwrap application-level results. For example, query_call_or_panic::<Result<T, E>, _>(...) returns Result<T, E>.

Source

pub fn query_call_as<T, A>( &self, canister_id: Principal, caller: Principal, method: &str, args: A, ) -> Result<T, PicCallError>

Generic query call helper with an explicit caller principal.

Source

pub fn query_call_as_or_panic<T, A>( &self, canister_id: Principal, caller: Principal, method: &str, args: A, ) -> T

Generic query call helper with an explicit caller principal that panics on transport or Candid codec failure.

This does not unwrap application-level results. For example, query_call_as_or_panic::<Result<T, E>, _>(...) returns Result<T, E>.

Source

pub fn tick_n(&self, times: usize)

Advance PocketIC by a fixed number of ticks.

Source§

impl Pic

Source

pub fn dump_canister_debug(&self, canister_id: Principal, context: &str)

Dump basic PocketIC status and log context for one canister.

Source§

impl Pic

Source

pub fn create_and_install_with_args( &self, wasm: Vec<u8>, init_bytes: Vec<u8>, install_cycles: u128, ) -> Principal

Install one arbitrary wasm module with caller-provided init bytes.

This is the generic install path for downstreams that use ic-testkit without depending on application-specific init payload conventions.

Source

pub fn try_create_and_install_with_args( &self, wasm: Vec<u8>, init_bytes: Vec<u8>, install_cycles: u128, ) -> Result<Principal, PicInstallError>

Install one arbitrary wasm module with caller-provided init bytes.

Source

pub fn create_and_install(&self, spec: InstallSpec) -> Principal

Install one arbitrary wasm module from a generic install specification.

Source

pub fn try_create_and_install( &self, spec: InstallSpec, ) -> Result<Principal, PicInstallError>

Install one arbitrary wasm module from a generic install specification.

Source

pub fn create_and_install_many<I>(&self, specs: I) -> Vec<Principal>
where I: IntoIterator<Item = InstallSpec>,

Sequentially install multiple arbitrary wasm modules into this Pic.

Installs are attempted in iterator order. If one install fails, earlier installs remain in the PocketIC instance, the failed canister may exist with the id exposed by PicInstallError::canister_id(), and later installs are not attempted.

Source

pub fn try_create_and_install_many<I>( &self, specs: I, ) -> Result<Vec<Principal>, PicInstallError>
where I: IntoIterator<Item = InstallSpec>,

Sequentially install multiple arbitrary wasm modules into this Pic.

Installs are attempted in iterator order. If one install fails, earlier installs remain in the PocketIC instance, the failed canister may exist with the id exposed by PicInstallError::canister_id(), and later installs are not attempted.

Source

pub fn wait_out_install_code_rate_limit(&self, cooldown: Duration)

Wait out the PocketIC install_code cooldown window inside the same instance.

Source

pub fn retry_install_code_ok<T, F>( &self, retry_limit: usize, cooldown: Duration, op: F, ) -> Result<T, String>
where F: FnMut() -> Result<T, String>,

Retry one install_code-like operation while PocketIC still reports rate limiting.

Source

pub fn retry_install_code_err<F>( &self, retry_limit: usize, cooldown: Duration, first: Result<(), String>, op: F, ) -> Result<(), String>
where F: FnMut() -> Result<(), String>,

Retry one install_code-like failure path while PocketIC still reports rate limiting.

Source§

impl Pic

Source

pub fn capture_controller_snapshots<I>( &self, controller_id: Principal, canister_ids: I, ) -> Option<ControllerSnapshots>
where I: IntoIterator<Item = Principal>,

Capture one restorable snapshot per canister using a shared controller.

Source

pub fn restore_controller_snapshots( &self, controller_id: Principal, snapshots: &ControllerSnapshots, )

Restore a previously captured snapshot set using the same controller.

Source§

impl Pic

Source

pub fn tick(&self)

Advance one execution round in the owned PocketIC instance.

Source

pub fn advance_time(&self, duration: Duration)

Advance PocketIC wall-clock time by one duration.

Source

pub fn create_canister(&self) -> Principal

Create one canister with PocketIC default settings.

Source

pub fn add_cycles(&self, canister_id: Principal, amount: u128)

Add cycles to one existing canister.

Source

pub fn install_canister( &self, canister_id: Principal, wasm_module: Vec<u8>, arg: Vec<u8>, sender: Option<Principal>, )

Install one wasm module on one existing canister.

Source

pub fn upgrade_canister( &self, canister_id: Principal, wasm_module: Vec<u8>, arg: Vec<u8>, sender: Option<Principal>, ) -> Result<(), RejectResponse>

Upgrade one existing canister with a new wasm module.

Source

pub fn reinstall_canister( &self, canister_id: Principal, wasm_module: Vec<u8>, arg: Vec<u8>, sender: Option<Principal>, ) -> Result<(), RejectResponse>

Reinstall one existing canister with a new wasm module.

Source

pub fn submit_call( &self, canister_id: Principal, sender: Principal, method: &str, payload: Vec<u8>, ) -> Result<RawMessageId, RejectResponse>

Submit one raw update call without executing it immediately.

Source

pub fn await_call( &self, message_id: RawMessageId, ) -> Result<Vec<u8>, RejectResponse>

Await one previously submitted raw update call.

Source

pub fn canister_status( &self, canister_id: Principal, sender: Option<Principal>, ) -> Result<CanisterStatusResult, RejectResponse>

Fetch one canister status snapshot from PocketIC.

Source

pub fn fetch_canister_logs( &self, canister_id: Principal, sender: Principal, ) -> Result<Vec<CanisterLogRecord>, RejectResponse>

Fetch one canister log stream from PocketIC.

Source

pub fn current_time_nanos(&self) -> u64

Capture the current PocketIC wall-clock time as nanoseconds since epoch.

Source

pub fn restore_time_nanos(&self, nanos_since_epoch: u64)

Restore PocketIC wall-clock and certified time from a captured nanosecond value.

Auto Trait Implementations§

§

impl Freeze for Pic

§

impl !RefUnwindSafe for Pic

§

impl Send for Pic

§

impl Sync for Pic

§

impl Unpin for Pic

§

impl UnsafeUnpin for Pic

§

impl !UnwindSafe for Pic

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more