ic_testkit/pic/
standalone.rs1use candid::Principal;
2use pocket_ic::PocketIc;
3
4use super::{CanisterInstallExt, InstallSpec, StandaloneCanisterInstallError};
5
6pub struct StandaloneCanisterFixture {
11 pocket_ic: PocketIc,
12 canister_id: Principal,
13}
14
15impl StandaloneCanisterFixture {
16 #[must_use]
22 pub fn install(pocket_ic: PocketIc, spec: InstallSpec) -> Self {
23 Self::try_install(pocket_ic, spec)
24 .unwrap_or_else(|err| panic!("failed to install standalone canister fixture: {err}"))
25 }
26
27 pub fn try_install(
32 pocket_ic: PocketIc,
33 spec: InstallSpec,
34 ) -> Result<Self, StandaloneCanisterInstallError> {
35 let canister_id = match pocket_ic.try_create_and_install(spec) {
36 Ok(canister_id) => canister_id,
37 Err(error) => return Err(StandaloneCanisterInstallError::new(pocket_ic, error)),
38 };
39
40 Ok(Self {
41 pocket_ic,
42 canister_id,
43 })
44 }
45
46 #[must_use]
48 pub const fn pocket_ic(&self) -> &PocketIc {
49 &self.pocket_ic
50 }
51
52 #[must_use]
54 pub const fn canister_id(&self) -> Principal {
55 self.canister_id
56 }
57
58 #[must_use]
60 pub fn into_parts(self) -> (PocketIc, Principal) {
61 (self.pocket_ic, self.canister_id)
62 }
63}