mirror of
https://gitlab.com/pulsechaincom/lighthouse-pulse.git
synced 2025-01-07 11:32:21 +00:00
Add remaining SSZ generic tests
This commit is contained in:
parent
b280c220eb
commit
97be6b52cc
@ -5,7 +5,7 @@ pub struct SszGeneric {
|
||||
#[serde(alias = "type")]
|
||||
pub type_name: String,
|
||||
pub valid: bool,
|
||||
pub value: String,
|
||||
pub value: Option<String>,
|
||||
pub ssz: Option<String>,
|
||||
}
|
||||
|
||||
@ -42,14 +42,23 @@ impl Test for TestDocCases<SszGeneric> {
|
||||
}
|
||||
|
||||
/// Execute a `ssz_generic` test case.
|
||||
fn ssz_generic_test<T>(should_be_ok: bool, ssz: &String, value: &String) -> Result<(), Error>
|
||||
fn ssz_generic_test<T>(
|
||||
should_be_ok: bool,
|
||||
ssz: &String,
|
||||
value: &Option<String>,
|
||||
) -> Result<(), Error>
|
||||
where
|
||||
T: Decode + TestDecode + Debug + PartialEq<T>,
|
||||
{
|
||||
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
|
||||
};
|
||||
|
@ -1,36 +1,5 @@
|
||||
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_generic() {
|
||||
let doc: TestDoc<SszGeneric> = 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"));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user