mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-27 01:33:33 +00:00
@@ -12,6 +12,8 @@ mod epoch_processing_final_updates;
|
||||
mod epoch_processing_justification_and_finalization;
|
||||
mod epoch_processing_registry_updates;
|
||||
mod epoch_processing_slashings;
|
||||
mod genesis_initialization;
|
||||
mod genesis_validity;
|
||||
mod operations_attestation;
|
||||
mod operations_attester_slashing;
|
||||
mod operations_block_header;
|
||||
@@ -36,6 +38,8 @@ pub use epoch_processing_final_updates::*;
|
||||
pub use epoch_processing_justification_and_finalization::*;
|
||||
pub use epoch_processing_registry_updates::*;
|
||||
pub use epoch_processing_slashings::*;
|
||||
pub use genesis_initialization::*;
|
||||
pub use genesis_validity::*;
|
||||
pub use operations_attestation::*;
|
||||
pub use operations_attester_slashing::*;
|
||||
pub use operations_block_header::*;
|
||||
|
||||
45
tests/ef_tests/src/cases/genesis_initialization.rs
Normal file
45
tests/ef_tests/src/cases/genesis_initialization.rs
Normal file
@@ -0,0 +1,45 @@
|
||||
use super::*;
|
||||
use crate::bls_setting::BlsSetting;
|
||||
use crate::case_result::compare_beacon_state_results_without_caches;
|
||||
use serde_derive::Deserialize;
|
||||
use state_processing::initialize_beacon_state_from_eth1;
|
||||
use types::{BeaconState, Deposit, EthSpec, Hash256};
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[serde(bound = "E: EthSpec")]
|
||||
pub struct GenesisInitialization<E: EthSpec> {
|
||||
pub description: String,
|
||||
pub bls_setting: Option<BlsSetting>,
|
||||
pub eth1_block_hash: Hash256,
|
||||
pub eth1_timestamp: u64,
|
||||
pub deposits: Vec<Deposit>,
|
||||
pub state: Option<BeaconState<E>>,
|
||||
}
|
||||
|
||||
impl<E: EthSpec> YamlDecode for GenesisInitialization<E> {
|
||||
fn yaml_decode(yaml: &str) -> Result<Self, Error> {
|
||||
Ok(serde_yaml::from_str(yaml).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> Case for GenesisInitialization<E> {
|
||||
fn description(&self) -> String {
|
||||
self.description.clone()
|
||||
}
|
||||
|
||||
fn result(&self, _case_index: usize) -> Result<(), Error> {
|
||||
self.bls_setting.unwrap_or_default().check()?;
|
||||
let spec = &E::default_spec();
|
||||
|
||||
let mut result = initialize_beacon_state_from_eth1(
|
||||
self.eth1_block_hash,
|
||||
self.eth1_timestamp,
|
||||
self.deposits.clone(),
|
||||
spec,
|
||||
);
|
||||
|
||||
let mut expected = self.state.clone();
|
||||
|
||||
compare_beacon_state_results_without_caches(&mut result, &mut expected)
|
||||
}
|
||||
}
|
||||
42
tests/ef_tests/src/cases/genesis_validity.rs
Normal file
42
tests/ef_tests/src/cases/genesis_validity.rs
Normal file
@@ -0,0 +1,42 @@
|
||||
use super::*;
|
||||
use crate::bls_setting::BlsSetting;
|
||||
use serde_derive::Deserialize;
|
||||
use state_processing::is_valid_genesis_state;
|
||||
use types::{BeaconState, EthSpec};
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[serde(bound = "E: EthSpec")]
|
||||
pub struct GenesisValidity<E: EthSpec> {
|
||||
pub description: String,
|
||||
pub bls_setting: Option<BlsSetting>,
|
||||
pub genesis: BeaconState<E>,
|
||||
pub is_valid: bool,
|
||||
}
|
||||
|
||||
impl<E: EthSpec> YamlDecode for GenesisValidity<E> {
|
||||
fn yaml_decode(yaml: &str) -> Result<Self, Error> {
|
||||
Ok(serde_yaml::from_str(yaml).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> Case for GenesisValidity<E> {
|
||||
fn description(&self) -> String {
|
||||
self.description.clone()
|
||||
}
|
||||
|
||||
fn result(&self, _case_index: usize) -> Result<(), Error> {
|
||||
self.bls_setting.unwrap_or_default().check()?;
|
||||
let spec = &E::default_spec();
|
||||
|
||||
let is_valid = is_valid_genesis_state(&self.genesis, spec);
|
||||
|
||||
if is_valid == self.is_valid {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(Error::NotEqual(format!(
|
||||
"Got {}, expected {}",
|
||||
is_valid, self.is_valid
|
||||
)))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -134,6 +134,14 @@ impl Doc {
|
||||
// FIXME: skipped due to compact committees issue
|
||||
// run_test::<EpochProcessingFinalUpdates<MainnetEthSpec>>(self)
|
||||
}
|
||||
("genesis", "initialization", "minimal") => {
|
||||
run_test::<GenesisInitialization<MinimalEthSpec>>(self)
|
||||
}
|
||||
("genesis", "initialization", "mainnet") => {
|
||||
run_test::<GenesisInitialization<MainnetEthSpec>>(self)
|
||||
}
|
||||
("genesis", "validity", "minimal") => run_test::<GenesisValidity<MinimalEthSpec>>(self),
|
||||
("genesis", "validity", "mainnet") => run_test::<GenesisValidity<MainnetEthSpec>>(self),
|
||||
(runner, handler, config) => panic!(
|
||||
"No implementation for runner: \"{}\", handler: \"{}\", config: \"{}\"",
|
||||
runner, handler, config
|
||||
|
||||
@@ -205,3 +205,21 @@ fn epoch_processing_final_updates() {
|
||||
Doc::assert_tests_pass(file);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn genesis_initialization() {
|
||||
yaml_files_in_test_dir(&Path::new("genesis").join("initialization"))
|
||||
.into_par_iter()
|
||||
.for_each(|file| {
|
||||
Doc::assert_tests_pass(file);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn genesis_validity() {
|
||||
yaml_files_in_test_dir(&Path::new("genesis").join("validity"))
|
||||
.into_par_iter()
|
||||
.for_each(|file| {
|
||||
Doc::assert_tests_pass(file);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user