From d856f343008744e29fa2cc0aa5ee466e4d3991c9 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Tue, 14 Jan 2020 06:57:33 +1100 Subject: [PATCH] Add more testing --- eth2/lmd_ghost/src/proto_array.rs | 78 ++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/eth2/lmd_ghost/src/proto_array.rs b/eth2/lmd_ghost/src/proto_array.rs index 9aa8dc7948..2b088911c8 100644 --- a/eth2/lmd_ghost/src/proto_array.rs +++ b/eth2/lmd_ghost/src/proto_array.rs @@ -1856,6 +1856,82 @@ mod test_proto_array_fork_choice { "should find get_hash(10)" ); - // TODO: play with the validator balances and watch the head move about. + // Set the balances of the last two validators to zero + let balances = vec![1, 1, 0, 0]; + + // Check the head is 9 again. + // + // . + // . + // . + // | + // 8 + // / \ + // head-> 9 10 + assert_eq!( + fork_choice + .find_head( + Epoch::new(1), + get_hash(5), + Epoch::new(0), + Hash256::zero(), + &balances + ) + .expect("should find head"), + get_hash(9), + "should find get_hash(9)" + ); + + // Set the balances of the last two validators back to 1 + let balances = vec![1; 4]; + + // Check the head is 10. + // + // . + // . + // . + // | + // 8 + // / \ + // 9 10 <- head + assert_eq!( + fork_choice + .find_head( + Epoch::new(1), + get_hash(5), + Epoch::new(0), + Hash256::zero(), + &balances + ) + .expect("should find head"), + get_hash(10), + "should find get_hash(10)" + ); + + // Remove the last two validators + let balances = vec![1; 2]; + + // Check the head is 9 again. + // + // . + // . + // . + // | + // 8 + // / \ + // head-> 9 10 + assert_eq!( + fork_choice + .find_head( + Epoch::new(1), + get_hash(5), + Epoch::new(0), + Hash256::zero(), + &balances + ) + .expect("should find head"), + get_hash(9), + "should find get_hash(9)" + ); } }