BLS and SSZ static tests

This commit is contained in:
Michael Sproul
2019-08-28 18:46:16 +10:00
parent aed2f6407d
commit 23a308e595
16 changed files with 481 additions and 178 deletions

View File

@@ -1,5 +1,6 @@
use super::*;
use std::fmt::Debug;
use std::path::Path;
mod bls_aggregate_pubkeys;
mod bls_aggregate_sigs;
@@ -53,6 +54,11 @@ pub use shuffling::*;
pub use ssz_generic::*;
pub use ssz_static::*;
pub trait LoadCase: Sized {
/// Load the test case from a test case directory.
fn load_from_dir(_path: &Path) -> Result<Self, Error>;
}
pub trait Case: Debug {
/// An optional field for implementing a custom description.
///
@@ -68,6 +74,26 @@ pub trait Case: Debug {
fn result(&self, case_index: usize) -> Result<(), Error>;
}
pub trait BlsCase: serde::de::DeserializeOwned {}
impl<T> YamlDecode for T
where
T: BlsCase,
{
fn yaml_decode(string: &str) -> Result<Self, Error> {
serde_yaml::from_str(string).map_err(|e| Error::FailedToParseTest(format!("{:?}", e)))
}
}
impl<T> LoadCase for T
where
T: BlsCase,
{
fn load_from_dir(path: &Path) -> Result<Self, Error> {
Self::yaml_decode_file(&path.join("data.yaml"))
}
}
#[derive(Debug)]
pub struct Cases<T> {
pub test_cases: Vec<T>,
@@ -86,6 +112,7 @@ where
}
}
// FIXME(michael): delete this
impl<T: YamlDecode> YamlDecode for Cases<T> {
/// Decodes a YAML list of test cases
fn yaml_decode(yaml: &str) -> Result<Self, Error> {