mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-02-21 14:58:12 +00:00
add exited tests for rewards. make some valiators exited/withdrawable in slashed tests
This commit is contained in:
parent
4f401133e1
commit
f0742b2f2d
@ -2,6 +2,7 @@ from random import Random
|
|||||||
|
|
||||||
from eth2spec.phase0 import spec as spec_phase0
|
from eth2spec.phase0 import spec as spec_phase0
|
||||||
from eth2spec.test.helpers.attestations import prepare_state_with_full_attestations
|
from eth2spec.test.helpers.attestations import prepare_state_with_full_attestations
|
||||||
|
from eth2spec.test.helpers.state import next_epoch
|
||||||
from eth2spec.utils.ssz.ssz_typing import Container, uint64, List
|
from eth2spec.utils.ssz.ssz_typing import Container, uint64, List
|
||||||
|
|
||||||
|
|
||||||
@ -61,6 +62,32 @@ def run_attestation_component_deltas(spec, state, component_delta_fn, matching_a
|
|||||||
assert penalties[index] == 0
|
assert penalties[index] == 0
|
||||||
|
|
||||||
|
|
||||||
|
def exit_random_validators(spec, state, rng):
|
||||||
|
if spec.get_current_epoch(state) < 5:
|
||||||
|
# Move epochs forward to allow for some validators already exited/withdrawable
|
||||||
|
for _ in range(5):
|
||||||
|
next_epoch(spec, state)
|
||||||
|
|
||||||
|
current_epoch = spec.get_current_epoch(state)
|
||||||
|
# Exit ~1/2 of validators
|
||||||
|
for validator in state.validators:
|
||||||
|
if rng.choice([True, False]):
|
||||||
|
continue
|
||||||
|
|
||||||
|
validator.exit_epoch = rng.choice([current_epoch - 1, current_epoch - 2, current_epoch - 3])
|
||||||
|
# ~1/2 are withdrawable
|
||||||
|
if rng.choice([True, False]):
|
||||||
|
validator.withdrawable_epoch = current_epoch
|
||||||
|
else:
|
||||||
|
validator.withdrawable_epoch = current_epoch + 1
|
||||||
|
|
||||||
|
|
||||||
|
def slash_random_validators(spec, state, rng):
|
||||||
|
# Slash ~1/2 of validators
|
||||||
|
for validator in state.validators:
|
||||||
|
validator.slashed = rng.choice([True, False])
|
||||||
|
|
||||||
|
|
||||||
def run_test_empty(spec, state, runner):
|
def run_test_empty(spec, state, runner):
|
||||||
# Do not add any attestations to state
|
# Do not add any attestations to state
|
||||||
|
|
||||||
@ -105,12 +132,18 @@ def run_test_one_attestation_one_correct(spec, state, runner):
|
|||||||
yield from runner(spec, state)
|
yield from runner(spec, state)
|
||||||
|
|
||||||
|
|
||||||
def run_test_with_slashed_validators(spec, state, runner):
|
def run_test_with_exited_validators(spec, state, runner, rng=Random(1337)):
|
||||||
|
exit_random_validators(spec, state, rng)
|
||||||
prepare_state_with_full_attestations(spec, state)
|
prepare_state_with_full_attestations(spec, state)
|
||||||
|
|
||||||
# Slash half of validators
|
yield from runner(spec, state)
|
||||||
for validator in state.validators[:len(state.validators) // 2]:
|
|
||||||
validator.slashed = True
|
|
||||||
|
def run_test_with_slashed_validators(spec, state, runner, rng=Random(3322)):
|
||||||
|
exit_random_validators(spec, state, rng)
|
||||||
|
slash_random_validators(spec, state, rng)
|
||||||
|
|
||||||
|
prepare_state_with_full_attestations(spec, state)
|
||||||
|
|
||||||
yield from runner(spec, state)
|
yield from runner(spec, state)
|
||||||
|
|
||||||
@ -156,6 +189,9 @@ def run_test_full_fraction_incorrect(spec, state, correct_target, correct_head,
|
|||||||
|
|
||||||
|
|
||||||
def run_test_full_random(spec, state, runner, rng=Random(8020)):
|
def run_test_full_random(spec, state, runner, rng=Random(8020)):
|
||||||
|
exit_random_validators(spec, state, rng)
|
||||||
|
slash_random_validators(spec, state, rng)
|
||||||
|
|
||||||
prepare_state_with_full_attestations(spec, state)
|
prepare_state_with_full_attestations(spec, state)
|
||||||
|
|
||||||
for pending_attestation in state.previous_epoch_attestations:
|
for pending_attestation in state.previous_epoch_attestations:
|
||||||
|
@ -49,6 +49,12 @@ def test_one_attestation_one_correct(spec, state):
|
|||||||
yield from rewards_helpers.run_test_one_attestation_one_correct(spec, state, run_get_head_deltas)
|
yield from rewards_helpers.run_test_one_attestation_one_correct(spec, state, run_get_head_deltas)
|
||||||
|
|
||||||
|
|
||||||
|
@with_all_phases
|
||||||
|
@spec_state_test
|
||||||
|
def test_with_exited_validators(spec, state):
|
||||||
|
yield from rewards_helpers.run_test_with_exited_validators(spec, state, run_get_head_deltas)
|
||||||
|
|
||||||
|
|
||||||
@with_all_phases
|
@with_all_phases
|
||||||
@spec_state_test
|
@spec_state_test
|
||||||
def test_with_slashed_validators(spec, state):
|
def test_with_slashed_validators(spec, state):
|
||||||
|
@ -116,6 +116,19 @@ def test_full_but_partial_participation_leak(spec, state):
|
|||||||
yield from rewards_helpers.run_test_full_but_partial_participation(spec, state, run_get_inactivity_penalty_deltas)
|
yield from rewards_helpers.run_test_full_but_partial_participation(spec, state, run_get_inactivity_penalty_deltas)
|
||||||
|
|
||||||
|
|
||||||
|
@with_all_phases
|
||||||
|
@spec_state_test
|
||||||
|
def test_with_exited_validators_no_leak(spec, state):
|
||||||
|
yield from rewards_helpers.run_test_with_exited_validators(spec, state, run_get_inactivity_penalty_deltas)
|
||||||
|
|
||||||
|
|
||||||
|
@with_all_phases
|
||||||
|
@spec_state_test
|
||||||
|
def test_with_exited_validators_leak(spec, state):
|
||||||
|
transition_state_to_leak(spec, state)
|
||||||
|
yield from rewards_helpers.run_test_with_exited_validators(spec, state, run_get_inactivity_penalty_deltas)
|
||||||
|
|
||||||
|
|
||||||
@with_all_phases
|
@with_all_phases
|
||||||
@spec_state_test
|
@spec_state_test
|
||||||
def test_with_slashed_validators_no_leak(spec, state):
|
def test_with_slashed_validators_no_leak(spec, state):
|
||||||
|
@ -84,6 +84,12 @@ def test_full_but_partial_participation(spec, state):
|
|||||||
yield from rewards_helpers.run_test_full_but_partial_participation(spec, state, run_get_inclusion_delay_deltas)
|
yield from rewards_helpers.run_test_full_but_partial_participation(spec, state, run_get_inclusion_delay_deltas)
|
||||||
|
|
||||||
|
|
||||||
|
@with_all_phases
|
||||||
|
@spec_state_test
|
||||||
|
def test_with_exited_validators(spec, state):
|
||||||
|
yield from rewards_helpers.run_test_with_exited_validators(spec, state, run_get_inclusion_delay_deltas)
|
||||||
|
|
||||||
|
|
||||||
@with_all_phases
|
@with_all_phases
|
||||||
@spec_state_test
|
@spec_state_test
|
||||||
def test_with_slashed_validators(spec, state):
|
def test_with_slashed_validators(spec, state):
|
||||||
|
@ -49,6 +49,12 @@ def test_one_attestation_one_correct(spec, state):
|
|||||||
yield from rewards_helpers.run_test_one_attestation_one_correct(spec, state, run_get_source_deltas)
|
yield from rewards_helpers.run_test_one_attestation_one_correct(spec, state, run_get_source_deltas)
|
||||||
|
|
||||||
|
|
||||||
|
@with_all_phases
|
||||||
|
@spec_state_test
|
||||||
|
def test_with_exited_validators(spec, state):
|
||||||
|
yield from rewards_helpers.run_test_with_exited_validators(spec, state, run_get_source_deltas)
|
||||||
|
|
||||||
|
|
||||||
@with_all_phases
|
@with_all_phases
|
||||||
@spec_state_test
|
@spec_state_test
|
||||||
def test_with_slashed_validators(spec, state):
|
def test_with_slashed_validators(spec, state):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user