Add test for when skip slots kill all validators (#657)
This commit is contained in:
parent
5853326342
commit
fc75dca9a3
@ -12,9 +12,14 @@ use beacon_chain::{
|
|||||||
BlockProcessingOutcome,
|
BlockProcessingOutcome,
|
||||||
};
|
};
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
use state_processing::{
|
||||||
|
per_slot_processing, per_slot_processing::Error as SlotProcessingError, EpochProcessingError,
|
||||||
|
};
|
||||||
use store::Store;
|
use store::Store;
|
||||||
use types::test_utils::{SeedableRng, TestRandom, XorShiftRng};
|
use types::test_utils::{SeedableRng, TestRandom, XorShiftRng};
|
||||||
use types::{Deposit, EthSpec, Hash256, Keypair, MinimalEthSpec, RelativeEpoch, Slot};
|
use types::{
|
||||||
|
BeaconStateError, Deposit, EthSpec, Hash256, Keypair, MinimalEthSpec, RelativeEpoch, Slot,
|
||||||
|
};
|
||||||
|
|
||||||
// Should ideally be divisible by 3.
|
// Should ideally be divisible by 3.
|
||||||
pub const VALIDATOR_COUNT: usize = 24;
|
pub const VALIDATOR_COUNT: usize = 24;
|
||||||
@ -32,6 +37,30 @@ fn get_harness(validator_count: usize) -> BeaconChainHarness<HarnessType<Minimal
|
|||||||
harness
|
harness
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn massive_skips() {
|
||||||
|
let harness = get_harness(8);
|
||||||
|
let spec = &MinimalEthSpec::default_spec();
|
||||||
|
let mut state = harness.chain.head().beacon_state;
|
||||||
|
|
||||||
|
// Run per_slot_processing until it returns an error.
|
||||||
|
let error = loop {
|
||||||
|
match per_slot_processing(&mut state, spec) {
|
||||||
|
Ok(_) => continue,
|
||||||
|
Err(e) => break e,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
assert!(state.slot > 1, "the state should skip at least one slot");
|
||||||
|
assert_eq!(
|
||||||
|
error,
|
||||||
|
SlotProcessingError::EpochProcessingError(EpochProcessingError::BeaconStateError(
|
||||||
|
BeaconStateError::InsufficientValidators
|
||||||
|
)),
|
||||||
|
"should return error indicating that validators have been slashed out"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn iterators() {
|
fn iterators() {
|
||||||
let num_blocks_produced = MinimalEthSpec::slots_per_epoch() * 2 - 1;
|
let num_blocks_produced = MinimalEthSpec::slots_per_epoch() * 2 - 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user