Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Better tests
  • Loading branch information
timorl committed Jan 19, 2023
commit 8452d68d49593887b27791363f51fe695911ee8c
34 changes: 31 additions & 3 deletions finality-aleph/src/sync/forest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,23 @@ mod tests {
assert_eq!(forest.state(&child.id()), Uninterested);
}

#[test]
fn rejects_body_when_parent_unimported() {
let (initial_header, mut forest) = setup();
let child = initial_header.random_child();
let grandchild = child.random_child();
assert!(!forest
.update_header(&child, None, false)
.expect("header was correct"));
assert_eq!(
forest.update_body(&grandchild),
Err(Error::ParentNotImported)
);
assert!(forest.try_finalize().is_none());
assert_eq!(forest.state(&child.id()), Uninterested);
assert_eq!(forest.state(&grandchild.id()), Uninterested);
}

#[test]
fn finalizes_first_block() {
let (initial_header, mut forest) = setup();
Expand Down Expand Up @@ -606,12 +623,20 @@ mod tests {
#[test]
fn prunes_huge_branch() {
let (initial_header, mut forest) = setup();
for header in initial_header.random_branch().take(HUGE_BRANCH_LENGTH) {
let fork: Vec<_> = initial_header
.random_branch()
.take(HUGE_BRANCH_LENGTH)
.collect();
for header in &fork {
let peer_id = rand::random();
assert!(!forest
.update_header(&header, Some(peer_id), false)
assert!(forest
.update_header(header, Some(peer_id), true)
.expect("header was correct"));
assert!(forest.try_finalize().is_none());
match forest.state(&header.id()) {
TopRequired(holders) => assert!(holders.contains(&peer_id)),
other_state => panic!("Expected top required, got {:?}.", other_state),
}
}
let child = MockJustification::for_header(initial_header.random_child());
let peer_id = rand::random();
Expand All @@ -630,6 +655,9 @@ mod tests {
.update_body(child.header())
.expect("header was correct"));
assert_eq!(forest.try_finalize().expect("the block is ready"), child);
for header in &fork {
assert_eq!(forest.state(&header.id()), Uninterested);
}
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion finality-aleph/src/sync/forest/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ enum InnerVertex<J: Justification> {
},
}

/// The vomplete vertex, including metadata about peers that know most about the data it refers to.
/// The complete vertex, including metadata about peers that know most about the data it refers to.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Vertex<I: PeerId, J: Justification> {
inner: InnerVertex<J>,
Expand Down