mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-01-12 03:34:20 +00:00
ensure balance differential as a sanity check
This commit is contained in:
parent
58c0da9059
commit
df89763777
@ -155,3 +155,15 @@ def ensure_state_has_validators_across_lifecycle(spec, state):
|
||||
has_slashed = any(filter(lambda v: v.slashed, state.validators))
|
||||
|
||||
return has_pending and has_active and has_exited and has_slashed
|
||||
|
||||
|
||||
def has_active_balance_differential(spec, state):
|
||||
"""
|
||||
Ensure there is a difference between the total balance of
|
||||
all _active_ validators and _all_ validators.
|
||||
"""
|
||||
epoch = spec.get_current_epoch(state)
|
||||
active_indices = spec.get_active_validator_indices(state, epoch)
|
||||
active_balance = spec.get_total_balance(state, set(active_indices))
|
||||
total_balance = spec.get_total_balance(state, set(range(len(state.validators))))
|
||||
return active_balance // spec.EFFECTIVE_BALANCE_INCREMENT != total_balance // spec.EFFECTIVE_BALANCE_INCREMENT
|
||||
|
@ -10,6 +10,7 @@ from eth2spec.test.context import (
|
||||
)
|
||||
import eth2spec.test.helpers.rewards as rewards_helpers
|
||||
from eth2spec.test.helpers.random import randomize_state, patch_state_to_non_leaking
|
||||
from eth2spec.test.helpers.state import has_active_balance_differential
|
||||
from eth2spec.test.helpers.voluntary_exits import get_unslashed_exited_validators
|
||||
|
||||
|
||||
@ -48,6 +49,7 @@ def test_full_random_4(spec, state):
|
||||
assert spec.is_in_inactivity_leak(state)
|
||||
target_validators = get_unslashed_exited_validators(spec, state)
|
||||
assert len(target_validators) != 0
|
||||
assert has_active_balance_differential(spec, state)
|
||||
yield from rewards_helpers.run_deltas(spec, state)
|
||||
|
||||
|
||||
@ -85,4 +87,5 @@ def test_full_random_without_leak_0(spec, state):
|
||||
assert not spec.is_in_inactivity_leak(state)
|
||||
target_validators = get_unslashed_exited_validators(spec, state)
|
||||
assert len(target_validators) != 0
|
||||
assert has_active_balance_differential(spec, state)
|
||||
yield from rewards_helpers.run_deltas(spec, state)
|
||||
|
Loading…
x
Reference in New Issue
Block a user