diff --git a/tests/core/pyspec/eth2spec/test/helpers/state.py b/tests/core/pyspec/eth2spec/test/helpers/state.py index d8fda3754..327bebaf8 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/state.py +++ b/tests/core/pyspec/eth2spec/test/helpers/state.py @@ -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 diff --git a/tests/core/pyspec/eth2spec/test/phase0/rewards/test_random.py b/tests/core/pyspec/eth2spec/test/phase0/rewards/test_random.py index 68a6a3279..44f22270b 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/rewards/test_random.py +++ b/tests/core/pyspec/eth2spec/test/phase0/rewards/test_random.py @@ -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)