Struct pocket_ic::PocketIc

source ·
pub struct PocketIc {
    pub instance_id: InstanceId,
    /* private fields */
}
Expand description

Main entry point for interacting with PocketIC.

Fields§

§instance_id: InstanceId

The unique ID of this PocketIC instance.

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 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.

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.

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 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 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 canister_status( &self, canister_id: CanisterId, sender: Option<Principal> ) -> Result<CanisterStatusResponse, 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. 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.

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 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 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.

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

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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