2019-05-14 01:13:28 +00:00
|
|
|
use super::*;
|
2019-05-22 06:15:52 +00:00
|
|
|
use std::fmt::Debug;
|
2019-05-14 01:13:28 +00:00
|
|
|
|
2019-05-21 00:32:14 +00:00
|
|
|
mod bls_aggregate_pubkeys;
|
|
|
|
mod bls_aggregate_sigs;
|
2019-05-21 02:46:22 +00:00
|
|
|
mod bls_g2_compressed;
|
|
|
|
mod bls_g2_uncompressed;
|
|
|
|
mod bls_priv_to_pub;
|
|
|
|
mod bls_sign_msg;
|
2019-05-22 05:34:12 +00:00
|
|
|
mod operations_deposit;
|
2019-05-23 00:11:15 +00:00
|
|
|
mod operations_exit;
|
2019-05-22 22:48:09 +00:00
|
|
|
mod operations_transfer;
|
2019-05-14 01:13:28 +00:00
|
|
|
mod ssz_generic;
|
2019-05-14 05:08:42 +00:00
|
|
|
mod ssz_static;
|
2019-05-14 01:13:28 +00:00
|
|
|
|
2019-05-21 00:32:14 +00:00
|
|
|
pub use bls_aggregate_pubkeys::*;
|
|
|
|
pub use bls_aggregate_sigs::*;
|
2019-05-21 02:46:22 +00:00
|
|
|
pub use bls_g2_compressed::*;
|
|
|
|
pub use bls_g2_uncompressed::*;
|
|
|
|
pub use bls_priv_to_pub::*;
|
|
|
|
pub use bls_sign_msg::*;
|
2019-05-22 05:34:12 +00:00
|
|
|
pub use operations_deposit::*;
|
2019-05-23 00:11:15 +00:00
|
|
|
pub use operations_exit::*;
|
2019-05-22 22:48:09 +00:00
|
|
|
pub use operations_transfer::*;
|
2019-05-14 01:13:28 +00:00
|
|
|
pub use ssz_generic::*;
|
2019-05-14 05:08:42 +00:00
|
|
|
pub use ssz_static::*;
|
2019-05-14 01:13:28 +00:00
|
|
|
|
2019-05-23 06:55:50 +00:00
|
|
|
pub trait Case: Debug {
|
|
|
|
/// An optional field for implementing a custom description.
|
|
|
|
///
|
|
|
|
/// Defaults to "no description".
|
|
|
|
fn description(&self) -> String {
|
|
|
|
"no description".to_string()
|
|
|
|
}
|
|
|
|
|
2019-05-22 08:13:22 +00:00
|
|
|
/// Execute a test and return the result.
|
|
|
|
///
|
|
|
|
/// `case_index` reports the index of the case in the set of test cases. It is not strictly
|
|
|
|
/// necessary, but it's useful when troubleshooting specific failing tests.
|
|
|
|
fn result(&self, case_index: usize) -> Result<(), Error>;
|
2019-05-22 06:15:52 +00:00
|
|
|
}
|
|
|
|
|
2019-05-15 01:45:50 +00:00
|
|
|
#[derive(Debug)]
|
2019-05-15 01:17:32 +00:00
|
|
|
pub struct Cases<T> {
|
2019-05-14 01:13:28 +00:00
|
|
|
pub test_cases: Vec<T>,
|
|
|
|
}
|
2019-05-14 05:08:42 +00:00
|
|
|
|
2019-05-22 06:15:52 +00:00
|
|
|
impl<T> EfTest for Cases<T>
|
|
|
|
where
|
|
|
|
T: Case + Debug,
|
|
|
|
{
|
|
|
|
fn test_results(&self) -> Vec<CaseResult> {
|
|
|
|
self.test_cases
|
|
|
|
.iter()
|
|
|
|
.enumerate()
|
2019-05-22 08:13:22 +00:00
|
|
|
.map(|(i, tc)| CaseResult::new(i, tc, tc.result(i)))
|
2019-05-22 06:15:52 +00:00
|
|
|
.collect()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-15 01:17:32 +00:00
|
|
|
impl<T: YamlDecode> YamlDecode for Cases<T> {
|
2019-05-14 05:08:42 +00:00
|
|
|
/// Decodes a YAML list of test cases
|
2019-05-15 01:12:49 +00:00
|
|
|
fn yaml_decode(yaml: &String) -> Result<Self, Error> {
|
2019-05-15 07:14:28 +00:00
|
|
|
let mut p = 0;
|
|
|
|
let mut elems: Vec<&str> = yaml
|
|
|
|
.match_indices("\n- ")
|
|
|
|
// Skip the `\n` used for matching a new line
|
|
|
|
.map(|(i, _)| i + 1)
|
|
|
|
.map(|i| {
|
|
|
|
let yaml_element = &yaml[p..i];
|
|
|
|
p = i;
|
|
|
|
|
|
|
|
yaml_element
|
|
|
|
})
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
elems.push(&yaml[p..]);
|
|
|
|
|
|
|
|
let test_cases = elems
|
|
|
|
.iter()
|
|
|
|
.map(|s| {
|
|
|
|
// Remove the `- ` prefix.
|
|
|
|
let s = &s[2..];
|
|
|
|
// Remove a single level of indenting.
|
|
|
|
s.replace("\n ", "\n")
|
|
|
|
})
|
|
|
|
.map(|s| T::yaml_decode(&s.to_string()).unwrap())
|
|
|
|
.collect();
|
2019-05-14 05:08:42 +00:00
|
|
|
|
|
|
|
Ok(Self { test_cases })
|
|
|
|
}
|
|
|
|
}
|