pub struct PocketIc {
pub instance_id: InstanceId,
/* private fields */
}Expand description
Main entry point for interacting with PocketIC.
Fields§
§instance_id: InstanceIdThe unique ID of this PocketIC instance.
Implementations§
source§impl PocketIc
impl PocketIc
sourcepub fn new() -> Self
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.
sourcepub fn from_config(config: impl Into<ExtendedSubnetConfigSet>) -> Self
pub fn from_config(config: impl Into<ExtendedSubnetConfigSet>) -> Self
Creates a new PocketIC instance with the specified subnet config. The server is started if it’s not already running.
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: CanisterId,
data: Vec<u8>,
compression: BlobCompression
)
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.
sourcepub fn get_stable_memory(&self, canister_id: CanisterId) -> Vec<u8> ⓘ
pub fn get_stable_memory(&self, canister_id: CanisterId) -> 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 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 get_time(&self) -> SystemTime
pub fn get_time(&self) -> SystemTime
Get the current time of the IC.
sourcepub fn set_time(&self, time: SystemTime)
pub fn set_time(&self, time: SystemTime)
Set the current 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 cycle_balance(&self, canister_id: CanisterId) -> u128
pub fn cycle_balance(&self, canister_id: CanisterId) -> u128
Get the current cycles balance of a canister.
sourcepub fn add_cycles(&self, canister_id: CanisterId, amount: u128) -> u128
pub fn add_cycles(&self, canister_id: CanisterId, amount: u128) -> u128
Add cycles to a canister. Returns the new balance.
sourcepub fn update_call(
&self,
canister_id: CanisterId,
sender: Principal,
method: &str,
payload: Vec<u8>
) -> Result<WasmResult, UserError>
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.
sourcepub fn query_call(
&self,
canister_id: CanisterId,
sender: Principal,
method: &str,
payload: Vec<u8>
) -> Result<WasmResult, UserError>
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.
sourcepub fn canister_status(
&self,
canister_id: CanisterId,
sender: Option<Principal>
) -> Result<CanisterStatusResponse, CallError>
pub fn canister_status( &self, canister_id: CanisterId, sender: Option<Principal> ) -> Result<CanisterStatusResponse, CallError>
Request a canister’s status.
sourcepub fn create_canister(&self) -> CanisterId
pub fn create_canister(&self) -> CanisterId
Create a canister with default settings as the anonymous principal.
sourcepub fn create_canister_with_settings(
&self,
sender: Option<Principal>,
settings: Option<CanisterSettings>
) -> CanisterId
pub fn create_canister_with_settings( &self, sender: Option<Principal>, settings: Option<CanisterSettings> ) -> CanisterId
Create a canister with optional custom settings and a sender.
sourcepub fn create_canister_with_id(
&self,
sender: Option<Principal>,
settings: Option<CanisterSettings>,
canister_id: CanisterId
) -> Result<CanisterId, String>
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. Panics if the canister ID is not contained in any of the subnets.
The canister ID must be contained in the Bitcoin, Fiduciary, II, SNS or NNS subnet range, it is not intended to be used on regular app or system subnets, where it can lead to conflicts on which the function panics.
sourcepub fn create_canister_on_subnet(
&self,
sender: Option<Principal>,
settings: Option<CanisterSettings>,
subnet_id: SubnetId
) -> CanisterId
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.
sourcepub fn install_canister(
&self,
canister_id: CanisterId,
wasm_module: Vec<u8>,
arg: Vec<u8>,
sender: Option<Principal>
)
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.
sourcepub fn upgrade_canister(
&self,
canister_id: CanisterId,
wasm_module: Vec<u8>,
arg: Vec<u8>,
sender: Option<Principal>
) -> Result<(), CallError>
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.
sourcepub fn reinstall_canister(
&self,
canister_id: CanisterId,
wasm_module: Vec<u8>,
arg: Vec<u8>,
sender: Option<Principal>
) -> Result<(), CallError>
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.
sourcepub fn set_controllers(
&self,
canister_id: CanisterId,
sender: Option<Principal>,
new_controllers: Vec<Principal>
) -> Result<(), CallError>
pub fn set_controllers( &self, canister_id: CanisterId, sender: Option<Principal>, new_controllers: Vec<Principal> ) -> Result<(), CallError>
Set canister’s controllers.
sourcepub fn start_canister(
&self,
canister_id: CanisterId,
sender: Option<Principal>
) -> Result<(), CallError>
pub fn start_canister( &self, canister_id: CanisterId, sender: Option<Principal> ) -> Result<(), CallError>
Start a canister.
sourcepub fn stop_canister(
&self,
canister_id: CanisterId,
sender: Option<Principal>
) -> Result<(), CallError>
pub fn stop_canister( &self, canister_id: CanisterId, sender: Option<Principal> ) -> Result<(), CallError>
Stop a canister.
sourcepub fn delete_canister(
&self,
canister_id: CanisterId,
sender: Option<Principal>
) -> Result<(), CallError>
pub fn delete_canister( &self, canister_id: CanisterId, sender: Option<Principal> ) -> Result<(), CallError>
Delete a canister.
sourcepub fn canister_exists(&self, canister_id: CanisterId) -> bool
pub fn canister_exists(&self, canister_id: CanisterId) -> bool
Checks whether the provided canister exists.
sourcepub fn get_subnet(&self, canister_id: CanisterId) -> Option<SubnetId>
pub fn get_subnet(&self, canister_id: CanisterId) -> Option<SubnetId>
Returns the subnet ID of the canister if the canister exists.