pub struct PocketIc { /* private fields */ }Expand description
Main entry point for interacting with PocketIC.
Implementations§
Source§impl PocketIc
impl PocketIc
Sourcepub fn new() -> PocketIc
pub fn new() -> PocketIc
Creates a new PocketIC instance with a single application subnet on the server. The server is started if it’s not already running.
Sourcepub fn new_from_existing_instance(
server_url: Url,
instance_id: usize,
max_request_time_ms: Option<u64>,
) -> PocketIc
pub fn new_from_existing_instance( server_url: Url, instance_id: usize, max_request_time_ms: Option<u64>, ) -> PocketIc
Creates a PocketIC handle to an existing instance on a running server. Note that this handle does not extend the lifetime of the existing instance, i.e., the existing instance is deleted and this handle stops working when the PocketIC handle that created the existing instance is dropped.
pub fn drop_and_take_state(self) -> Option<PocketIcState>
Sourcepub fn get_server_url(&self) -> Url
pub fn get_server_url(&self) -> Url
Returns the URL of the PocketIC server on which this PocketIC instance is running.
Sourcepub fn instance_id(&self) -> usize
pub fn instance_id(&self) -> usize
Returns the instance ID.
Sourcepub fn topology(&self) -> Topology
pub fn topology(&self) -> Topology
Returns the topology of the different subnets of this PocketIC instance.
Sourcepub fn upload_blob(&self, blob: Vec<u8>, compression: BlobCompression) -> BlobId
pub fn upload_blob(&self, blob: Vec<u8>, compression: BlobCompression) -> BlobId
Upload and store a binary blob to the PocketIC server.
Sourcepub fn set_stable_memory(
&self,
canister_id: Principal,
data: Vec<u8>,
compression: BlobCompression,
)
pub fn set_stable_memory( &self, canister_id: Principal, data: Vec<u8>, compression: BlobCompression, )
Set stable memory of a canister. Optional GZIP compression can be used for reduced data traffic.
Sourcepub fn get_stable_memory(&self, canister_id: Principal) -> Vec<u8> ⓘ
pub fn get_stable_memory(&self, canister_id: Principal) -> Vec<u8> ⓘ
Get stable memory of a canister.
Sourcepub fn list_instances() -> Vec<String>
pub fn list_instances() -> Vec<String>
List all instances and their status.
Sourcepub fn verify_canister_signature(
&self,
msg: Vec<u8>,
sig: Vec<u8>,
pubkey: Vec<u8>,
root_pubkey: Vec<u8>,
) -> Result<(), String>
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.
Sourcepub fn tick(&self)
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.
Sourcepub fn tick_with_configs(&self, configs: TickConfigs)
pub fn tick_with_configs(&self, configs: TickConfigs)
Make the IC produce and progress by one block with custom configs for the round.
Sourcepub fn auto_progress(&self) -> Url
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 requests
for this instance can be made.
Sourcepub fn auto_progress_enabled(&self) -> bool
pub fn auto_progress_enabled(&self) -> bool
Returns whether automatic progress is enabled on the PocketIC instance.
Sourcepub fn stop_progress(&self)
pub fn stop_progress(&self)
Stops automatic progress (see auto_progress) on the IC.
Sourcepub fn url(&self) -> Option<Url>
pub fn url(&self) -> Option<Url>
Returns the URL at which /api requests
for this instance can be made if the HTTP
gateway has been started.
Sourcepub fn make_live(&mut self, listen_at: Option<u16>) -> Url
pub fn make_live(&mut self, listen_at: Option<u16>) -> Url
Creates an HTTP gateway for this PocketIC instance binding to 127.0.0.1
and an optionally specified port (defaults to choosing an arbitrary unassigned port);
listening on localhost;
and configures the PocketIC instance to make progress automatically, i.e.,
periodically update the time of the PocketIC instance to the real time
and process messages on the PocketIC instance.
Returns the URL at which /api requests
for this instance can be made.
Sourcepub fn make_live_with_params(
&mut self,
ip_addr: Option<IpAddr>,
listen_at: Option<u16>,
domains: Option<Vec<String>>,
https_config: Option<HttpsConfig>,
) -> Url
pub fn make_live_with_params( &mut self, ip_addr: Option<IpAddr>, listen_at: Option<u16>, domains: Option<Vec<String>>, https_config: Option<HttpsConfig>, ) -> Url
Creates an HTTP gateway for this PocketIC instance binding
to an optionally specified IP address (defaults to 127.0.0.1)
and port (defaults to choosing an arbitrary unassigned port);
listening on 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 process messages on the PocketIC instance.
Returns the URL at which /api requests
for this instance can be made.
Sourcepub fn stop_live(&mut self)
pub fn stop_live(&mut self)
Stops auto progress (automatic time updates and round executions) and the HTTP gateway for this IC instance.
Sourcepub fn root_key(&self) -> Option<Vec<u8>>
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.
Sourcepub fn set_certified_time(&self, time: Time)
pub fn set_certified_time(&self, time: Time)
Set the current certified time of the IC, on all subnets.
Sourcepub fn advance_time(&self, duration: Duration)
pub fn advance_time(&self, duration: Duration)
Advance the time on the IC on all subnets by some nanoseconds.
Sourcepub fn get_controllers(&self, canister_id: Principal) -> Vec<Principal>
pub fn get_controllers(&self, canister_id: Principal) -> Vec<Principal>
Get the controllers of a canister. Panics if the canister does not exist.
Sourcepub fn cycle_balance(&self, canister_id: Principal) -> u128
pub fn cycle_balance(&self, canister_id: Principal) -> u128
Get the current cycles balance of a canister.
Sourcepub fn add_cycles(&self, canister_id: Principal, amount: u128) -> u128
pub fn add_cycles(&self, canister_id: Principal, amount: u128) -> u128
Add cycles to a canister. Returns the new balance.
Sourcepub fn submit_call(
&self,
canister_id: Principal,
sender: Principal,
method: &str,
payload: Vec<u8>,
) -> Result<RawMessageId, RejectResponse>
pub fn submit_call( &self, canister_id: Principal, sender: Principal, method: &str, payload: Vec<u8>, ) -> Result<RawMessageId, RejectResponse>
Submit an update call (without executing it immediately).
Sourcepub fn submit_call_with_effective_principal(
&self,
canister_id: Principal,
effective_principal: RawEffectivePrincipal,
sender: Principal,
method: &str,
payload: Vec<u8>,
) -> Result<RawMessageId, RejectResponse>
pub fn submit_call_with_effective_principal( &self, canister_id: Principal, effective_principal: RawEffectivePrincipal, sender: Principal, method: &str, payload: Vec<u8>, ) -> Result<RawMessageId, RejectResponse>
Submit an update call with a provided effective principal (without executing it immediately).
Sourcepub fn submit_call_with_effective_principal_and_sender_info(
&self,
canister_id: Principal,
effective_principal: RawEffectivePrincipal,
sender: Principal,
method: &str,
payload: Vec<u8>,
sender_info: RawSenderInfo,
) -> Result<RawMessageId, RejectResponse>
pub fn submit_call_with_effective_principal_and_sender_info( &self, canister_id: Principal, effective_principal: RawEffectivePrincipal, sender: Principal, method: &str, payload: Vec<u8>, sender_info: RawSenderInfo, ) -> Result<RawMessageId, RejectResponse>
Submit an update call with a provided effective principal and sender info (without executing it immediately).
Sourcepub fn submit_call_with_sender_info(
&self,
canister_id: Principal,
sender: Principal,
method: &str,
payload: Vec<u8>,
sender_info: RawSenderInfo,
) -> Result<RawMessageId, RejectResponse>
pub fn submit_call_with_sender_info( &self, canister_id: Principal, sender: Principal, method: &str, payload: Vec<u8>, sender_info: RawSenderInfo, ) -> Result<RawMessageId, RejectResponse>
Submit an update call with sender info (without executing it immediately).
Sourcepub fn await_call(
&self,
message_id: RawMessageId,
) -> Result<Vec<u8>, RejectResponse>
pub fn await_call( &self, message_id: RawMessageId, ) -> Result<Vec<u8>, RejectResponse>
Await an update call submitted previously by submit_call or submit_call_with_effective_principal.
Sourcepub fn ingress_status(
&self,
message_id: RawMessageId,
) -> Option<Result<Vec<u8>, RejectResponse>>
pub fn ingress_status( &self, message_id: RawMessageId, ) -> Option<Result<Vec<u8>, RejectResponse>>
Fetch the status of an update call submitted previously by submit_call or submit_call_with_effective_principal.
Note that the status of the update call can only change if the PocketIC instance is in live mode
or a round has been executed due to a separate PocketIC library call, e.g., PocketIc::tick().
Sourcepub fn ingress_status_as(
&self,
message_id: RawMessageId,
caller: Principal,
) -> IngressStatusResult
pub fn ingress_status_as( &self, message_id: RawMessageId, caller: Principal, ) -> IngressStatusResult
Fetch the status of an update call submitted previously by submit_call or submit_call_with_effective_principal.
Note that the status of the update call can only change if the PocketIC instance is in live mode
or a round has been executed due to a separate PocketIC library call, e.g., PocketIc::tick().
If the status of the update call is known, but the update call was submitted by a different caller, then an error is returned.
Sourcepub fn await_call_no_ticks(
&self,
message_id: RawMessageId,
) -> Result<Vec<u8>, RejectResponse>
pub fn await_call_no_ticks( &self, message_id: RawMessageId, ) -> Result<Vec<u8>, RejectResponse>
Await an update call submitted previously by submit_call or submit_call_with_effective_principal.
Note that the status of the update call can only change if the PocketIC instance is in live mode
or a round has been executed due to a separate PocketIC library call, e.g., PocketIc::tick().
Sourcepub fn update_call(
&self,
canister_id: Principal,
sender: Principal,
method: &str,
payload: Vec<u8>,
) -> Result<Vec<u8>, RejectResponse>
pub fn update_call( &self, canister_id: Principal, sender: Principal, method: &str, payload: Vec<u8>, ) -> Result<Vec<u8>, RejectResponse>
Execute an update call on a canister.
Sourcepub fn query_call(
&self,
canister_id: Principal,
sender: Principal,
method: &str,
payload: Vec<u8>,
) -> Result<Vec<u8>, RejectResponse>
pub fn query_call( &self, canister_id: Principal, sender: Principal, method: &str, payload: Vec<u8>, ) -> Result<Vec<u8>, RejectResponse>
Execute a query call on a canister.
Sourcepub fn fetch_canister_logs(
&self,
canister_id: Principal,
sender: Principal,
) -> Result<Vec<CanisterLogRecord>, RejectResponse>
pub fn fetch_canister_logs( &self, canister_id: Principal, sender: Principal, ) -> Result<Vec<CanisterLogRecord>, RejectResponse>
Fetch canister logs via a query call to the management canister.
Sourcepub fn canister_status(
&self,
canister_id: Principal,
sender: Option<Principal>,
) -> Result<CanisterStatusResult, RejectResponse>
pub fn canister_status( &self, canister_id: Principal, sender: Option<Principal>, ) -> Result<CanisterStatusResult, RejectResponse>
Request a canister’s status.
Sourcepub fn create_canister(&self) -> Principal
pub fn create_canister(&self) -> Principal
Create a canister with default settings as the anonymous principal. The canister is created with 100T cycles.
Sourcepub fn create_canister_with_settings(
&self,
sender: Option<Principal>,
settings: Option<CanisterSettings>,
) -> Principal
pub fn create_canister_with_settings( &self, sender: Option<Principal>, settings: Option<CanisterSettings>, ) -> Principal
Create a canister with optional custom settings and a sender. The canister is created with 100T cycles.
Sourcepub fn create_canister_with_id(
&self,
sender: Option<Principal>,
settings: Option<CanisterSettings>,
canister_id: Principal,
) -> Result<Principal, String>
pub fn create_canister_with_id( &self, sender: Option<Principal>, settings: Option<CanisterSettings>, canister_id: Principal, ) -> Result<Principal, String>
Creates a canister with a specific canister ID and optional custom settings. The canister is created with 100T cycles. 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).
Sourcepub fn create_canister_on_subnet(
&self,
sender: Option<Principal>,
settings: Option<CanisterSettings>,
subnet_id: Principal,
) -> Principal
pub fn create_canister_on_subnet( &self, sender: Option<Principal>, settings: Option<CanisterSettings>, subnet_id: Principal, ) -> Principal
Create a canister on a specific subnet with optional custom settings. The canister is created with 100T cycles.
Sourcepub fn create_canister_with_params(
&self,
sender: Option<Principal>,
params: CreateCanisterParams,
) -> Result<Principal, String>
pub fn create_canister_with_params( &self, sender: Option<Principal>, params: CreateCanisterParams, ) -> Result<Principal, String>
Create a canister with optional cycles, settings, and placement.
The placement specifies either a target subnet or a specific canister ID.
Defaults to 100T cycles if params.cycles is None.
Returns an error if the specified canister ID is already in use.
Sourcepub fn upload_chunk(
&self,
canister_id: Principal,
sender: Option<Principal>,
chunk: Vec<u8>,
) -> Result<Vec<u8>, RejectResponse>
pub fn upload_chunk( &self, canister_id: Principal, sender: Option<Principal>, chunk: Vec<u8>, ) -> Result<Vec<u8>, RejectResponse>
Upload a WASM chunk to the WASM chunk store of a canister. Returns the WASM chunk hash.
Sourcepub fn stored_chunks(
&self,
canister_id: Principal,
sender: Option<Principal>,
) -> Result<Vec<Vec<u8>>, RejectResponse>
pub fn stored_chunks( &self, canister_id: Principal, sender: Option<Principal>, ) -> Result<Vec<Vec<u8>>, RejectResponse>
List WASM chunk hashes in the WASM chunk store of a canister.
Sourcepub fn clear_chunk_store(
&self,
canister_id: Principal,
sender: Option<Principal>,
) -> Result<(), RejectResponse>
pub fn clear_chunk_store( &self, canister_id: Principal, sender: Option<Principal>, ) -> Result<(), RejectResponse>
Clear the WASM chunk store of a canister.
Sourcepub fn install_chunked_canister(
&self,
canister_id: Principal,
sender: Option<Principal>,
mode: CanisterInstallMode,
store_canister_id: Principal,
chunk_hashes_list: Vec<Vec<u8>>,
wasm_module_hash: Vec<u8>,
arg: Vec<u8>,
) -> Result<(), RejectResponse>
pub fn install_chunked_canister( &self, canister_id: Principal, sender: Option<Principal>, mode: CanisterInstallMode, store_canister_id: Principal, chunk_hashes_list: Vec<Vec<u8>>, wasm_module_hash: Vec<u8>, arg: Vec<u8>, ) -> Result<(), RejectResponse>
Install a WASM module assembled from chunks on an existing canister.
Sourcepub fn install_canister(
&self,
canister_id: Principal,
wasm_module: Vec<u8>,
arg: Vec<u8>,
sender: Option<Principal>,
)
pub fn install_canister( &self, canister_id: Principal, wasm_module: Vec<u8>, arg: Vec<u8>, sender: Option<Principal>, )
Install a WASM module on an existing canister.
Sourcepub fn upgrade_canister(
&self,
canister_id: Principal,
wasm_module: Vec<u8>,
arg: Vec<u8>,
sender: Option<Principal>,
) -> Result<(), RejectResponse>
pub fn upgrade_canister( &self, canister_id: Principal, wasm_module: Vec<u8>, arg: Vec<u8>, sender: Option<Principal>, ) -> Result<(), RejectResponse>
Upgrade a canister with a new WASM module.
Sourcepub fn upgrade_eop_canister(
&self,
canister_id: Principal,
wasm_module: Vec<u8>,
arg: Vec<u8>,
sender: Option<Principal>,
) -> Result<(), RejectResponse>
pub fn upgrade_eop_canister( &self, canister_id: Principal, wasm_module: Vec<u8>, arg: Vec<u8>, sender: Option<Principal>, ) -> Result<(), RejectResponse>
Upgrade a Motoko EOP canister with a new WASM module.
Sourcepub fn reinstall_canister(
&self,
canister_id: Principal,
wasm_module: Vec<u8>,
arg: Vec<u8>,
sender: Option<Principal>,
) -> Result<(), RejectResponse>
pub fn reinstall_canister( &self, canister_id: Principal, wasm_module: Vec<u8>, arg: Vec<u8>, sender: Option<Principal>, ) -> Result<(), RejectResponse>
Reinstall a canister WASM module.
Sourcepub fn uninstall_canister(
&self,
canister_id: Principal,
sender: Option<Principal>,
) -> Result<(), RejectResponse>
pub fn uninstall_canister( &self, canister_id: Principal, sender: Option<Principal>, ) -> Result<(), RejectResponse>
Uninstall a canister.
Sourcepub fn take_canister_snapshot(
&self,
canister_id: Principal,
sender: Option<Principal>,
replace_snapshot: Option<Vec<u8>>,
) -> Result<Snapshot, RejectResponse>
pub fn take_canister_snapshot( &self, canister_id: Principal, sender: Option<Principal>, replace_snapshot: Option<Vec<u8>>, ) -> Result<Snapshot, RejectResponse>
Take canister snapshot.
Sourcepub fn load_canister_snapshot(
&self,
canister_id: Principal,
sender: Option<Principal>,
snapshot_id: Vec<u8>,
) -> Result<(), RejectResponse>
pub fn load_canister_snapshot( &self, canister_id: Principal, sender: Option<Principal>, snapshot_id: Vec<u8>, ) -> Result<(), RejectResponse>
Load canister snapshot.
Sourcepub fn list_canister_snapshots(
&self,
canister_id: Principal,
sender: Option<Principal>,
) -> Result<Vec<Snapshot>, RejectResponse>
pub fn list_canister_snapshots( &self, canister_id: Principal, sender: Option<Principal>, ) -> Result<Vec<Snapshot>, RejectResponse>
List canister snapshots.
Sourcepub fn delete_canister_snapshot(
&self,
canister_id: Principal,
sender: Option<Principal>,
snapshot_id: Vec<u8>,
) -> Result<(), RejectResponse>
pub fn delete_canister_snapshot( &self, canister_id: Principal, sender: Option<Principal>, snapshot_id: Vec<u8>, ) -> Result<(), RejectResponse>
Delete canister snapshot.
Sourcepub fn update_canister_settings(
&self,
canister_id: Principal,
sender: Option<Principal>,
settings: CanisterSettings,
) -> Result<(), RejectResponse>
pub fn update_canister_settings( &self, canister_id: Principal, sender: Option<Principal>, settings: CanisterSettings, ) -> Result<(), RejectResponse>
Update canister settings.
Sourcepub fn set_controllers(
&self,
canister_id: Principal,
sender: Option<Principal>,
new_controllers: Vec<Principal>,
) -> Result<(), RejectResponse>
pub fn set_controllers( &self, canister_id: Principal, sender: Option<Principal>, new_controllers: Vec<Principal>, ) -> Result<(), RejectResponse>
Set canister’s controllers.
Sourcepub fn start_canister(
&self,
canister_id: Principal,
sender: Option<Principal>,
) -> Result<(), RejectResponse>
pub fn start_canister( &self, canister_id: Principal, sender: Option<Principal>, ) -> Result<(), RejectResponse>
Start a canister.
Sourcepub fn stop_canister(
&self,
canister_id: Principal,
sender: Option<Principal>,
) -> Result<(), RejectResponse>
pub fn stop_canister( &self, canister_id: Principal, sender: Option<Principal>, ) -> Result<(), RejectResponse>
Stop a canister.
Sourcepub fn delete_canister(
&self,
canister_id: Principal,
sender: Option<Principal>,
) -> Result<(), RejectResponse>
pub fn delete_canister( &self, canister_id: Principal, sender: Option<Principal>, ) -> Result<(), RejectResponse>
Delete a canister.
Sourcepub fn canister_exists(&self, canister_id: Principal) -> bool
pub fn canister_exists(&self, canister_id: Principal) -> bool
Checks whether the provided canister exists.
Sourcepub fn delete_subnet(&self, subnet_id: Principal)
pub fn delete_subnet(&self, subnet_id: Principal)
Deletes a subnet. Panics if the subnet does not exist or is a named subnet.
Sourcepub fn get_subnet(&self, canister_id: Principal) -> Option<Principal>
pub fn get_subnet(&self, canister_id: Principal) -> Option<Principal>
Returns the subnet ID of the canister if the canister exists.
Sourcepub fn get_subnet_metrics(&self, subnet_id: Principal) -> Option<SubnetMetrics>
pub fn get_subnet_metrics(&self, subnet_id: Principal) -> Option<SubnetMetrics>
Returns subnet metrics for a given subnet.
pub fn update_call_with_effective_principal( &self, canister_id: Principal, effective_principal: RawEffectivePrincipal, sender: Principal, method: &str, payload: Vec<u8>, ) -> Result<Vec<u8>, RejectResponse>
Sourcepub fn update_call_with_effective_principal_and_sender_info(
&self,
canister_id: Principal,
effective_principal: RawEffectivePrincipal,
sender: Principal,
method: &str,
payload: Vec<u8>,
sender_info: RawSenderInfo,
) -> Result<Vec<u8>, RejectResponse>
pub fn update_call_with_effective_principal_and_sender_info( &self, canister_id: Principal, effective_principal: RawEffectivePrincipal, sender: Principal, method: &str, payload: Vec<u8>, sender_info: RawSenderInfo, ) -> Result<Vec<u8>, RejectResponse>
Execute an update call with a provided effective principal and sender info on a canister.
Sourcepub fn update_call_with_sender_info(
&self,
canister_id: Principal,
sender: Principal,
method: &str,
payload: Vec<u8>,
sender_info: RawSenderInfo,
) -> Result<Vec<u8>, RejectResponse>
pub fn update_call_with_sender_info( &self, canister_id: Principal, sender: Principal, method: &str, payload: Vec<u8>, sender_info: RawSenderInfo, ) -> Result<Vec<u8>, RejectResponse>
Execute an update call with sender info on a canister.
Sourcepub fn query_call_with_effective_principal(
&self,
canister_id: Principal,
effective_principal: RawEffectivePrincipal,
sender: Principal,
method: &str,
payload: Vec<u8>,
) -> Result<Vec<u8>, RejectResponse>
pub fn query_call_with_effective_principal( &self, canister_id: Principal, effective_principal: RawEffectivePrincipal, sender: Principal, method: &str, payload: Vec<u8>, ) -> Result<Vec<u8>, RejectResponse>
Execute a query call on a canister explicitly specifying an effective principal to route the request: this API is useful for making generic query calls (including management canister query calls) without using dedicated functions from this library (e.g., making generic query calls in dfx to a PocketIC instance).
Sourcepub fn query_call_with_effective_principal_and_sender_info(
&self,
canister_id: Principal,
effective_principal: RawEffectivePrincipal,
sender: Principal,
method: &str,
payload: Vec<u8>,
sender_info: RawSenderInfo,
) -> Result<Vec<u8>, RejectResponse>
pub fn query_call_with_effective_principal_and_sender_info( &self, canister_id: Principal, effective_principal: RawEffectivePrincipal, sender: Principal, method: &str, payload: Vec<u8>, sender_info: RawSenderInfo, ) -> Result<Vec<u8>, RejectResponse>
Execute a query call with a provided effective principal and sender info on a canister.
Sourcepub fn query_call_with_sender_info(
&self,
canister_id: Principal,
sender: Principal,
method: &str,
payload: Vec<u8>,
sender_info: RawSenderInfo,
) -> Result<Vec<u8>, RejectResponse>
pub fn query_call_with_sender_info( &self, canister_id: Principal, sender: Principal, method: &str, payload: Vec<u8>, sender_info: RawSenderInfo, ) -> Result<Vec<u8>, RejectResponse>
Execute a query call with sender info on a canister.
Sourcepub fn get_canister_http(&self) -> Vec<CanisterHttpRequest>
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.
Sourcepub fn mock_canister_http_response(
&self,
mock_canister_http_response: MockCanisterHttpResponse,
)
pub fn mock_canister_http_response( &self, mock_canister_http_response: MockCanisterHttpResponse, )
Mock a response to a pending canister HTTP outcall.
Sourcepub fn canister_snapshot_download(
&self,
canister_id: Principal,
sender: Principal,
snapshot_id: Vec<u8>,
snapshot_dir: PathBuf,
)
pub fn canister_snapshot_download( &self, canister_id: Principal, sender: Principal, snapshot_id: Vec<u8>, snapshot_dir: PathBuf, )
Download a canister snapshot to a given snapshot directory. The sender must be a controller of the canister. The snapshot directory must be empty if it exists.
Sourcepub fn canister_snapshot_upload(
&self,
canister_id: Principal,
sender: Principal,
replace_snapshot: Option<Vec<u8>>,
snapshot_dir: PathBuf,
) -> Vec<u8> ⓘ
pub fn canister_snapshot_upload( &self, canister_id: Principal, sender: Principal, replace_snapshot: Option<Vec<u8>>, snapshot_dir: PathBuf, ) -> Vec<u8> ⓘ
Upload a canister snapshot from a given snapshot directory. The sender must be a controller of the canister. Returns the snapshot ID of the uploaded snapshot.
Trait Implementations§
Source§impl CandidCallExt for PocketIc
impl CandidCallExt for PocketIc
Source§fn update_candid<T, A>(
&self,
canister_id: Principal,
method: &str,
args: A,
) -> Result<T, CandidCallError>
fn update_candid<T, A>( &self, canister_id: Principal, method: &str, args: A, ) -> Result<T, CandidCallError>
Generic update call helper (serializes args + decodes result).
Source§fn update_candid_or_panic<T, A>(
&self,
canister_id: Principal,
method: &str,
args: A,
) -> T
fn update_candid_or_panic<T, A>( &self, canister_id: Principal, method: &str, args: A, ) -> T
Generic update call helper that panics on rejection or Candid codec failure.
This does not unwrap application-level results. For example,
update_candid_or_panic::<Result<T, E>, _>(...) returns Result<T, E>.
Source§fn update_candid_as<T, A>(
&self,
canister_id: Principal,
caller: Principal,
method: &str,
args: A,
) -> Result<T, CandidCallError>
fn update_candid_as<T, A>( &self, canister_id: Principal, caller: Principal, method: &str, args: A, ) -> Result<T, CandidCallError>
Generic update call helper with an explicit caller principal.
Source§fn update_candid_as_or_panic<T, A>(
&self,
canister_id: Principal,
caller: Principal,
method: &str,
args: A,
) -> T
fn update_candid_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 rejection or Candid codec failure.
This does not unwrap application-level results. For example,
update_candid_as_or_panic::<Result<T, E>, _>(...) returns Result<T, E>.
Source§fn query_candid<T, A>(
&self,
canister_id: Principal,
method: &str,
args: A,
) -> Result<T, CandidCallError>
fn query_candid<T, A>( &self, canister_id: Principal, method: &str, args: A, ) -> Result<T, CandidCallError>
Generic query call helper.
Source§fn query_candid_or_panic<T, A>(
&self,
canister_id: Principal,
method: &str,
args: A,
) -> T
fn query_candid_or_panic<T, A>( &self, canister_id: Principal, method: &str, args: A, ) -> T
Generic query call helper that panics on rejection or Candid codec failure.
This does not unwrap application-level results. For example,
query_candid_or_panic::<Result<T, E>, _>(...) returns Result<T, E>.
Source§fn query_candid_as<T, A>(
&self,
canister_id: Principal,
caller: Principal,
method: &str,
args: A,
) -> Result<T, CandidCallError>
fn query_candid_as<T, A>( &self, canister_id: Principal, caller: Principal, method: &str, args: A, ) -> Result<T, CandidCallError>
Generic query call helper with an explicit caller principal.
Source§fn query_candid_as_or_panic<T, A>(
&self,
canister_id: Principal,
caller: Principal,
method: &str,
args: A,
) -> T
fn query_candid_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 rejection or Candid codec failure.
This does not unwrap application-level results. For example,
query_candid_as_or_panic::<Result<T, E>, _>(...) returns Result<T, E>.
Source§impl CanisterInstallExt for PocketIc
impl CanisterInstallExt for PocketIc
Source§fn create_and_install_with_args(
&self,
wasm: Vec<u8>,
init_bytes: Vec<u8>,
install_cycles: u128,
) -> Principal
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§fn try_create_and_install_with_args(
&self,
wasm: Vec<u8>,
init_bytes: Vec<u8>,
install_cycles: u128,
) -> Result<Principal, CanisterInstallError>
fn try_create_and_install_with_args( &self, wasm: Vec<u8>, init_bytes: Vec<u8>, install_cycles: u128, ) -> Result<Principal, CanisterInstallError>
Install one arbitrary wasm module with caller-provided init bytes.
Source§fn create_and_install(&self, spec: InstallSpec) -> Principal
fn create_and_install(&self, spec: InstallSpec) -> Principal
Install one arbitrary wasm module from a generic install specification.
Source§fn try_create_and_install(
&self,
spec: InstallSpec,
) -> Result<Principal, CanisterInstallError>
fn try_create_and_install( &self, spec: InstallSpec, ) -> Result<Principal, CanisterInstallError>
Install one arbitrary wasm module from a generic install specification.
Source§fn create_and_install_many<I>(&self, specs: I) -> Vec<Principal>where
I: IntoIterator<Item = InstallSpec>,
fn create_and_install_many<I>(&self, specs: I) -> Vec<Principal>where
I: IntoIterator<Item = InstallSpec>,
Sequentially install multiple arbitrary wasm modules into this PocketIC instance.
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 CanisterInstallError::canister_id(), and later
installs are not attempted.
Source§fn try_create_and_install_many<I>(
&self,
specs: I,
) -> Result<Vec<Principal>, CanisterInstallError>where
I: IntoIterator<Item = InstallSpec>,
fn try_create_and_install_many<I>(
&self,
specs: I,
) -> Result<Vec<Principal>, CanisterInstallError>where
I: IntoIterator<Item = InstallSpec>,
Sequentially install multiple arbitrary wasm modules into this PocketIC instance.
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 CanisterInstallError::canister_id(), and later
installs are not attempted.
Source§fn wait_out_install_code_rate_limit(&self, cooldown: Duration)
fn wait_out_install_code_rate_limit(&self, cooldown: Duration)
Wait out the PocketIC install_code cooldown window inside the same instance.
Source§fn retry_install_code<T, F>(
&self,
policy: RetryPolicy,
op: F,
) -> Result<T, String>
fn retry_install_code<T, F>( &self, policy: RetryPolicy, op: F, ) -> Result<T, String>
Source§impl PocketIcDiagnosticsExt for PocketIc
impl PocketIcDiagnosticsExt for PocketIc
Source§fn dump_canister_debug(&self, canister_id: Principal, context: &str)
fn dump_canister_debug(&self, canister_id: Principal, context: &str)
Dump basic PocketIC status and log context for one canister.