pocket_ic

Struct PocketIc

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

Main entry point for interacting with PocketIC.

Implementations§

Source§

impl PocketIc

Source

pub fn new() -> Self

Creates a new PocketIC instance with a single application subnet on the server. The server is started if it’s not already running.

Source

pub fn instance_id(&self) -> InstanceId

Returns the instance ID.

Source

pub fn topology(&self) -> Topology

Returns the topology of the different subnets of this PocketIC instance.

Source

pub fn upload_blob(&self, blob: Vec<u8>, compression: BlobCompression) -> BlobId

Upload and store a binary blob to the PocketIC server.

Source

pub fn set_stable_memory( &self, canister_id: CanisterId, data: Vec<u8>, compression: BlobCompression, )

Set stable memory of a canister. Optional GZIP compression can be used for reduced data traffic.

Source

pub fn get_stable_memory(&self, canister_id: CanisterId) -> Vec<u8>

Get stable memory of a canister.

Source

pub fn list_instances() -> Vec<String>

List all instances and their status.

Source

pub fn verify_canister_signature( &self, msg: Vec<u8>, sig: Vec<u8>, pubkey: Vec<u8>, root_pubkey: Vec<u8>, ) -> Result<(), String>

Verify a canister signature.

Source

pub fn tick(&self)

Make the IC produce and progress by one block. Note that multiple ticks might be necessary to observe an expected effect, e.g., if the effect depends on inter-canister calls or heartbeats.

Source

pub fn auto_progress(&self) -> Url

Configures the IC to make progress automatically, i.e., periodically update the time of the IC to the real time and execute rounds on the subnets. Returns the URL at which /api/v2 requests for this instance can be made.

Source

pub fn stop_progress(&self)

Stops automatic progress (see auto_progress) on the IC.

Source

pub fn url(&self) -> Option<Url>

Returns the URL at which /api/v2 requests for this instance can be made if the HTTP gateway has been started.

Source

pub fn make_live(&mut self, listen_at: Option<u16>) -> Url

Creates an HTTP gateway for this IC instance listening on an optionally specified port and configures the IC instance to make progress automatically, i.e., periodically update the time of the IC to the real time and execute rounds on the subnets. Returns the URL at which /api/v2 requests for this instance can be made.

Source

pub async fn make_live_with_params( &mut self, listen_at: Option<u16>, domains: Option<Vec<String>>, https_config: Option<HttpsConfig>, ) -> Url

Creates an HTTP gateway for this PocketIC instance listening on an optionally specified port (defaults to choosing an arbitrary unassigned port) and optionally specified domains (default to localhost) and using an optionally specified TLS certificate (if provided, an HTTPS gateway is created) and configures the PocketIC instance to make progress automatically, i.e., periodically update the time of the PocketIC instance to the real time and execute rounds on the subnets. Returns the URL at which /api/v2 requests for this instance can be made.

Source

pub fn stop_live(&mut self)

Stops auto progress (automatic time updates and round executions) and the HTTP gateway for this IC instance.

Source

pub fn make_deterministic(&mut self)

👎Deprecated: Use stop_live instead.

Use stop_live instead.

Source

pub fn root_key(&self) -> Option<Vec<u8>>

Get the root key of this IC instance. Returns None if the IC has no NNS subnet.

Source

pub fn get_time(&self) -> SystemTime

Get the current time of the IC.

Source

pub fn set_time(&self, time: SystemTime)

Set the current time of the IC, on all subnets.

Source

pub fn advance_time(&self, duration: Duration)

Advance the time on the IC on all subnets by some nanoseconds.

Source

pub fn get_controllers(&self, canister_id: CanisterId) -> Vec<Principal>

Get the controllers of a canister. Panics if the canister does not exist.

Source

pub fn cycle_balance(&self, canister_id: CanisterId) -> u128

Get the current cycles balance of a canister.

Source

pub fn add_cycles(&self, canister_id: CanisterId, amount: u128) -> u128

Add cycles to a canister. Returns the new balance.

Source

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

Submit an update call (without executing it immediately).

Source

pub fn submit_call_with_effective_principal( &self, canister_id: CanisterId, effective_principal: RawEffectivePrincipal, sender: Principal, method: &str, payload: Vec<u8>, ) -> Result<RawMessageId, UserError>

Submit an update call with a provided effective principal (without executing it immediately).

Source

pub fn await_call( &self, message_id: RawMessageId, ) -> Result<WasmResult, UserError>

Await an update call submitted previously by submit_call_with_effective_principal.

Source

pub fn update_call( &self, canister_id: CanisterId, sender: Principal, method: &str, payload: Vec<u8>, ) -> Result<WasmResult, UserError>

Execute an update call on a canister.

Source

pub fn query_call( &self, canister_id: CanisterId, sender: Principal, method: &str, payload: Vec<u8>, ) -> Result<WasmResult, UserError>

Execute a query call on a canister.

Source

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

Fetch canister logs via a query call to the management canister.

Source

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

Request a canister’s status.

Source

pub fn create_canister(&self) -> CanisterId

Create a canister with default settings as the anonymous principal.

Source

pub fn create_canister_with_settings( &self, sender: Option<Principal>, settings: Option<CanisterSettings>, ) -> CanisterId

