Pass case_index
through Case
trait
This commit is contained in:
parent
b2666d700c
commit
14d879d75f
@ -22,7 +22,11 @@ pub use ssz_generic::*;
|
||||
pub use ssz_static::*;
|
||||
|
||||
pub trait Case {
|
||||
fn result(&self) -> Result<(), Error>;
|
||||
/// 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>;
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -38,7 +42,7 @@ where
|
||||
self.test_cases
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, tc)| CaseResult::new(i, tc, tc.result()))
|
||||
.map(|(i, tc)| CaseResult::new(i, tc, tc.result(i)))
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ impl YamlDecode for BlsAggregatePubkeys {
|
||||
}
|
||||
|
||||
impl Case for BlsAggregatePubkeys {
|
||||
fn result(&self) -> Result<(), Error> {
|
||||
fn result(&self, _case_index: usize) -> Result<(), Error> {
|
||||
let mut aggregate_pubkey = AggregatePublicKey::new();
|
||||
|
||||
for key_str in &self.input {
|
||||
|
@ -16,7 +16,7 @@ impl YamlDecode for BlsAggregateSigs {
|
||||
}
|
||||
|
||||
impl Case for BlsAggregateSigs {
|
||||
fn result(&self) -> Result<(), Error> {
|
||||
fn result(&self, _case_index: usize) -> Result<(), Error> {
|
||||
let mut aggregate_signature = AggregateSignature::new();
|
||||
|
||||
for key_str in &self.input {
|
||||
|
@ -22,7 +22,7 @@ impl YamlDecode for BlsG2Compressed {
|
||||
}
|
||||
|
||||
impl Case for BlsG2Compressed {
|
||||
fn result(&self) -> Result<(), Error> {
|
||||
fn result(&self, _case_index: usize) -> Result<(), Error> {
|
||||
// Convert message and domain to required types
|
||||
let msg = hex::decode(&self.input.message[2..])
|
||||
.map_err(|e| Error::FailedToParseTest(format!("{:?}", e)))?;
|
||||
|
@ -22,7 +22,7 @@ impl YamlDecode for BlsG2Uncompressed {
|
||||
}
|
||||
|
||||
impl Case for BlsG2Uncompressed {
|
||||
fn result(&self) -> Result<(), Error> {
|
||||
fn result(&self, _case_index: usize) -> Result<(), Error> {
|
||||
// Convert message and domain to required types
|
||||
let msg = hex::decode(&self.input.message[2..])
|
||||
.map_err(|e| Error::FailedToParseTest(format!("{:?}", e)))?;
|
||||
|
@ -16,7 +16,7 @@ impl YamlDecode for BlsPrivToPub {
|
||||
}
|
||||
|
||||
impl Case for BlsPrivToPub {
|
||||
fn result(&self) -> Result<(), Error> {
|
||||
fn result(&self, _case_index: usize) -> Result<(), Error> {
|
||||
let secret = &self.input;
|
||||
|
||||
// Convert message and domain to required types
|
||||
|
@ -23,7 +23,7 @@ impl YamlDecode for BlsSign {
|
||||
}
|
||||
|
||||
impl Case for BlsSign {
|
||||
fn result(&self) -> Result<(), Error> {
|
||||
fn result(&self, _case_index: usize) -> Result<(), Error> {
|
||||
// Convert private_key, message and domain to required types
|
||||
let mut sk = hex::decode(&self.input.privkey[2..])
|
||||
.map_err(|e| Error::FailedToParseTest(format!("{:?}", e)))?;
|
||||
|
@ -21,13 +21,14 @@ impl<E: EthSpec> YamlDecode for OperationsDeposit<E> {
|
||||
}
|
||||
|
||||
impl<E: EthSpec> Case for OperationsDeposit<E> {
|
||||
fn result(&self) -> Result<(), Error> {
|
||||
fn result(&self, _case_index: usize) -> Result<(), Error> {
|
||||
let mut state = self.pre.clone();
|
||||
let deposit = self.deposit.clone();
|
||||
let mut expected = self.post.clone();
|
||||
|
||||
let mut result =
|
||||
process_deposits(&mut state, &[deposit], &E::spec()).and_then(|_| Ok(state));
|
||||
let result = process_deposits(&mut state, &[deposit], &E::spec());
|
||||
|
||||
let mut result = result.and_then(|_| Ok(state));
|
||||
|
||||
compare_beacon_state_results_without_caches(&mut result, &mut expected)
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ impl YamlDecode for SszGeneric {
|
||||
}
|
||||
|
||||
impl Case for SszGeneric {
|
||||
fn result(&self) -> Result<(), Error> {
|
||||
fn result(&self, _case_index: usize) -> Result<(), Error> {
|
||||
if let Some(ssz) = &self.ssz {
|
||||
match self.type_name.as_ref() {
|
||||
"uint8" => ssz_generic_test::<u8>(self.valid, ssz, &self.value),
|
||||
|
@ -51,7 +51,7 @@ impl<E> SszStatic<E> {
|
||||
}
|
||||
|
||||
impl<E: EthSpec> Case for SszStatic<E> {
|
||||
fn result(&self) -> Result<(), Error> {
|
||||
fn result(&self, _case_index: usize) -> Result<(), Error> {
|
||||
match self.type_name.as_ref() {
|
||||
"Fork" => ssz_static_test::<Fork, E>(self),
|
||||
"Crosslink" => ssz_static_test::<Crosslink, E>(self),
|
||||
|
@ -52,11 +52,12 @@ fn ssz_static() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "fake_crypto")]
|
||||
#[cfg(not(feature = "fake_crypto"))]
|
||||
fn operations_deposit() {
|
||||
yaml_files_in_test_dir(&Path::new("operations").join("deposit"))
|
||||
// .into_par_iter()
|
||||
.into_iter()
|
||||
.rev()
|
||||
.for_each(|file| {
|
||||
Doc::assert_tests_pass(file);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user