Enable operations tests, start testing

This commit is contained in:
Paul Hauner 2019-05-22 16:46:50 +10:00
parent 2cffca7b1a
commit 30d582f40d
No known key found for this signature in database
GPG Key ID: 5E2CFF9B75FA63DF
3 changed files with 24 additions and 20 deletions

View File

@ -1,6 +1,8 @@
use super::*; use super::*;
use std::fmt::Debug; use std::fmt::Debug;
pub const MAX_VALUE_STRING_LEN: usize = 500;
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone)]
pub struct CaseResult { pub struct CaseResult {
pub case_index: usize, pub case_index: usize,
@ -32,21 +34,29 @@ where
(Err(_), None) => Ok(()), (Err(_), None) => Ok(()),
// Fail: The test failed when it should have produced a result (fail). // Fail: The test failed when it should have produced a result (fail).
(Err(e), Some(expected)) => Err(Error::NotEqual(format!( (Err(e), Some(expected)) => Err(Error::NotEqual(format!(
"Got {:?} Expected {:?}", "Got {:?} | Expected {:?}",
e, expected e,
fmt_val(expected)
))), ))),
// Fail: The test produced a result when it should have failed (fail). // Fail: The test produced a result when it should have failed (fail).
(Ok(result), None) => Err(Error::DidntFail(format!("Got {:?}", result))), (Ok(result), None) => Err(Error::DidntFail(format!("Got {:?}", fmt_val(result)))),
// Potential Pass: The test should have produced a result, and it did. // Potential Pass: The test should have produced a result, and it did.
(Ok(result), Some(expected)) => { (Ok(result), Some(expected)) => {
if result == expected { if result == expected {
Ok(()) Ok(())
} else { } else {
Err(Error::NotEqual(format!( Err(Error::NotEqual(format!(
"Got {:?} expected {:?}", "Got {:?} | Expected {:?}",
result, expected fmt_val(result),
fmt_val(expected)
))) )))
} }
} }
} }
} }
fn fmt_val<T: Debug>(val: T) -> String {
let mut string = format!("{:?}", val);
string.truncate(MAX_VALUE_STRING_LEN);
string
}

View File

@ -1,5 +1,7 @@
use super::*; use super::*;
use crate::case_result::compare_result;
use serde_derive::Deserialize; use serde_derive::Deserialize;
use state_processing::per_block_processing::process_deposits;
use types::{BeaconState, Deposit, EthSpec}; use types::{BeaconState, Deposit, EthSpec};
#[derive(Debug, Clone, Deserialize)] #[derive(Debug, Clone, Deserialize)]
@ -18,19 +20,13 @@ impl<E: EthSpec> YamlDecode for OperationsDeposit<E> {
} }
} }
/* impl<E: EthSpec> Case for OperationsDeposit<E> {
impl<T: EthSpec> EfTest for Cases<OperationsDeposit<T>> { fn result(&self) -> Result<(), Error> {
fn test_results<E: EthSpec>(&self) -> Vec<CaseResult> { let mut state = self.pre.clone();
self.test_cases let deposit = self.deposit.clone();
.iter()
.enumerate()
.map(|(i, tc)| {
// TODO: run test
let result = Ok(());
CaseResult::new(i, tc, result) let result = process_deposits(&mut state, &[deposit], &E::spec()).and_then(|_| Ok(state));
})
.collect() compare_result(&result, &self.post)
} }
} }
*/

View File

@ -51,14 +51,12 @@ impl Doc {
("bls", "msg_hash_uncompressed", "mainnet") => vec![], ("bls", "msg_hash_uncompressed", "mainnet") => vec![],
("bls", "priv_to_pub", "mainnet") => run_test::<BlsPrivToPub>(self), ("bls", "priv_to_pub", "mainnet") => run_test::<BlsPrivToPub>(self),
("bls", "sign_msg", "mainnet") => run_test::<BlsSign>(self), ("bls", "sign_msg", "mainnet") => run_test::<BlsSign>(self),
/*
("operations", "deposit", "mainnet") => { ("operations", "deposit", "mainnet") => {
run_test::<OperationsDeposit<MainnetEthSpec>>(self) run_test::<OperationsDeposit<MainnetEthSpec>>(self)
} }
("operations", "deposit", "minimal") => { ("operations", "deposit", "minimal") => {
run_test::<OperationsDeposit<MinimalEthSpec>>(self) run_test::<OperationsDeposit<MinimalEthSpec>>(self)
} }
*/
(runner, handler, config) => panic!( (runner, handler, config) => panic!(
"No implementation for runner: \"{}\", handler: \"{}\", config: \"{}\"", "No implementation for runner: \"{}\", handler: \"{}\", config: \"{}\"",
runner, handler, config runner, handler, config