test: add ParentMissing error case
- derive(PartialEq) only for tests
This commit is contained in:
parent
f1a621fa11
commit
f51a763ca3
|
@ -21,7 +21,8 @@ pub struct Branches<Id> {
|
|||
tips: HashSet<Id>,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Clone, Debug)]
|
||||
#[derive(Clone, Debug)]
|
||||
#[cfg_attr(test, derive(PartialEq))]
|
||||
pub struct Branch<Id> {
|
||||
id: Id,
|
||||
parent: Id,
|
||||
|
@ -131,6 +132,7 @@ where
|
|||
}
|
||||
|
||||
#[derive(Debug, Clone, Error)]
|
||||
#[cfg_attr(test, derive(PartialEq))]
|
||||
pub enum Error<Id> {
|
||||
#[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));
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue