state transitions tests: check more fields

This commit is contained in:
Michael Sproul 2019-04-03 17:14:11 +11:00
parent b21cc64949
commit 19fad1012f
No known key found for this signature in database
GPG Key ID: 77B1309D2E54E914
3 changed files with 28 additions and 8 deletions

View File

@ -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<Fork>,
pub validator_registry: Option<Vec<Validator>>,
pub validator_balances: Option<Vec<u64>>,
pub previous_epoch_attestations: Option<Vec<PendingAttestation>>,
pub current_epoch_attestations: Option<Vec<PendingAttestation>>,
pub historical_roots: Option<Vec<Hash256>>,
pub finalized_epoch: Option<Epoch>,
pub latest_block_roots: Option<Vec<Hash256>>,
}
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);

View File

@ -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)

View File

@ -81,7 +81,7 @@ pub struct BeaconState {
// Recent state
pub latest_crosslinks: TreeHashVector<Crosslink>,
latest_block_roots: TreeHashVector<Hash256>,
pub latest_block_roots: TreeHashVector<Hash256>,
latest_state_roots: TreeHashVector<Hash256>,
latest_active_index_roots: TreeHashVector<Hash256>,
latest_slashed_balances: TreeHashVector<u64>,