test: add ParentMissing error case

- derive(PartialEq) only for tests
This commit is contained in:
Roman 2024-05-31 12:57:56 +02:00
parent f1a621fa11
commit f51a763ca3
No known key found for this signature in database
GPG Key ID: B8FE070B54E11B75
1 changed files with 17 additions and 2 deletions

View File

@ -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(&not_a_parent)
.ok_or(Error::ParentMissing(not_a_parent))
{
Ok(_) => (),
Err(e) => {
assert_ne!(e, Error::ParentMissing(parent));
}
};
}
}