diff --git a/consensus/cryptarchia-engine/src/lib.rs b/consensus/cryptarchia-engine/src/lib.rs index d437270d..b48c4b96 100644 --- a/consensus/cryptarchia-engine/src/lib.rs +++ b/consensus/cryptarchia-engine/src/lib.rs @@ -21,7 +21,8 @@ pub struct Branches { tips: HashSet, } -#[derive(PartialEq, Clone, Debug)] +#[derive(Clone, Debug)] +#[cfg_attr(test, derive(PartialEq))] pub struct Branch { id: Id, parent: Id, @@ -131,6 +132,7 @@ where } #[derive(Debug, Clone, Error)] +#[cfg_attr(test, derive(PartialEq))] pub enum Error { #[error("Parent block: {0:?} is not know to this node")] ParentMissing(Id), @@ -220,7 +222,7 @@ where #[cfg(test)] pub mod tests { - use super::{Cryptarchia, Slot}; + use super::{Cryptarchia, Error, Slot}; use crate::Config; use std::hash::{DefaultHasher, Hash, Hasher}; @@ -360,5 +362,18 @@ pub mod tests { let slot = Slot::genesis(); assert_eq!(slot + 10u64, Slot::from(10)); + + let strange_engine = Cryptarchia::from_genesis([100; 32], config()); + let not_a_parent = strange_engine.genesis(); + + _ = match branches + .get(¬_a_parent) + .ok_or(Error::ParentMissing(not_a_parent)) + { + Ok(_) => (), + Err(e) => { + assert_ne!(e, Error::ParentMissing(parent)); + } + }; } }