diff --git a/tests/core/pyspec/eth2spec/test/fork_choice/test_on_attestation.py b/tests/core/pyspec/eth2spec/test/fork_choice/test_on_attestation.py index 09248944c..87a39a620 100644 --- a/tests/core/pyspec/eth2spec/test/fork_choice/test_on_attestation.py +++ b/tests/core/pyspec/eth2spec/test/fork_choice/test_on_attestation.py @@ -1,7 +1,7 @@ from eth2spec.test.context import with_all_phases, spec_state_test from eth2spec.test.helpers.block import build_empty_block_for_next_slot from eth2spec.test.helpers.attestations import get_valid_attestation, sign_attestation -from eth2spec.test.helpers.state import transition_to, state_transition_and_sign_block +from eth2spec.test.helpers.state import transition_to, state_transition_and_sign_block, next_epoch def run_on_attestation(spec, state, store, attestation, valid=True): @@ -179,7 +179,7 @@ def test_on_attestation_future_epoch(spec, state): spec.on_block(store, signed_block) # move state forward but not store - state.slot = block.slot + spec.SLOTS_PER_EPOCH + next_epoch(spec, state) attestation = get_valid_attestation(spec, state, slot=state.slot, signed=True) run_on_attestation(spec, state, store, attestation, False) diff --git a/tests/core/pyspec/eth2spec/test/helpers/state.py b/tests/core/pyspec/eth2spec/test/helpers/state.py index aad329ff4..5816785f7 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/state.py +++ b/tests/core/pyspec/eth2spec/test/helpers/state.py @@ -14,6 +14,13 @@ def next_slot(spec, state): spec.process_slots(state, state.slot + 1) +def next_slots(spec, state, slots): + """ + Transition given slots forward. + """ + spec.process_slots(state, state.slot + slots) + + def transition_to(spec, state, slot): """ Transition to ``slot``. diff --git a/tests/core/pyspec/eth2spec/test/phase_0/block_processing/test_process_attestation.py b/tests/core/pyspec/eth2spec/test/phase_0/block_processing/test_process_attestation.py index 64a64c72d..1dbdafec2 100644 --- a/tests/core/pyspec/eth2spec/test/phase_0/block_processing/test_process_attestation.py +++ b/tests/core/pyspec/eth2spec/test/phase_0/block_processing/test_process_attestation.py @@ -13,7 +13,7 @@ from eth2spec.test.helpers.attestations import ( sign_attestation, ) from eth2spec.test.helpers.state import ( - next_epoch, + next_epoch, next_slots ) from eth2spec.test.helpers.block import apply_empty_block from eth2spec.utils.ssz.ssz_typing import Bitlist @@ -58,7 +58,7 @@ def run_attestation_processing(spec, state, attestation, valid=True): @spec_state_test def test_success(spec, state): attestation = get_valid_attestation(spec, state, signed=True) - state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY + next_slots(spec, state, spec.MIN_ATTESTATION_INCLUSION_DELAY) yield from run_attestation_processing(spec, state, attestation) @@ -68,9 +68,9 @@ def test_success(spec, state): @with_custom_state(balances_fn=low_balances, threshold_fn=lambda spec: spec.EJECTION_BALANCE) @single_phase def test_success_multi_proposer_index_iterations(spec, state): - state.slot += spec.SLOTS_PER_EPOCH * 2 + next_slots(spec, state, spec.SLOTS_PER_EPOCH * 2) attestation = get_valid_attestation(spec, state, signed=True) - state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY + next_slots(spec, state, spec.MIN_ATTESTATION_INCLUSION_DELAY) yield from run_attestation_processing(spec, state, attestation) @@ -91,7 +91,7 @@ def test_success_previous_epoch(spec, state): @always_bls def test_invalid_attestation_signature(spec, state): attestation = get_valid_attestation(spec, state) - state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY + next_slots(spec, state, spec.MIN_ATTESTATION_INCLUSION_DELAY) yield from run_attestation_processing(spec, state, attestation, False) @@ -120,7 +120,7 @@ def test_after_epoch_slots(spec, state): @with_all_phases @spec_state_test def test_old_source_epoch(spec, state): - state.slot = spec.SLOTS_PER_EPOCH * 5 + next_slots(spec, state, spec.SLOTS_PER_EPOCH * 5) state.finalized_checkpoint.epoch = 2 state.previous_justified_checkpoint.epoch = 3 state.current_justified_checkpoint.epoch = 4 @@ -142,7 +142,7 @@ def test_old_source_epoch(spec, state): @always_bls def test_wrong_index_for_committee_signature(spec, state): attestation = get_valid_attestation(spec, state) - state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY + next_slots(spec, state, spec.MIN_ATTESTATION_INCLUSION_DELAY) attestation.data.index += 1 @@ -160,7 +160,7 @@ def test_wrong_index_for_slot(spec, state): index = spec.MAX_COMMITTEES_PER_SLOT - 1 attestation = get_valid_attestation(spec, state) - state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY + next_slots(spec, state, spec.MIN_ATTESTATION_INCLUSION_DELAY) attestation.data.index = index @@ -172,7 +172,7 @@ def test_wrong_index_for_slot(spec, state): @never_bls def test_invalid_index(spec, state): attestation = get_valid_attestation(spec, state) - state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY + next_slots(spec, state, spec.MIN_ATTESTATION_INCLUSION_DELAY) # off by one (with respect to valid range) on purpose attestation.data.index = spec.MAX_COMMITTEES_PER_SLOT @@ -223,7 +223,7 @@ def test_future_target_epoch(spec, state): # manually add signature for correct participants attestation.signature = sign_aggregate_attestation(spec, state, attestation.data, participants) - state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY + next_slots(spec, state, spec.MIN_ATTESTATION_INCLUSION_DELAY) yield from run_attestation_processing(spec, state, attestation, False) @@ -232,7 +232,7 @@ def test_future_target_epoch(spec, state): @spec_state_test def test_new_source_epoch(spec, state): attestation = get_valid_attestation(spec, state) - state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY + next_slots(spec, state, spec.MIN_ATTESTATION_INCLUSION_DELAY) attestation.data.source.epoch += 1 @@ -245,7 +245,7 @@ def test_new_source_epoch(spec, state): @spec_state_test def test_source_root_is_target_root(spec, state): attestation = get_valid_attestation(spec, state) - state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY + next_slots(spec, state, spec.MIN_ATTESTATION_INCLUSION_DELAY) attestation.data.source.root = attestation.data.target.root @@ -264,7 +264,7 @@ def test_invalid_current_source_root(spec, state): state.current_justified_checkpoint = spec.Checkpoint(epoch=4, root=b'\x32' * 32) attestation = get_valid_attestation(spec, state, slot=(spec.SLOTS_PER_EPOCH * 3) + 1) - state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY + next_slots(spec, state, spec.MIN_ATTESTATION_INCLUSION_DELAY) # Test logic sanity checks: assert state.current_justified_checkpoint.root != state.previous_justified_checkpoint.root @@ -282,7 +282,7 @@ def test_invalid_current_source_root(spec, state): @spec_state_test def test_bad_source_root(spec, state): attestation = get_valid_attestation(spec, state) - state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY + next_slots(spec, state, spec.MIN_ATTESTATION_INCLUSION_DELAY) attestation.data.source.root = b'\x42' * 32 @@ -295,7 +295,7 @@ def test_bad_source_root(spec, state): @spec_state_test def test_empty_aggregation_bits(spec, state): attestation = get_valid_attestation(spec, state) - state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY + next_slots(spec, state, spec.MIN_ATTESTATION_INCLUSION_DELAY) attestation.aggregation_bits = Bitlist[spec.MAX_VALIDATORS_PER_COMMITTEE]( *([0b0] * len(attestation.aggregation_bits))) @@ -309,7 +309,7 @@ def test_empty_aggregation_bits(spec, state): @spec_state_test def test_too_many_aggregation_bits(spec, state): attestation = get_valid_attestation(spec, state, signed=True) - state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY + next_slots(spec, state, spec.MIN_ATTESTATION_INCLUSION_DELAY) # one too many bits attestation.aggregation_bits.append(0b0) @@ -321,7 +321,7 @@ def test_too_many_aggregation_bits(spec, state): @spec_state_test def test_too_few_aggregation_bits(spec, state): attestation = get_valid_attestation(spec, state) - state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY + next_slots(spec, state, spec.MIN_ATTESTATION_INCLUSION_DELAY) attestation.aggregation_bits = Bitlist[spec.MAX_VALIDATORS_PER_COMMITTEE]( *([0b1] + [0b0] * (len(attestation.aggregation_bits) - 1))) diff --git a/tests/core/pyspec/eth2spec/test/phase_0/block_processing/test_process_proposer_slashing.py b/tests/core/pyspec/eth2spec/test/phase_0/block_processing/test_process_proposer_slashing.py index 30b3c1fdd..ad910f227 100644 --- a/tests/core/pyspec/eth2spec/test/phase_0/block_processing/test_process_proposer_slashing.py +++ b/tests/core/pyspec/eth2spec/test/phase_0/block_processing/test_process_proposer_slashing.py @@ -2,7 +2,7 @@ from eth2spec.test.context import spec_state_test, expect_assertion_error, alway from eth2spec.test.helpers.block_header import sign_block_header from eth2spec.test.helpers.keys import privkeys from eth2spec.test.helpers.proposer_slashings import get_valid_proposer_slashing -from eth2spec.test.helpers.state import get_balance +from eth2spec.test.helpers.state import get_balance, next_epoch def run_proposer_slashing_processing(spec, state, proposer_slashing, valid=True): @@ -135,7 +135,7 @@ def test_proposer_is_withdrawn(spec, state): proposer_slashing = get_valid_proposer_slashing(spec, state, signed_1=True, signed_2=True) # move 1 epoch into future, to allow for past withdrawable epoch - state.slot += spec.SLOTS_PER_EPOCH + next_epoch(spec, state) # set proposer withdrawable_epoch in past current_epoch = spec.get_current_epoch(state) proposer_index = proposer_slashing.proposer_index diff --git a/tests/core/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_final_updates.py b/tests/core/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_final_updates.py index 58882a44f..2e71346aa 100644 --- a/tests/core/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_final_updates.py +++ b/tests/core/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_final_updates.py @@ -2,6 +2,7 @@ from eth2spec.test.context import spec_state_test, with_all_phases from eth2spec.test.phase_0.epoch_processing.run_epoch_process_base import ( run_epoch_processing_with, run_epoch_processing_to ) +from eth2spec.test.helpers.state import transition_to def run_process_final_updates(spec, state): @@ -13,7 +14,8 @@ def run_process_final_updates(spec, state): def test_eth1_vote_no_reset(spec, state): assert spec.SLOTS_PER_ETH1_VOTING_PERIOD > spec.SLOTS_PER_EPOCH # skip ahead to the end of the epoch - state.slot = spec.SLOTS_PER_EPOCH - 1 + transition_to(spec, state, spec.SLOTS_PER_EPOCH - 1) + for i in range(state.slot + 1): # add a vote for each skipped slot. state.eth1_data_votes.append( spec.Eth1Data(deposit_root=b'\xaa' * 32, diff --git a/tests/core/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_justification_and_finalization.py b/tests/core/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_justification_and_finalization.py index 6fc4e30cb..9f9e1c316 100644 --- a/tests/core/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_justification_and_finalization.py +++ b/tests/core/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_justification_and_finalization.py @@ -2,6 +2,7 @@ from eth2spec.test.context import spec_state_test, with_all_phases from eth2spec.test.phase_0.epoch_processing.run_epoch_process_base import ( run_epoch_processing_with ) +from eth2spec.test.helpers.state import transition_to def run_process_just_and_fin(spec, state): @@ -82,7 +83,7 @@ def put_checkpoints_in_block_roots(spec, state, checkpoints): def finalize_on_234(spec, state, epoch, sufficient_support): assert epoch > 4 - state.slot = (spec.SLOTS_PER_EPOCH * epoch) - 1 # skip ahead to just before epoch + transition_to(spec, state, spec.SLOTS_PER_EPOCH * epoch - 1) # skip ahead to just before epoch # 43210 -- epochs ago # 3210x -- justification bitfield indices @@ -117,7 +118,7 @@ def finalize_on_234(spec, state, epoch, sufficient_support): def finalize_on_23(spec, state, epoch, sufficient_support): assert epoch > 3 - state.slot = (spec.SLOTS_PER_EPOCH * epoch) - 1 # skip ahead to just before epoch + transition_to(spec, state, spec.SLOTS_PER_EPOCH * epoch - 1) # skip ahead to just before epoch # 43210 -- epochs ago # 210xx -- justification bitfield indices (pre shift) @@ -195,7 +196,7 @@ def finalize_on_123(spec, state, epoch, sufficient_support): def finalize_on_12(spec, state, epoch, sufficient_support, messed_up_target): assert epoch > 2 - state.slot = (spec.SLOTS_PER_EPOCH * epoch) - 1 # skip ahead to just before epoch + transition_to(spec, state, spec.SLOTS_PER_EPOCH * epoch - 1) # skip ahead to just before epoch # 43210 -- epochs ago # 210xx -- justification bitfield indices (pre shift) diff --git a/tests/core/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_registry_updates.py b/tests/core/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_registry_updates.py index 526aba277..a5f4d9227 100644 --- a/tests/core/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_registry_updates.py +++ b/tests/core/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_registry_updates.py @@ -1,4 +1,4 @@ -from eth2spec.test.helpers.state import next_epoch +from eth2spec.test.helpers.state import next_epoch, next_slots from eth2spec.test.context import spec_state_test, with_all_phases from eth2spec.test.phase_0.epoch_processing.run_epoch_process_base import run_epoch_processing_with @@ -101,7 +101,7 @@ def test_activation_queue_sorting(spec, state): state.validators[mock_activations - 1].activation_eligibility_epoch = epoch # move state forward and finalize to allow for activations - state.slot += spec.SLOTS_PER_EPOCH * 3 + next_slots(spec, state, spec.SLOTS_PER_EPOCH * 3) state.finalized_checkpoint.epoch = epoch + 1 yield from run_process_registry_updates(spec, state) @@ -113,10 +113,10 @@ def test_activation_queue_sorting(spec, state): # the second last is at the end of the queue, and did not make the churn, # hence is not assigned an activation_epoch yet. assert state.validators[mock_activations - 2].activation_epoch == spec.FAR_FUTURE_EPOCH - # the one at churn_limit - 1 did not make it, it was out-prioritized - assert state.validators[churn_limit - 1].activation_epoch == spec.FAR_FUTURE_EPOCH + # the one at churn_limit did not make it, it was out-prioritized + assert state.validators[churn_limit].activation_epoch == spec.FAR_FUTURE_EPOCH # but the the one in front of the above did - assert state.validators[churn_limit - 2].activation_epoch != spec.FAR_FUTURE_EPOCH + assert state.validators[churn_limit - 1].activation_epoch != spec.FAR_FUTURE_EPOCH @with_all_phases @@ -131,7 +131,8 @@ def test_activation_queue_efficiency(spec, state): state.validators[i].activation_eligibility_epoch = epoch + 1 # move state forward and finalize to allow for activations - state.slot += spec.SLOTS_PER_EPOCH * 3 + next_slots(spec, state, spec.SLOTS_PER_EPOCH * 3) + state.finalized_checkpoint.epoch = epoch + 1 # Run first registry update. Do not yield test vectors diff --git a/tests/core/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_slashings.py b/tests/core/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_slashings.py index c58da5a4a..23c8ce11a 100644 --- a/tests/core/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_slashings.py +++ b/tests/core/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_slashings.py @@ -2,6 +2,7 @@ from eth2spec.test.context import spec_state_test, with_all_phases from eth2spec.test.phase_0.epoch_processing.run_epoch_process_base import ( run_epoch_processing_with, run_epoch_processing_to ) +from eth2spec.test.helpers.state import next_epoch def run_process_slashings(spec, state): @@ -79,7 +80,7 @@ def test_small_penalty(spec, state): @spec_state_test def test_scaled_penalties(spec, state): # skip to next epoch - state.slot = spec.SLOTS_PER_EPOCH + next_epoch(spec, state) # Also mock some previous slashings, so that we test to have the delta in the penalties computation. base = spec.EJECTION_BALANCE diff --git a/tests/core/pyspec/eth2spec/test/sanity/test_blocks.py b/tests/core/pyspec/eth2spec/test/sanity/test_blocks.py index 9027660ab..e533b3b0a 100644 --- a/tests/core/pyspec/eth2spec/test/sanity/test_blocks.py +++ b/tests/core/pyspec/eth2spec/test/sanity/test_blocks.py @@ -2,7 +2,7 @@ from copy import deepcopy from eth2spec.utils import bls -from eth2spec.test.helpers.state import get_balance, state_transition_and_sign_block, next_slot +from eth2spec.test.helpers.state import get_balance, state_transition_and_sign_block, next_slot, next_epoch from eth2spec.test.helpers.block import build_empty_block_for_next_slot, build_empty_block, sign_block, \ transition_unsigned_block from eth2spec.test.helpers.keys import privkeys, pubkeys @@ -11,7 +11,7 @@ from eth2spec.test.helpers.proposer_slashings import get_valid_proposer_slashing from eth2spec.test.helpers.attestations import get_valid_attestation from eth2spec.test.helpers.deposits import prepare_state_and_deposit -from eth2spec.test.context import spec_state_test, with_all_phases, expect_assertion_error, always_bls +from eth2spec.test.context import spec_state_test, with_all_phases, expect_assertion_error, always_bls, with_phases @with_all_phases @@ -260,7 +260,8 @@ def test_proposer_after_inactive_index(spec, state): state.validators[inactive_index].exit_epoch = spec.get_current_epoch(state) # skip forward, get brand new proposers - state.slot = spec.SLOTS_PER_EPOCH * 2 + next_epoch(spec, state) + next_epoch(spec, state) block = build_empty_block_for_next_slot(spec, state) state_transition_and_sign_block(spec, state, block) @@ -372,7 +373,7 @@ def test_deposit_top_up(spec, state): @with_all_phases @spec_state_test def test_attestation(spec, state): - state.slot = spec.SLOTS_PER_EPOCH + next_epoch(spec, state) yield 'pre', state @@ -399,7 +400,9 @@ def test_attestation(spec, state): assert spec.hash_tree_root(state.previous_epoch_attestations) == pre_current_attestations_root -@with_all_phases +# In phase1 a committee is computed for PERSISTENT_COMMITTEE_PERIOD slots ago, +# exceeding the minimal-config randao mixes memory size. +@with_phases(['phase0']) @spec_state_test def test_voluntary_exit(spec, state): validator_index = spec.get_active_validator_indices(