diff --git a/tests/ef_tests/src/test_doc_cases/ssz_generic.rs b/tests/ef_tests/src/test_doc_cases/ssz_generic.rs index b99c6f005..d2bccbdd5 100644 --- a/tests/ef_tests/src/test_doc_cases/ssz_generic.rs +++ b/tests/ef_tests/src/test_doc_cases/ssz_generic.rs @@ -5,7 +5,7 @@ pub struct SszGeneric { #[serde(alias = "type")] pub type_name: String, pub valid: bool, - pub value: String, + pub value: Option, pub ssz: Option, } @@ -42,14 +42,23 @@ impl Test for TestDocCases { } /// Execute a `ssz_generic` test case. -fn ssz_generic_test(should_be_ok: bool, ssz: &String, value: &String) -> Result<(), Error> +fn ssz_generic_test( + should_be_ok: bool, + ssz: &String, + value: &Option, +) -> Result<(), Error> where T: Decode + TestDecode + Debug + PartialEq, { let ssz = hex::decode(&ssz[2..]).map_err(|e| Error::FailedToParseTest(format!("{:?}", e)))?; - let expected = if should_be_ok { - Some(T::test_decode(value)?) + // We do not cater for the scenario where the test is valid but we are not passed any SSZ. + if should_be_ok && value.is_none() { + panic!("Unexpected test input. Cannot pass without value.") + } + + let expected = if let Some(string) = value { + Some(T::test_decode(string)?) } else { None }; diff --git a/tests/ef_tests/tests/tests.rs b/tests/ef_tests/tests/tests.rs index 2bcd29dab..dd7e7d9d1 100644 --- a/tests/ef_tests/tests/tests.rs +++ b/tests/ef_tests/tests/tests.rs @@ -1,36 +1,5 @@ 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_generic() { - let doc: TestDoc = load_test_case("ssz_generic/uint/uint_bounds.yaml"); - - let results = doc.test(); - - let failures: Vec<&TestCaseResult> = results.iter().filter(|r| r.result.is_err()).collect(); - - if !failures.is_empty() { - panic!("{:?}", failures); - } -} -*/ +use std::path::PathBuf; fn test_file(trailing_path: &str) -> PathBuf { let mut file_path_buf = PathBuf::from(env!("CARGO_MANIFEST_DIR")); @@ -54,4 +23,14 @@ mod ssz_generic { fn uint_bounds() { TestDoc::assert_tests_pass(ssz_generic_file("uint/uint_bounds.yaml")); } + + #[test] + fn uint_random() { + TestDoc::assert_tests_pass(ssz_generic_file("uint/uint_random.yaml")); + } + + #[test] + fn uint_wrong_length() { + TestDoc::assert_tests_pass(ssz_generic_file("uint/uint_wrong_length.yaml")); + } }