Add zero() methods for cry_state and agg_vote

This commit is contained in:
Paul Hauner 2018-07-11 14:14:22 +10:00
parent 6e0eec6543
commit 5bcb62f6c4
2 changed files with 26 additions and 12 deletions

View File

@ -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]

View File

@ -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()
}