Skip to content

Commit

Permalink
move op tests to test_blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
djrtwo committed Oct 16, 2020
1 parent aab58e4 commit a34970f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 54 deletions.
45 changes: 45 additions & 0 deletions tests/core/pyspec/eth2spec/test/phase0/sanity/test_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,51 @@ def test_multiple_different_validator_exits_same_block(spec, state):
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
@spec_state_test
def test_balance_driven_status_transitions(spec, state):
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion tests/generators/sanity/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def cases_fn() -> Iterable[gen_typing.TestCase]:
if __name__ == "__main__":
phase_0_mods = {key: 'eth2spec.test.phase0.sanity.test_' + key for key in [
'blocks',
'multi_operations',
'slots',
]}
phase_1_mods = {**{key: 'eth2spec.test.phase1.sanity.test_' + key for key in [
Expand Down

0 comments on commit a34970f

Please sign in to comment.