Create a canister with optional custom settings and a sender.

Source

pub fn create_canister_with_id( &self, sender: Option<Principal>, settings: Option<CanisterSettings>, canister_id: CanisterId, ) -> Result<CanisterId, String>

Creates a canister with a specific canister ID and optional custom settings. Returns an error if the canister ID is already in use. Creates a new subnet if the canister ID is not contained in any of the subnets.

The canister ID must be an IC mainnet canister ID that does not belong to the NNS or II subnet, otherwise the function might panic (for NNS and II canister IDs, the PocketIC instance should already be created with those subnets).

Source

pub fn create_canister_on_subnet( &self, sender: Option<Principal>, settings: Option<CanisterSettings>, subnet_id: SubnetId, ) -> CanisterId

Create a canister on a specific subnet with optional custom settings.

Source

pub fn upload_chunk( &self, canister_id: CanisterId, sender: Option<Principal>, chunk: Vec<u8>, ) -> Result<Vec<u8>, CallError>

Upload a WASM chunk to the WASM chunk store of a canister. Returns the WASM chunk hash.

Source

pub fn stored_chunks( &self, canister_id: CanisterId, sender: Option<Principal>, ) -> Result<Vec<Vec<u8>>, CallError>

List WASM chunk hashes in the WASM chunk store of a canister.

Source

pub fn clear_chunk_store( &self, canister_id: CanisterId, sender: Option<Principal>, ) -> Result<(), CallError>

Clear the WASM chunk store of a canister.

Source

pub fn install_chunked_canister( &self, canister_id: CanisterId, sender: Option<Principal>, mode: CanisterInstallMode, store_canister_id: CanisterId, chunk_hashes_list: Vec<Vec<u8>>, wasm_module_hash: Vec<u8>, arg: Vec<u8>, ) -> Result<(), CallError>

Install a WASM module assembled from chunks on an existing canister.

Source

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

Install a WASM module on an existing canister.

Source

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

Upgrade a canister with a new WASM module.

Source

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

Reinstall a canister WASM module.

Source

pub fn uninstall_canister( &self, canister_id: CanisterId, sender: Option<Principal>, ) -> Result<(), CallError>

Uninstall a canister.

Source

pub fn take_canister_snapshot( &self, canister_id: CanisterId, sender: Option<Principal>, replace_snapshot: Option<Vec<u8>>, ) -> Result<Snapshot, CallError>

Take canister snapshot.

Source

pub fn load_canister_snapshot( &self, canister_id: CanisterId, sender: Option<Principal>, snapshot_id: Vec<u8>, ) -> Result<(), CallError>

Load canister snapshot.

Source

pub fn list_canister_snapshots( &self, canister_id: CanisterId, sender: Option<Principal>, ) -> Result<Vec<Snapshot>, CallError>

List canister snapshots.

Source

pub fn delete_canister_snapshot( &self, canister_id: CanisterId, sender: Option<Principal>, snapshot_id: Vec<u8>, ) -> Result<(), CallError>

Delete canister snapshot.

Source

pub fn update_canister_settings( &self, canister_id: CanisterId, sender: Option<Principal>, settings: CanisterSettings, ) -> Result<(), CallError>

Update canister settings.

Source

pub fn set_controllers( &self, canister_id: CanisterId, sender: Option<Principal>, new_controllers: Vec<Principal>, ) -> Result<(), CallError>

Set canister’s controllers.

Source

pub fn start_canister( &self, canister_id: CanisterId, sender: Option<Principal>, ) -> Result<(), CallError>

Start a canister.

Source

pub fn stop_canister( &self, canister_id: CanisterId, sender: Option<Principal>, ) -> Result<(), CallError>

Stop a canister.

Source

pub fn delete_canister( &self, canister_id: CanisterId, sender: Option<Principal>, ) -> Result<(), CallError>

Delete a canister.

Source

pub fn canister_exists(&self, canister_id: CanisterId) -> bool

Checks whether the provided canister exists.

Source

pub fn get_subnet(&self, canister_id: CanisterId) -> Option<SubnetId>

Returns the subnet ID of the canister if the canister exists.

Source

pub fn get_subnet_metrics(&self, subnet_id: Principal) -> Option<SubnetMetrics>

Returns subnet metrics for a given subnet.

Source

pub fn get_canister_http(&self) -> Vec<CanisterHttpRequest>

Get the pending canister HTTP outcalls. Note that an additional PocketIc::tick is necessary after a canister executes a message making a canister HTTP outcall for the HTTP outcall to be retrievable here. Note that, unless a PocketIC instance is in auto progress mode, a response to the pending canister HTTP outcalls must be produced by the test driver and passed on to the PocketIC instace using PocketIc::mock_canister_http_response. In auto progress mode, the PocketIC server produces a response for every pending canister HTTP outcall by actually making an HTTP request to the specified URL.

Source

pub fn mock_canister_http_response( &self, mock_canister_http_response: MockCanisterHttpResponse, )

Mock a response to a pending canister HTTP outcall.

Trait Implementations§

Source§

impl Default for PocketIc

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for PocketIc

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. 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<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
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T