diff --git a/tests/core/pyspec/eth2spec/test/helpers/rewards.py b/tests/core/pyspec/eth2spec/test/helpers/rewards.py index 1867db08f..ec617bda9 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/rewards.py +++ b/tests/core/pyspec/eth2spec/test/helpers/rewards.py @@ -255,7 +255,19 @@ def run_get_inactivity_penalty_deltas(spec, state): else: assert penalties[index] > base_penalty else: - assert penalties[index] == 0 + if not is_post_altair(spec): + assert penalties[index] == 0 + continue + else: + # post altair, this penalty is derived from the inactivity score + # regardless if the state is leaking or not... + if index in matching_attesting_indices: + assert penalties[index] == 0 + else: + # copied from spec: + penalty_numerator = state.validators[index].effective_balance * state.inactivity_scores[index] + penalty_denominator = spec.config.INACTIVITY_SCORE_BIAS * spec.INACTIVITY_PENALTY_QUOTIENT_ALTAIR + assert penalties[index] == penalty_numerator // penalty_denominator def transition_state_to_leak(spec, state, epochs=None): 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 1184a6617..78c6846ae 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/rewards/test_random.py +++ b/tests/core/pyspec/eth2spec/test/phase0/rewards/test_random.py @@ -9,6 +9,7 @@ from eth2spec.test.context import ( low_balances, misc_balances, ) import eth2spec.test.helpers.rewards as rewards_helpers +from eth2spec.test.helpers.random import randomize_state, patch_state_to_non_leaking @with_all_phases @@ -57,3 +58,14 @@ def test_full_random_low_balances_1(spec, state): @single_phase def test_full_random_misc_balances(spec, state): yield from rewards_helpers.run_test_full_random(spec, state, rng=Random(7070)) + + +@with_all_phases +@spec_state_test +def test_full_random_without_leak_0(spec, state): + rng = Random(1010) + randomize_state(spec, state, rng) + assert spec.is_in_inactivity_leak(state) + patch_state_to_non_leaking(spec, state) + assert not spec.is_in_inactivity_leak(state) + yield from rewards_helpers.run_deltas(spec, state)