move op tests to test_blocks
This commit is contained in:
parent
aab58e4700
commit
a34970f8a3
|
@ -882,6 +882,51 @@ def test_multiple_different_validator_exits_same_block(spec, state):
|
||||||
assert state.validators[index].exit_epoch < spec.FAR_FUTURE_EPOCH
|
assert state.validators[index].exit_epoch < spec.FAR_FUTURE_EPOCH
|
||||||
|
|
||||||
|
|
||||||
|
def run_slash_and_exit(spec, state, slash_index, exit_index, valid=True):
|
||||||
|
"""
|
||||||
|
Helper function to run a test that slashes and exits two validators
|
||||||
|
"""
|
||||||
|
# move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit
|
||||||
|
state.slot += spec.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH
|
||||||
|
|
||||||
|
yield 'pre', state
|
||||||
|
|
||||||
|
block = build_empty_block_for_next_slot(spec, state)
|
||||||
|
|
||||||
|
proposer_slashing = get_valid_proposer_slashing(
|
||||||
|
spec, state, slashed_index=slash_index, signed_1=True, signed_2=True)
|
||||||
|
signed_exit = prepare_signed_exits(spec, state, [exit_index])[0]
|
||||||
|
|
||||||
|
block.body.proposer_slashings.append(proposer_slashing)
|
||||||
|
block.body.voluntary_exits.append(signed_exit)
|
||||||
|
|
||||||
|
signed_block = state_transition_and_sign_block(spec, state, block, expect_fail=(not valid))
|
||||||
|
|
||||||
|
yield 'blocks', [signed_block]
|
||||||
|
|
||||||
|
if valid:
|
||||||
|
yield 'post', state
|
||||||
|
else:
|
||||||
|
yield 'post', None
|
||||||
|
|
||||||
|
|
||||||
|
@with_all_phases
|
||||||
|
@spec_state_test
|
||||||
|
@disable_process_reveal_deadlines
|
||||||
|
def test_slash_and_exit_same_index(spec, state):
|
||||||
|
validator_index = spec.get_active_validator_indices(state, spec.get_current_epoch(state))[-1]
|
||||||
|
yield from run_slash_and_exit(spec, state, validator_index, validator_index, valid=False)
|
||||||
|
|
||||||
|
|
||||||
|
@with_all_phases
|
||||||
|
@spec_state_test
|
||||||
|
@disable_process_reveal_deadlines
|
||||||
|
def test_slash_and_exit_diff_index(spec, state):
|
||||||
|
slash_index = spec.get_active_validator_indices(state, spec.get_current_epoch(state))[-1]
|
||||||
|
exit_index = spec.get_active_validator_indices(state, spec.get_current_epoch(state))[-2]
|
||||||
|
yield from run_slash_and_exit(spec, state, slash_index, exit_index)
|
||||||
|
|
||||||
|
|
||||||
@with_all_phases
|
@with_all_phases
|
||||||
@spec_state_test
|
@spec_state_test
|
||||||
def test_balance_driven_status_transitions(spec, state):
|
def test_balance_driven_status_transitions(spec, state):
|
||||||
|
|
|
@ -1,53 +0,0 @@
|
||||||
from eth2spec.test.helpers.state import (
|
|
||||||
state_transition_and_sign_block,
|
|
||||||
)
|
|
||||||
from eth2spec.test.helpers.block import (
|
|
||||||
build_empty_block_for_next_slot,
|
|
||||||
)
|
|
||||||
from eth2spec.test.helpers.proposer_slashings import get_valid_proposer_slashing
|
|
||||||
from eth2spec.test.helpers.voluntary_exits import prepare_signed_exits
|
|
||||||
|
|
||||||
from eth2spec.test.context import (
|
|
||||||
spec_state_test,
|
|
||||||
with_all_phases,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def run_slash_and_exit(spec, state, slash_index, exit_index, valid=True):
|
|
||||||
# move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit
|
|
||||||
state.slot += spec.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH
|
|
||||||
|
|
||||||
yield 'pre', state
|
|
||||||
|
|
||||||
block = build_empty_block_for_next_slot(spec, state)
|
|
||||||
|
|
||||||
proposer_slashing = get_valid_proposer_slashing(
|
|
||||||
spec, state, slashed_index=slash_index, signed_1=True, signed_2=True)
|
|
||||||
signed_exit = prepare_signed_exits(spec, state, [exit_index])[0]
|
|
||||||
|
|
||||||
block.body.proposer_slashings.append(proposer_slashing)
|
|
||||||
block.body.voluntary_exits.append(signed_exit)
|
|
||||||
|
|
||||||
signed_block = state_transition_and_sign_block(spec, state, block, expect_fail=(not valid))
|
|
||||||
|
|
||||||
yield 'blocks', [signed_block]
|
|
||||||
|
|
||||||
if valid:
|
|
||||||
yield 'post', state
|
|
||||||
else:
|
|
||||||
yield 'post', None
|
|
||||||
|
|
||||||
|
|
||||||
@with_all_phases
|
|
||||||
@spec_state_test
|
|
||||||
def test_slash_and_exit_same_index(spec, state):
|
|
||||||
validator_index = spec.get_active_validator_indices(state, spec.get_current_epoch(state))[-1]
|
|
||||||
yield from run_slash_and_exit(spec, state, validator_index, validator_index, valid=False)
|
|
||||||
|
|
||||||
|
|
||||||
@with_all_phases
|
|
||||||
@spec_state_test
|
|
||||||
def test_slash_and_exit_diff_index(spec, state):
|
|
||||||
slash_index = spec.get_active_validator_indices(state, spec.get_current_epoch(state))[-1]
|
|
||||||
exit_index = spec.get_active_validator_indices(state, spec.get_current_epoch(state))[-2]
|
|
||||||
yield from run_slash_and_exit(spec, state, slash_index, exit_index)
|
|
|
@ -34,7 +34,6 @@ def create_provider(fork_name: str, handler_name: str,
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
phase_0_mods = {key: 'eth2spec.test.phase0.sanity.test_' + key for key in [
|
phase_0_mods = {key: 'eth2spec.test.phase0.sanity.test_' + key for key in [
|
||||||
'blocks',
|
'blocks',
|
||||||
'multi_operations',
|
|
||||||
'slots',
|
'slots',
|
||||||
]}
|
]}
|
||||||
phase_1_mods = {**{key: 'eth2spec.test.phase1.sanity.test_' + key for key in [
|
phase_1_mods = {**{key: 'eth2spec.test.phase1.sanity.test_' + key for key in [
|
||||||
|
|
Loading…
Reference in New Issue