mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-01-13 04:04:19 +00:00
state is kwarg
This commit is contained in:
parent
5155bc6c4f
commit
ed71efc061
@ -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)
|
||||
|
@ -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
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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),
|
||||
)
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user