diff --git a/eth2/state_processing/tests/tests.rs b/eth2/state_processing/tests/tests.rs index 193511852..54fd6bf8d 100644 --- a/eth2/state_processing/tests/tests.rs +++ b/eth2/state_processing/tests/tests.rs @@ -1,14 +1,9 @@ use serde_derive::Deserialize; use serde_yaml; #[cfg(not(debug_assertions))] -use state_processing::{ - per_block_processing, per_block_processing_without_verifying_block_signature, - per_slot_processing, -}; +use state_processing::{per_block_processing, per_slot_processing}; use std::{fs::File, io::prelude::*, path::PathBuf}; use types::*; -#[allow(unused_imports)] -use yaml_utils; #[derive(Debug, Deserialize)] pub struct ExpectedState { @@ -17,6 +12,11 @@ pub struct ExpectedState { pub fork: Option, pub validator_registry: Option>, pub validator_balances: Option>, + pub previous_epoch_attestations: Option>, + pub current_epoch_attestations: Option>, + pub historical_roots: Option>, + pub finalized_epoch: Option, + pub latest_block_roots: Option>, } impl ExpectedState { @@ -42,6 +42,11 @@ impl ExpectedState { cfe!(fork), cfe!(validator_registry), cfe!(validator_balances), + cfe!(previous_epoch_attestations), + cfe!(current_epoch_attestations), + cfe!(historical_roots), + cfe!(finalized_epoch), + cfe!(latest_block_roots), ] .into_iter() .flat_map(|x| x) @@ -108,7 +113,7 @@ fn run_state_transition_test(test_name: &str) { println!("Error in {} (#{}), on block {}", test_case.name, i, j); println!("{:?}", res); ok = false; - }; + } } let mismatched_fields = test_case.expected_state.check(&state); diff --git a/eth2/state_processing/yaml_utils/expected_state_fields.py b/eth2/state_processing/yaml_utils/expected_state_fields.py new file mode 100755 index 000000000..df4cb83f7 --- /dev/null +++ b/eth2/state_processing/yaml_utils/expected_state_fields.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python3 + +# Script to extract all the fields of the state mentioned in `expected_state` fields of tests +# in the `spec` directory. These fields can then be added to the `ExpectedState` struct. +# Might take a while to run. + +import os, yaml + +if __name__ == "__main__": + yaml_files = (filename for filename in os.listdir("specs") if filename.endswith(".yaml")) + parsed_yaml = (yaml.load(open("specs/" + filename, "r")) for filename in yaml_files) + all_fields = set() + for y in parsed_yaml: + all_fields.update(*({key for key in case["expected_state"]} for case in y["test_cases"])) + print(all_fields) diff --git a/eth2/types/src/beacon_state.rs b/eth2/types/src/beacon_state.rs index c068c4e03..0461e947b 100644 --- a/eth2/types/src/beacon_state.rs +++ b/eth2/types/src/beacon_state.rs @@ -81,7 +81,7 @@ pub struct BeaconState { // Recent state pub latest_crosslinks: TreeHashVector, - latest_block_roots: TreeHashVector, + pub latest_block_roots: TreeHashVector, latest_state_roots: TreeHashVector, latest_active_index_roots: TreeHashVector, latest_slashed_balances: TreeHashVector,