Add (failing) attester_slashing tests

This commit is contained in:
Paul Hauner 2019-05-24 13:57:44 +10:00
parent 686963bd34
commit 07931d1f5a
No known key found for this signature in database
GPG Key ID: 5E2CFF9B75FA63DF
4 changed files with 60 additions and 0 deletions

View File

@ -7,6 +7,7 @@ mod bls_g2_compressed;
mod bls_g2_uncompressed;
mod bls_priv_to_pub;
mod bls_sign_msg;
mod operations_attester_slashing;
mod operations_deposit;
mod operations_exit;
mod operations_proposer_slashing;
@ -21,6 +22,7 @@ pub use bls_g2_compressed::*;
pub use bls_g2_uncompressed::*;
pub use bls_priv_to_pub::*;
pub use bls_sign_msg::*;
pub use operations_attester_slashing::*;
pub use operations_deposit::*;
pub use operations_exit::*;
pub use operations_proposer_slashing::*;

View File

@ -0,0 +1,42 @@
use super::*;
use crate::case_result::compare_beacon_state_results_without_caches;
use serde_derive::Deserialize;
use state_processing::per_block_processing::process_attester_slashings;
use types::{AttesterSlashing, BeaconState, EthSpec};
#[derive(Debug, Clone, Deserialize)]
pub struct OperationsAttesterSlashing<E: EthSpec> {
pub description: String,
#[serde(bound = "E: EthSpec")]
pub pre: BeaconState<E>,
pub attester_slashing: AttesterSlashing,
#[serde(bound = "E: EthSpec")]
pub post: Option<BeaconState<E>>,
}
impl<E: EthSpec> YamlDecode for OperationsAttesterSlashing<E> {
fn yaml_decode(yaml: &String) -> Result<Self, Error> {
Ok(serde_yaml::from_str(&yaml.as_str()).unwrap())
}
}
impl<E: EthSpec> Case for OperationsAttesterSlashing<E> {
fn description(&self) -> String {
self.description.clone()
}
fn result(&self, _case_index: usize) -> Result<(), Error> {
let mut state = self.pre.clone();
let attester_slashing = self.attester_slashing.clone();
let mut expected = self.post.clone();
// Processing requires the epoch cache.
state.build_all_caches(&E::spec()).unwrap();
let result = process_attester_slashings(&mut state, &[attester_slashing], &E::spec());
let mut result = result.and_then(|_| Ok(state));
compare_beacon_state_results_without_caches(&mut result, &mut expected)
}
}

View File

@ -77,6 +77,12 @@ impl Doc {
("operations", "proposer_slashing", "minimal") => {
run_test::<OperationsProposerSlashing<MinimalEthSpec>>(self)
}
("operations", "attester_slashing", "mainnet") => {
run_test::<OperationsAttesterSlashing<MainnetEthSpec>>(self)
}
("operations", "attester_slashing", "minimal") => {
run_test::<OperationsAttesterSlashing<MinimalEthSpec>>(self)
}
(runner, handler, config) => panic!(
"No implementation for runner: \"{}\", handler: \"{}\", config: \"{}\"",
runner, handler, config

View File

@ -110,6 +110,16 @@ fn operations_proposer_slashing() {
});
}
#[test]
#[cfg(not(feature = "fake_crypto"))]
fn operations_attester_slashing() {
yaml_files_in_test_dir(&Path::new("operations").join("attester_slashing"))
.into_par_iter()
.for_each(|file| {
Doc::assert_tests_pass(file);
});
}
#[test]
#[cfg(not(feature = "fake_crypto"))]
fn bls() {