mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-29 20:27:14 +00:00
Add BeaconChainHarness::builder (#2707)
## Issue Addressed NA ## Proposed Changes This PR is near-identical to https://github.com/sigp/lighthouse/pull/2652, however it is to be merged into `unstable` instead of `merge-f2f`. Please see that PR for reasoning. I'm making this duplicate PR to merge to `unstable` in an effort to shrink the diff between `unstable` and `merge-f2f` by doing smaller, lead-up PRs. ## Additional Info NA
This commit is contained in:
@@ -14,11 +14,10 @@ use fork_choice::{
|
||||
ForkChoiceStore, InvalidAttestation, InvalidBlock, QueuedAttestation,
|
||||
SAFE_SLOTS_TO_UPDATE_JUSTIFIED,
|
||||
};
|
||||
use store::{MemoryStore, StoreConfig};
|
||||
use store::MemoryStore;
|
||||
use types::{
|
||||
test_utils::{generate_deterministic_keypair, generate_deterministic_keypairs},
|
||||
BeaconBlock, BeaconBlockRef, BeaconState, Checkpoint, Epoch, EthSpec, Hash256,
|
||||
IndexedAttestation, MainnetEthSpec, Slot, SubnetId,
|
||||
test_utils::generate_deterministic_keypair, BeaconBlock, BeaconBlockRef, BeaconState,
|
||||
Checkpoint, Epoch, EthSpec, Hash256, IndexedAttestation, MainnetEthSpec, Slot, SubnetId,
|
||||
};
|
||||
|
||||
pub type E = MainnetEthSpec;
|
||||
@@ -48,25 +47,23 @@ impl fmt::Debug for ForkChoiceTest {
|
||||
impl ForkChoiceTest {
|
||||
/// Creates a new tester.
|
||||
pub fn new() -> Self {
|
||||
let harness = BeaconChainHarness::new_with_store_config(
|
||||
MainnetEthSpec,
|
||||
None,
|
||||
generate_deterministic_keypairs(VALIDATOR_COUNT),
|
||||
StoreConfig::default(),
|
||||
);
|
||||
let harness = BeaconChainHarness::builder(MainnetEthSpec)
|
||||
.default_spec()
|
||||
.deterministic_keypairs(VALIDATOR_COUNT)
|
||||
.fresh_ephemeral_store()
|
||||
.build();
|
||||
|
||||
Self { harness }
|
||||
}
|
||||
|
||||
/// Creates a new tester with a custom chain config.
|
||||
pub fn new_with_chain_config(chain_config: ChainConfig) -> Self {
|
||||
let harness = BeaconChainHarness::new_with_chain_config(
|
||||
MainnetEthSpec,
|
||||
None,
|
||||
generate_deterministic_keypairs(VALIDATOR_COUNT),
|
||||
StoreConfig::default(),
|
||||
chain_config,
|
||||
);
|
||||
let harness = BeaconChainHarness::builder(MainnetEthSpec)
|
||||
.default_spec()
|
||||
.chain_config(chain_config)
|
||||
.deterministic_keypairs(VALIDATOR_COUNT)
|
||||
.fresh_ephemeral_store()
|
||||
.build();
|
||||
|
||||
Self { harness }
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ use crate::per_block_processing::errors::{
|
||||
ProposerSlashingInvalid,
|
||||
};
|
||||
use crate::{per_block_processing::process_operations, BlockSignatureStrategy, VerifySignatures};
|
||||
use beacon_chain::store::StoreConfig;
|
||||
use beacon_chain::test_utils::{BeaconChainHarness, EphemeralHarnessType};
|
||||
use lazy_static::lazy_static;
|
||||
use ssz_types::Bitfield;
|
||||
@@ -32,12 +31,11 @@ fn get_harness<E: EthSpec>(
|
||||
// Set the state and block to be in the last slot of the `epoch_offset`th epoch.
|
||||
let last_slot_of_epoch =
|
||||
(MainnetEthSpec::genesis_epoch() + epoch_offset).end_slot(E::slots_per_epoch());
|
||||
let harness = BeaconChainHarness::new_with_store_config(
|
||||
E::default(),
|
||||
None,
|
||||
KEYPAIRS[0..num_validators].to_vec(),
|
||||
StoreConfig::default(),
|
||||
);
|
||||
let harness = BeaconChainHarness::builder(E::default())
|
||||
.default_spec()
|
||||
.keypairs(KEYPAIRS[0..num_validators].to_vec())
|
||||
.fresh_ephemeral_store()
|
||||
.build();
|
||||
let state = harness.get_current_state();
|
||||
if last_slot_of_epoch > Slot::new(0) {
|
||||
harness.add_attested_blocks_at_slots(
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#![cfg(test)]
|
||||
use crate::per_epoch_processing::process_epoch;
|
||||
use beacon_chain::store::StoreConfig;
|
||||
use beacon_chain::test_utils::BeaconChainHarness;
|
||||
use beacon_chain::types::{EthSpec, MinimalEthSpec};
|
||||
use bls::Hash256;
|
||||
@@ -11,12 +10,11 @@ use types::Slot;
|
||||
fn runs_without_error() {
|
||||
Builder::from_env(Env::default().default_filter_or("error")).init();
|
||||
|
||||
let harness = BeaconChainHarness::new_with_store_config(
|
||||
MinimalEthSpec,
|
||||
None,
|
||||
types::test_utils::generate_deterministic_keypairs(8),
|
||||
StoreConfig::default(),
|
||||
);
|
||||
let harness = BeaconChainHarness::builder(MinimalEthSpec)
|
||||
.default_spec()
|
||||
.deterministic_keypairs(8)
|
||||
.fresh_ephemeral_store()
|
||||
.build();
|
||||
harness.advance_slot();
|
||||
|
||||
let spec = MinimalEthSpec::default_spec();
|
||||
@@ -55,11 +53,11 @@ mod release_tests {
|
||||
spec.altair_fork_epoch = Some(Epoch::new(1));
|
||||
|
||||
let altair_state = {
|
||||
let harness = BeaconChainHarness::new(
|
||||
MainnetEthSpec,
|
||||
Some(spec.clone()),
|
||||
types::test_utils::generate_deterministic_keypairs(8),
|
||||
);
|
||||
let harness = BeaconChainHarness::builder(MainnetEthSpec)
|
||||
.spec(spec.clone())
|
||||
.deterministic_keypairs(8)
|
||||
.fresh_ephemeral_store()
|
||||
.build();
|
||||
|
||||
harness.advance_slot();
|
||||
|
||||
@@ -113,11 +111,11 @@ mod release_tests {
|
||||
spec.altair_fork_epoch = None;
|
||||
|
||||
let base_state = {
|
||||
let harness = BeaconChainHarness::new(
|
||||
MainnetEthSpec,
|
||||
Some(spec.clone()),
|
||||
types::test_utils::generate_deterministic_keypairs(8),
|
||||
);
|
||||
let harness = BeaconChainHarness::builder(MainnetEthSpec)
|
||||
.spec(spec.clone())
|
||||
.deterministic_keypairs(8)
|
||||
.fresh_ephemeral_store()
|
||||
.build();
|
||||
|
||||
harness.advance_slot();
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use beacon_chain::store::StoreConfig;
|
||||
use beacon_chain::test_utils::{BeaconChainHarness, EphemeralHarnessType};
|
||||
use types::{BeaconState, EthSpec, MainnetEthSpec};
|
||||
|
||||
@@ -6,12 +5,11 @@ const TREE_HASH_LOOPS: usize = 1_000;
|
||||
const VALIDATOR_COUNT: usize = 1_000;
|
||||
|
||||
fn get_harness<T: EthSpec>() -> BeaconChainHarness<EphemeralHarnessType<T>> {
|
||||
let harness = BeaconChainHarness::new_with_store_config(
|
||||
T::default(),
|
||||
None,
|
||||
types::test_utils::generate_deterministic_keypairs(VALIDATOR_COUNT),
|
||||
StoreConfig::default(),
|
||||
);
|
||||
let harness = BeaconChainHarness::builder(T::default())
|
||||
.default_spec()
|
||||
.deterministic_keypairs(VALIDATOR_COUNT)
|
||||
.fresh_ephemeral_store()
|
||||
.build();
|
||||
|
||||
harness.advance_slot();
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#![cfg(test)]
|
||||
use crate::test_utils::*;
|
||||
use beacon_chain::store::StoreConfig;
|
||||
use beacon_chain::test_utils::{BeaconChainHarness, EphemeralHarnessType};
|
||||
use beacon_chain::types::*;
|
||||
use swap_or_not_shuffle::shuffle_list;
|
||||
@@ -13,12 +12,11 @@ lazy_static! {
|
||||
}
|
||||
|
||||
fn get_harness<E: EthSpec>(validator_count: usize) -> BeaconChainHarness<EphemeralHarnessType<E>> {
|
||||
let harness = BeaconChainHarness::new_with_store_config(
|
||||
E::default(),
|
||||
None,
|
||||
KEYPAIRS[0..validator_count].to_vec(),
|
||||
StoreConfig::default(),
|
||||
);
|
||||
let harness = BeaconChainHarness::builder(E::default())
|
||||
.default_spec()
|
||||
.keypairs(KEYPAIRS[0..validator_count].to_vec())
|
||||
.fresh_ephemeral_store()
|
||||
.build();
|
||||
harness.advance_slot();
|
||||
harness
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#![cfg(test)]
|
||||
use crate::test_utils::*;
|
||||
use crate::test_utils::{SeedableRng, XorShiftRng};
|
||||
use beacon_chain::store::config::StoreConfig;
|
||||
use beacon_chain::test_utils::{
|
||||
interop_genesis_state, test_spec, BeaconChainHarness, EphemeralHarnessType,
|
||||
};
|
||||
@@ -29,12 +28,11 @@ fn get_harness<E: EthSpec>(
|
||||
validator_count: usize,
|
||||
slot: Slot,
|
||||
) -> BeaconChainHarness<EphemeralHarnessType<E>> {
|
||||
let harness = BeaconChainHarness::new_with_store_config(
|
||||
E::default(),
|
||||
None,
|
||||
KEYPAIRS[0..validator_count].to_vec(),
|
||||
StoreConfig::default(),
|
||||
);
|
||||
let harness = BeaconChainHarness::builder(E::default())
|
||||
.default_spec()
|
||||
.keypairs(KEYPAIRS[0..validator_count].to_vec())
|
||||
.fresh_ephemeral_store()
|
||||
.build();
|
||||
|
||||
let skip_to_slot = slot - SLOT_OFFSET;
|
||||
if skip_to_slot > Slot::new(0) {
|
||||
|
||||
Reference in New Issue
Block a user