v0.6.2: update test infrastructure
This commit is contained in:
		
							parent
							
								
									37c67117d3
								
							
						
					
					
						commit
						beacf42aaf
					
				| @ -3,9 +3,7 @@ use fixed_len_vec::typenum::{Unsigned, U1024, U8, U8192}; | |||||||
| use serde_derive::{Deserialize, Serialize}; | use serde_derive::{Deserialize, Serialize}; | ||||||
| use std::fmt::Debug; | use std::fmt::Debug; | ||||||
| 
 | 
 | ||||||
| pub trait EthSpec: | pub trait EthSpec: 'static + Default + Sync + Send + Clone + Debug + PartialEq { | ||||||
|     'static + Default + Sync + Send + Clone + Debug + PartialEq + serde::de::DeserializeOwned |  | ||||||
| { |  | ||||||
|     type ShardCount: Unsigned + Clone + Sync + Send + Debug + PartialEq; |     type ShardCount: Unsigned + Clone + Sync + Send + Debug + PartialEq; | ||||||
|     type SlotsPerHistoricalRoot: Unsigned + Clone + Sync + Send + Debug + PartialEq; |     type SlotsPerHistoricalRoot: Unsigned + Clone + Sync + Send + Debug + PartialEq; | ||||||
|     type LatestRandaoMixesLength: Unsigned + Clone + Sync + Send + Debug + PartialEq; |     type LatestRandaoMixesLength: Unsigned + Clone + Sync + Send + Debug + PartialEq; | ||||||
|  | |||||||
| @ -1 +1 @@ | |||||||
| Subproject commit 746712e8a5c5b97d1bbc7724e5ccd09920c50a30 | Subproject commit cfc6e3c91d781f0dfe493ceb548391f5e88e54c7 | ||||||
| @ -1,17 +1,14 @@ | |||||||
| use super::*; | use super::*; | ||||||
| use crate::case_result::compare_beacon_state_results_without_caches; | use crate::case_result::compare_beacon_state_results_without_caches; | ||||||
| use serde_derive::Deserialize; | 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_epoch_processing::registry_updates::process_registry_updates; | ||||||
| use state_processing::per_slot_processing; | use types::{BeaconState, EthSpec}; | ||||||
| use types::{BeaconBlock, BeaconState, EthSpec}; |  | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, Clone, Deserialize)] | #[derive(Debug, Clone, Deserialize)] | ||||||
| pub struct EpochProcessingRegistryUpdates<E: EthSpec> { | pub struct EpochProcessingRegistryUpdates<E: EthSpec> { | ||||||
|     pub description: String, |     pub description: String, | ||||||
|     #[serde(bound = "E: EthSpec")] |     #[serde(bound = "E: EthSpec")] | ||||||
|     pub pre: BeaconState<E>, |     pub pre: BeaconState<E>, | ||||||
|     pub trigger_block: BeaconBlock, |  | ||||||
|     #[serde(bound = "E: EthSpec")] |     #[serde(bound = "E: EthSpec")] | ||||||
|     pub post: Option<BeaconState<E>>, |     pub post: Option<BeaconState<E>>, | ||||||
| } | } | ||||||
| @ -35,13 +32,6 @@ impl<E: EthSpec> Case for EpochProcessingRegistryUpdates<E> { | |||||||
|         // Processing requires the epoch cache.
 |         // Processing requires the epoch cache.
 | ||||||
|         state.build_all_caches(spec).unwrap(); |         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); |         let mut result = process_registry_updates(&mut state, spec).map(|_| state); | ||||||
| 
 | 
 | ||||||
