diff --git a/Cargo.lock b/Cargo.lock index 7b488140a29..183a862f09f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -18476,9 +18476,10 @@ dependencies = [ name = "rejoin-test-lib" version = "0.9.0" dependencies = [ + "candid", "canister-test", "chrono", - "dfn_json", + "dfn_candid", "futures", "ic-system-test-driver", "slog", @@ -20173,10 +20174,12 @@ dependencies = [ name = "statesync-test" version = "0.9.0" dependencies = [ + "candid", "canister-test", - "dfn_core", - "dfn_json", - "dfn_macro", + "ic-cdk 0.16.0", + "ic-cdk-macros 0.9.0", + "ic-management-canister-types", + "ic-state-machine-tests", "ic-test-utilities", "ic-types", "lazy_static", diff --git a/rs/rust_canisters/statesync_test/BUILD.bazel b/rs/rust_canisters/statesync_test/BUILD.bazel index eacc8a7e7db..092900b0b58 100644 --- a/rs/rust_canisters/statesync_test/BUILD.bazel +++ b/rs/rust_canisters/statesync_test/BUILD.bazel @@ -6,8 +6,8 @@ package(default_visibility = ["//visibility:public"]) DEPENDENCIES = [ # Keep sorted. - "//rs/rust_canisters/dfn_core", - "//rs/rust_canisters/dfn_json", + "@crate_index//:candid", + "@crate_index//:ic-cdk", "@crate_index//:lazy_static", "@crate_index//:rand", "@crate_index//:rand_pcg", @@ -18,13 +18,15 @@ DEPENDENCIES = [ DEV_DEPENDENCIES = [ # Keep sorted. "//rs/rust_canisters/canister_test", + "//rs/state_machine_tests", "//rs/test_utilities", + "//rs/types/management_canister_types", "//rs/types/types", ] MACRO_DEPENDENCIES = [ # Keep sorted. - "//rs/rust_canisters/dfn_macro", + "@crate_index//:ic-cdk-macros", ] rust_binary( diff --git a/rs/rust_canisters/statesync_test/Cargo.toml b/rs/rust_canisters/statesync_test/Cargo.toml index 948742e013c..820a8bc0422 100644 --- a/rs/rust_canisters/statesync_test/Cargo.toml +++ b/rs/rust_canisters/statesync_test/Cargo.toml @@ -11,9 +11,9 @@ name = "statesync-test-canister" path = "src/main.rs" [dependencies] -dfn_core = { path = "../dfn_core" } -dfn_json = { path = "../dfn_json" } -dfn_macro = { path = "../dfn_macro" } +candid = { workspace = true } +ic-cdk = { workspace = true } +ic-cdk-macros = { workspace = true } lazy_static = { workspace = true } rand = { workspace = true } rand_pcg = "0.3.1" @@ -22,6 +22,8 @@ serde_json = { workspace = true } [dev-dependencies] canister-test = { path = "../../rust_canisters/canister_test" } +ic-management-canister-types = { path = "../../types/management_canister_types" } +ic-state-machine-tests = { path = "../../state_machine_tests" } ic-test-utilities = { path = "../../test_utilities" } ic-types = { path = "../../types/types" } diff --git a/rs/rust_canisters/statesync_test/src/main.rs b/rs/rust_canisters/statesync_test/src/main.rs index 63170f50524..e8d078ff4a8 100644 --- a/rs/rust_canisters/statesync_test/src/main.rs +++ b/rs/rust_canisters/statesync_test/src/main.rs @@ -1,7 +1,7 @@ /// This canister is used in the testcase 5_2. The canister stores a vector of /// variable length, and the number of times the canister update method has /// been called. -use dfn_macro::{query, update}; +use ic_cdk_macros::{query, update}; use lazy_static::lazy_static; use rand::{Rng, SeedableRng}; use rand_pcg::Pcg64Mcg; diff --git a/rs/rust_canisters/statesync_test/test/test.rs b/rs/rust_canisters/statesync_test/test/test.rs index 7e26ae4bfdd..e6afdf8b240 100644 --- a/rs/rust_canisters/statesync_test/test/test.rs +++ b/rs/rust_canisters/statesync_test/test/test.rs @@ -1,51 +1,68 @@ +use candid::{Decode, Encode}; use canister_test::*; +use ic_management_canister_types::CanisterSettingsArgsBuilder; +use ic_state_machine_tests::StateMachine; #[test] fn test_statesync_test_canisters() { - local_test_e(|r| async move { - let proj = Project::new(); + let env = StateMachine::new(); - println!("Start installing statesync test canister"); - let canister = proj - .cargo_bin("statesync-test-canister", &[]) - .install(&r) - .with_memory_allocation(8 * 1024 * 1024 * 1024) // 8GiB - .bytes(Vec::new()) - .await?; - println!("Installed statesync test canister"); + let features = []; + let wasm = Project::cargo_bin_maybe_from_env("statesync-test-canister", &features); + let canister_id = env + .install_canister( + wasm.bytes(), + vec![], + Some( + CanisterSettingsArgsBuilder::new() + .with_memory_allocation(8 * 1024 * 1024 * 1024) + .build(), + ), + ) + .expect("Failed to install canister"); - let mut res: Result = canister - .query_("read_state", dfn_json::json, 0_usize) - .await - .unwrap(); - assert_eq!( - res, - Ok(0), - "Queried first element of state vector, should have been 0, was {:?}", - res - ); + let result = env + .query(canister_id, "read_state", Encode!(&0usize).unwrap()) + .unwrap(); + let res = assert_reply(result); + let val = Decode!(&res, Result).unwrap(); + assert_eq!( + val, + Ok(0), + "Queried first element of state vector, should have been 0, was {:?}", + res + ); - res = canister - .update_("change_state", dfn_json::json, 33_u32) - .await - .unwrap(); - assert_eq!( - res, - Ok(1), - "Changed state for the first time, result should have been 1, was {:?}", - res - ); + let result = env + .execute_ingress(canister_id, "change_state", Encode!(&33u32).unwrap()) + .unwrap(); + let res = assert_reply(result); + let val = Decode!(&res, Result).unwrap(); + assert_eq!( + val, + Ok(1), + "Changed state for the first time, result should have been 1, was {:?}", + res + ); - res = canister - .query_("read_state", dfn_json::json, 0_usize) - .await - .unwrap(); - assert_eq!( - res, - Ok(119), - "Queried 0th element of state vector, should be 20 for seed 33, was {:?}", - res - ); - Ok(()) - }) + let result = env + .query(canister_id, "read_state", Encode!(&0usize).unwrap()) + .unwrap(); + let res = assert_reply(result); + let val = Decode!(&res, Result).unwrap(); + assert_eq!( + val, + Ok(119), + "Queried 0th element of state vector, should be 20 for seed 33, was {:?}", + res + ); +} + +fn assert_reply(res: WasmResult) -> Vec { + match res { + WasmResult::Reply(res) => res, + WasmResult::Reject(_) => { + unreachable!("Unexpected reject, should have been a reply"); + } + } } diff --git a/rs/tests/message_routing/rejoin_test_lib/BUILD.bazel b/rs/tests/message_routing/rejoin_test_lib/BUILD.bazel index 27659fd7ea8..fe8a5768130 100644 --- a/rs/tests/message_routing/rejoin_test_lib/BUILD.bazel +++ b/rs/tests/message_routing/rejoin_test_lib/BUILD.bazel @@ -9,8 +9,9 @@ rust_library( crate_name = "rejoin_test_lib", deps = [ "//rs/rust_canisters/canister_test", - "//rs/rust_canisters/dfn_json", + "//rs/rust_canisters/dfn_candid", "//rs/tests/driver:ic-system-test-driver", + "@crate_index//:candid", "@crate_index//:chrono", "@crate_index//:futures", "@crate_index//:slog", diff --git a/rs/tests/message_routing/rejoin_test_lib/Cargo.toml b/rs/tests/message_routing/rejoin_test_lib/Cargo.toml index 5d8eac8c2ac..3692004d329 100644 --- a/rs/tests/message_routing/rejoin_test_lib/Cargo.toml +++ b/rs/tests/message_routing/rejoin_test_lib/Cargo.toml @@ -7,13 +7,14 @@ description.workspace = true documentation.workspace = true [dependencies] +candid = { workspace = true } canister-test = { path = "../../../rust_canisters/canister_test" } chrono = { workspace = true } futures = { workspace = true } ic-system-test-driver = { path = "../../driver" } slog = { workspace = true } tokio = { workspace = true } -dfn_json = { path = "../../../rust_canisters/dfn_json" } +dfn_candid = { path = "../../../rust_canisters/dfn_candid" } [lib] name = "rejoin_test_lib" diff --git a/rs/tests/message_routing/rejoin_test_lib/rejoin_test_lib.rs b/rs/tests/message_routing/rejoin_test_lib/rejoin_test_lib.rs index 88433e314e7..c7e4ac665b8 100644 --- a/rs/tests/message_routing/rejoin_test_lib/rejoin_test_lib.rs +++ b/rs/tests/message_routing/rejoin_test_lib/rejoin_test_lib.rs @@ -364,14 +364,11 @@ async fn modify_canister_heap( continue; } let seed_for_canister = i + (x - 1) * num_canisters + seed; + let payload = (x as u32, seed_for_canister as u32); // Each call will expand the memory by writing a chunk of 128 MiB. // There are 8 chunks in the canister, so the memory will grow by 1 GiB after 8 calls. - let _res: Result = canister - .update_( - "expand_state", - dfn_json::json, - (x as u32, seed_for_canister as u32), - ) + let _res: Result = canister + .update_("expand_state", dfn_candid::candid, payload) .await .unwrap_or_else(|e| { panic!(