2019-02-28 12:13:00 +00:00
|
|
|
use clap::{App, Arg};
|
|
|
|
use env_logger::{Builder, Env};
|
2019-03-02 07:59:47 +00:00
|
|
|
use manifest::Manifest;
|
2019-02-28 12:13:00 +00:00
|
|
|
use std::{fs::File, io::prelude::*};
|
2019-03-02 07:59:47 +00:00
|
|
|
use yaml_rust::YamlLoader;
|
2019-02-28 12:13:00 +00:00
|
|
|
|
|
|
|
mod beacon_chain_harness;
|
2019-03-02 07:59:47 +00:00
|
|
|
mod manifest;
|
2019-02-28 12:13:00 +00:00
|
|
|
mod validator_harness;
|
|
|
|
|
2019-03-02 07:59:47 +00:00
|
|
|
use validator_harness::ValidatorHarness;
|
|
|
|
|
2019-02-28 12:13:00 +00:00
|
|
|
fn main() {
|
|
|
|
let matches = App::new("Lighthouse Test Harness Runner")
|
|
|
|
.version("0.0.1")
|
|
|
|
.author("Sigma Prime <contact@sigmaprime.io>")
|
|
|
|
.about("Runs `test_harness` using a YAML manifest.")
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("yaml")
|
|
|
|
.long("yaml")
|
|
|
|
.value_name("FILE")
|
|
|
|
.help("YAML file manifest.")
|
|
|
|
.required(true),
|
|
|
|
)
|
|
|
|
.get_matches();
|
|
|
|
|
|
|
|
Builder::from_env(Env::default().default_filter_or("debug")).init();
|
|
|
|
|
|
|
|
if let Some(yaml_file) = matches.value_of("yaml") {
|
|
|
|
let docs = {
|
|
|
|
let mut file = File::open(yaml_file).unwrap();
|
|
|
|
|
|
|
|
let mut yaml_str = String::new();
|
|
|
|
file.read_to_string(&mut yaml_str).unwrap();
|
|
|
|
|
|
|
|
YamlLoader::load_from_str(&yaml_str).unwrap()
|
|
|
|
};
|
|
|
|
|
|
|
|
for doc in &docs {
|
2019-03-03 04:07:54 +00:00
|
|
|
// For each `test_cases` YAML in the document, build a `Manifest`, execute it and
|
|
|
|
// assert that the execution result matches the manifest description.
|
|
|
|
//
|
|
|
|
// In effect, for each `test_case` a new `BeaconChainHarness` is created from genesis
|
|
|
|
// and a new `BeaconChain` is built as per the manifest.
|
|
|
|
//
|
|
|
|
// After the `BeaconChain` has been built out as per the manifest, a dump of all blocks
|
|
|
|
// and states in the chain is obtained and checked against the `results` specified in
|
|
|
|
// the `test_case`.
|
|
|
|
//
|
|
|
|
// If any of the expectations in the results are not met, the process
|
|
|
|
// panics with a message.
|
2019-02-28 12:13:00 +00:00
|
|
|
for test_case in doc["test_cases"].as_vec().unwrap() {
|
|
|
|
let manifest = Manifest::from_yaml(test_case);
|
2019-03-01 02:28:07 +00:00
|
|
|
manifest.assert_result_valid(manifest.execute())
|
2019-02-28 12:13:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|