diff --git a/eth2/types/src/beacon_state/beacon_state_types.rs b/eth2/types/src/beacon_state/beacon_state_types.rs index b5ab93725..ec6eb68bc 100644 --- a/eth2/types/src/beacon_state/beacon_state_types.rs +++ b/eth2/types/src/beacon_state/beacon_state_types.rs @@ -3,9 +3,7 @@ use fixed_len_vec::typenum::{Unsigned, U1024, U8, U8192}; use serde_derive::{Deserialize, Serialize}; use std::fmt::Debug; -pub trait EthSpec: - 'static + Default + Sync + Send + Clone + Debug + PartialEq + serde::de::DeserializeOwned -{ +pub trait EthSpec: 'static + Default + Sync + Send + Clone + Debug + PartialEq { type ShardCount: Unsigned + Clone + Sync + Send + Debug + PartialEq; type SlotsPerHistoricalRoot: Unsigned + Clone + Sync + Send + Debug + PartialEq; type LatestRandaoMixesLength: Unsigned + Clone + Sync + Send + Debug + PartialEq; diff --git a/tests/ef_tests/eth2.0-spec-tests b/tests/ef_tests/eth2.0-spec-tests index 746712e8a..cfc6e3c91 160000 --- a/tests/ef_tests/eth2.0-spec-tests +++ b/tests/ef_tests/eth2.0-spec-tests @@ -1 +1 @@ -Subproject commit 746712e8a5c5b97d1bbc7724e5ccd09920c50a30 +Subproject commit cfc6e3c91d781f0dfe493ceb548391f5e88e54c7 diff --git a/tests/ef_tests/src/cases/epoch_processing_registry_updates.rs b/tests/ef_tests/src/cases/epoch_processing_registry_updates.rs index 17c2e8da7..d91a7a4c3 100644 --- a/tests/ef_tests/src/cases/epoch_processing_registry_updates.rs +++ b/tests/ef_tests/src/cases/epoch_processing_registry_updates.rs @@ -1,17 +1,14 @@ use super::*; use crate::case_result::compare_beacon_state_results_without_caches; use serde_derive::Deserialize; -use state_processing::per_block_processing::per_block_processing; use state_processing::per_epoch_processing::registry_updates::process_registry_updates; -use state_processing::per_slot_processing; -use types::{BeaconBlock, BeaconState, EthSpec}; +use types::{BeaconState, EthSpec}; #[derive(Debug, Clone, Deserialize)] pub struct EpochProcessingRegistryUpdates { pub description: String, #[serde(bound = "E: EthSpec")] pub pre: BeaconState, - pub trigger_block: BeaconBlock, #[serde(bound = "E: EthSpec")] pub post: Option>, } @@ -35,13 +32,6 @@ impl Case for EpochProcessingRegistryUpdates { // Processing requires the epoch cache. state.build_all_caches(spec).unwrap(); - // Apply the trigger block. - // FIXME: trigger block gets applied to state after per-epoch processing (test bug) - while state.slot < self.trigger_block.slot { - per_slot_processing(&mut state, spec).expect("slot processing failed"); - } - per_block_processing(&mut state, &self.trigger_block, spec).expect("process block"); - let mut result = process_registry_updates(&mut state, spec).map(|_| state); compare_beacon_state_results_without_caches(&mut result, &mut expected) diff --git a/tests/ef_tests/src/cases/ssz_static.rs b/tests/ef_tests/src/cases/ssz_static.rs index bef29a399..374b90bd2 100644 --- a/tests/ef_tests/src/cases/ssz_static.rs +++ b/tests/ef_tests/src/cases/ssz_static.rs @@ -14,76 +14,82 @@ use types::{ ProposerSlashing, Transfer, Validator, VoluntaryExit, }; +// Enum variant names are used by Serde when deserializing the test YAML #[derive(Debug, Clone, Deserialize)] -pub struct SszStatic { - pub type_name: String, +pub enum SszStatic +where + E: EthSpec, +{ + Fork(SszStaticInner), + Crosslink(SszStaticInner), + Eth1Data(SszStaticInner), + AttestationData(SszStaticInner), + AttestationDataAndCustodyBit(SszStaticInner), + IndexedAttestation(SszStaticInner), + DepositData(SszStaticInner), + BeaconBlockHeader(SszStaticInner), + Validator(SszStaticInner), + PendingAttestation(SszStaticInner), + HistoricalBatch(SszStaticInner, E>), + ProposerSlashing(SszStaticInner), + AttesterSlashing(SszStaticInner), + Attestation(SszStaticInner), + Deposit(SszStaticInner), + VoluntaryExit(SszStaticInner), + Transfer(SszStaticInner), + BeaconBlockBody(SszStaticInner), + BeaconBlock(SszStaticInner), + BeaconState(SszStaticInner, E>), +} + +#[derive(Debug, Clone, Deserialize)] +pub struct SszStaticInner +where + E: EthSpec, +{ + pub value: T, pub serialized: String, pub root: String, - #[serde(skip)] - pub raw_yaml: String, #[serde(skip, default)] _phantom: PhantomData, } -#[derive(Debug, Clone, Deserialize)] -pub struct Value { - value: T, -} - -impl YamlDecode for SszStatic { +impl YamlDecode for SszStatic { fn yaml_decode(yaml: &String) -> Result { - let mut ssz_static: SszStatic = serde_yaml::from_str(&yaml.as_str()).unwrap(); - - ssz_static.raw_yaml = yaml.clone(); - - Ok(ssz_static) - } -} - -impl SszStatic { - fn value(&self) -> Result { - let wrapper: Value = serde_yaml::from_str(&self.raw_yaml.as_str()).map_err(|e| { - Error::FailedToParseTest(format!("Unable to parse {} YAML: {:?}", self.type_name, e)) - })?; - - Ok(wrapper.value) + serde_yaml::from_str(yaml).map_err(|e| Error::FailedToParseTest(format!("{:?}", e))) } } impl Case for SszStatic { fn result(&self, _case_index: usize) -> Result<(), Error> { - match self.type_name.as_ref() { - "Fork" => ssz_static_test::(self), - "Crosslink" => ssz_static_test::(self), - "Eth1Data" => ssz_static_test::(self), - "AttestationData" => ssz_static_test::(self), - "AttestationDataAndCustodyBit" => { - ssz_static_test::(self) - } - "IndexedAttestation" => ssz_static_test::(self), - "DepositData" => ssz_static_test::(self), - "BeaconBlockHeader" => ssz_static_test::(self), - "Validator" => ssz_static_test::(self), - "PendingAttestation" => ssz_static_test::(self), - "HistoricalBatch" => ssz_static_test::, E>(self), - "ProposerSlashing" => ssz_static_test::(self), - "AttesterSlashing" => ssz_static_test::(self), - "Attestation" => ssz_static_test::(self), - "Deposit" => ssz_static_test::(self), - "VoluntaryExit" => ssz_static_test::(self), - "Transfer" => ssz_static_test::(self), - "BeaconBlockBody" => ssz_static_test::(self), - "BeaconBlock" => ssz_static_test::(self), - "BeaconState" => ssz_static_test::, E>(self), - _ => Err(Error::FailedToParseTest(format!( - "Unknown type: {}", - self.type_name - ))), + use self::SszStatic::*; + + match *self { + Fork(ref val) => ssz_static_test(val), + Crosslink(ref val) => ssz_static_test(val), + Eth1Data(ref val) => ssz_static_test(val), + AttestationData(ref val) => ssz_static_test(val), + AttestationDataAndCustodyBit(ref val) => ssz_static_test(val), + IndexedAttestation(ref val) => ssz_static_test(val), + DepositData(ref val) => ssz_static_test(val), + BeaconBlockHeader(ref val) => ssz_static_test(val), + Validator(ref val) => ssz_static_test(val), + PendingAttestation(ref val) => ssz_static_test(val), + HistoricalBatch(ref val) => ssz_static_test(val), + ProposerSlashing(ref val) => ssz_static_test(val), + AttesterSlashing(ref val) => ssz_static_test(val), + Attestation(ref val) => ssz_static_test(val), + Deposit(ref val) => ssz_static_test(val), + VoluntaryExit(ref val) => ssz_static_test(val), + Transfer(ref val) => ssz_static_test(val), + BeaconBlockBody(ref val) => ssz_static_test(val), + BeaconBlock(ref val) => ssz_static_test(val), + BeaconState(ref val) => ssz_static_test(val), } } } -fn ssz_static_test(tc: &SszStatic) -> Result<(), Error> +fn ssz_static_test(tc: &SszStaticInner) -> Result<(), Error> where T: Clone + Decode @@ -98,7 +104,7 @@ where // Verify we can decode SSZ in the same way we can decode YAML. let ssz = hex::decode(&tc.serialized[2..]) .map_err(|e| Error::FailedToParseTest(format!("{:?}", e)))?; - let expected = tc.value::()?; + let expected = tc.value.clone(); let decode_result = T::from_ssz_bytes(&ssz); compare_result(&decode_result, &Some(expected))?; diff --git a/tests/ef_tests/src/doc.rs b/tests/ef_tests/src/doc.rs index 67888fc84..f69d1f998 100644 --- a/tests/ef_tests/src/doc.rs +++ b/tests/ef_tests/src/doc.rs @@ -86,6 +86,9 @@ impl Doc { ("epoch_processing", "crosslinks", "minimal") => { run_test::>(self) } + ("epoch_processing", "crosslinks", "mainnet") => { + run_test::>(self) + } ("epoch_processing", "registry_updates", "minimal") => { run_test::>(self) }