Add zero() to PartialCrosslinkRecord

This commit is contained in:
Paul Hauner 2018-07-15 12:13:45 +10:00
parent 20f976ca40
commit 061946b5c7

View File

@ -8,11 +8,10 @@ pub struct PartialCrosslinkRecord {
} }
impl PartialCrosslinkRecord { impl PartialCrosslinkRecord {
pub fn new_for_shard(shard_id: u16, pub fn zero() -> Self {
shard_block_hash: Sha256Digest) -> PartialCrosslinkRecord { Self {
PartialCrosslinkRecord { shard_id: 0,
shard_id: shard_id, shard_block_hash: Sha256Digest::zero(),
shard_block_hash: shard_block_hash,
voter_bitfield: Bitfield::new() voter_bitfield: Bitfield::new()
} }
} }
@ -36,21 +35,17 @@ mod tests {
use super::*; use super::*;
#[test] #[test]
fn test_new_for_shard() { fn test_zero() {
let id = 1; let p = PartialCrosslinkRecord::zero();
let hash = Sha256Digest::random(); assert_eq!(p.shard_id, 0);
let p = PartialCrosslinkRecord::new_for_shard(id, hash); assert_eq!(p.shard_block_hash.is_zero(), true);
assert_eq!(p.shard_id, id); assert_eq!(p.voter_bitfield.num_true_bits(), 0);
assert_eq!(p.shard_block_hash, hash);
} }
#[test] #[test]
fn test_rlp_serialization() { fn test_rlp_serialization() {
let p = PartialCrosslinkRecord { let mut p = PartialCrosslinkRecord::zero();
shard_id: 1, p.shard_id = 1;
shard_block_hash: Sha256Digest::zero(),
voter_bitfield: Bitfield::new()
};
let e = rlp::encode(&p); let e = rlp::encode(&p);
assert_eq!(e.len(), 35); assert_eq!(e.len(), 35);
assert_eq!(e[0], 1); assert_eq!(e[0], 1);