PR feedback
This commit is contained in:
parent
67da1ba2bf
commit
cbba5426fe
|
@ -11,9 +11,6 @@ from eth2spec.test.helpers.fork_transition import (
|
||||||
transition_to_next_epoch_and_append_blocks,
|
transition_to_next_epoch_and_append_blocks,
|
||||||
)
|
)
|
||||||
from eth2spec.test.helpers.random import set_some_new_deposits
|
from eth2spec.test.helpers.random import set_some_new_deposits
|
||||||
from eth2spec.test.helpers.state import (
|
|
||||||
transition_to,
|
|
||||||
)
|
|
||||||
from eth2spec.test.helpers.voluntary_exits import prepare_signed_exits
|
from eth2spec.test.helpers.voluntary_exits import prepare_signed_exits
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,8 +19,12 @@ from eth2spec.test.helpers.voluntary_exits import prepare_signed_exits
|
||||||
#
|
#
|
||||||
|
|
||||||
@fork_transition_test(PHASE0, ALTAIR, fork_epoch=2)
|
@fork_transition_test(PHASE0, ALTAIR, fork_epoch=2)
|
||||||
def test_transition_with_one_fourth_exiting_validators_exit_post_fork(
|
def test_transition_with_one_fourth_exiting_validators_exit_post_fork(state,
|
||||||
state, fork_epoch, spec, post_spec, pre_tag, post_tag):
|
fork_epoch,
|
||||||
|
spec,
|
||||||
|
post_spec,
|
||||||
|
pre_tag,
|
||||||
|
post_tag):
|
||||||
"""
|
"""
|
||||||
1/4 exiting but still active validators at the fork transition.
|
1/4 exiting but still active validators at the fork transition.
|
||||||
"""
|
"""
|
||||||
|
@ -51,6 +52,7 @@ def test_transition_with_one_fourth_exiting_validators_exit_post_fork(
|
||||||
# ensure that some of the current sync committee members are exiting
|
# ensure that some of the current sync committee members are exiting
|
||||||
exited_pubkeys = [state.validators[index].pubkey for index in exited_indices]
|
exited_pubkeys = [state.validators[index].pubkey for index in exited_indices]
|
||||||
assert any(set(exited_pubkeys).intersection(list(state.current_sync_committee.pubkeys)))
|
assert any(set(exited_pubkeys).intersection(list(state.current_sync_committee.pubkeys)))
|
||||||
|
assert any(set(exited_pubkeys).difference(list(state.current_sync_committee.pubkeys)))
|
||||||
|
|
||||||
# continue regular state transition with new spec into next epoch
|
# continue regular state transition with new spec into next epoch
|
||||||
transition_to_next_epoch_and_append_blocks(post_spec, state, post_tag, blocks)
|
transition_to_next_epoch_and_append_blocks(post_spec, state, post_tag, blocks)
|
||||||
|
@ -67,8 +69,12 @@ def test_transition_with_one_fourth_exiting_validators_exit_post_fork(
|
||||||
|
|
||||||
|
|
||||||
@fork_transition_test(PHASE0, ALTAIR, fork_epoch=2)
|
@fork_transition_test(PHASE0, ALTAIR, fork_epoch=2)
|
||||||
def test_transition_with_one_fourth_exiting_validators_exit_at_fork(
|
def test_transition_with_one_fourth_exiting_validators_exit_at_fork(state,
|
||||||
state, fork_epoch, spec, post_spec, pre_tag, post_tag):
|
fork_epoch,
|
||||||
|
spec,
|
||||||
|
post_spec,
|
||||||
|
pre_tag,
|
||||||
|
post_tag):
|
||||||
"""
|
"""
|
||||||
1/4 exiting but still active validators at the fork transition.
|
1/4 exiting but still active validators at the fork transition.
|
||||||
"""
|
"""
|
||||||
|
@ -117,7 +123,8 @@ def test_transition_with_voluntary_exit_at_fork(state, fork_epoch, spec, post_sp
|
||||||
Create an attester slashing at the transition.
|
Create an attester slashing at the transition.
|
||||||
fork_epoch=260 because mainnet `SHARD_COMMITTEE_PERIOD` is 256 epochs.
|
fork_epoch=260 because mainnet `SHARD_COMMITTEE_PERIOD` is 256 epochs.
|
||||||
"""
|
"""
|
||||||
transition_to(spec, state, spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH)
|
# Fast forward to the future epoch so that validator can do voluntary exit
|
||||||
|
state.slot = spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH
|
||||||
transition_until_fork(spec, state, fork_epoch)
|
transition_until_fork(spec, state, fork_epoch)
|
||||||
|
|
||||||
yield "pre", state
|
yield "pre", state
|
||||||
|
@ -209,7 +216,7 @@ def test_transition_with_deposit_at_fork(state, fork_epoch, spec, post_spec, pre
|
||||||
fill_cur_epoch=True,
|
fill_cur_epoch=True,
|
||||||
fill_prev_epoch=True,
|
fill_prev_epoch=True,
|
||||||
)
|
)
|
||||||
blocks.extend([pre_tag(block) for block in blocks_in_epoch])
|
blocks.extend([post_tag(block) for block in blocks_in_epoch])
|
||||||
assert state.finalized_checkpoint.epoch == state.validators[validator_index].activation_eligibility_epoch
|
assert state.finalized_checkpoint.epoch == state.validators[validator_index].activation_eligibility_epoch
|
||||||
|
|
||||||
# continue regular state transition with new spec into next epoch
|
# continue regular state transition with new spec into next epoch
|
|
@ -22,8 +22,12 @@ from eth2spec.test.helpers.inactivity_scores import (
|
||||||
|
|
||||||
|
|
||||||
@fork_transition_test(PHASE0, ALTAIR, fork_epoch=1)
|
@fork_transition_test(PHASE0, ALTAIR, fork_epoch=1)
|
||||||
def test_transition_with_one_fourth_slashed_active_validators_pre_fork(
|
def test_transition_with_one_fourth_slashed_active_validators_pre_fork(state,
|
||||||
state, fork_epoch, spec, post_spec, pre_tag, post_tag):
|
fork_epoch,
|
||||||
|
spec,
|
||||||
|
post_spec,
|
||||||
|
pre_tag,
|
||||||
|
post_tag):
|
||||||
"""
|
"""
|
||||||
1/4 validators are slashed but still active at the fork transition.
|
1/4 validators are slashed but still active at the fork transition.
|
||||||
"""
|
"""
|
||||||
|
@ -53,6 +57,7 @@ def test_transition_with_one_fourth_slashed_active_validators_pre_fork(
|
||||||
# ensure that some of the current sync committee members are the slashed
|
# ensure that some of the current sync committee members are the slashed
|
||||||
slashed_pubkeys = [state.validators[index].pubkey for index in slashed_indices]
|
slashed_pubkeys = [state.validators[index].pubkey for index in slashed_indices]
|
||||||
assert any(set(slashed_pubkeys).intersection(list(state.current_sync_committee.pubkeys)))
|
assert any(set(slashed_pubkeys).intersection(list(state.current_sync_committee.pubkeys)))
|
||||||
|
assert any(set(slashed_pubkeys).difference(list(state.current_sync_committee.pubkeys)))
|
||||||
|
|
||||||
# continue regular state transition with new spec into next epoch
|
# continue regular state transition with new spec into next epoch
|
||||||
to_slot = post_spec.SLOTS_PER_EPOCH + state.slot
|
to_slot = post_spec.SLOTS_PER_EPOCH + state.slot
|
||||||
|
|
|
@ -16,8 +16,8 @@ def zero_inactivity_scores(spec, state, rng=None):
|
||||||
def slash_some_validators_for_inactivity_scores_test(spec, state, rng=Random(40404040), fraction=0.25):
|
def slash_some_validators_for_inactivity_scores_test(spec, state, rng=Random(40404040), fraction=0.25):
|
||||||
"""
|
"""
|
||||||
``run_inactivity_scores_test`` runs at the next epoch from `state`.
|
``run_inactivity_scores_test`` runs at the next epoch from `state`.
|
||||||
# We retrieve the proposer of this future state to avoid
|
We retrieve the proposer of this future state to avoid
|
||||||
# accidentally slashing that validator
|
accidentally slashing that validator
|
||||||
"""
|
"""
|
||||||
future_state = state.copy()
|
future_state = state.copy()
|
||||||
next_epoch_via_block(spec, future_state)
|
next_epoch_via_block(spec, future_state)
|
||||||
|
|
|
@ -7,7 +7,8 @@ from eth2spec.test.helpers.state import next_epoch
|
||||||
|
|
||||||
|
|
||||||
def set_some_new_deposits(spec, state, rng):
|
def set_some_new_deposits(spec, state, rng):
|
||||||
eligible_indices = queuing_indices = []
|
eligible_indices = []
|
||||||
|
queuing_indices = []
|
||||||
num_validators = len(state.validators)
|
num_validators = len(state.validators)
|
||||||
# Set ~1/10 to just recently deposited
|
# Set ~1/10 to just recently deposited
|
||||||
for index in range(num_validators):
|
for index in range(num_validators):
|
||||||
|
|
Loading…
Reference in New Issue