mirror of
https://gitlab.com/pulsechaincom/lighthouse-pulse.git
synced 2024-12-22 03:30:38 +00:00
Add RLP encoding to part. xlink rec.
This commit is contained in:
parent
909d624730
commit
455aa3782a
@ -1,4 +1,5 @@
|
||||
use super::utils::types::{ Sha256Digest, Bitfield };
|
||||
use super::rlp::{ RlpStream, Encodable };
|
||||
|
||||
pub struct PartialCrosslinkRecord {
|
||||
pub shard_id: u16,
|
||||
@ -17,9 +18,21 @@ impl PartialCrosslinkRecord {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* RLP Encoding
|
||||
*/
|
||||
impl Encodable for PartialCrosslinkRecord {
|
||||
fn rlp_append(&self, s: &mut RlpStream) {
|
||||
s.append(&self.shard_id);
|
||||
s.append(&self.shard_block_hash);
|
||||
s.append(&self.voter_bitfield);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::super::rlp;
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
@ -30,4 +43,20 @@ mod tests {
|
||||
assert_eq!(p.shard_id, id);
|
||||
assert_eq!(p.shard_block_hash, hash);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_serialization() {
|
||||
let p = PartialCrosslinkRecord {
|
||||
shard_id: 1,
|
||||
shard_block_hash: Sha256Digest::zero(),
|
||||
voter_bitfield: Vec::new()
|
||||
};
|
||||
let e = rlp::encode(&p);
|
||||
println!("{:?}", e);
|
||||
assert_eq!(e.len(), 35);
|
||||
assert_eq!(e[0], 1);
|
||||
assert_eq!(e[1], 160);
|
||||
assert_eq!(e[2..34], [0; 32]);
|
||||
assert_eq!(e[34], 128);
|
||||
}
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ mod tests {
|
||||
let balance_delta = 99;
|
||||
let r = RecentPropserRecord::new(index, randao_commitment, balance_delta);
|
||||
let e = rlp::encode(&r);
|
||||
assert_eq!(e.len(), 35);
|
||||
assert_eq!(e[0], 1);
|
||||
assert_eq!(e[1], 160);
|
||||
assert_eq!(e[2..34], [0; 32]);
|
||||
|
Loading…
Reference in New Issue
Block a user