Skip to content

Commit

Permalink
fix(exhaustive): CON-1248 Extend ExhaustiveSet unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
eichhorl committed Mar 14, 2024
1 parent f9372c7 commit 8385491
Show file tree
Hide file tree
Showing 5 changed files with 314 additions and 115 deletions.
2 changes: 1 addition & 1 deletion rs/types/types/src/consensus/ecdsa_refs.rs
Expand Up @@ -299,6 +299,7 @@ impl TranscriptAttributes for IDkgTranscriptParamsRef {

/// Attributes of `IDkgTranscript`.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Hash)]
#[cfg_attr(test, derive(ExhaustiveSet))]
pub struct IDkgTranscriptAttributes {
receivers: BTreeSet<NodeId>,
algorithm_id: AlgorithmId,
Expand Down Expand Up @@ -649,7 +650,6 @@ impl TryFrom<&pb::UnmaskedTimesMaskedParams> for UnmaskedTimesMaskedParams {

/// ECDSA Quadruple in creation.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(test, derive(ExhaustiveSet))]
pub struct QuadrupleInCreation {
pub kappa_masked_config: Option<RandomTranscriptParams>,
pub kappa_masked: Option<MaskedTranscript>,
Expand Down
5 changes: 5 additions & 0 deletions rs/types/types/src/crypto/canister_threshold_sig/idkg.rs
Expand Up @@ -672,6 +672,7 @@ impl<'de> Deserialize<'de> for InitialIDkgDealings {
/// When the transcript derives from earlier transcripts, these are included
/// in this enum.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Hash)]
#[cfg_attr(test, derive(ExhaustiveSet))]
pub enum IDkgMaskedTranscriptOrigin {
Random,
UnmaskedTimesMasked(IDkgTranscriptId, IDkgTranscriptId),
Expand All @@ -682,6 +683,7 @@ pub enum IDkgMaskedTranscriptOrigin {
/// The earlier transcripts used to derive this transcript are included in this
/// enum.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Hash)]
#[cfg_attr(test, derive(ExhaustiveSet))]
pub enum IDkgUnmaskedTranscriptOrigin {
ReshareMasked(IDkgTranscriptId),
ReshareUnmasked(IDkgTranscriptId),
Expand All @@ -690,6 +692,7 @@ pub enum IDkgUnmaskedTranscriptOrigin {

/// Type and origin of an IDkg transcript.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Hash)]
#[cfg_attr(test, derive(ExhaustiveSet))]
pub enum IDkgTranscriptType {
/// Masked transcripts contain dealings based on Pedersen verifiable secret sharing which
/// perfectly hides the value shared in the dealing. This means that the commitment to the
Expand All @@ -713,6 +716,7 @@ pub enum IDkgTranscriptType {
/// * [`Unmasked`][`IDkgTranscriptType::Unmasked`] if the commitment is not perfectly hiding and
/// may reveal some information about the shared value.
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Hash)]
#[cfg_attr(test, derive(ExhaustiveSet))]
pub struct IDkgTranscript {
pub transcript_id: IDkgTranscriptId,
pub receivers: IDkgReceivers,
Expand Down Expand Up @@ -994,6 +998,7 @@ impl_display_using_debug!(IDkgTranscript);

/// Dealing of an IDkg sharing.
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Hash)]
#[cfg_attr(test, derive(ExhaustiveSet))]
pub struct IDkgDealing {
pub transcript_id: IDkgTranscriptId,
#[serde(with = "serde_bytes")]
Expand Down
5 changes: 5 additions & 0 deletions rs/types/types/src/crypto/threshold_sig/ni_dkg.rs
Expand Up @@ -7,6 +7,8 @@ use crate::NumberOfNodes;
use crate::{Height, PrincipalId, PrincipalIdBlobParseError, RegistryVersion, SubnetId};
use core::fmt;
use ic_crypto_internal_types::sign::threshold_sig::ni_dkg::{CspNiDkgDealing, CspNiDkgTranscript};
#[cfg(test)]
use ic_exhaustive_derive::ExhaustiveSet;
use ic_protobuf::types::v1 as pb;
use ic_protobuf::types::v1::NiDkgId as NiDkgIdProto;
use serde::{Deserialize, Serialize};
Expand All @@ -32,6 +34,7 @@ mod tests;
#[derive(
Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize, EnumIter,
)]
#[cfg_attr(test, derive(ExhaustiveSet))]
pub enum NiDkgTag {
LowThreshold = 1,
HighThreshold = 2,
Expand All @@ -48,6 +51,7 @@ impl From<&NiDkgTag> for pb::NiDkgTag {

/// The subnet for which the DKG generates keys.
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
#[cfg_attr(test, derive(ExhaustiveSet))]
pub enum NiDkgTargetSubnet {
/// `Local` means the subnet creates keys for itself.
Local,
Expand All @@ -67,6 +71,7 @@ pub enum NiDkgTargetSubnet {
/// Please refer to the rustdoc of `NiDkgTargetSubnet::Remote` for an
/// explanation of why this is needed.
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)]
#[cfg_attr(test, derive(ExhaustiveSet))]
pub struct NiDkgTargetId([u8; NiDkgTargetId::SIZE]);
ic_crypto_internal_types::derive_serde!(NiDkgTargetId, NiDkgTargetId::SIZE);

Expand Down
3 changes: 3 additions & 0 deletions rs/types/types/src/crypto/threshold_sig/ni_dkg/id.rs
@@ -1,12 +1,15 @@
//! Types related to the non-interactive DKG ID.
use super::*;
#[cfg(test)]
use ic_exhaustive_derive::ExhaustiveSet;
use ic_protobuf::types::v1 as pb;

#[cfg(test)]
mod tests;

/// The ID for non-interactive DKG. Identifies a DKG epoch.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
#[cfg_attr(test, derive(ExhaustiveSet))]
pub struct NiDkgId {
/// This field refers to the height of the block denoting the start of the
/// computation of this DKG instance (resulting into a transcript later).
Expand Down

0 comments on commit 8385491

Please sign in to comment.