Skip to content

Commit

Permalink
feat(PocketIC): PocketIC certifies time after setting or advancing time
Browse files Browse the repository at this point in the history
  • Loading branch information
mraszyk committed Jan 22, 2025
1 parent 14ba37e commit a5d6f3a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
12 changes: 7 additions & 5 deletions packages/pocket-ic/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}

Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions rs/pocket_ic_server/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<RawMessageId, RejectResponse>`.
- The response types `RawWasmResult` and `UserError` in `RawCanisterResult` are replaced by `Vec<u8>` and `RejectResponse`.
- The endpoint `/instances/<instance_id>/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/<instance_id>/update/execute_ingress_message`:
Expand Down
3 changes: 2 additions & 1 deletion rs/pocket_ic_server/src/pocket_ic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit a5d6f3a

Please sign in to comment.