Improve error messages for ef_tests
This commit is contained in:
parent
d0ab1a0576
commit
92610b4fd3
@ -153,7 +153,7 @@ fn test_cache_initialization<'a, T: EthSpec>(
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Drop the cache.
|
// Drop the cache.
|
||||||
state.drop_cache(relative_epoch);
|
state.drop_committee_cache(relative_epoch);
|
||||||
|
|
||||||
// Assert a call to a cache-using function fail.
|
// Assert a call to a cache-using function fail.
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -13,10 +13,10 @@ pub struct CaseResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl CaseResult {
|
impl CaseResult {
|
||||||
pub fn new<T: Debug>(case_index: usize, case: &T, result: Result<(), Error>) -> Self {
|
pub fn new(case_index: usize, case: &impl Case, result: Result<(), Error>) -> Self {
|
||||||
CaseResult {
|
CaseResult {
|
||||||
case_index,
|
case_index,
|
||||||
desc: format!("{:?}", case),
|
desc: case.description(),
|
||||||
result,
|
result,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -60,7 +60,7 @@ where
|
|||||||
|
|
||||||
if !mismatching_fields.is_empty() {
|
if !mismatching_fields.is_empty() {
|
||||||
Err(Error::NotEqual(format!(
|
Err(Error::NotEqual(format!(
|
||||||
"Fields not equal: {:#?}",
|
"Fields not equal (a = expected, b = result): {:#?}",
|
||||||
mismatching_fields
|
mismatching_fields
|
||||||
)))
|
)))
|
||||||
} else {
|
} else {
|
||||||
|
@ -25,7 +25,14 @@ pub use operations_transfer::*;
|
|||||||
pub use ssz_generic::*;
|
pub use ssz_generic::*;
|
||||||
pub use ssz_static::*;
|
pub use ssz_static::*;
|
||||||
|
|
||||||
pub trait Case {
|
pub trait Case: Debug {
|
||||||
|
/// An optional field for implementing a custom description.
|
||||||
|
///
|
||||||
|
/// Defaults to "no description".
|
||||||
|
fn description(&self) -> String {
|
||||||
|
"no description".to_string()
|
||||||
|
}
|
||||||
|
|
||||||
/// Execute a test and return the result.
|
/// 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
|
/// `case_index` reports the index of the case in the set of test cases. It is not strictly
|
||||||
|
@ -21,6 +21,10 @@ impl<E: EthSpec> YamlDecode for OperationsDeposit<E> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<E: EthSpec> Case for OperationsDeposit<E> {
|
impl<E: EthSpec> Case for OperationsDeposit<E> {
|
||||||
|
fn description(&self) -> String {
|
||||||
|
self.description.clone()
|
||||||
|
}
|
||||||
|
|
||||||
fn result(&self, _case_index: usize) -> Result<(), Error> {
|
fn result(&self, _case_index: usize) -> Result<(), Error> {
|
||||||
let mut state = self.pre.clone();
|
let mut state = self.pre.clone();
|
||||||
let deposit = self.deposit.clone();
|
let deposit = self.deposit.clone();
|
||||||
|
@ -21,12 +21,16 @@ impl<E: EthSpec> YamlDecode for OperationsExit<E> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<E: EthSpec> Case for OperationsExit<E> {
|
impl<E: EthSpec> Case for OperationsExit<E> {
|
||||||
|
fn description(&self) -> String {
|
||||||
|
self.description.clone()
|
||||||
|
}
|
||||||
|
|
||||||
fn result(&self, _case_index: usize) -> Result<(), Error> {
|
fn result(&self, _case_index: usize) -> Result<(), Error> {
|
||||||
let mut state = self.pre.clone();
|
let mut state = self.pre.clone();
|
||||||
let exit = self.voluntary_exit.clone();
|
let exit = self.voluntary_exit.clone();
|
||||||
let mut expected = self.post.clone();
|
let mut expected = self.post.clone();
|
||||||
|
|
||||||
// Epoch processing requires the epoch cache.
|
// Exit processing requires the epoch cache.
|
||||||
state.build_all_caches(&E::spec()).unwrap();
|
state.build_all_caches(&E::spec()).unwrap();
|
||||||
|
|
||||||
let result = process_exits(&mut state, &[exit], &E::spec());
|
let result = process_exits(&mut state, &[exit], &E::spec());
|
||||||
|
@ -21,12 +21,22 @@ impl<E: EthSpec> YamlDecode for OperationsTransfer<E> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<E: EthSpec> Case for OperationsTransfer<E> {
|
impl<E: EthSpec> Case for OperationsTransfer<E> {
|
||||||
|
fn description(&self) -> String {
|
||||||
|
self.description.clone()
|
||||||
|
}
|
||||||
|
|
||||||
fn result(&self, _case_index: usize) -> Result<(), Error> {
|
fn result(&self, _case_index: usize) -> Result<(), Error> {
|
||||||
let mut state = self.pre.clone();
|
let mut state = self.pre.clone();
|
||||||
let transfer = self.transfer.clone();
|
let transfer = self.transfer.clone();
|
||||||
let mut expected = self.post.clone();
|
let mut expected = self.post.clone();
|
||||||
|
|
||||||
let result = process_transfers(&mut state, &[transfer], &E::spec());
|
// Transfer processing requires the epoch cache.
|
||||||
|
state.build_all_caches(&E::spec()).unwrap();
|
||||||
|
|
||||||
|
let mut spec = E::spec();
|
||||||
|
spec.max_transfers = 1;
|
||||||
|
|
||||||
|
let result = process_transfers(&mut state, &[transfer], &spec);
|
||||||
|
|
||||||
let mut result = result.and_then(|_| Ok(state));
|
let mut result = result.and_then(|_| Ok(state));
|
||||||
|
|
||||||
|
@ -123,7 +123,12 @@ pub fn print_failures(doc: &Doc, results: &[CaseResult]) {
|
|||||||
let error = failure.result.clone().unwrap_err();
|
let error = failure.result.clone().unwrap_err();
|
||||||
|
|
||||||
println!("-------");
|
println!("-------");
|
||||||
println!("case[{}] failed with {}:", failure.case_index, error.name());
|
println!(
|
||||||
|
"case[{}] ({}) failed with {}:",
|
||||||
|
failure.case_index,
|
||||||
|
failure.desc,
|
||||||
|
error.name()
|
||||||
|
);
|
||||||
println!("{}", error.message());
|
println!("{}", error.message());
|
||||||
}
|
}
|
||||||
println!("");
|
println!("");
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use types::EthSpec;
|
use types::EthSpec;
|
||||||
|
|
||||||
pub use case_result::CaseResult;
|
pub use case_result::CaseResult;
|
||||||
|
pub use cases::Case;
|
||||||
pub use doc::Doc;
|
pub use doc::Doc;
|
||||||
pub use error::Error;
|
pub use error::Error;
|
||||||
pub use yaml_decode::YamlDecode;
|
pub use yaml_decode::YamlDecode;
|
||||||
|
@ -33,9 +33,9 @@ fn yaml_files_in_test_dir(dir: &Path) -> Vec<PathBuf> {
|
|||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// Reverse the file order. Assuming files come in lexicographical order, doing it in
|
// Reverse the file order. Assuming files come in lexicographical order, executing tests in
|
||||||
// reverse means we get the "minimal" tests before the "mainnet" tests. This makes life
|
// reverse means we get the "minimal" tests before the "mainnet" tests. This makes life easier
|
||||||
// easier for debugging.
|
// for debugging.
|
||||||
paths.reverse();
|
paths.reverse();
|
||||||
paths
|
paths
|
||||||
}
|
}
|
||||||
@ -70,20 +70,16 @@ fn operations_deposit() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// No transfers are permitted in phase 0.
|
|
||||||
/*
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(not(feature = "fake_crypto"))]
|
#[cfg(not(feature = "fake_crypto"))]
|
||||||
fn operations_transfer() {
|
fn operations_transfer() {
|
||||||
yaml_files_in_test_dir(&Path::new("operations").join("transfer"))
|
yaml_files_in_test_dir(&Path::new("operations").join("transfer"))
|
||||||
// .into_par_iter()
|
.into_par_iter()
|
||||||
.into_iter()
|
|
||||||
.rev()
|
.rev()
|
||||||
.for_each(|file| {
|
.for_each(|file| {
|
||||||
Doc::assert_tests_pass(file);
|
Doc::assert_tests_pass(file);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(not(feature = "fake_crypto"))]
|
#[cfg(not(feature = "fake_crypto"))]
|
||||||
|
Loading…
Reference in New Issue
Block a user