Skip to content

Commit

Permalink
canister_info changes can have load_snapshot records
Browse files Browse the repository at this point in the history
  • Loading branch information
lwshang committed Aug 7, 2024
1 parent 755eafe commit 77c7e13
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
25 changes: 18 additions & 7 deletions e2e-tests/canisters/management_caller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ mod snapshot {
use ic_cdk::api::management_canister::main::*;

#[update]
async fn execute_snapshot_methods() -> CanisterInfoResponse {
async fn execute_snapshot_methods() {
let arg = CreateCanisterArgument::default();
let canister_id = create_canister(arg, 2_000_000_000_000u128)
.await
Expand All @@ -138,31 +138,42 @@ mod snapshot {
canister_id,
replace_snapshot: None,
};
let snapshot1 = take_canister_snapshot(arg).await.unwrap().0;
let snapshot = take_canister_snapshot(arg).await.unwrap().0;

let arg = LoadCanisterSnapshotArgs {
canister_id,
snapshot_id: snapshot1.id.clone(),
snapshot_id: snapshot.id.clone(),
sender_canister_version: None,
};
assert!(load_canister_snapshot(arg).await.is_ok());

let canister_id_record = CanisterIdRecord { canister_id };
let snapshots = list_canister_snapshots(canister_id_record).await.unwrap().0;
assert_eq!(snapshots.len(), 1);
assert_eq!(snapshots[0].id, snapshot1.id);
assert_eq!(snapshots[0].id, snapshot.id);

let arg = DeleteCanisterSnapshotArgs {
canister_id,
snapshot_id: snapshot1.id.clone(),
snapshot_id: snapshot.id.clone(),
};
assert!(delete_canister_snapshot(arg).await.is_ok());

let arg = CanisterInfoRequest {
canister_id,
num_requested_changes: None,
num_requested_changes: Some(1),
};
canister_info(arg).await.unwrap().0
let canister_info_response = canister_info(arg).await.unwrap().0;
assert_eq!(canister_info_response.total_num_changes, 3);
assert_eq!(canister_info_response.recent_changes.len(), 1);
if let CanisterChange {
details: CanisterChangeDetails::LoadSnapshot(load_snapshot_record),
..
} = &canister_info_response.recent_changes[0]
{
assert_eq!(load_snapshot_record.snapshot_id, snapshot.id);
} else {
panic!("Expected the most recent change to be LoadSnapshot");
}
}
}

Expand Down
6 changes: 2 additions & 4 deletions e2e-tests/tests/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,10 +563,8 @@ fn test_snapshot() {
let canister_id = pic.create_canister();
pic.add_cycles(canister_id, 300_000_000_000_000_000_000_000_000u128);
pic.install_canister(canister_id, wasm, vec![], None);
let canister_info_response: (CanisterInfoResponse,) =
call_candid(&pic, canister_id, "execute_snapshot_methods", ())
.expect("Error calling execute_snapshot_methods");
println!("{canister_info_response:?}");
let () = call_candid(&pic, canister_id, "execute_snapshot_methods", ())
.expect("Error calling execute_snapshot_methods");
}

#[test]
Expand Down

0 comments on commit 77c7e13

Please sign in to comment.