Fix consensus, SSZ, tree hash & run merge EF tests (#2622)

* Update to v1.1.0-beta.4 (squash of #2548)

* SSZ, cached tree hash, EF tests
This commit is contained in:
Michael Sproul
2021-09-24 14:55:21 +10:00
committed by Paul Hauner
parent 3718c36c51
commit ef6158f4ee
23 changed files with 312 additions and 205 deletions

View File

@@ -0,0 +1,25 @@
use crate::FixedVector;
use eth2_serde_utils::hex::{self, PrefixedHexVisitor};
use serde::{Deserializer, Serializer};
use typenum::Unsigned;
pub fn serialize<S, U>(bytes: &FixedVector<u8, U>, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
U: Unsigned,
{
let mut hex_string: String = "0x".to_string();
hex_string.push_str(&hex::encode(&bytes[..]));
serializer.serialize_str(&hex_string)
}
pub fn deserialize<'de, D, U>(deserializer: D) -> Result<FixedVector<u8, U>, D::Error>
where
D: Deserializer<'de>,
U: Unsigned,
{
let vec = deserializer.deserialize_string(PrefixedHexVisitor)?;
FixedVector::new(vec)
.map_err(|e| serde::de::Error::custom(format!("invalid fixed vector: {:?}", e)))
}

View File

@@ -0,0 +1,26 @@
//! Serialize `VariableList<u8, N>` as 0x-prefixed hex string.
use crate::VariableList;
use eth2_serde_utils::hex::{self, PrefixedHexVisitor};
use serde::{Deserializer, Serializer};
use typenum::Unsigned;
pub fn serialize<S, N>(bytes: &VariableList<u8, N>, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
N: Unsigned,
{
let mut hex_string: String = "0x".to_string();
hex_string.push_str(&hex::encode(&**bytes));
serializer.serialize_str(&hex_string)
}
pub fn deserialize<'de, D, N>(deserializer: D) -> Result<VariableList<u8, N>, D::Error>
where
D: Deserializer<'de>,
N: Unsigned,
{
let bytes = deserializer.deserialize_str(PrefixedHexVisitor)?;
VariableList::new(bytes)
.map_err(|e| serde::de::Error::custom(format!("invalid variable list: {:?}", e)))
}

View File

@@ -1,2 +1,4 @@
pub mod hex_fixed_vec;
pub mod hex_var_list;
pub mod quoted_u64_fixed_vec;
pub mod quoted_u64_var_list;