ef_tests: attestation tests

This commit is contained in:
Michael Sproul 2019-06-04 11:05:35 +10:00
parent 10884359af
commit 5020028bbc
No known key found for this signature in database
GPG Key ID: 77B1309D2E54E914
5 changed files with 60 additions and 0 deletions

View File

@ -9,6 +9,7 @@ mod bls_priv_to_pub;
mod bls_sign_msg;
mod epoch_processing_crosslinks;
mod epoch_processing_registry_updates;
mod operations_attestation;
mod operations_attester_slashing;
mod operations_deposit;
mod operations_exit;
@ -26,6 +27,7 @@ pub use bls_priv_to_pub::*;
pub use bls_sign_msg::*;
pub use epoch_processing_crosslinks::*;
pub use epoch_processing_registry_updates::*;
pub use operations_attestation::*;
pub use operations_attester_slashing::*;
pub use operations_deposit::*;
pub use operations_exit::*;

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_attestations;
use types::{Attestation, BeaconState, EthSpec};
#[derive(Debug, Clone, Deserialize)]
pub struct OperationsAttestation<E: EthSpec> {
pub description: String,
#[serde(bound = "E: EthSpec")]
pub pre: BeaconState<E>,
pub attestation: Attestation,
#[serde(bound = "E: EthSpec")]
pub post: Option<BeaconState<E>>,
}
impl<E: EthSpec> YamlDecode for OperationsAttestation<E> {
fn yaml_decode(yaml: &String) -> Result<Self, Error> {
Ok(serde_yaml::from_str(&yaml.as_str()).unwrap())
}
}
impl<E: EthSpec> Case for OperationsAttestation<E> {
fn description(&self) -> String {
self.description.clone()
}
fn result(&self, _case_index: usize) -> Result<(), Error> {
let mut state = self.pre.clone();
let attestation = self.attestation.clone();
let mut expected = self.post.clone();
// Processing requires the epoch cache.
state.build_all_caches(&E::spec()).unwrap();
let result = process_attestations(&mut state, &[attestation], &E::spec());
let mut result = result.and_then(|_| Ok(state));
compare_beacon_state_results_without_caches(&mut result, &mut expected)
}
}

View File

@ -83,6 +83,12 @@ impl Doc {
("operations", "attester_slashing", "minimal") => {
run_test::<OperationsAttesterSlashing<MinimalEthSpec>>(self)
}
("operations", "attestation", "mainnet") => {
run_test::<OperationsAttestation<MainnetEthSpec>>(self)
}
("operations", "attestation", "minimal") => {
run_test::<OperationsAttestation<MinimalEthSpec>>(self)
}
("epoch_processing", "crosslinks", "minimal") => {
run_test::<EpochProcessingCrosslinks<MinimalEthSpec>>(self)
}

View File

@ -23,6 +23,7 @@ impl EthSpec for MinimalEthSpec {
// TODO: this spec is likely incorrect!
let mut spec = FewValidatorsEthSpec::spec();
spec.shuffle_round_count = 10;
spec.min_attestation_inclusion_delay = 2;
spec
}
}

View File

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