mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-30 04:37:13 +00:00
Enable all ssz tests
This commit is contained in:
@@ -66,12 +66,6 @@ excluded_paths = [
|
|||||||
"tests/.*/gloas/ssz_static/ExecutionPayloadHeader/.*",
|
"tests/.*/gloas/ssz_static/ExecutionPayloadHeader/.*",
|
||||||
# ForkChoiceNode is internal to fork choice and probably doesn't need SSZ tests.
|
# ForkChoiceNode is internal to fork choice and probably doesn't need SSZ tests.
|
||||||
"tests/.*/gloas/ssz_static/ForkChoiceNode/.*",
|
"tests/.*/gloas/ssz_static/ForkChoiceNode/.*",
|
||||||
# EIP-7916 is still in draft and hasn't been implemented yet https://eips.ethereum.org/EIPS/eip-7916
|
|
||||||
"tests/general/phase0/ssz_generic/progressive_bitlist",
|
|
||||||
"tests/general/phase0/ssz_generic/containers/.*/ProgressiveBitsStruct.*",
|
|
||||||
"tests/general/phase0/ssz_generic/containers/.*/ProgressiveTestStruct.*",
|
|
||||||
"tests/general/phase0/ssz_generic/progressive_containers/.*",
|
|
||||||
"tests/general/phase0/ssz_generic/compatible_unions/.*",
|
|
||||||
# Ignore full epoch tests for now (just test the sub-transitions).
|
# Ignore full epoch tests for now (just test the sub-transitions).
|
||||||
"tests/.*/.*/epoch_processing/.*/pre_epoch.ssz_snappy",
|
"tests/.*/.*/epoch_processing/.*/pre_epoch.ssz_snappy",
|
||||||
"tests/.*/.*/epoch_processing/.*/post_epoch.ssz_snappy",
|
"tests/.*/.*/epoch_processing/.*/post_epoch.ssz_snappy",
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use crate::decode::{context_yaml_decode_file, log_file_access, snappy_decode_fil
|
|||||||
use context_deserialize::{ContextDeserialize, context_deserialize};
|
use context_deserialize::{ContextDeserialize, context_deserialize};
|
||||||
use milhouse::{List, ProgressiveList, Vector};
|
use milhouse::{List, ProgressiveList, Vector};
|
||||||
use serde::{Deserialize, Deserializer, de::Error as SerdeError};
|
use serde::{Deserialize, Deserializer, de::Error as SerdeError};
|
||||||
|
use serde_json::Value as JsonValue;
|
||||||
use ssz::ProgressiveBitList;
|
use ssz::ProgressiveBitList;
|
||||||
use ssz_derive::{Decode, Encode};
|
use ssz_derive::{Decode, Encode};
|
||||||
use ssz_types::{BitList, BitVector, FixedVector, VariableList};
|
use ssz_types::{BitList, BitVector, FixedVector, VariableList};
|
||||||
@@ -15,6 +16,43 @@ use tree_hash_derive::TreeHash;
|
|||||||
use typenum::*;
|
use typenum::*;
|
||||||
use types::ForkName;
|
use types::ForkName;
|
||||||
|
|
||||||
|
/// Helper struct for deserializing compatible unions from `{selector, data}` YAML format.
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct CompatibleUnionYaml {
|
||||||
|
selector: u8,
|
||||||
|
data: JsonValue,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Implements `Deserialize` for compatible union types to handle the EF test YAML format.
|
||||||
|
///
|
||||||
|
/// Deserialize into `CompatibleUnionYaml` which captures `selector` (`u8`) and
|
||||||
|
/// `data` (`JsonValue`).
|
||||||
|
/// Match on the selector to determine which variant to construct.
|
||||||
|
/// Deserialize the `data` field into the appropriate inner type.
|
||||||
|
macro_rules! impl_compatible_union_deserialize {
|
||||||
|
($type:ty, { $($selector:literal => $variant:ident($inner:ty)),+ $(,)? }) => {
|
||||||
|
impl<'de> Deserialize<'de> for $type {
|
||||||
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
let yaml = CompatibleUnionYaml::deserialize(deserializer)?;
|
||||||
|
match yaml.selector {
|
||||||
|
$(
|
||||||
|
$selector => {
|
||||||
|
let inner: $inner = serde_json::from_value(yaml.data).map_err(D::Error::custom)?;
|
||||||
|
Ok(<$type>::$variant(inner))
|
||||||
|
}
|
||||||
|
)+
|
||||||
|
s => Err(D::Error::custom(format!(
|
||||||
|
"unknown selector {s} for {}", stringify!($type)
|
||||||
|
))),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
type U1280 = op!(U128 * U10);
|
type U1280 = op!(U128 * U10);
|
||||||
type U1281 = op!(U1280 + U1);
|
type U1281 = op!(U1280 + U1);
|
||||||
|
|
||||||
@@ -252,6 +290,17 @@ impl Case for SszGeneric {
|
|||||||
[type_name => test_container]
|
[type_name => test_container]
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
"compatible_unions" => {
|
||||||
|
let type_name = parts[0];
|
||||||
|
|
||||||
|
type_dispatch!(
|
||||||
|
ssz_generic_test,
|
||||||
|
(&self.path, fork_name),
|
||||||
|
_,
|
||||||
|
<>,
|
||||||
|
[type_name => test_container]
|
||||||
|
)?;
|
||||||
|
}
|
||||||
_ => panic!("unsupported handler: {}", self.handler_name),
|
_ => panic!("unsupported handler: {}", self.handler_name),
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -425,7 +474,7 @@ struct ProgressiveComplexTestStruct {
|
|||||||
H: ProgressiveList<ProgressiveVarTestStruct>,
|
H: ProgressiveList<ProgressiveVarTestStruct>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Decode, Encode, TreeHash, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Decode, Encode, TreeHash)]
|
||||||
#[ssz(enum_behaviour = "compatible_union")]
|
#[ssz(enum_behaviour = "compatible_union")]
|
||||||
#[tree_hash(enum_behaviour = "compatible_union")]
|
#[tree_hash(enum_behaviour = "compatible_union")]
|
||||||
#[context_deserialize(ForkName)]
|
#[context_deserialize(ForkName)]
|
||||||
@@ -434,7 +483,11 @@ enum CompatibleUnionA {
|
|||||||
ProgressiveSingleFieldContainerTestStruct(ProgressiveSingleFieldContainerTestStruct),
|
ProgressiveSingleFieldContainerTestStruct(ProgressiveSingleFieldContainerTestStruct),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Decode, Encode, TreeHash, Deserialize)]
|
impl_compatible_union_deserialize!(CompatibleUnionA, {
|
||||||
|
1 => ProgressiveSingleFieldContainerTestStruct(ProgressiveSingleFieldContainerTestStruct),
|
||||||
|
});
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Decode, Encode, TreeHash)]
|
||||||
#[ssz(enum_behaviour = "compatible_union")]
|
#[ssz(enum_behaviour = "compatible_union")]
|
||||||
#[tree_hash(enum_behaviour = "compatible_union")]
|
#[tree_hash(enum_behaviour = "compatible_union")]
|
||||||
#[context_deserialize(ForkName)]
|
#[context_deserialize(ForkName)]
|
||||||
@@ -445,7 +498,12 @@ enum CompatibleUnionBC {
|
|||||||
ProgressiveVarTestStruct(ProgressiveVarTestStruct),
|
ProgressiveVarTestStruct(ProgressiveVarTestStruct),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Decode, Encode, TreeHash, Deserialize)]
|
impl_compatible_union_deserialize!(CompatibleUnionBC, {
|
||||||
|
2 => ProgressiveSingleListContainerTestStruct(ProgressiveSingleListContainerTestStruct),
|
||||||
|
3 => ProgressiveVarTestStruct(ProgressiveVarTestStruct),
|
||||||
|
});
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Decode, Encode, TreeHash)]
|
||||||
#[ssz(enum_behaviour = "compatible_union")]
|
#[ssz(enum_behaviour = "compatible_union")]
|
||||||
#[tree_hash(enum_behaviour = "compatible_union")]
|
#[tree_hash(enum_behaviour = "compatible_union")]
|
||||||
#[context_deserialize(ForkName)]
|
#[context_deserialize(ForkName)]
|
||||||
@@ -460,6 +518,13 @@ enum CompatibleUnionABCA {
|
|||||||
A2(ProgressiveSingleFieldContainerTestStruct),
|
A2(ProgressiveSingleFieldContainerTestStruct),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl_compatible_union_deserialize!(CompatibleUnionABCA, {
|
||||||
|
1 => A1(ProgressiveSingleFieldContainerTestStruct),
|
||||||
|
2 => B1(ProgressiveSingleListContainerTestStruct),
|
||||||
|
3 => C1(ProgressiveVarTestStruct),
|
||||||
|
4 => A2(ProgressiveSingleFieldContainerTestStruct),
|
||||||
|
});
|
||||||
|
|
||||||
fn byte_list_from_hex_str<'de, D, N: Unsigned>(
|
fn byte_list_from_hex_str<'de, D, N: Unsigned>(
|
||||||
deserializer: D,
|
deserializer: D,
|
||||||
) -> Result<VariableList<u8, N>, D::Error>
|
) -> Result<VariableList<u8, N>, D::Error>
|
||||||
|
|||||||
@@ -1198,3 +1198,5 @@ pub struct Containers;
|
|||||||
type_name!(Containers, "containers");
|
type_name!(Containers, "containers");
|
||||||
pub struct ProgressiveContainers;
|
pub struct ProgressiveContainers;
|
||||||
type_name!(ProgressiveContainers, "progressive_containers");
|
type_name!(ProgressiveContainers, "progressive_containers");
|
||||||
|
pub struct CompatibleUnions;
|
||||||
|
type_name!(CompatibleUnions, "compatible_unions");
|
||||||
|
|||||||
@@ -856,6 +856,7 @@ fn ssz_generic_progressive() {
|
|||||||
SszGenericHandler::<BasicProgressiveList>::default().run();
|
SszGenericHandler::<BasicProgressiveList>::default().run();
|
||||||
SszGenericHandler::<ProgressiveBitlist>::default().run();
|
SszGenericHandler::<ProgressiveBitlist>::default().run();
|
||||||
SszGenericHandler::<ProgressiveContainers>::default().run();
|
SszGenericHandler::<ProgressiveContainers>::default().run();
|
||||||
|
SszGenericHandler::<CompatibleUnions>::default().run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in New Issue
Block a user