add spec test case for rewards with exited validators and _no_ leak

This commit is contained in:
Alex Stokes 2021-08-31 12:46:00 -07:00
parent e341f4e1f8
commit 7cb5901ee6
No known key found for this signature in database
GPG Key ID: 99B3D88FD6C55A69
2 changed files with 25 additions and 1 deletions

View File

@ -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):

View File

@ -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)