use ic_testkit::pocket_ic::{self, PocketIcBuilder, nonblocking::PocketIc};
use ic_wire::Limits;
use std::time::Duration;
pub async fn upgrade_stopped(
pic: &PocketIc,
canister: pocket_ic::CanisterId,
wasm: Vec<u8>,
args: Vec<u8>,
sender: Option<pocket_ic::CanisterId>,
) -> Result<(), pocket_ic::RejectResponse> {
pic.stop_canister(canister, sender).await?;
let result = pic.upgrade_canister(canister, wasm, args, sender).await;
pic.start_canister(canister, sender).await?;
result
}
pub const LIMITS: Limits = Limits {
bytes: 65_536,
allocation: 8 * 1024 * 1024,
nodes: 65_536,
depth: 32,
};
pub async fn instance() -> Result<PocketIc, String> {
let endpoint = std::env::var("IC_TESTKIT_POCKET_IC_URL").map_err(|_| {
"run through scripts/with-pocketic.sh or supply IC_TESTKIT_POCKET_IC_URL".to_owned()
})?;
let url = endpoint
.parse()
.map_err(|_| "invalid PocketIC endpoint".to_owned())?;
tokio::time::timeout(
Duration::from_secs(30),
PocketIcBuilder::new()
.with_application_subnet()
.with_server_url(url)
.with_max_request_time_ms(Some(30_000))
.build_async(),
)
.await
.map_err(|_| {
"PocketIC instance creation timed out; remote creation may have occurred".to_owned()
})
}