From ac210ee3acf63f7c2695c26f1c6a44b41c866307 Mon Sep 17 00:00:00 2001 From: Martin Raszyk Date: Mon, 8 Jul 2024 07:51:21 +0000 Subject: [PATCH] fix(PocketIC): executing query call on new PocketIC instance crashed PocketIC server --- packages/pocket-ic/src/nonblocking.rs | 4 ---- packages/pocket-ic/tests/tests.rs | 16 ++++++++++++++++ rs/pocket_ic_server/CHANGELOG.md | 3 +++ rs/pocket_ic_server/src/pocket_ic.rs | 5 +++++ 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/packages/pocket-ic/src/nonblocking.rs b/packages/pocket-ic/src/nonblocking.rs index 20c1d18048f..50e37da8055 100644 --- a/packages/pocket-ic/src/nonblocking.rs +++ b/packages/pocket-ic/src/nonblocking.rs @@ -299,8 +299,6 @@ impl PocketIc { /// for this instance can be made. #[instrument(skip(self), fields(instance_id=self.instance_id))] pub async fn make_live(&mut self, listen_at: Option) -> Url { - // Execute a tick to make sure all subnets have a certified state. - self.tick().await; self.auto_progress().await; self.start_http_gateway(listen_at, None, None).await } @@ -319,8 +317,6 @@ impl PocketIc { domain: String, https_config: HttpsConfig, ) -> Url { - // Execute a tick to make sure all subnets have a certified state. - self.tick().await; self.auto_progress().await; self.start_http_gateway(listen_at, Some(domain), Some(https_config)) .await diff --git a/packages/pocket-ic/tests/tests.rs b/packages/pocket-ic/tests/tests.rs index e69554be290..a15807f6ad8 100644 --- a/packages/pocket-ic/tests/tests.rs +++ b/packages/pocket-ic/tests/tests.rs @@ -1027,3 +1027,19 @@ fn test_xnet_call_and_create_canister_with_specified_id() { } } } + +#[test] +fn test_query_call_on_new_pocket_ic() { + let pic = PocketIc::new(); + + let topology = pic.topology(); + let app_subnet = topology.get_app_subnets()[0]; + let canister_id = Principal::from_slice( + &topology.0.get(&app_subnet).unwrap().canister_ranges[0] + .start + .canister_id, + ); + + pic.query_call(canister_id, Principal::anonymous(), "foo", vec![]) + .unwrap_err(); +} diff --git a/rs/pocket_ic_server/CHANGELOG.md b/rs/pocket_ic_server/CHANGELOG.md index 011b56cf6e8..6833456e4a8 100644 --- a/rs/pocket_ic_server/CHANGELOG.md +++ b/rs/pocket_ic_server/CHANGELOG.md @@ -19,6 +19,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - New CLI option `--ready-file` to specify a file which is created by the PocketIC server once it is ready to accept HTTP connections. - A new endpoint `/instances//_/dashboard` serving a PocketIC dashboard. +### Fixed +- Executing a query call on a new PocketIC instance crashed the PocketIC server. + ## 4.0.0 - 2024-04-30 ### Added diff --git a/rs/pocket_ic_server/src/pocket_ic.rs b/rs/pocket_ic_server/src/pocket_ic.rs index 880d91b7c2b..f96ddd54578 100644 --- a/rs/pocket_ic_server/src/pocket_ic.rs +++ b/rs/pocket_ic_server/src/pocket_ic.rs @@ -286,6 +286,11 @@ impl PocketIc { subnet.reload_registry(); } + // We execute a round on every subnet to make sure it has a state to certify. + for subnet in subnets.read().unwrap().values() { + subnet.execute_round(); + } + Self { subnets, routing_table,