test: getters for Branches
- derive(PartialEq) for Branch
This commit is contained in:
parent
e904793b7e
commit
39ace002e9
|
@ -21,6 +21,7 @@ pub struct Branches<Id> {
|
|||
tips: HashSet<Id>,
|
||||
}
|
||||
|
||||
#[derive(PartialEq)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Branch<Id> {
|
||||
id: Id,
|
||||
|
@ -220,7 +221,7 @@ where
|
|||
|
||||
#[cfg(test)]
|
||||
pub mod tests {
|
||||
use super::Cryptarchia;
|
||||
use super::{Cryptarchia};
|
||||
use crate::Config;
|
||||
use std::hash::{DefaultHasher, Hash, Hasher};
|
||||
|
||||
|
@ -320,4 +321,27 @@ pub mod tests {
|
|||
res[..8].copy_from_slice(&hash.to_be_bytes());
|
||||
res
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_getters() {
|
||||
let engine = Cryptarchia::from_genesis([0; 32], config());
|
||||
let parent = engine.genesis();
|
||||
|
||||
// Get branch directly from HashMap
|
||||
let branch1 = engine.branches.get(&parent).ok_or("At least one branch should be there");
|
||||
|
||||
let branches = engine.branches();
|
||||
|
||||
// Get branch using getter
|
||||
let branch2 = branches.get(&parent).ok_or("At least one branch should be there");
|
||||
|
||||
assert_eq!(branch1, branch2);
|
||||
assert_eq!(branch1.expect("id is set").id(), branch2.expect("id is set").id());
|
||||
assert_eq!(branch1.expect("parent is set").parent(), branch2.expect("parent is set").parent());
|
||||
assert_eq!(branch1.expect("slot is set").slot(), branch2.expect("slot is set").slot());
|
||||
assert_eq!(branch1.expect("length is set").length(), branch2.expect("length is set").length());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue