From 31d960011f43be78d303621e2b572a0bdf2218ab Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Mon, 13 May 2019 17:56:46 +1000 Subject: [PATCH] Add basic code for new testing format --- .gitmodules | 3 +++ Cargo.toml | 1 + tests/ef_tests/Cargo.toml | 10 ++++++++++ tests/ef_tests/eth2.0-spec-tests | 1 + tests/ef_tests/src/lib.rs | 30 ++++++++++++++++++++++++++++++ tests/ef_tests/tests/tests.rs | 27 +++++++++++++++++++++++++++ 6 files changed, 72 insertions(+) create mode 100644 .gitmodules create mode 100644 tests/ef_tests/Cargo.toml create mode 160000 tests/ef_tests/eth2.0-spec-tests create mode 100644 tests/ef_tests/src/lib.rs create mode 100644 tests/ef_tests/tests/tests.rs diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 000000000..1b0e150ce --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "tests/ef_tests/eth2.0-spec-tests"] + path = tests/ef_tests/eth2.0-spec-tests + url = https://github.com/ethereum/eth2.0-spec-tests diff --git a/Cargo.toml b/Cargo.toml index 893189941..704bfde13 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,6 +29,7 @@ members = [ "beacon_node/rpc", "beacon_node/version", "beacon_node/beacon_chain", + "tests/ef_tests", "protos", "validator_client", "account_manager", diff --git a/tests/ef_tests/Cargo.toml b/tests/ef_tests/Cargo.toml new file mode 100644 index 000000000..367cbbe14 --- /dev/null +++ b/tests/ef_tests/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "ef_tests" +version = "0.1.0" +authors = ["Paul Hauner "] +edition = "2018" + +[dependencies] +serde = "1.0" +serde_derive = "1.0" +serde_yaml = "0.8" diff --git a/tests/ef_tests/eth2.0-spec-tests b/tests/ef_tests/eth2.0-spec-tests new file mode 160000 index 000000000..161a36ee6 --- /dev/null +++ b/tests/ef_tests/eth2.0-spec-tests @@ -0,0 +1 @@ +Subproject commit 161a36ee6232d8d251d798c8262638ed0c34c9c6 diff --git a/tests/ef_tests/src/lib.rs b/tests/ef_tests/src/lib.rs new file mode 100644 index 000000000..f7308c32b --- /dev/null +++ b/tests/ef_tests/src/lib.rs @@ -0,0 +1,30 @@ +use serde_derive::Deserialize; + +#[derive(Debug, Deserialize)] +pub struct TestDoc { + pub title: String, + pub summary: String, + pub forks_timeline: String, + pub forks: Vec, + pub config: String, + pub runner: String, + pub handler: String, + pub test_cases: Vec, +} + +#[derive(Debug, Deserialize)] +pub struct SszGenericCase { + #[serde(alias = "type")] + pub type_name: String, + pub valid: bool, + pub value: String, + pub ssz: Option, +} + +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + assert_eq!(2 + 2, 4); + } +} diff --git a/tests/ef_tests/tests/tests.rs b/tests/ef_tests/tests/tests.rs new file mode 100644 index 000000000..023b7c18a --- /dev/null +++ b/tests/ef_tests/tests/tests.rs @@ -0,0 +1,27 @@ +use ef_tests::*; +use serde::de::DeserializeOwned; +use std::{fs::File, io::prelude::*, path::PathBuf}; + +fn load_test_case(test_name: &str) -> TestDoc { + let mut file = { + let mut file_path_buf = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + file_path_buf.push(format!("eth2.0-spec-tests/tests/{}", test_name)); + + File::open(file_path_buf).unwrap() + }; + + let mut yaml_str = String::new(); + file.read_to_string(&mut yaml_str).unwrap(); + yaml_str = yaml_str.to_lowercase(); + + serde_yaml::from_str(&yaml_str.as_str()).unwrap() +} + +#[test] +fn ssz() { + let doc: TestDoc = load_test_case("ssz_generic/uint/uint_bounds.yaml"); + + dbg!(doc); + + assert!(false); +}