Add basic code for new testing format

This commit is contained in:
Paul Hauner 2019-05-13 17:56:46 +10:00
parent bf23a5b7b0
commit 31d960011f
No known key found for this signature in database
GPG Key ID: D362883A9218FCC6
6 changed files with 72 additions and 0 deletions

3
.gitmodules vendored Normal file
View File

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

View File

@ -29,6 +29,7 @@ members = [
"beacon_node/rpc",
"beacon_node/version",
"beacon_node/beacon_chain",
"tests/ef_tests",
"protos",
"validator_client",
"account_manager",

10
tests/ef_tests/Cargo.toml Normal file
View File

@ -0,0 +1,10 @@
[package]
name = "ef_tests"
version = "0.1.0"
authors = ["Paul Hauner <paul@paulhauner.com>"]
edition = "2018"
[dependencies]
serde = "1.0"
serde_derive = "1.0"
serde_yaml = "0.8"

@ -0,0 +1 @@
Subproject commit 161a36ee6232d8d251d798c8262638ed0c34c9c6

30
tests/ef_tests/src/lib.rs Normal file
View File

@ -0,0 +1,30 @@
use serde_derive::Deserialize;
#[derive(Debug, Deserialize)]
pub struct TestDoc<T> {
pub title: String,
pub summary: String,
pub forks_timeline: String,
pub forks: Vec<String>,
pub config: String,
pub runner: String,
pub handler: String,
pub test_cases: Vec<T>,
}
#[derive(Debug, Deserialize)]
pub struct SszGenericCase {
#[serde(alias = "type")]
pub type_name: String,
pub valid: bool,
pub value: String,
pub ssz: Option<String>,
}
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}

View File

@ -0,0 +1,27 @@
use ef_tests::*;
use serde::de::DeserializeOwned;
use std::{fs::File, io::prelude::*, path::PathBuf};
fn load_test_case<T: DeserializeOwned>(test_name: &str) -> TestDoc<T> {
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<SszGenericCase> = load_test_case("ssz_generic/uint/uint_bounds.yaml");
dbg!(doc);
assert!(false);
}