Skip to content

Commit

Permalink
Merge branch 'main' into bindgen_next
Browse files Browse the repository at this point in the history
  • Loading branch information
lwshang committed Sep 18, 2024
2 parents 9ad8dfa + 19bfaf3 commit e78726a
Show file tree
Hide file tree
Showing 27 changed files with 554 additions and 66 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release-candid-extractor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
Expand Down
100 changes: 67 additions & 33 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ opt-level = 'z'

[workspace.dependencies]
ic0 = { path = "src/ic0", version = "0.23.0" }
ic-cdk = { path = "src/ic-cdk", version = "0.15.0" }
ic-cdk-timers = { path = "src/ic-cdk-timers", version = "0.9.0" }
ic-cdk = { path = "src/ic-cdk", version = "0.16.0" }
ic-cdk-timers = { path = "src/ic-cdk-timers", version = "0.10.0" }

candid = "0.10.9"
candid_parser = "0.2.0-beta.3"
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ This repo provides libraries and tools to facilitate developing canisters in Rus
- [`ic0`](src/ic0):
Internet Computer System API binding.
- [`ic-cdk`](src/ic-cdk):
Internet Computer Canister Development Kit
Internet Computer Canister Development Kit.
- [`ic-cdk-bindgen`](src/ic-cdk-bindgen):
Generate Rust bindings from Candid to make inter-canister calls.
- [`ic-cdk-macros`](src/ic-cdk-macros):
Expand All @@ -53,8 +53,7 @@ crate-type = ["cdylib"]

[dependencies]
ic-cdk = "0.15"
# Only necessary if you want to define Candid data types
candid = "0.10"
candid = "0.10" # required if you want to define Candid data types
```

Then in Rust source code:
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ path = "canisters/chunk.rs"

[dev-dependencies]
hex.workspace = true
pocket-ic = "3"
pocket-ic = "4"
68 changes: 68 additions & 0 deletions e2e-tests/canisters/management_caller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,72 @@ mod provisional {
}
}

mod snapshot {
use super::*;
use ic_cdk::api::management_canister::main::*;

#[update]
async fn execute_snapshot_methods() {
let arg = CreateCanisterArgument::default();
let canister_id = create_canister(arg, 2_000_000_000_000u128)
.await
.unwrap()
.0
.canister_id;

// Cannot take a snapshot of a canister that is empty.
// So we install a minimal wasm module.
let arg = InstallCodeArgument {
mode: CanisterInstallMode::Install,
canister_id,
// A minimal valid wasm module
// wat2wasm "(module)"
wasm_module: b"\x00asm\x01\x00\x00\x00".to_vec(),
arg: vec![],
};
install_code(arg).await.unwrap();

let arg = TakeCanisterSnapshotArgs {
canister_id,
replace_snapshot: None,
};
let snapshot = take_canister_snapshot(arg).await.unwrap().0;

let arg = LoadCanisterSnapshotArgs {
canister_id,
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, snapshot.id);

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

let arg = CanisterInfoRequest {
canister_id,
num_requested_changes: Some(1),
};
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");
}
}
}

fn main() {}
Loading

0 comments on commit e78726a

Please # to comment.