2019-02-28 12:13:00 +00:00
|
|
|
use clap::{App, Arg};
|
|
|
|
use env_logger::{Builder, Env};
|
|
|
|
use std::{fs::File, io::prelude::*};
|
2019-03-03 04:12:19 +00:00
|
|
|
use test_case::TestCase;
|
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-03 04:12:19 +00:00
|
|
|
mod test_case;
|
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>")
|
2019-03-03 04:12:19 +00:00
|
|
|
.about("Runs `test_harness` using a YAML test_case.")
|
2019-02-28 12:13:00 +00:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("yaml")
|
|
|
|
.long("yaml")
|
|
|
|
.value_name("FILE")
|
2019-03-03 04:12:19 +00:00
|
|
|
.help("YAML file test_case.")
|
2019-02-28 12:13:00 +00:00
|
|
|
.required(true),
|
|
|
|
)
|
2019-03-03 05:15:00 +00:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("log")
|
|
|
|
.long("log-level")
|
|
|
|
.value_name("LOG_LEVEL")
|
|
|
|
.help("Logging level.")
|
|
|
|
.possible_values(&["error", "warn", "info", "debug", "trace"])
|
|
|
|
.default_value("debug")
|
|
|
|
.required(true),
|
|
|
|
)
|
2019-02-28 12:13:00 +00:00
|
|
|
.get_matches();
|
|
|
|
|
2019-03-03 05:15:00 +00:00
|
|
|
if let Some(log_level) = matches.value_of("log") {
|
|
|
|
Builder::from_env(Env::default().default_filter_or(log_level)).init();
|
|
|
|
}
|
2019-02-28 12:13:00 +00:00
|
|
|
|
|
|
|
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:12:19 +00:00
|
|
|
// For each `test_cases` YAML in the document, build a `TestCase`, execute it and
|
|
|
|
// assert that the execution result matches the test_case description.
|
2019-03-03 04:07:54 +00:00
|
|
|
//
|
|
|
|
// In effect, for each `test_case` a new `BeaconChainHarness` is created from genesis
|
2019-03-03 04:12:19 +00:00
|
|
|
// and a new `BeaconChain` is built as per the test_case.
|
2019-03-03 04:07:54 +00:00
|
|
|
//
|
2019-03-03 04:12:19 +00:00
|
|
|
// After the `BeaconChain` has been built out as per the test_case, a dump of all blocks
|
2019-03-03 04:07:54 +00:00
|
|
|
// 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() {
|
2019-03-03 04:12:19 +00:00
|
|
|
let test_case = TestCase::from_yaml(test_case);
|
|
|
|
test_case.assert_result_valid(test_case.execute())
|
2019-02-28 12:13:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|