diff --git a/tests/ef_tests/Cargo.toml b/tests/ef_tests/Cargo.toml index b7596755d..10a0cc7b6 100644 --- a/tests/ef_tests/Cargo.toml +++ b/tests/ef_tests/Cargo.toml @@ -18,6 +18,7 @@ serde_yaml = "0.8" ssz = { path = "../../eth2/utils/ssz" } tree_hash = { path = "../../eth2/utils/tree_hash" } cached_tree_hash = { path = "../../eth2/utils/cached_tree_hash" } +state_processing = { path = "../../eth2/state_processing" } types = { path = "../../eth2/types" } walkdir = "2" yaml-rust = { git = "https://github.com/sigp/yaml-rust", branch = "escape_all_str"} diff --git a/tests/ef_tests/eth2.0-spec-tests b/tests/ef_tests/eth2.0-spec-tests index 161a36ee6..6fde1e806 160000 --- a/tests/ef_tests/eth2.0-spec-tests +++ b/tests/ef_tests/eth2.0-spec-tests @@ -1 +1 @@ -Subproject commit 161a36ee6232d8d251d798c8262638ed0c34c9c6 +Subproject commit 6fde1e806b340d946839d6261c63c779f0cadd81 diff --git a/tests/ef_tests/src/cases.rs b/tests/ef_tests/src/cases.rs index f62150893..d31dfc953 100644 --- a/tests/ef_tests/src/cases.rs +++ b/tests/ef_tests/src/cases.rs @@ -1,6 +1,4 @@ use super::*; -use crate::yaml_decode::*; -use yaml_rust::YamlLoader; mod bls_aggregate_pubkeys; mod bls_aggregate_sigs; @@ -8,6 +6,7 @@ mod bls_g2_compressed; mod bls_g2_uncompressed; mod bls_priv_to_pub; mod bls_sign_msg; +mod operations_deposit; mod ssz_generic; mod ssz_static; @@ -17,6 +16,7 @@ pub use bls_g2_compressed::*; pub use bls_g2_uncompressed::*; pub use bls_priv_to_pub::*; pub use bls_sign_msg::*; +pub use operations_deposit::*; pub use ssz_generic::*; pub use ssz_static::*; diff --git a/tests/ef_tests/src/cases/operations_deposit.rs b/tests/ef_tests/src/cases/operations_deposit.rs new file mode 100644 index 000000000..9ff2327e3 --- /dev/null +++ b/tests/ef_tests/src/cases/operations_deposit.rs @@ -0,0 +1,34 @@ +use super::*; +use serde_derive::Deserialize; +use types::{BeaconState, Deposit, EthSpec}; + +#[derive(Debug, Clone, Deserialize)] +pub struct OperationsDeposit { + pub description: String, + #[serde(bound = "E: EthSpec")] + pub pre: BeaconState, + pub deposit: Deposit, + #[serde(bound = "E: EthSpec")] + pub post: Option>, +} + +impl YamlDecode for OperationsDeposit { + fn yaml_decode(yaml: &String) -> Result { + Ok(serde_yaml::from_str(&yaml.as_str()).unwrap()) + } +} + +impl EfTest for Cases> { + fn test_results(&self) -> Vec { + self.test_cases + .iter() + .enumerate() + .map(|(i, tc)| { + // TODO: run test + let result = Ok(()); + + CaseResult::new(i, tc, result) + }) + .collect() + } +} diff --git a/tests/ef_tests/src/doc.rs b/tests/ef_tests/src/doc.rs index d10f8e935..d0498c61b 100644 --- a/tests/ef_tests/src/doc.rs +++ b/tests/ef_tests/src/doc.rs @@ -2,7 +2,7 @@ use crate::case_result::CaseResult; use crate::cases::*; use crate::doc_header::DocHeader; use crate::eth_specs::{MainnetEthSpec, MinimalEthSpec}; -use crate::yaml_decode::{extract_yaml_by_key, yaml_split_header_and_cases, YamlDecode}; +use crate::yaml_decode::{yaml_split_header_and_cases, YamlDecode}; use crate::EfTest; use serde_derive::Deserialize; use std::{fs::File, io::prelude::*, path::PathBuf}; @@ -58,6 +58,12 @@ impl Doc { ("bls", "msg_hash_uncompressed", "mainnet") => vec![], ("bls", "priv_to_pub", "mainnet") => run_test::(self), ("bls", "sign_msg", "mainnet") => run_test::(self), + ("operations", "deposit", "mainnet") => { + run_test::, MainnetEthSpec>(self) + } + ("operations", "deposit", "minimal") => { + run_test::, MinimalEthSpec>(self) + } (runner, handler, config) => panic!( "No implementation for runner: \"{}\", handler: \"{}\", config: \"{}\"", runner, handler, config diff --git a/tests/ef_tests/tests/tests.rs b/tests/ef_tests/tests/tests.rs index 58aadf473..8c9ae8d7d 100644 --- a/tests/ef_tests/tests/tests.rs +++ b/tests/ef_tests/tests/tests.rs @@ -1,13 +1,13 @@ use ef_tests::*; use rayon::prelude::*; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use walkdir::WalkDir; -fn yaml_files_in_test_dir(dir: &str) -> Vec { - let mut base_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); - base_path.push("eth2.0-spec-tests"); - base_path.push("tests"); - base_path.push(dir); +fn yaml_files_in_test_dir(dir: &Path) -> Vec { + let base_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("eth2.0-spec-tests") + .join("tests") + .join(dir); assert!( base_path.exists(), @@ -34,7 +34,7 @@ fn yaml_files_in_test_dir(dir: &str) -> Vec { #[test] #[cfg(feature = "fake_crypto")] fn ssz_generic() { - yaml_files_in_test_dir("ssz_generic") + yaml_files_in_test_dir(&Path::new("ssz_generic")) .into_par_iter() .for_each(|file| { Doc::assert_tests_pass(file); @@ -44,17 +44,28 @@ fn ssz_generic() { #[test] #[cfg(feature = "fake_crypto")] fn ssz_static() { - yaml_files_in_test_dir("ssz_static") + yaml_files_in_test_dir(&Path::new("ssz_static")) .into_par_iter() .for_each(|file| { Doc::assert_tests_pass(file); }); } +#[test] +#[cfg(feature = "fake_crypto")] +fn operations_deposit() { + yaml_files_in_test_dir(&Path::new("operations").join("deposit")) + // .into_par_iter() + .into_iter() + .for_each(|file| { + Doc::assert_tests_pass(file); + }); +} + #[test] #[cfg(not(feature = "fake_crypto"))] fn bls() { - yaml_files_in_test_dir("bls") + yaml_files_in_test_dir(&Path::new("bls")) .into_par_iter() .for_each(|file| { Doc::assert_tests_pass(file);