mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-15 02:42:38 +00:00
Marge fixes to test_harness, add serdehex crate
This commit is contained in:
@@ -40,12 +40,25 @@ macro_rules! impl_encodable_for_uint {
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! impl_encodable_for_u8_array {
|
||||
($len: expr) => {
|
||||
impl Encodable for [u8; $len] {
|
||||
fn ssz_append(&self, s: &mut SszStream) {
|
||||
let bytes: Vec<u8> = self.iter().cloned().collect();
|
||||
s.append_encoded_raw(&bytes);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl_encodable_for_uint!(u8, 8);
|
||||
impl_encodable_for_uint!(u16, 16);
|
||||
impl_encodable_for_uint!(u32, 32);
|
||||
impl_encodable_for_uint!(u64, 64);
|
||||
impl_encodable_for_uint!(usize, 64);
|
||||
|
||||
impl_encodable_for_u8_array!(4);
|
||||
|
||||
impl Encodable for bool {
|
||||
fn ssz_append(&self, s: &mut SszStream) {
|
||||
let byte = if *self { 0b1000_0000 } else { 0b0000_0000 };
|
||||
@@ -77,6 +90,7 @@ where
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::ssz_encode;
|
||||
|
||||
#[test]
|
||||
fn test_ssz_encode_h256() {
|
||||
@@ -226,4 +240,15 @@ mod tests {
|
||||
ssz.append(&x);
|
||||
assert_eq!(ssz.drain(), vec![0b1000_0000]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ssz_encode_u8_array() {
|
||||
let x: [u8; 4] = [0, 1, 7, 8];
|
||||
let ssz = ssz_encode(&x);
|
||||
assert_eq!(ssz, vec![0, 1, 7, 8]);
|
||||
|
||||
let x: [u8; 4] = [255, 255, 255, 255];
|
||||
let ssz = ssz_encode(&x);
|
||||
assert_eq!(ssz, vec![255, 255, 255, 255]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user