ic_test_state_machine_client/
management_canister.rs

1// `ic-cdk` use this crate as a dependency in its tests.
2// To break the circular dependency, we define the management canister types directly
3// instead of using them from `ic-cdk`.
4// There is a plan to move management canister types out of `ic-cdk`.
5// Once that happens, we can use the management canister types in a consistent way.
6
7use candid::{CandidType, Nat, Principal};
8use serde::{Deserialize, Serialize};
9
10pub(crate) type CanisterId = Principal;
11
12#[derive(
13    CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Default,
14)]
15pub struct CanisterSettings {
16    /// A list of principals. Must be between 0 and 10 in size.
17    pub controllers: Option<Vec<Principal>>,
18    /// Must be a number between 0 and 100, inclusively.
19    pub compute_allocation: Option<Nat>,
20    /// Must be a number between 0 and 2^48^ (i.e 256TB), inclusively.
21    pub memory_allocation: Option<Nat>,
22    /// Must be a number between 0 and 2^64^-1, inclusively, and indicates a length of time in seconds.
23    pub freezing_threshold: Option<Nat>,
24}
25
26/// Argument type of [create_canister](super::create_canister).
27#[derive(
28    CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Default,
29)]
30pub(crate) struct CreateCanisterArgument {
31    /// See [CanisterSettings].
32    pub settings: Option<CanisterSettings>,
33}
34
35#[derive(
36    CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy,
37)]
38// #[serde(rename_all = "lowercase")]
39pub(crate) enum CanisterInstallMode {
40    /// A fresh install of a new canister.
41    #[serde(rename = "install")]
42    Install,
43    /// Reinstalling a canister that was already installed.
44    #[serde(rename = "reinstall")]
45    Reinstall,
46    /// Upgrade an existing canister.
47    #[serde(rename = "upgrade")]
48    Upgrade,
49}
50
51pub(crate) type WasmModule = Vec<u8>;
52
53#[derive(
54    CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone,
55)]
56pub(crate) struct InstallCodeArgument {
57    /// See [CanisterInstallMode].
58    pub mode: CanisterInstallMode,
59    /// Principle of the canister.
60    pub canister_id: CanisterId,
61    /// Code to be installed.
62    pub wasm_module: WasmModule,
63    /// The argument to be passed to `canister_init` or `canister_post_upgrade`.
64    pub arg: Vec<u8>,
65}
66
67/// A wrapper of canister id.
68#[derive(
69    CandidType, Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy,
70)]
71pub(crate) struct CanisterIdRecord {
72    /// Principle of the canister.
73    pub canister_id: CanisterId,
74}