mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-08 17:26:04 +00:00
Start adding ffg tests
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
mod ffg_updates;
|
||||||
mod no_votes;
|
mod no_votes;
|
||||||
mod votes;
|
mod votes;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,255 @@
|
|||||||
|
use super::*;
|
||||||
|
|
||||||
|
pub fn get_ffg_case_01_test_definition() -> ForkChoiceTestDefinition {
|
||||||
|
let mut balances = vec![1; 2];
|
||||||
|
let mut ops = vec![];
|
||||||
|
|
||||||
|
// Ensure that the head starts at the finalized block.
|
||||||
|
ops.push(Operation::FindHead {
|
||||||
|
justified_epoch: Epoch::new(0),
|
||||||
|
justified_root: get_hash(0),
|
||||||
|
finalized_epoch: Epoch::new(0),
|
||||||
|
justified_state_balances: balances.clone(),
|
||||||
|
expected_head: get_hash(0),
|
||||||
|
});
|
||||||
|
|
||||||
|
// Build the following tree (stick? lol).
|
||||||
|
//
|
||||||
|
// 0 <- just: 0, fin: 0
|
||||||
|
// |
|
||||||
|
// 1 <- just: 0, fin: 0
|
||||||
|
// |
|
||||||
|
// 2 <- just: 1, fin: 0
|
||||||
|
// |
|
||||||
|
// 3 <- just: 2, fin: 1
|
||||||
|
ops.push(Operation::ProcessBlock {
|
||||||
|
slot: Slot::new(1),
|
||||||
|
root: get_hash(1),
|
||||||
|
parent_root: get_hash(0),
|
||||||
|
justified_epoch: Epoch::new(0),
|
||||||
|
finalized_epoch: Epoch::new(0),
|
||||||
|
});
|
||||||
|
ops.push(Operation::ProcessBlock {
|
||||||
|
slot: Slot::new(2),
|
||||||
|
root: get_hash(2),
|
||||||
|
parent_root: get_hash(1),
|
||||||
|
justified_epoch: Epoch::new(1),
|
||||||
|
finalized_epoch: Epoch::new(0),
|
||||||
|
});
|
||||||
|
ops.push(Operation::ProcessBlock {
|
||||||
|
slot: Slot::new(3),
|
||||||
|
root: get_hash(3),
|
||||||
|
parent_root: get_hash(2),
|
||||||
|
justified_epoch: Epoch::new(2),
|
||||||
|
finalized_epoch: Epoch::new(1),
|
||||||
|
});
|
||||||
|
|
||||||
|
// Ensure that with justified epoch 0 we find 3
|
||||||
|
//
|
||||||
|
// 0 <- start
|
||||||
|
// |
|
||||||
|
// 1
|
||||||
|
// |
|
||||||
|
// 2
|
||||||
|
// |
|
||||||
|
// 3 <- head
|
||||||
|
ops.push(Operation::FindHead {
|
||||||
|
justified_epoch: Epoch::new(0),
|
||||||
|
justified_root: get_hash(0),
|
||||||
|
finalized_epoch: Epoch::new(0),
|
||||||
|
justified_state_balances: balances.clone(),
|
||||||
|
expected_head: get_hash(3),
|
||||||
|
});
|
||||||
|
|
||||||
|
// Ensure that with justified epoch 1 we find 2
|
||||||
|
//
|
||||||
|
// 0
|
||||||
|
// |
|
||||||
|
// 1
|
||||||
|
// |
|
||||||
|
// 2 <- start
|
||||||
|
// |
|
||||||
|
// 3 <- head
|
||||||
|
ops.push(Operation::FindHead {
|
||||||
|
justified_epoch: Epoch::new(1),
|
||||||
|
justified_root: get_hash(2),
|
||||||
|
finalized_epoch: Epoch::new(0),
|
||||||
|
justified_state_balances: balances.clone(),
|
||||||
|
expected_head: get_hash(2),
|
||||||
|
});
|
||||||
|
|
||||||
|
// Ensure that with justified epoch 2 we find 3
|
||||||
|
//
|
||||||
|
// 0
|
||||||
|
// |
|
||||||
|
// 1
|
||||||
|
// |
|
||||||
|
// 2
|
||||||
|
// |
|
||||||
|
// 3 <- start + head
|
||||||
|
ops.push(Operation::FindHead {
|
||||||
|
justified_epoch: Epoch::new(2),
|
||||||
|
justified_root: get_hash(3),
|
||||||
|
finalized_epoch: Epoch::new(1),
|
||||||
|
justified_state_balances: balances.clone(),
|
||||||
|
expected_head: get_hash(3),
|
||||||
|
});
|
||||||
|
|
||||||
|
// END OF TESTS
|
||||||
|
ForkChoiceTestDefinition {
|
||||||
|
finalized_block_slot: Slot::new(0),
|
||||||
|
justified_epoch: Epoch::new(1),
|
||||||
|
finalized_epoch: Epoch::new(1),
|
||||||
|
finalized_root: get_hash(0),
|
||||||
|
operations: ops,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
|
||||||
|
let mut balances = vec![1; 2];
|
||||||
|
let mut ops = vec![];
|
||||||
|
|
||||||
|
// Ensure that the head starts at the finalized block.
|
||||||
|
ops.push(Operation::FindHead {
|
||||||
|
justified_epoch: Epoch::new(1),
|
||||||
|
justified_root: get_hash(0),
|
||||||
|
finalized_epoch: Epoch::new(1),
|
||||||
|
justified_state_balances: balances.clone(),
|
||||||
|
expected_head: get_hash(0),
|
||||||
|
});
|
||||||
|
|
||||||
|
// Build the following tree.
|
||||||
|
//
|
||||||
|
// 0
|
||||||
|
// / \
|
||||||
|
// just: 0, fin: 0 -> 1 2 <- just: 0, fin: 0
|
||||||
|
// | |
|
||||||
|
// just: 1, fin: 0 -> 3 4 <- just: 0, fin: 0
|
||||||
|
// | |
|
||||||
|
// just: 1, fin: 0 -> 5 6 <- just: 0, fin: 0
|
||||||
|
// | |
|
||||||
|
// just: 1, fin: 0 -> 7 8 <- just: 1, fin: 0
|
||||||
|
// | |
|
||||||
|
// just: 2, fin: 0 -> 9 10 <- just: 2, fin: 0
|
||||||
|
|
||||||
|
// Left branch
|
||||||
|
ops.push(Operation::ProcessBlock {
|
||||||
|
slot: Slot::new(1),
|
||||||
|
root: get_hash(1),
|
||||||
|
parent_root: get_hash(0),
|
||||||
|
justified_epoch: Epoch::new(0),
|
||||||
|
finalized_epoch: Epoch::new(0),
|
||||||
|
});
|
||||||
|
ops.push(Operation::ProcessBlock {
|
||||||
|
slot: Slot::new(2),
|
||||||
|
root: get_hash(3),
|
||||||
|
parent_root: get_hash(1),
|
||||||
|
justified_epoch: Epoch::new(1),
|
||||||
|
finalized_epoch: Epoch::new(0),
|
||||||
|
});
|
||||||
|
ops.push(Operation::ProcessBlock {
|
||||||
|
slot: Slot::new(3),
|
||||||
|
root: get_hash(5),
|
||||||
|
parent_root: get_hash(3),
|
||||||
|
justified_epoch: Epoch::new(1),
|
||||||
|
finalized_epoch: Epoch::new(0),
|
||||||
|
});
|
||||||
|
ops.push(Operation::ProcessBlock {
|
||||||
|
slot: Slot::new(4),
|
||||||
|
root: get_hash(7),
|
||||||
|
parent_root: get_hash(5),
|
||||||
|
justified_epoch: Epoch::new(1),
|
||||||
|
finalized_epoch: Epoch::new(0),
|
||||||
|
});
|
||||||
|
ops.push(Operation::ProcessBlock {
|
||||||
|
slot: Slot::new(4),
|
||||||
|
root: get_hash(9),
|
||||||
|
parent_root: get_hash(7),
|
||||||
|
justified_epoch: Epoch::new(2),
|
||||||
|
finalized_epoch: Epoch::new(0),
|
||||||
|
});
|
||||||
|
|
||||||
|
// Right branch
|
||||||
|
ops.push(Operation::ProcessBlock {
|
||||||
|
slot: Slot::new(1),
|
||||||
|
root: get_hash(2),
|
||||||
|
parent_root: get_hash(0),
|
||||||
|
justified_epoch: Epoch::new(0),
|
||||||
|
finalized_epoch: Epoch::new(0),
|
||||||
|
});
|
||||||
|
ops.push(Operation::ProcessBlock {
|
||||||
|
slot: Slot::new(2),
|
||||||
|
root: get_hash(4),
|
||||||
|
parent_root: get_hash(2),
|
||||||
|
justified_epoch: Epoch::new(0),
|
||||||
|
finalized_epoch: Epoch::new(0),
|
||||||
|
});
|
||||||
|
ops.push(Operation::ProcessBlock {
|
||||||
|
slot: Slot::new(3),
|
||||||
|
root: get_hash(6),
|
||||||
|
parent_root: get_hash(4),
|
||||||
|
justified_epoch: Epoch::new(0),
|
||||||
|
finalized_epoch: Epoch::new(0),
|
||||||
|
});
|
||||||
|
ops.push(Operation::ProcessBlock {
|
||||||
|
slot: Slot::new(4),
|
||||||
|
root: get_hash(8),
|
||||||
|
parent_root: get_hash(6),
|
||||||
|
justified_epoch: Epoch::new(1),
|
||||||
|
finalized_epoch: Epoch::new(0),
|
||||||
|
});
|
||||||
|
ops.push(Operation::ProcessBlock {
|
||||||
|
slot: Slot::new(4),
|
||||||
|
root: get_hash(10),
|
||||||
|
parent_root: get_hash(8),
|
||||||
|
justified_epoch: Epoch::new(2),
|
||||||
|
finalized_epoch: Epoch::new(0),
|
||||||
|
});
|
||||||
|
|
||||||
|
// Ensure that if we start at 0 we find 10.
|
||||||
|
//
|
||||||
|
// 0 <-- start
|
||||||
|
// / \
|
||||||
|
// 1 2
|
||||||
|
// | |
|
||||||
|
// 3 4
|
||||||
|
// | |
|
||||||
|
// 5 6
|
||||||
|
// | |
|
||||||
|
// 7 8
|
||||||
|
// | |
|
||||||
|
// 9 10 <-- head
|
||||||
|
ops.push(Operation::FindHead {
|
||||||
|
justified_epoch: Epoch::new(0),
|
||||||
|
justified_root: get_hash(0),
|
||||||
|
finalized_epoch: Epoch::new(0),
|
||||||
|
justified_state_balances: balances.clone(),
|
||||||
|
expected_head: get_hash(10),
|
||||||
|
});
|
||||||
|
|
||||||
|
// END OF TESTS
|
||||||
|
ForkChoiceTestDefinition {
|
||||||
|
finalized_block_slot: Slot::new(0),
|
||||||
|
justified_epoch: Epoch::new(1),
|
||||||
|
finalized_epoch: Epoch::new(1),
|
||||||
|
finalized_root: get_hash(0),
|
||||||
|
operations: ops,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ffg_case_01() {
|
||||||
|
let test = get_ffg_case_01_test_definition();
|
||||||
|
test.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ffg_case_02() {
|
||||||
|
let test = get_ffg_case_02_test_definition();
|
||||||
|
test.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -225,3 +225,13 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
|
|||||||
operations,
|
operations,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
#[test]
|
||||||
|
fn test() {
|
||||||
|
let test = get_no_votes_test_definition();
|
||||||
|
test.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -691,14 +691,9 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
#[test]
|
|
||||||
fn no_votes() {
|
|
||||||
let test = get_no_votes_test_definition();
|
|
||||||
test.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn votes() {
|
fn test() {
|
||||||
let test = get_votes_test_definition();
|
let test = get_votes_test_definition();
|
||||||
test.run();
|
test.run();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -692,7 +692,7 @@ mod test_compute_deltas {
|
|||||||
for vote in votes.0 {
|
for vote in votes.0 {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
vote.current_root, vote.next_root,
|
vote.current_root, vote.next_root,
|
||||||
"the vote shoulds should have been updated"
|
"the vote should have been updated"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user