mirror of
https://gitlab.com/pulsechaincom/lighthouse-pulse.git
synced 2024-12-22 03:30:38 +00:00
Add RLP encoding for CrosslinkRecord
This commit is contained in:
parent
f4a1f5bd34
commit
02fd250ddc
@ -1,4 +1,5 @@
|
||||
use super::utils::types::Sha256Digest;
|
||||
use super::rlp::{ RlpStream, Encodable };
|
||||
|
||||
pub struct CrosslinkRecord {
|
||||
pub epoch: u64,
|
||||
@ -14,8 +15,19 @@ impl CrosslinkRecord {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* RLP Encoding
|
||||
*/
|
||||
impl Encodable for CrosslinkRecord {
|
||||
fn rlp_append(&self, s: &mut RlpStream) {
|
||||
s.append(&self.epoch);
|
||||
s.append(&self.hash);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::super::rlp;
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
@ -26,4 +38,17 @@ mod tests {
|
||||
assert_eq!(c.epoch, epoch);
|
||||
assert_eq!(c.hash, hash);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_serialization() {
|
||||
let c = CrosslinkRecord {
|
||||
epoch: 100,
|
||||
hash: Sha256Digest::zero()
|
||||
};
|
||||
let e = rlp::encode(&c);
|
||||
assert_eq!(e.len(), 34);
|
||||
assert_eq!(e[0], 100);
|
||||
assert_eq!(e[1], 160);
|
||||
assert_eq!(e[2..34], [0; 32]);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user