Fix the new BLS to execution change test

This commit is contained in:
Michael Sproul
2023-01-25 15:47:07 +11:00
parent 79a20e8a5f
commit e48487db01
8 changed files with 123 additions and 65 deletions

View File

@@ -1,5 +1,7 @@
use beacon_chain::{
test_utils::{BeaconChainHarness, BoxedMutator, EphemeralHarnessType},
test_utils::{
BeaconChainHarness, BoxedMutator, Builder as HarnessBuilder, EphemeralHarnessType,
},
BeaconChain, BeaconChainTypes,
};
use directory::DEFAULT_ROOT_DIR;
@@ -55,25 +57,39 @@ pub struct ApiServer<E: EthSpec, SFut: Future<Output = ()>> {
pub external_peer_id: PeerId,
}
type Initializer<E> = Box<
dyn FnOnce(HarnessBuilder<EphemeralHarnessType<E>>) -> HarnessBuilder<EphemeralHarnessType<E>>,
>;
type Mutator<E> = BoxedMutator<E, MemoryStore<E>, MemoryStore<E>>;
impl<E: EthSpec> InteractiveTester<E> {
pub async fn new(spec: Option<ChainSpec>, validator_count: usize) -> Self {
Self::new_with_mutator(spec, validator_count, None).await
Self::new_with_initializer_and_mutator(spec, validator_count, None, None).await
}
pub async fn new_with_mutator(
pub async fn new_with_initializer_and_mutator(
spec: Option<ChainSpec>,
validator_count: usize,
initializer: Option<Initializer<E>>,
mutator: Option<Mutator<E>>,
) -> Self {
let mut harness_builder = BeaconChainHarness::builder(E::default())
.spec_or_default(spec)
.deterministic_keypairs(validator_count)
.logger(test_logger())
.mock_execution_layer()
.fresh_ephemeral_store();
.mock_execution_layer();
harness_builder = if let Some(initializer) = initializer {
// Apply custom initialization provided by the caller.
initializer(harness_builder)
} else {
// Apply default initial configuration.
harness_builder
.deterministic_keypairs(validator_count)
.fresh_ephemeral_store()
};
// Add a mutator for the beacon chain builder which will be called in
// `HarnessBuilder::build`.
if let Some(mutator) = mutator {
harness_builder = harness_builder.initial_mutator(mutator);
}

View File

@@ -1,8 +1,15 @@
//! Tests for API behaviour across fork boundaries.
use crate::common::*;
use beacon_chain::{test_utils::RelativeSyncCommittee, StateSkipConfig};
use beacon_chain::{
test_utils::{RelativeSyncCommittee, DEFAULT_ETH1_BLOCK_HASH, HARNESS_GENESIS_TIME},
StateSkipConfig,
};
use eth2::types::{IndexedErrorMessage, StateId, SyncSubcommittee};
use types::{Address, ChainSpec, Epoch, EthSpec, MinimalEthSpec, Slot};
use genesis::{bls_withdrawal_credentials, interop_genesis_state_with_withdrawal_credentials};
use types::{
test_utils::{generate_deterministic_keypair, generate_deterministic_keypairs},
Address, ChainSpec, Epoch, EthSpec, Hash256, MinimalEthSpec, Slot,
};
type E = MinimalEthSpec;
@@ -338,7 +345,39 @@ async fn bls_to_execution_changes_update_all_around_capella_fork() {
let fork_epoch = Epoch::new(2);
let spec = capella_spec(fork_epoch);
let max_bls_to_execution_changes = E::max_bls_to_execution_changes();
let tester = InteractiveTester::<E>::new(Some(spec.clone()), validator_count).await;
// Use a genesis state with entirely BLS withdrawal credentials.
// Offset keypairs by `validator_count` to create keys distinct from the signing keys.
let validator_keypairs = generate_deterministic_keypairs(validator_count);
let withdrawal_keypairs = (0..validator_count)
.map(|i| Some(generate_deterministic_keypair(i + validator_count)))
.collect::<Vec<_>>();
let withdrawal_credentials = withdrawal_keypairs
.iter()
.map(|keypair| bls_withdrawal_credentials(&keypair.as_ref().unwrap().pk, &spec))
.collect::<Vec<_>>();
let genesis_state = interop_genesis_state_with_withdrawal_credentials(
&validator_keypairs,
&withdrawal_credentials,
HARNESS_GENESIS_TIME,
Hash256::from_slice(DEFAULT_ETH1_BLOCK_HASH),
None,
&spec,
)
.unwrap();
let tester = InteractiveTester::<E>::new_with_initializer_and_mutator(
Some(spec.clone()),
validator_count,
Some(Box::new(|harness_builder| {
harness_builder
.keypairs(validator_keypairs)
.withdrawal_keypairs(withdrawal_keypairs)
.genesis_state_ephemeral_store(genesis_state)
})),
None,
)
.await;
let harness = &tester.harness;
let client = &tester.client;

View File

@@ -278,9 +278,10 @@ pub async fn proposer_boost_re_org_test(
let num_empty_votes = Some(attesters_per_slot * percent_empty_votes / 100);
let num_head_votes = Some(attesters_per_slot * percent_head_votes / 100);
let tester = InteractiveTester::<E>::new_with_mutator(
let tester = InteractiveTester::<E>::new_with_initializer_and_mutator(
Some(spec),
validator_count,
None,
Some(Box::new(move |builder| {
builder
.proposer_re_org_threshold(Some(ReOrgThreshold(re_org_threshold)))