Skip to content

Commit

Permalink
Merge branch 'dimitris/more-structured-enums' into 'master'
Browse files Browse the repository at this point in the history
chore: Add round trip encoding test for StopCanisterContext

 

See merge request dfinity-lab/public/ic!19206
  • Loading branch information
dsarlis committed May 16, 2024
2 parents ee6addc + 0e1b478 commit 7e3f241
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions rs/types/types/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use crate::time::CoarseTime;
use crate::{user_id_into_protobuf, user_id_try_from_protobuf, Cycles, Funds, NumBytes, UserId};
pub use blob::Blob;
use ic_base_types::{CanisterId, PrincipalId};
#[cfg(test)]
use ic_exhaustive_derive::ExhaustiveSet;
use ic_management_canister_types::CanisterChangeOrigin;
use ic_protobuf::proxy::{try_from_option_field, ProxyDecodeError};
use ic_protobuf::state::canister_state_bits::v1 as pb;
Expand Down Expand Up @@ -100,6 +102,7 @@ pub type StopCanisterCallId = Id<StopCanisterCallIdTag, u64>;
/// Stores info needed for processing and tracking requests to
/// stop canisters.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(test, derive(ExhaustiveSet))]
pub enum StopCanisterContext {
Ingress {
sender: UserId,
Expand Down Expand Up @@ -534,8 +537,10 @@ impl CanisterCallOrTask {
#[cfg(test)]
mod tests {
use super::*;
use crate::exhaustive::ExhaustiveSet;
use crate::{time::expiry_time_from_now, Time};
use assert_matches::assert_matches;
use ic_crypto_test_utils_reproducible_rng::reproducible_rng;
use maplit::btreemap;
use serde_cbor::Value;
use std::{convert::TryFrom, io::Cursor};
Expand Down Expand Up @@ -830,4 +835,14 @@ mod tests {
[1, 2]
);
}

#[test]
fn stop_canister_context_proto_round_trip() {
for initial in StopCanisterContext::exhaustive_set(&mut reproducible_rng()) {
let encoded = pb::StopCanisterContext::from(&initial);
let round_trip = StopCanisterContext::try_from(encoded).unwrap();

assert_eq!(initial, round_trip);
}
}
}

0 comments on commit 7e3f241

Please sign in to comment.