fix altair test generators
This commit is contained in:
parent
3e386184bc
commit
06eed71856
|
@ -1,7 +1,9 @@
|
|||
from eth2spec.test.context import (
|
||||
PHASE0, ALTAIR,
|
||||
MINIMAL,
|
||||
with_phases,
|
||||
with_custom_state,
|
||||
with_configs,
|
||||
spec_test, with_state,
|
||||
low_balances, misc_balances, large_validator_set,
|
||||
)
|
||||
|
@ -106,6 +108,8 @@ def test_fork_random_misc_balances(spec, phases, state):
|
|||
|
||||
|
||||
@with_phases(phases=[PHASE0], other_phases=[ALTAIR])
|
||||
@with_configs([MINIMAL],
|
||||
reason="mainnet config leads to larger validator set than limit of public/private keys pre-generated")
|
||||
@with_custom_state(balances_fn=large_validator_set, threshold_fn=lambda spec: spec.EJECTION_BALANCE)
|
||||
@spec_test
|
||||
@with_meta_tags(ALTAIR_FORK_TEST_META_TAGS)
|
||||
|
|
|
@ -27,6 +27,26 @@ def has_enough_for_reward(spec, state, index):
|
|||
)
|
||||
|
||||
|
||||
def has_enough_for_leak_penalty(spec, state, index):
|
||||
"""
|
||||
Check if effective_balance and state of leak is high enough for a leak penalty.
|
||||
|
||||
At very low balances / leak values, it is possible for a validator have a positive effective_balance
|
||||
and be in a leak, but have zero leak penalty.
|
||||
"""
|
||||
|
||||
if is_post_altair(spec):
|
||||
return (
|
||||
state.validators[index].effective_balance * state.inactivity_scores[index]
|
||||
> spec.INACTIVITY_SCORE_BIAS * spec.INACTIVITY_PENALTY_QUOTIENT_ALTAIR
|
||||
)
|
||||
else:
|
||||
return (
|
||||
state.validators[index].effective_balance * spec.get_finality_delay(state)
|
||||
> spec.INACTIVITY_PENALTY_QUOTIENT
|
||||
)
|
||||
|
||||
|
||||
def run_deltas(spec, state):
|
||||
"""
|
||||
Run all deltas functions yielding:
|
||||
|
@ -213,7 +233,7 @@ def run_get_inactivity_penalty_deltas(spec, state):
|
|||
|
||||
if not has_enough_for_reward(spec, state, index):
|
||||
assert penalties[index] == 0
|
||||
elif index in matching_attesting_indices:
|
||||
elif index in matching_attesting_indices or not has_enough_for_leak_penalty(spec, state, index):
|
||||
assert penalties[index] == base_penalty
|
||||
else:
|
||||
assert penalties[index] > base_penalty
|
||||
|
|
Loading…
Reference in New Issue