Add zero method to active_state

This commit is contained in:
Paul Hauner 2018-07-11 18:14:40 +10:00
parent 0d7ea19a55
commit 911eda7a2a

View File

@ -16,10 +16,10 @@ pub struct ActiveState {
} }
impl ActiveState { impl ActiveState {
pub fn new_for_height(height: u64) -> ActiveState { pub fn zero() -> Self {
ActiveState { Self {
height: height, height: 0,
randao: Sha256Digest::random(), randao: Sha256Digest::zero(),
ffg_voter_bitfield: Vec::new(), ffg_voter_bitfield: Vec::new(),
recent_attesters: Vec::new(), recent_attesters: Vec::new(),
partial_crosslinks: Vec::new(), partial_crosslinks: Vec::new(),
@ -67,15 +67,16 @@ mod tests {
use super::*; use super::*;
#[test] #[test]
fn test_new_for_height() { fn test_zero_fn() {
let h = 1; let a = ActiveState::zero();
let a = ActiveState::new_for_height(h); assert_eq!(a.height, 0);
assert_eq!(a.height, h); // TODO: test all the things
assert_eq!(a.total_skip_count, 0);
} }
#[test] #[test]
fn test_num_recent_proposers() { fn test_num_recent_proposers() {
let mut a = ActiveState::new_for_height(1); let mut a = ActiveState::zero();
for _ in 1..5 { for _ in 1..5 {
a.recent_proposers.push(RecentPropserRecord::new( a.recent_proposers.push(RecentPropserRecord::new(
1, 1,
@ -87,7 +88,7 @@ mod tests {
#[test] #[test]
fn test_num_recent_attesters() { fn test_num_recent_attesters() {
let mut a = ActiveState::new_for_height(1); let mut a = ActiveState::zero();
for _ in 1..5 { for _ in 1..5 {
a.recent_attesters.push(1); a.recent_attesters.push(1);
} }