|         compare_beacon_state_results_without_caches(&mut result, &mut expected) |         compare_beacon_state_results_without_caches(&mut result, &mut expected) | ||||||
|  | |||||||
| @ -14,76 +14,82 @@ use types::{ | |||||||
|     ProposerSlashing, Transfer, Validator, VoluntaryExit, |     ProposerSlashing, Transfer, Validator, VoluntaryExit, | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | // Enum variant names are used by Serde when deserializing the test YAML
 | ||||||
| #[derive(Debug, Clone, Deserialize)] | #[derive(Debug, Clone, Deserialize)] | ||||||
| pub struct SszStatic<E> { | pub enum SszStatic<E> | ||||||
|     pub type_name: String, | where | ||||||
|  |     E: EthSpec, | ||||||
|  | { | ||||||
|  |     Fork(SszStaticInner<Fork, E>), | ||||||
|  |     Crosslink(SszStaticInner<Crosslink, E>), | ||||||
|  |     Eth1Data(SszStaticInner<Eth1Data, E>), | ||||||
|  |     AttestationData(SszStaticInner<AttestationData, E>), | ||||||
|  |     AttestationDataAndCustodyBit(SszStaticInner<AttestationDataAndCustodyBit, E>), | ||||||
|  |     IndexedAttestation(SszStaticInner<IndexedAttestation, E>), | ||||||
|  |     DepositData(SszStaticInner<DepositData, E>), | ||||||
|  |     BeaconBlockHeader(SszStaticInner<BeaconBlockHeader, E>), | ||||||
|  |     Validator(SszStaticInner<Validator, E>), | ||||||
|  |     PendingAttestation(SszStaticInner<PendingAttestation, E>), | ||||||
|  |     HistoricalBatch(SszStaticInner<HistoricalBatch<E>, E>), | ||||||
|  |     ProposerSlashing(SszStaticInner<ProposerSlashing, E>), | ||||||
|  |     AttesterSlashing(SszStaticInner<AttesterSlashing, E>), | ||||||
|  |     Attestation(SszStaticInner<Attestation, E>), | ||||||
|  |     Deposit(SszStaticInner<Deposit, E>), | ||||||
|  |     VoluntaryExit(SszStaticInner<VoluntaryExit, E>), | ||||||
|  |     Transfer(SszStaticInner<Transfer, E>), | ||||||
|  |     BeaconBlockBody(SszStaticInner<BeaconBlockBody, E>), | ||||||
|  |     BeaconBlock(SszStaticInner<BeaconBlock, E>), | ||||||
|  |     BeaconState(SszStaticInner<BeaconState<E>, E>), | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | #[derive(Debug, Clone, Deserialize)] | ||||||
|  | pub struct SszStaticInner<T, E> | ||||||
|  | where | ||||||
|  |     E: EthSpec, | ||||||
|  | { | ||||||
|  |     pub value: T, | ||||||
|     pub serialized: String, |     pub serialized: String, | ||||||
|     pub root: String, |     pub root: String, | ||||||
|     #[serde(skip)] |  | ||||||
|     pub raw_yaml: String, |  | ||||||
|     #[serde(skip, default)] |     #[serde(skip, default)] | ||||||
|     _phantom: PhantomData<E>, |     _phantom: PhantomData<E>, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, Clone, Deserialize)] | impl<E: EthSpec + serde::de::DeserializeOwned> YamlDecode for SszStatic<E> { | ||||||
| pub struct Value<T> { |  | ||||||
|     value: T, |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| impl<E> YamlDecode for SszStatic<E> { |  | ||||||
|     fn yaml_decode(yaml: &String) -> Result<Self, Error> { |     fn yaml_decode(yaml: &String) -> Result<Self, Error> { | ||||||
|         let mut ssz_static: SszStatic<E> = serde_yaml::from_str(&yaml.as_str()).unwrap(); |         serde_yaml::from_str(yaml).map_err(|e| Error::FailedToParseTest(format!("{:?}", e))) | ||||||
| 
 |  | ||||||
|         ssz_static.raw_yaml = yaml.clone(); |  | ||||||
| 
 |  | ||||||
|         Ok(ssz_static) |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| impl<E> SszStatic<E> { |  | ||||||
|     fn value<T: serde::de::DeserializeOwned>(&self) -> Result<T, Error> { |  | ||||||
|         let wrapper: Value<T> = 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) |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl<E: EthSpec> Case for SszStatic<E> { | impl<E: EthSpec> Case for SszStatic<E> { | ||||||
|     fn result(&self, _case_index: usize) -> Result<(), Error> { |     fn result(&self, _case_index: usize) -> Result<(), Error> { | ||||||
|         match self.type_name.as_ref() { |         use self::SszStatic::*; | ||||||
|             "Fork" => ssz_static_test::<Fork, E>(self), | 
 | ||||||
|             "Crosslink" => ssz_static_test::<Crosslink, E>(self), |         match *self { | ||||||
|             "Eth1Data" => ssz_static_test::<Eth1Data, E>(self), |             Fork(ref val) => ssz_static_test(val), | ||||||
|             "AttestationData" => ssz_static_test::<AttestationData, E>(self), |             Crosslink(ref val) => ssz_static_test(val), | ||||||
|             "AttestationDataAndCustodyBit" => { |             Eth1Data(ref val) => ssz_static_test(val), | ||||||
|                 ssz_static_test::<AttestationDataAndCustodyBit, E>(self) |             AttestationData(ref val) => ssz_static_test(val), | ||||||
|             } |             AttestationDataAndCustodyBit(ref val) => ssz_static_test(val), | ||||||
|             "IndexedAttestation" => ssz_static_test::<IndexedAttestation, E>(self), |             IndexedAttestation(ref val) => ssz_static_test(val), | ||||||
|             "DepositData" => ssz_static_test::<DepositData, E>(self), |             DepositData(ref val) => ssz_static_test(val), | ||||||
|             "BeaconBlockHeader" => ssz_static_test::<BeaconBlockHeader, E>(self), |             BeaconBlockHeader(ref val) => ssz_static_test(val), | ||||||
|             "Validator" => ssz_static_test::<Validator, E>(self), |             Validator(ref val) => ssz_static_test(val), | ||||||
|             "PendingAttestation" => ssz_static_test::<PendingAttestation, E>(self), |             PendingAttestation(ref val) => ssz_static_test(val), | ||||||
|             "HistoricalBatch" => ssz_static_test::<HistoricalBatch<E>, E>(self), |             HistoricalBatch(ref val) => ssz_static_test(val), | ||||||
|             "ProposerSlashing" => ssz_static_test::<ProposerSlashing, E>(self), |             ProposerSlashing(ref val) => ssz_static_test(val), | ||||||
|             "AttesterSlashing" => ssz_static_test::<AttesterSlashing, E>(self), |             AttesterSlashing(ref val) => ssz_static_test(val), | ||||||
|             "Attestation" => ssz_static_test::<Attestation, E>(self), |             Attestation(ref val) => ssz_static_test(val), | ||||||
|             "Deposit" => ssz_static_test::<Deposit, E>(self), |             Deposit(ref val) => ssz_static_test(val), | ||||||
|             "VoluntaryExit" => ssz_static_test::<VoluntaryExit, E>(self), |             VoluntaryExit(ref val) => ssz_static_test(val), | ||||||
|             "Transfer" => ssz_static_test::<Transfer, E>(self), |             Transfer(ref val) => ssz_static_test(val), | ||||||
|             "BeaconBlockBody" => ssz_static_test::<BeaconBlockBody, E>(self), |             BeaconBlockBody(ref val) => ssz_static_test(val), | ||||||
|             "BeaconBlock" => ssz_static_test::<BeaconBlock, E>(self), |             BeaconBlock(ref val) => ssz_static_test(val), | ||||||
|             "BeaconState" => ssz_static_test::<BeaconState<E>, E>(self), |             BeaconState(ref val) => ssz_static_test(val), | ||||||
|             _ => Err(Error::FailedToParseTest(format!( |  | ||||||
|                 "Unknown type: {}", |  | ||||||
|                 self.type_name |  | ||||||
|             ))), |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| fn ssz_static_test<T, E: EthSpec>(tc: &SszStatic<E>) -> Result<(), Error> | fn ssz_static_test<T, E: EthSpec>(tc: &SszStaticInner<T, E>) -> Result<(), Error> | ||||||
| where | where | ||||||
|     T: Clone |     T: Clone | ||||||
|         + Decode |         + Decode | ||||||
| @ -98,7 +104,7 @@ where | |||||||
|     // Verify we can decode SSZ in the same way we can decode YAML.
 |     // Verify we can decode SSZ in the same way we can decode YAML.
 | ||||||
|     let ssz = hex::decode(&tc.serialized[2..]) |     let ssz = hex::decode(&tc.serialized[2..]) | ||||||
|         .map_err(|e| Error::FailedToParseTest(format!("{:?}", e)))?; |         .map_err(|e| Error::FailedToParseTest(format!("{:?}", e)))?; | ||||||
|     let expected = tc.value::<T>()?; |     let expected = tc.value.clone(); | ||||||
|     let decode_result = T::from_ssz_bytes(&ssz); |     let decode_result = T::from_ssz_bytes(&ssz); | ||||||
|     compare_result(&decode_result, &Some(expected))?; |     compare_result(&decode_result, &Some(expected))?; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -86,6 +86,9 @@ impl Doc { | |||||||
|             ("epoch_processing", "crosslinks", "minimal") => { |             ("epoch_processing", "crosslinks", "minimal") => { | ||||||
|                 run_test::<EpochProcessingCrosslinks<MinimalEthSpec>>(self) |                 run_test::<EpochProcessingCrosslinks<MinimalEthSpec>>(self) | ||||||
|             } |             } | ||||||
|  |             ("epoch_processing", "crosslinks", "mainnet") => { | ||||||
|  |                 run_test::<EpochProcessingCrosslinks<MainnetEthSpec>>(self) | ||||||
|  |             } | ||||||
|             ("epoch_processing", "registry_updates", "minimal") => { |             ("epoch_processing", "registry_updates", "minimal") => { | ||||||
|                 run_test::<EpochProcessingRegistryUpdates<MinimalEthSpec>>(self) |                 run_test::<EpochProcessingRegistryUpdates<MinimalEthSpec>>(self) | ||||||
|             } |             } | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user