diff --git a/beacon_node/beacon_chain/src/test_utils.rs b/beacon_node/beacon_chain/src/test_utils.rs index 5e61fb79a80..67a53b90497 100644 --- a/beacon_node/beacon_chain/src/test_utils.rs +++ b/beacon_node/beacon_chain/src/test_utils.rs @@ -229,6 +229,29 @@ impl BeaconChainHarness> { target_aggregators_per_committee: u64, store_config: StoreConfig, chain_config: ChainConfig, + ) -> Self { + Self::new_with_mutator( + eth_spec_instance, + spec, + validator_keypairs, + target_aggregators_per_committee, + store_config, + chain_config, + |x| x, + ) + } + + /// Apply a function to beacon chain builder before building. + pub fn new_with_mutator( + eth_spec_instance: E, + spec: Option, + validator_keypairs: Vec, + target_aggregators_per_committee: u64, + store_config: StoreConfig, + chain_config: ChainConfig, + mutator: impl FnOnce( + BeaconChainBuilder>, + ) -> BeaconChainBuilder>, ) -> Self { let data_dir = tempdir().expect("should create temporary data_dir"); let mut spec = spec.unwrap_or_else(test_spec::); @@ -240,7 +263,7 @@ impl BeaconChainHarness> { let log = test_logger(); let store = HotColdDB::open_ephemeral(store_config, spec.clone(), log.clone()).unwrap(); - let chain = BeaconChainBuilder::new(eth_spec_instance) + let builder = BeaconChainBuilder::new(eth_spec_instance) .logger(log.clone()) .custom_spec(spec.clone()) .store(Arc::new(store)) @@ -260,9 +283,9 @@ impl BeaconChainHarness> { log.clone(), 1, ))) - .monitor_validators(true, vec![], log) - .build() - .expect("should build"); + .monitor_validators(true, vec![], log); + + let chain = mutator(builder).build().expect("should build"); Self { spec: chain.spec.clone(), diff --git a/beacon_node/beacon_chain/tests/block_verification.rs b/beacon_node/beacon_chain/tests/block_verification.rs index 446b19195ab..ccdb98a2310 100644 --- a/beacon_node/beacon_chain/tests/block_verification.rs +++ b/beacon_node/beacon_chain/tests/block_verification.rs @@ -4,7 +4,7 @@ extern crate lazy_static; use beacon_chain::test_utils::{ - AttestationStrategy, BeaconChainHarness, BlockStrategy, EphemeralHarnessType, + test_logger, AttestationStrategy, BeaconChainHarness, BlockStrategy, EphemeralHarnessType, }; use beacon_chain::{BeaconSnapshot, BlockError, ChainConfig, ChainSegmentResult}; use slasher::{Config as SlasherConfig, Slasher}; @@ -830,17 +830,25 @@ fn block_gossip_verification() { #[test] fn verify_block_for_gossip_slashing_detection() { - let mut harness = get_harness(VALIDATOR_COUNT); - let slasher_dir = tempdir().unwrap(); let slasher = Arc::new( Slasher::open( SlasherConfig::new(slasher_dir.path().into()).for_testing(), - harness.logger().clone(), + test_logger(), ) .unwrap(), ); - harness.chain.slasher = Some(slasher.clone()); + + let harness = BeaconChainHarness::new_with_mutator( + MainnetEthSpec, + None, + KEYPAIRS.to_vec(), + 1 << 32, + StoreConfig::default(), + ChainConfig::default(), + |builder| builder.slasher(slasher.clone()), + ); + harness.advance_slot(); let state = harness.get_current_state(); let (block1, _) = harness.make_block(state.clone(), Slot::new(1));