diff --git a/tests/ef_tests/src/lib.rs b/tests/ef_tests/src/lib.rs index ecfcae3cc..c028c6c12 100644 --- a/tests/ef_tests/src/lib.rs +++ b/tests/ef_tests/src/lib.rs @@ -3,7 +3,6 @@ use ethereum_types::{U128, U256}; use serde_derive::Deserialize; use ssz::Decode; use std::fmt::Debug; -use test_decode::TestDecode; pub use crate::error::*; pub use crate::eth_specs::*; @@ -11,13 +10,12 @@ pub use crate::test_case_result::*; pub use crate::test_doc::*; pub use crate::test_doc_cases::*; pub use crate::test_doc_header::*; -pub use crate::yaml_utils::*; +pub use yaml_decode::YamlDecode; mod error; mod eth_specs; mod test_case_result; -mod test_decode; mod test_doc; mod test_doc_cases; mod test_doc_header; -mod yaml_utils; +mod yaml_decode; diff --git a/tests/ef_tests/src/test_doc.rs b/tests/ef_tests/src/test_doc.rs index 316404cfa..99427779e 100644 --- a/tests/ef_tests/src/test_doc.rs +++ b/tests/ef_tests/src/test_doc.rs @@ -1,4 +1,5 @@ use super::*; +use crate::yaml_decode::*; use std::{fs::File, io::prelude::*, path::PathBuf}; use types::{EthSpec, FoundationEthSpec}; @@ -53,12 +54,12 @@ impl TestDoc { pub fn run_test(test_doc_yaml: &String) -> Vec where - TestDocCases: Test + serde::de::DeserializeOwned + TestDecode, + TestDocCases: Test + serde::de::DeserializeOwned + YamlDecode, { let test_cases_yaml = extract_yaml_by_key(test_doc_yaml, "test_cases"); let test_cases: TestDocCases = - TestDocCases::test_decode(&test_cases_yaml.to_string()).unwrap(); + TestDocCases::yaml_decode(&test_cases_yaml.to_string()).unwrap(); test_cases.test::() } diff --git a/tests/ef_tests/src/test_doc_cases.rs b/tests/ef_tests/src/test_doc_cases.rs index 45c24146c..199222cf4 100644 --- a/tests/ef_tests/src/test_doc_cases.rs +++ b/tests/ef_tests/src/test_doc_cases.rs @@ -1,4 +1,5 @@ use super::*; +use crate::yaml_decode::*; use yaml_rust::YamlLoader; mod ssz_generic; @@ -12,9 +13,9 @@ pub struct TestDocCases { pub test_cases: Vec, } -impl TestDecode for TestDocCases { +impl YamlDecode for TestDocCases { /// Decodes a YAML list of test cases - fn test_decode(yaml: &String) -> Result { + fn yaml_decode(yaml: &String) -> Result { let doc = &YamlLoader::load_from_str(yaml).unwrap()[0]; let mut test_cases: Vec = vec![]; @@ -24,7 +25,7 @@ impl TestDecode for TestDocCases { if doc[i].is_badvalue() { break; } else { - test_cases.push(T::test_decode(&yaml_to_string(&doc[i])).unwrap()) + test_cases.push(T::yaml_decode(&yaml_to_string(&doc[i])).unwrap()) } i += 1; 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 a0ed7da22..9585332ac 100644 --- a/tests/ef_tests/src/test_doc_cases/ssz_generic.rs +++ b/tests/ef_tests/src/test_doc_cases/ssz_generic.rs @@ -10,8 +10,8 @@ pub struct SszGeneric { pub ssz: Option, } -impl TestDecode for SszGeneric { - fn test_decode(yaml: &String) -> Result { +impl YamlDecode for SszGeneric { + fn yaml_decode(yaml: &String) -> Result { Ok(serde_yaml::from_str(&yaml.as_str()).unwrap()) } } @@ -55,7 +55,7 @@ fn ssz_generic_test( value: &Option, ) -> Result<(), Error> where - T: Decode + TestDecode + Debug + PartialEq, + T: Decode + YamlDecode + Debug + PartialEq, { let ssz = hex::decode(&ssz[2..]).map_err(|e| Error::FailedToParseTest(format!("{:?}", e)))?; @@ -65,7 +65,7 @@ where } let expected = if let Some(string) = value { - Some(T::test_decode(string)?) + Some(T::yaml_decode(string)?) } else { None }; diff --git a/tests/ef_tests/src/test_doc_cases/ssz_static.rs b/tests/ef_tests/src/test_doc_cases/ssz_static.rs index 789b5f17f..8b07ac645 100644 --- a/tests/ef_tests/src/test_doc_cases/ssz_static.rs +++ b/tests/ef_tests/src/test_doc_cases/ssz_static.rs @@ -21,8 +21,8 @@ pub struct Value { value: T, } -impl TestDecode for SszStatic { - fn test_decode(yaml: &String) -> Result { +impl YamlDecode for SszStatic { + fn yaml_decode(yaml: &String) -> Result { let mut ssz_static: SszStatic = serde_yaml::from_str(&yaml.as_str()).unwrap(); ssz_static.raw_yaml = yaml.clone(); diff --git a/tests/ef_tests/src/test_decode.rs b/tests/ef_tests/src/yaml_decode.rs similarity index 74% rename from tests/ef_tests/src/test_decode.rs rename to tests/ef_tests/src/yaml_decode.rs index 4ba25c1a8..7c2bd84ec 100644 --- a/tests/ef_tests/src/test_decode.rs +++ b/tests/ef_tests/src/yaml_decode.rs @@ -1,16 +1,20 @@ use super::*; use types::Fork; -pub trait TestDecode: Sized { +mod utils; + +pub use utils::*; + +pub trait YamlDecode: Sized { /// Decode an object from the test specification YAML. - fn test_decode(string: &String) -> Result; + fn yaml_decode(string: &String) -> Result; } /// Basic types can general be decoded with the `parse` fn if they implement `str::FromStr`. macro_rules! impl_via_parse { ($ty: ty) => { - impl TestDecode for $ty { - fn test_decode(string: &String) -> Result { + impl YamlDecode for $ty { + fn yaml_decode(string: &String) -> Result { string .parse::() .map_err(|e| Error::FailedToParseTest(format!("{:?}", e))) @@ -28,8 +32,8 @@ impl_via_parse!(u64); /// hex, so we use `from_dec_str` instead. macro_rules! impl_via_from_dec_str { ($ty: ty) => { - impl TestDecode for $ty { - fn test_decode(string: &String) -> Result { + impl YamlDecode for $ty { + fn yaml_decode(string: &String) -> Result { Self::from_dec_str(string).map_err(|e| Error::FailedToParseTest(format!("{:?}", e))) } } @@ -42,8 +46,8 @@ impl_via_from_dec_str!(U256); /// Types that already implement `serde::Deserialize` can be decoded using `serde_yaml`. macro_rules! impl_via_serde_yaml { ($ty: ty) => { - impl TestDecode for $ty { - fn test_decode(string: &String) -> Result { + impl YamlDecode for $ty { + fn yaml_decode(string: &String) -> Result { serde_yaml::from_str(string) .map_err(|e| Error::FailedToParseTest(format!("{:?}", e))) } diff --git a/tests/ef_tests/src/yaml_utils.rs b/tests/ef_tests/src/yaml_decode/utils.rs similarity index 100% rename from tests/ef_tests/src/yaml_utils.rs rename to tests/ef_tests/src/yaml_decode/utils.rs diff --git a/tests/ef_tests/tests/tests.rs b/tests/ef_tests/tests/tests.rs index d0452ab94..70966dc90 100644 --- a/tests/ef_tests/tests/tests.rs +++ b/tests/ef_tests/tests/tests.rs @@ -47,7 +47,6 @@ mod ssz_static { } #[test] - #[ignore] fn minimal_nil() { TestDoc::assert_tests_pass(ssz_generic_file("core/ssz_minimal_nil.yaml")); }