From ed71efc061954fb87871fa60824ad236e08b7f40 Mon Sep 17 00:00:00 2001 From: Carl Beekhuizen Date: Fri, 31 May 2019 10:41:39 +0200 Subject: [PATCH] state is kwarg --- .../test_process_proposer_slashing.py | 4 ++-- test_libs/pyspec/eth2spec/test/context.py | 17 ++++++++++------- .../epoch_processing/test_process_crosslinks.py | 6 ++---- .../test_process_registry_updates.py | 10 +++++----- .../eth2spec/test/helpers/attestations.py | 1 + 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/test_libs/pyspec/eth2spec/test/block_processing/test_process_proposer_slashing.py b/test_libs/pyspec/eth2spec/test/block_processing/test_process_proposer_slashing.py index b35241859..47f9ed1de 100644 --- a/test_libs/pyspec/eth2spec/test/block_processing/test_process_proposer_slashing.py +++ b/test_libs/pyspec/eth2spec/test/block_processing/test_process_proposer_slashing.py @@ -40,17 +40,17 @@ def run_proposer_slashing_processing(spec, state, proposer_slashing, valid=True) ) -@with_all_phases @spec_state_test +@with_all_phases def test_success(spec, state): proposer_slashing = get_valid_proposer_slashing(spec, state, signed_1=True, signed_2=True) yield from run_proposer_slashing_processing(spec, state, proposer_slashing) -@with_all_phases @always_bls @spec_state_test +@with_all_phases def test_invalid_sig_1(spec, state): proposer_slashing = get_valid_proposer_slashing(spec, state, signed_1=False, signed_2=True) yield from run_proposer_slashing_processing(spec, state, proposer_slashing, False) diff --git a/test_libs/pyspec/eth2spec/test/context.py b/test_libs/pyspec/eth2spec/test/context.py index 6b92f2151..dcdd8140b 100644 --- a/test_libs/pyspec/eth2spec/test/context.py +++ b/test_libs/pyspec/eth2spec/test/context.py @@ -4,10 +4,14 @@ from eth2spec.utils import bls from .helpers.genesis import create_genesis_state -from .utils import spectest, with_args, with_tags +from .utils import spectest, with_tags -# Provides a genesis state as first argument to the function decorated with this -with_state = with_args(lambda: [create_genesis_state(spec.SLOTS_PER_EPOCH * 8)]) + +def with_state(fn): + def entry(*args, **kw): + kw['state'] = create_genesis_state(spec=spec_phase0, num_validators=spec_phase0.SLOTS_PER_EPOCH * 8) + return fn(*args, **kw) + return entry # BLS is turned off by default *for performance purposes during TESTING*. @@ -88,18 +92,17 @@ def with_phase0(fn): Decorator to use phase 0's spec and helpers """ def entry(*args, **kw): - args = (spec_phase0, *args) - print(args) + kw['spec'] = spec_phase0 return fn(*args, **kw) return entry def with_phase1(fn): """ - Decorator to use phase 0's spec and helpers + Decorator to use phase 1's spec and helpers """ def entry(*args, **kw): - args = (spec_phase1, *args) + kw['spec'] = spec_phase1 return fn(*args, **kw) return entry diff --git a/test_libs/pyspec/eth2spec/test/epoch_processing/test_process_crosslinks.py b/test_libs/pyspec/eth2spec/test/epoch_processing/test_process_crosslinks.py index 54e8d5ef2..65d958678 100644 --- a/test_libs/pyspec/eth2spec/test/epoch_processing/test_process_crosslinks.py +++ b/test_libs/pyspec/eth2spec/test/epoch_processing/test_process_crosslinks.py @@ -24,13 +24,13 @@ def run_process_crosslinks(spec, state, valid=True): """ # transition state to slot before state transition slot = state.slot + (spec.SLOTS_PER_EPOCH - state.slot % spec.SLOTS_PER_EPOCH) - 1 - block = build_empty_block_for_next_slot(state) + block = build_empty_block_for_next_slot(spec, state) block.slot = slot sign_block(spec, state, block) spec.state_transition(state, block) # cache state before epoch transition - spec.spec.process_slot(state) + spec.process_slot(state) yield 'pre', state spec.process_crosslinks(state) @@ -91,7 +91,6 @@ def test_single_crosslink_update_from_previous_epoch(spec, state): # ensure rewarded for index in spec.get_crosslink_committee( - spec, state, attestation.data.target_epoch, attestation.data.crosslink.shard): @@ -144,7 +143,6 @@ def test_double_late_crosslink(spec, state): assert state.previous_crosslinks[shard] == state.current_crosslinks[shard] # ensure no reward, only penalties for the failed crosslink for index in spec.get_crosslink_committee( - spec, state, attestation_2.data.target_epoch, attestation_2.data.crosslink.shard): diff --git a/test_libs/pyspec/eth2spec/test/epoch_processing/test_process_registry_updates.py b/test_libs/pyspec/eth2spec/test/epoch_processing/test_process_registry_updates.py index a3249a406..e6679f844 100644 --- a/test_libs/pyspec/eth2spec/test/epoch_processing/test_process_registry_updates.py +++ b/test_libs/pyspec/eth2spec/test/epoch_processing/test_process_registry_updates.py @@ -35,13 +35,13 @@ def run_process_registry_updates(spec, state, valid=True): @spec_state_test def test_activation(spec, state): index = 0 - assert spec.is_active_validator(state.validator_registry[index], spec.spec.get_current_epoch(state)) + assert spec.is_active_validator(state.validator_registry[index], spec.get_current_epoch(state)) # Mock a new deposit state.validator_registry[index].activation_eligibility_epoch = spec.FAR_FUTURE_EPOCH state.validator_registry[index].activation_epoch = spec.FAR_FUTURE_EPOCH state.validator_registry[index].effective_balance = spec.MAX_EFFECTIVE_BALANCE - assert not spec.is_active_validator(state.validator_registry[index], spec.spec.get_current_epoch(state)) + assert not spec.is_active_validator(state.validator_registry[index], spec.get_current_epoch(state)) for _ in range(spec.ACTIVATION_EXIT_DELAY + 1): next_epoch(spec, state) @@ -52,7 +52,7 @@ def test_activation(spec, state): assert state.validator_registry[index].activation_epoch != spec.FAR_FUTURE_EPOCH assert spec.is_active_validator( state.validator_registry[index], - spec.spec.get_current_epoch(state), + spec.get_current_epoch(state), ) @@ -60,7 +60,7 @@ def test_activation(spec, state): @spec_state_test def test_ejection(spec, state): index = 0 - assert spec.is_active_validator(state.validator_registry[index], spec.spec.get_current_epoch(state)) + assert spec.is_active_validator(state.validator_registry[index], spec.get_current_epoch(state)) assert state.validator_registry[index].exit_epoch == spec.FAR_FUTURE_EPOCH # Mock an ejection @@ -74,5 +74,5 @@ def test_ejection(spec, state): assert state.validator_registry[index].exit_epoch != spec.FAR_FUTURE_EPOCH assert not spec.is_active_validator( state.validator_registry[index], - spec.spec.get_current_epoch(state), + spec.get_current_epoch(state), ) diff --git a/test_libs/pyspec/eth2spec/test/helpers/attestations.py b/test_libs/pyspec/eth2spec/test/helpers/attestations.py index a4eac3fb7..369738ed4 100644 --- a/test_libs/pyspec/eth2spec/test/helpers/attestations.py +++ b/test_libs/pyspec/eth2spec/test/helpers/attestations.py @@ -89,6 +89,7 @@ def sign_aggregate_attestation(spec, state, attestation_data, participants: List privkey = privkeys[validator_index] signatures.append( get_attestation_signature( + spec, state, attestation_data, privkey