2019-05-15 01:41:25 +00:00
|
|
|
use crate::case_result::CaseResult;
|
|
|
|
use crate::cases::*;
|
|
|
|
use crate::doc_header::DocHeader;
|
2019-05-15 05:08:48 +00:00
|
|
|
use crate::eth_specs::{MainnetEthSpec, MinimalEthSpec};
|
2019-05-22 05:34:12 +00:00
|
|
|
use crate::yaml_decode::{yaml_split_header_and_cases, YamlDecode};
|
2019-05-15 01:41:25 +00:00
|
|
|
use crate::EfTest;
|
|
|
|
use serde_derive::Deserialize;
|
2019-05-14 01:13:28 +00:00
|
|
|
use std::{fs::File, io::prelude::*, path::PathBuf};
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize)]
|
2019-05-15 01:15:34 +00:00
|
|
|
pub struct Doc {
|
2019-05-15 07:14:28 +00:00
|
|
|
pub header_yaml: String,
|
|
|
|
pub cases_yaml: String,
|
2019-05-15 02:30:42 +00:00
|
|
|
pub path: PathBuf,
|
2019-05-14 01:13:28 +00:00
|
|
|
}
|
|
|
|
|
2019-05-15 01:15:34 +00:00
|
|
|
impl Doc {
|
2019-05-14 05:08:42 +00:00
|
|
|
fn from_path(path: PathBuf) -> Self {
|
2019-05-15 02:30:42 +00:00
|
|
|
let mut file = File::open(path.clone()).unwrap();
|
2019-05-14 01:13:28 +00:00
|
|
|
|
|
|
|
let mut yaml = String::new();
|
|
|
|
file.read_to_string(&mut yaml).unwrap();
|
|
|
|
|
2019-05-15 07:14:28 +00:00
|
|
|
let (header_yaml, cases_yaml) = yaml_split_header_and_cases(yaml.clone());
|
|
|
|
|
|
|
|
Self {
|
|
|
|
header_yaml,
|
|
|
|
cases_yaml,
|
|
|
|
path,
|
|
|
|
}
|
2019-05-14 01:13:28 +00:00
|
|
|
}
|
|
|
|
|
2019-05-15 02:30:42 +00:00
|
|
|
pub fn test_results(&self) -> Vec<CaseResult> {
|
2019-05-15 07:14:28 +00:00
|
|
|
let header: DocHeader = serde_yaml::from_str(&self.header_yaml.as_str()).unwrap();
|
2019-05-14 01:13:28 +00:00
|
|
|
|
2019-05-14 05:08:42 +00:00
|
|
|
match (
|
|
|
|
header.runner.as_ref(),
|
|
|
|
header.handler.as_ref(),
|
|
|
|
header.config.as_ref(),
|
|
|
|
) {
|
2019-05-22 06:15:52 +00:00
|
|
|
("ssz", "uint", _) => run_test::<SszGeneric>(self),
|
|
|
|
("ssz", "static", "minimal") => run_test::<SszStatic<MinimalEthSpec>>(self),
|
|
|
|
("ssz", "static", "mainnet") => run_test::<SszStatic<MainnetEthSpec>>(self),
|
2019-06-04 06:35:33 +00:00
|
|
|
("sanity", "slots", "minimal") => run_test::<SanitySlots<MinimalEthSpec>>(self),
|
|
|
|
("sanity", "slots", "mainnet") => run_test::<SanitySlots<MainnetEthSpec>>(self),
|
2019-05-23 13:22:54 +00:00
|
|
|
("shuffling", "core", "minimal") => run_test::<Shuffling<MinimalEthSpec>>(self),
|
|
|
|
("shuffling", "core", "mainnet") => run_test::<Shuffling<MainnetEthSpec>>(self),
|
2019-05-22 06:15:52 +00:00
|
|
|
("bls", "aggregate_pubkeys", "mainnet") => run_test::<BlsAggregatePubkeys>(self),
|
|
|
|
("bls", "aggregate_sigs", "mainnet") => run_test::<BlsAggregateSigs>(self),
|
|
|
|
("bls", "msg_hash_compressed", "mainnet") => run_test::<BlsG2Compressed>(self),
|
2019-05-22 04:18:48 +00:00
|
|
|
// Note this test fails due to a difference in our internal representations. It does
|
|
|
|
// not effect verification or external representation.
|
|
|
|
//
|
|
|
|
// It is skipped.
|
|
|
|
("bls", "msg_hash_uncompressed", "mainnet") => vec![],
|
2019-05-22 06:15:52 +00:00
|
|
|
("bls", "priv_to_pub", "mainnet") => run_test::<BlsPrivToPub>(self),
|
|
|
|
("bls", "sign_msg", "mainnet") => run_test::<BlsSign>(self),
|
2019-05-22 05:34:12 +00:00
|
|
|
("operations", "deposit", "mainnet") => {
|
2019-05-22 06:15:52 +00:00
|
|
|
run_test::<OperationsDeposit<MainnetEthSpec>>(self)
|
2019-05-22 05:34:12 +00:00
|
|
|
}
|
|
|
|
("operations", "deposit", "minimal") => {
|
2019-05-22 06:15:52 +00:00
|
|
|
run_test::<OperationsDeposit<MinimalEthSpec>>(self)
|
2019-05-22 05:34:12 +00:00
|
|
|
}
|
2019-05-22 22:48:09 +00:00
|
|
|
("operations", "transfer", "mainnet") => {
|
|
|
|
run_test::<OperationsTransfer<MainnetEthSpec>>(self)
|
|
|
|
}
|
|
|
|
("operations", "transfer", "minimal") => {
|
|
|
|
run_test::<OperationsTransfer<MinimalEthSpec>>(self)
|
|
|
|
}
|
2019-05-23 00:11:15 +00:00
|
|
|
("operations", "voluntary_exit", "mainnet") => {
|
|
|
|
run_test::<OperationsExit<MainnetEthSpec>>(self)
|
|
|
|
}
|
|
|
|
("operations", "voluntary_exit", "minimal") => {
|
|
|
|
run_test::<OperationsExit<MinimalEthSpec>>(self)
|
|
|
|
}
|
2019-05-23 14:15:12 +00:00
|
|
|
("operations", "proposer_slashing", "mainnet") => {
|
|
|
|
run_test::<OperationsProposerSlashing<MainnetEthSpec>>(self)
|
|
|
|
}
|
|
|
|
("operations", "proposer_slashing", "minimal") => {
|
|
|
|
run_test::<OperationsProposerSlashing<MinimalEthSpec>>(self)
|
|
|
|
}
|
2019-05-24 03:57:44 +00:00
|
|
|
("operations", "attester_slashing", "mainnet") => {
|
|
|
|
run_test::<OperationsAttesterSlashing<MainnetEthSpec>>(self)
|
|
|
|
}
|
|
|
|
("operations", "attester_slashing", "minimal") => {
|
|
|
|
run_test::<OperationsAttesterSlashing<MinimalEthSpec>>(self)
|
|
|
|
}
|
2019-06-04 01:05:35 +00:00
|
|
|
("operations", "attestation", "mainnet") => {
|
|
|
|
run_test::<OperationsAttestation<MainnetEthSpec>>(self)
|
|
|
|
}
|
|
|
|
("operations", "attestation", "minimal") => {
|
|
|
|
run_test::<OperationsAttestation<MinimalEthSpec>>(self)
|
|
|
|
}
|
2019-06-04 06:35:33 +00:00
|
|
|
("operations", "block_header", "mainnet") => {
|
|
|
|
run_test::<OperationsBlockHeader<MainnetEthSpec>>(self)
|
|
|
|
}
|
|
|
|
("operations", "block_header", "minimal") => {
|
|
|
|
run_test::<OperationsBlockHeader<MinimalEthSpec>>(self)
|
|
|
|
}
|
2019-05-28 06:03:26 +00:00
|
|
|
("epoch_processing", "crosslinks", "minimal") => {
|
|
|
|
run_test::<EpochProcessingCrosslinks<MinimalEthSpec>>(self)
|
|
|
|
}
|
2019-05-29 05:31:34 +00:00
|
|
|
("epoch_processing", "crosslinks", "mainnet") => {
|
|
|
|
run_test::<EpochProcessingCrosslinks<MainnetEthSpec>>(self)
|
|
|
|
}
|
2019-05-28 06:03:26 +00:00
|
|
|
("epoch_processing", "registry_updates", "minimal") => {
|
|
|
|
run_test::<EpochProcessingRegistryUpdates<MinimalEthSpec>>(self)
|
|
|
|
}
|
|
|
|
("epoch_processing", "registry_updates", "mainnet") => {
|
|
|
|
run_test::<EpochProcessingRegistryUpdates<MainnetEthSpec>>(self)
|
|
|
|
}
|
2019-05-14 05:08:42 +00:00
|
|
|
(runner, handler, config) => panic!(
|
|
|
|
"No implementation for runner: \"{}\", handler: \"{}\", config: \"{}\"",
|
|
|
|
runner, handler, config
|
2019-05-14 01:13:28 +00:00
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn assert_tests_pass(path: PathBuf) {
|
2019-05-15 02:30:42 +00:00
|
|
|
let doc = Self::from_path(path);
|
|
|
|
let results = doc.test_results();
|
2019-05-14 01:13:28 +00:00
|
|
|
|
2019-05-15 02:30:42 +00:00
|
|
|
if results.iter().any(|r| r.result.is_err()) {
|
|
|
|
print_failures(&doc, &results);
|
|
|
|
panic!("Tests failed (see above)");
|
2019-05-15 05:08:48 +00:00
|
|
|
} else {
|
|
|
|
println!("Passed {} tests in {:?}", results.len(), doc.path);
|
2019-05-14 01:13:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-22 06:15:52 +00:00
|
|
|
pub fn run_test<T>(doc: &Doc) -> Vec<CaseResult>
|
2019-05-14 01:13:28 +00:00
|
|
|
where
|
2019-05-15 01:45:50 +00:00
|
|
|
Cases<T>: EfTest + YamlDecode,
|
2019-05-14 01:13:28 +00:00
|
|
|
{
|
2019-05-15 01:45:50 +00:00
|
|
|
// Extract only the "test_cases" YAML as a stand-alone string.
|
2019-05-15 07:14:28 +00:00
|
|
|
//let test_cases_yaml = extract_yaml_by_key(self., "test_cases");
|
2019-05-14 01:13:28 +00:00
|
|
|
|
2019-05-15 01:45:50 +00:00
|
|
|
// Pass only the "test_cases" YAML string to `yaml_decode`.
|
2019-05-15 07:14:28 +00:00
|
|
|
let test_cases: Cases<T> = Cases::yaml_decode(&doc.cases_yaml).unwrap();
|
2019-05-14 05:08:42 +00:00
|
|
|
|
2019-05-22 06:15:52 +00:00
|
|
|
test_cases.test_results()
|
2019-05-14 01:13:28 +00:00
|
|
|
}
|
2019-05-15 02:30:42 +00:00
|
|
|
|
|
|
|
pub fn print_failures(doc: &Doc, results: &[CaseResult]) {
|
2019-05-15 07:14:28 +00:00
|
|
|
let header: DocHeader = serde_yaml::from_str(&doc.header_yaml).unwrap();
|
2019-05-15 02:30:42 +00:00
|
|
|
let failures: Vec<&CaseResult> = results.iter().filter(|r| r.result.is_err()).collect();
|
|
|
|
|
|
|
|
println!("--------------------------------------------------");
|
|
|
|
println!("Test Failure");
|
|
|
|
println!("Title: {}", header.title);
|
|
|
|
println!("File: {:?}", doc.path);
|
|
|
|
println!("");
|
|
|
|
println!(
|
|
|
|
"{} tests, {} failures, {} passes.",
|
|
|
|
results.len(),
|
|
|
|
failures.len(),
|
|
|
|
results.len() - failures.len()
|
|
|
|
);
|
|
|
|
println!("");
|
|
|
|
|
|
|
|
for failure in failures {
|
2019-05-22 08:55:00 +00:00
|
|
|
let error = failure.result.clone().unwrap_err();
|
|
|
|
|
2019-05-15 02:30:42 +00:00
|
|
|
println!("-------");
|
2019-05-23 06:55:50 +00:00
|
|
|
println!(
|
|
|
|
"case[{}] ({}) failed with {}:",
|
|
|
|
failure.case_index,
|
|
|
|
failure.desc,
|
|
|
|
error.name()
|
|
|
|
);
|
2019-05-22 08:55:00 +00:00
|
|
|
println!("{}", error.message());
|
2019-05-15 02:30:42 +00:00
|
|
|
}
|
|
|
|
println!("");
|
|
|
|
}
|