Add RLP encoding for AggregateVote

This commit is contained in:
Paul Hauner 2018-07-09 16:11:56 +10:00
parent b96453d45e
commit f4a1f5bd34

View File

@ -1,5 +1,6 @@
use super::utils::types::*;
use super::utils::bls::AggregateSignature;
use super::rlp::{ RlpStream, Encodable };
pub struct AggregateVote {
pub shard_id: u16,
@ -21,9 +22,22 @@ impl AggregateVote {
}
}
/*
* RLP Encoding
*/
impl Encodable for AggregateVote {
fn rlp_append(&self, s: &mut RlpStream) {
s.append(&self.shard_id);
s.append(&self.shard_block_hash);
s.append(&self.notary_bitfield);
// s.append(&self.aggregate_sig); // TODO: represent this in RLP
}
}
#[cfg(test)]
mod tests {
use super::super::rlp;
use super::*;
#[test]
@ -34,4 +48,20 @@ mod tests {
assert_eq!(v.shard_id, id);
assert_eq!(v.shard_block_hash, hash);
}
#[test]
fn test_serialization() {
let a = AggregateVote {
shard_id: 100,
shard_block_hash: Sha256Digest::zero(),
notary_bitfield: Vec::new(),
aggregate_sig: AggregateSignature::new()
};
let e = rlp::encode(&a);
assert_eq!(e.len(), 35);
assert_eq!(e[0], 100);
assert_eq!(e[1], 160);
assert_eq!(e[2..34], [0; 32]);
assert_eq!(e[34], 128);
}
}