Add RLP encoding for AggregateVote
This commit is contained in:
parent
b96453d45e
commit
f4a1f5bd34
@ -1,5 +1,6 @@
|
|||||||
use super::utils::types::*;
|
use super::utils::types::*;
|
||||||
use super::utils::bls::AggregateSignature;
|
use super::utils::bls::AggregateSignature;
|
||||||
|
use super::rlp::{ RlpStream, Encodable };
|
||||||
|
|
||||||
pub struct AggregateVote {
|
pub struct AggregateVote {
|
||||||
pub shard_id: u16,
|
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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use super::super::rlp;
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -34,4 +48,20 @@ mod tests {
|
|||||||
assert_eq!(v.shard_id, id);
|
assert_eq!(v.shard_id, id);
|
||||||
assert_eq!(v.shard_block_hash, hash);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user