Pass case_index through Case trait

This commit is contained in:
Paul Hauner 2019-05-22 18:13:22 +10:00
parent b2666d700c
commit 14d879d75f
No known key found for this signature in database
GPG Key ID: 5E2CFF9B75FA63DF
11 changed files with 20 additions and 14 deletions

View File

@ -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()
}
}

View File

@ -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 {

View File

@ -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 {

View File

@ -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)))?;

View File

@ -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)))?;

View File

@ -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

View File

@ -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)))?;

View File

@ -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)
}

View File

@ -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),

View File

@ -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),

View File

@ -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);
});