diff --git a/packages/pocket-ic/tests/tests.rs b/packages/pocket-ic/tests/tests.rs index e0c090c8516..439383ce119 100644 --- a/packages/pocket-ic/tests/tests.rs +++ b/packages/pocket-ic/tests/tests.rs @@ -356,20 +356,24 @@ fn test_get_and_set_and_advance_time() { let unix_time_secs = 1630328630; let set_time = SystemTime::UNIX_EPOCH + std::time::Duration::from_secs(unix_time_secs); + pic.set_time(set_time); assert_eq!(pic.get_time(), set_time); + pic.tick(); - assert_eq!(pic.get_time(), set_time); + let current_time = pic.get_time(); + assert_eq!(current_time, set_time + std::time::Duration::from_nanos(1)); pic.advance_time(std::time::Duration::from_secs(420)); assert_eq!( pic.get_time(), - set_time + std::time::Duration::from_secs(420) + current_time + std::time::Duration::from_secs(420), ); + pic.tick(); assert_eq!( pic.get_time(), - set_time + std::time::Duration::from_secs(420) + current_time + std::time::Duration::from_secs(420) + std::time::Duration::from_nanos(1) ); } @@ -413,12 +417,10 @@ fn query_call_after_advance_time() { query_and_check_time(&pic, canister); pic.advance_time(std::time::Duration::from_secs(420)); - pic.tick(); query_and_check_time(&pic, canister); pic.advance_time(std::time::Duration::from_secs(0)); - pic.tick(); query_and_check_time(&pic, canister); } diff --git a/rs/pocket_ic_server/CHANGELOG.md b/rs/pocket_ic_server/CHANGELOG.md index fa0390e3828..b744e89baa5 100644 --- a/rs/pocket_ic_server/CHANGELOG.md +++ b/rs/pocket_ic_server/CHANGELOG.md @@ -22,6 +22,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - The response type `RawSubmitIngressResult` is replaced by `Result`. - The response types `RawWasmResult` and `UserError` in `RawCanisterResult` are replaced by `Vec` and `RejectResponse`. +- The endpoint `/instances//update/set_time` executes a round after setting time so that + a state with that time becomes certified and, e.g., query calls are evaluated on a state with the specified time. ### Removed - The endpoint `/instances//update/execute_ingress_message`: diff --git a/rs/pocket_ic_server/src/pocket_ic.rs b/rs/pocket_ic_server/src/pocket_ic.rs index 29505cc17c3..7ffb1c5353e 100644 --- a/rs/pocket_ic_server/src/pocket_ic.rs +++ b/rs/pocket_ic_server/src/pocket_ic.rs @@ -1178,9 +1178,10 @@ impl Operation for SetTime { ))), std::cmp::Ordering::Equal => OpOut::NoOutput, std::cmp::Ordering::Less => { - // Sets the time on all subnets. + // Sets the time and execute a round to certify that time on all subnets. for subnet in pic.subnets.get_all() { subnet.state_machine.set_time(set_time); + subnet.state_machine.execute_round(); } OpOut::NoOutput }