mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-10 20:22:02 +00:00
- Remove explicit `env_logger` usage from `state_processing` tests and `lcli`. - Set up tracing correctly for `lcli` (I've checked that we can see logs after this change). - I didn't do anything to set up logging for the `state_processing` tests, as these are rarely run manually (they never fail). We could add `test_logger` in there on an as-needed basis.
168 lines
5.7 KiB
Rust
168 lines
5.7 KiB
Rust
#![cfg(test)]
|
|
use crate::per_epoch_processing::process_epoch;
|
|
use beacon_chain::test_utils::BeaconChainHarness;
|
|
use beacon_chain::types::{EthSpec, MinimalEthSpec};
|
|
use bls::{FixedBytesExtended, Hash256};
|
|
use types::Slot;
|
|
|
|
#[tokio::test]
|
|
async fn runs_without_error() {
|
|
let harness = BeaconChainHarness::builder(MinimalEthSpec)
|
|
.default_spec()
|
|
.deterministic_keypairs(8)
|
|
.fresh_ephemeral_store()
|
|
.build();
|
|
harness.advance_slot();
|
|
|
|
let spec = MinimalEthSpec::default_spec();
|
|
let target_slot =
|
|
(MinimalEthSpec::genesis_epoch() + 4).end_slot(MinimalEthSpec::slots_per_epoch());
|
|
|
|
let state = harness.get_current_state();
|
|
harness
|
|
.add_attested_blocks_at_slots(
|
|
state,
|
|
Hash256::zero(),
|
|
(1..target_slot.as_u64())
|
|
.map(Slot::new)
|
|
.collect::<Vec<_>>()
|
|
.as_slice(),
|
|
(0..8).collect::<Vec<_>>().as_slice(),
|
|
)
|
|
.await;
|
|
let mut new_head_state = harness.get_current_state();
|
|
|
|
process_epoch(&mut new_head_state, &spec).unwrap();
|
|
}
|
|
|
|
#[cfg(not(debug_assertions))]
|
|
mod release_tests {
|
|
use super::*;
|
|
use crate::{
|
|
EpochProcessingError, SlotProcessingError, per_slot_processing::per_slot_processing,
|
|
};
|
|
use beacon_chain::test_utils::{AttestationStrategy, BlockStrategy};
|
|
use std::sync::Arc;
|
|
use types::{Epoch, ForkName, InconsistentFork, MainnetEthSpec};
|
|
|
|
#[tokio::test]
|
|
async fn altair_state_on_base_fork() {
|
|
let mut spec = MainnetEthSpec::default_spec();
|
|
let slots_per_epoch = MainnetEthSpec::slots_per_epoch();
|
|
// The Altair fork happens at epoch 1.
|
|
spec.altair_fork_epoch = Some(Epoch::new(1));
|
|
|
|
let altair_state = {
|
|
let harness = BeaconChainHarness::builder(MainnetEthSpec)
|
|
.spec(Arc::new(spec.clone()))
|
|
.deterministic_keypairs(8)
|
|
.fresh_ephemeral_store()
|
|
.build();
|
|
|
|
harness.advance_slot();
|
|
|
|
harness
|
|
.extend_chain(
|
|
// Build out enough blocks so we get an Altair block at the very end of an epoch.
|
|
(slots_per_epoch * 2 - 1) as usize,
|
|
BlockStrategy::OnCanonicalHead,
|
|
AttestationStrategy::AllValidators,
|
|
)
|
|
.await;
|
|
|
|
harness.get_current_state()
|
|
};
|
|
|
|
// Pre-conditions for a valid test.
|
|
assert_eq!(altair_state.fork_name(&spec).unwrap(), ForkName::Altair);
|
|
assert_eq!(
|
|
altair_state.slot(),
|
|
altair_state.current_epoch().end_slot(slots_per_epoch)
|
|
);
|
|
|
|
// Check the state is valid before starting this test.
|
|
process_epoch(&mut altair_state.clone(), &spec)
|
|
.expect("state passes intial epoch processing");
|
|
per_slot_processing(&mut altair_state.clone(), None, &spec)
|
|
.expect("state passes intial slot processing");
|
|
|
|
// Modify the spec so altair never happens.
|
|
spec.altair_fork_epoch = None;
|
|
|
|
let expected_err = InconsistentFork {
|
|
fork_at_slot: ForkName::Base,
|
|
object_fork: ForkName::Altair,
|
|
};
|
|
|
|
assert_eq!(altair_state.fork_name(&spec), Err(expected_err));
|
|
assert_eq!(
|
|
process_epoch(&mut altair_state.clone(), &spec),
|
|
Err(EpochProcessingError::InconsistentStateFork(expected_err))
|
|
);
|
|
assert_eq!(
|
|
per_slot_processing(&mut altair_state.clone(), None, &spec),
|
|
Err(SlotProcessingError::InconsistentStateFork(expected_err))
|
|
);
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn base_state_on_altair_fork() {
|
|
let mut spec = MainnetEthSpec::default_spec();
|
|
let slots_per_epoch = MainnetEthSpec::slots_per_epoch();
|
|
// The Altair fork never happens.
|
|
spec.altair_fork_epoch = None;
|
|
|
|
let base_state = {
|
|
let harness = BeaconChainHarness::builder(MainnetEthSpec)
|
|
.spec(Arc::new(spec.clone()))
|
|
.deterministic_keypairs(8)
|
|
.fresh_ephemeral_store()
|
|
.build();
|
|
|
|
harness.advance_slot();
|
|
|
|
harness
|
|
.extend_chain(
|
|
// Build out enough blocks so we get a block at the very end of an epoch.
|
|
(slots_per_epoch * 2 - 1) as usize,
|
|
BlockStrategy::OnCanonicalHead,
|
|
AttestationStrategy::AllValidators,
|
|
)
|
|
.await;
|
|
|
|
harness.get_current_state()
|
|
};
|
|
|
|
// Pre-conditions for a valid test.
|
|
assert_eq!(base_state.fork_name(&spec).unwrap(), ForkName::Base);
|
|
assert_eq!(
|
|
base_state.slot(),
|
|
base_state.current_epoch().end_slot(slots_per_epoch)
|
|
);
|
|
|
|
// Check the state is valid before starting this test.
|
|
process_epoch(&mut base_state.clone(), &spec)
|
|
.expect("state passes intial epoch processing");
|
|
per_slot_processing(&mut base_state.clone(), None, &spec)
|
|
.expect("state passes intial slot processing");
|
|
|
|
// Modify the spec so Altair happens at the first epoch.
|
|
spec.altair_fork_epoch = Some(Epoch::new(1));
|
|
|
|
let expected_err = InconsistentFork {
|
|
fork_at_slot: ForkName::Altair,
|
|
object_fork: ForkName::Base,
|
|
};
|
|
|
|
assert_eq!(base_state.fork_name(&spec), Err(expected_err));
|
|
assert_eq!(
|
|
process_epoch(&mut base_state.clone(), &spec),
|
|
Err(EpochProcessingError::InconsistentStateFork(expected_err))
|
|
);
|
|
assert_eq!(
|
|
per_slot_processing(&mut base_state.clone(), None, &spec),
|
|
Err(SlotProcessingError::InconsistentStateFork(expected_err))
|
|
);
|
|
}
|
|
}
|