Add test_harness
tests for attestation count
This commit is contained in:
parent
cd9494181c
commit
89cc92572a
@ -47,6 +47,8 @@ test_cases:
|
|||||||
states:
|
states:
|
||||||
- slot: 63
|
- slot: 63
|
||||||
num_validators: 1003
|
num_validators: 1003
|
||||||
|
num_previous_epoch_attestations: 0
|
||||||
|
num_current_epoch_attestations: 10
|
||||||
slashed_validators: [11, 12, 13, 14, 42]
|
slashed_validators: [11, 12, 13, 14, 42]
|
||||||
exited_validators: []
|
exited_validators: []
|
||||||
exit_initiated_validators: [50]
|
exit_initiated_validators: [50]
|
||||||
|
@ -16,6 +16,10 @@ pub struct StateCheck {
|
|||||||
pub slot: Slot,
|
pub slot: Slot,
|
||||||
/// Checked against `beacon_state.validator_registry.len()`.
|
/// Checked against `beacon_state.validator_registry.len()`.
|
||||||
pub num_validators: Option<usize>,
|
pub num_validators: Option<usize>,
|
||||||
|
/// The number of pending attestations from the previous epoch that should be in the state.
|
||||||
|
pub num_previous_epoch_attestations: Option<usize>,
|
||||||
|
/// The number of pending attestations from the current epoch that should be in the state.
|
||||||
|
pub num_current_epoch_attestations: Option<usize>,
|
||||||
/// A list of validator indices which have been penalized. Must be in ascending order.
|
/// A list of validator indices which have been penalized. Must be in ascending order.
|
||||||
pub slashed_validators: Option<Vec<u64>>,
|
pub slashed_validators: Option<Vec<u64>>,
|
||||||
/// A list of validator indices which have been fully exited. Must be in ascending order.
|
/// A list of validator indices which have been fully exited. Must be in ascending order.
|
||||||
@ -34,6 +38,8 @@ impl StateCheck {
|
|||||||
Self {
|
Self {
|
||||||
slot: Slot::from(as_u64(&yaml, "slot").expect("State must specify slot")),
|
slot: Slot::from(as_u64(&yaml, "slot").expect("State must specify slot")),
|
||||||
num_validators: as_usize(&yaml, "num_validators"),
|
num_validators: as_usize(&yaml, "num_validators"),
|
||||||
|
num_previous_epoch_attestations: as_usize(&yaml, "num_previous_epoch_attestations"),
|
||||||
|
num_current_epoch_attestations: as_usize(&yaml, "num_current_epoch_attestations"),
|
||||||
slashed_validators: as_vec_u64(&yaml, "slashed_validators"),
|
slashed_validators: as_vec_u64(&yaml, "slashed_validators"),
|
||||||
exited_validators: as_vec_u64(&yaml, "exited_validators"),
|
exited_validators: as_vec_u64(&yaml, "exited_validators"),
|
||||||
exit_initiated_validators: as_vec_u64(&yaml, "exit_initiated_validators"),
|
exit_initiated_validators: as_vec_u64(&yaml, "exit_initiated_validators"),
|
||||||
@ -58,6 +64,7 @@ impl StateCheck {
|
|||||||
"State slot is invalid."
|
"State slot is invalid."
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Check the validator count
|
||||||
if let Some(num_validators) = self.num_validators {
|
if let Some(num_validators) = self.num_validators {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
state.validator_registry.len(),
|
state.validator_registry.len(),
|
||||||
@ -67,6 +74,26 @@ impl StateCheck {
|
|||||||
info!("OK: num_validators = {}.", num_validators);
|
info!("OK: num_validators = {}.", num_validators);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check the previous epoch attestations
|
||||||
|
if let Some(n) = self.num_previous_epoch_attestations {
|
||||||
|
assert_eq!(
|
||||||
|
state.previous_epoch_attestations.len(),
|
||||||
|
n,
|
||||||
|
"previous epoch attestations count != expected."
|
||||||
|
);
|
||||||
|
info!("OK: num_previous_epoch_attestations = {}.", n);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check the current epoch attestations
|
||||||
|
if let Some(n) = self.num_current_epoch_attestations {
|
||||||
|
assert_eq!(
|
||||||
|
state.current_epoch_attestations.len(),
|
||||||
|
n,
|
||||||
|
"current epoch attestations count != expected."
|
||||||
|
);
|
||||||
|
info!("OK: num_current_epoch_attestations = {}.", n);
|
||||||
|
}
|
||||||
|
|
||||||
// Check for slashed validators.
|
// Check for slashed validators.
|
||||||
if let Some(ref slashed_validators) = self.slashed_validators {
|
if let Some(ref slashed_validators) = self.slashed_validators {
|
||||||
let actually_slashed_validators: Vec<u64> = state
|
let actually_slashed_validators: Vec<u64> = state
|
||||||
|
Loading…
Reference in New Issue
Block a user