diff --git a/src/state/aggregate_vote.rs b/src/state/aggregate_vote.rs index df7fb8b137..690fa907e0 100644 --- a/src/state/aggregate_vote.rs +++ b/src/state/aggregate_vote.rs @@ -10,12 +10,10 @@ pub struct AggregateVote { } impl AggregateVote { - pub fn new_for_shard(shard_id: u16, - shard_block_hash: Sha256Digest) - -> AggregateVote { - AggregateVote { - shard_id: shard_id, - shard_block_hash: shard_block_hash, + pub fn zero() -> Self { + Self { + shard_id: 0, + shard_block_hash: Sha256Digest::zero(), notary_bitfield: Vec::new(), aggregate_sig: AggregateSignature::new() } @@ -41,12 +39,10 @@ mod tests { use super::*; #[test] - fn test_new_for_shard() { - let id = 1; - let hash = Sha256Digest::random(); - let v = AggregateVote::new_for_shard(id, hash); - assert_eq!(v.shard_id, id); - assert_eq!(v.shard_block_hash, hash); + fn test_zero_fn() { + let v = AggregateVote::zero(); + // TODO: test this better + assert_eq!(v.shard_id, 0); } #[test] diff --git a/src/state/crystallized_state.rs b/src/state/crystallized_state.rs index 9f232fd8da..935be53cff 100644 --- a/src/state/crystallized_state.rs +++ b/src/state/crystallized_state.rs @@ -22,6 +22,24 @@ pub struct CrystallizedState { } impl CrystallizedState { + // Returns a new instance with all values set to zero. + pub fn zero() -> Self { + Self { + active_validators: Vec::new(), + queued_validators: Vec::new(), + exited_validators: Vec::new(), + current_shuffling: Vec::new(), + current_epoch: 0, + last_justified_epoch: 0, + last_finalized_epoch: 0, + dynasty: 0, + next_shard: 0, + current_checkpoint: Sha256Digest::zero(), + crosslink_records: Vec::new(), + total_deposits: U256::zero(), + } + } + pub fn num_active_validators(&self) -> usize { self.active_validators.len() }