add helper to check existence of many validator types
This commit is contained in:
parent
00df808f59
commit
4420d13816
|
@ -1,5 +1,6 @@
|
|||
from eth2spec.test.context import expect_assertion_error, is_post_altair
|
||||
from eth2spec.test.helpers.block import apply_empty_block, sign_block, transition_unsigned_block
|
||||
from eth2spec.test.helpers.voluntary_exits import get_exited_validators
|
||||
|
||||
|
||||
def get_balance(state, index):
|
||||
|
@ -133,3 +134,24 @@ def _set_empty_participation(spec, state, current=True, previous=True):
|
|||
|
||||
def set_empty_participation(spec, state, rng=None):
|
||||
_set_empty_participation(spec, state)
|
||||
|
||||
|
||||
def ensure_state_has_validators_across_lifecycle(spec, state):
|
||||
"""
|
||||
Scan the validator registry to ensure there is at least 1 validator
|
||||
for each of the following lifecycle states:
|
||||
1. Pending / deposited
|
||||
2. Active
|
||||
3. Exited
|
||||
4. Slashed
|
||||
"""
|
||||
has_pending = any(filter(spec.is_eligible_for_activation_queue, state.validators))
|
||||
|
||||
current_epoch = spec.get_current_epoch(state)
|
||||
has_active = any(filter(lambda v: spec.is_active_validator(v, current_epoch), state.validators))
|
||||
|
||||
has_exited = any(get_exited_validators(spec, state))
|
||||
|
||||
has_slashed = any(filter(lambda v: v.slashed, state.validators))
|
||||
|
||||
return has_pending and has_active and has_exited and has_slashed
|
||||
|
|
Loading…
Reference in New Issue