Update and add tests
This commit is contained in:
parent
fa6094837b
commit
93d19bdf40
|
@ -1,13 +1,22 @@
|
||||||
|
|
||||||
process_calls = [
|
process_calls = [
|
||||||
|
# PHASE0
|
||||||
'process_justification_and_finalization',
|
'process_justification_and_finalization',
|
||||||
'process_rewards_and_penalties',
|
'process_rewards_and_penalties',
|
||||||
'process_registry_updates',
|
'process_registry_updates',
|
||||||
'process_reveal_deadlines',
|
'process_reveal_deadlines',
|
||||||
'process_challenge_deadlines',
|
'process_challenge_deadlines',
|
||||||
'process_slashings',
|
'process_slashings',
|
||||||
'process_final_updates',
|
'process_eth1_data_votes_updates',
|
||||||
'after_process_final_updates',
|
'process_effective_balances_updates',
|
||||||
|
'process_slashings_updates',
|
||||||
|
'process_randao_mixes_updates',
|
||||||
|
'process_historical_roots_updates',
|
||||||
|
'process_participation_record_updates',
|
||||||
|
# LIGHTCLIENT_PATCH
|
||||||
|
'process_sync_committee_updates',
|
||||||
|
# PHASE1
|
||||||
|
'process_phase_1_final_updates',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ def test_sync_committees_progress(spec, state):
|
||||||
assert state.current_sync_committee == first_sync_committee
|
assert state.current_sync_committee == first_sync_committee
|
||||||
assert state.next_sync_committee == second_sync_committee
|
assert state.next_sync_committee == second_sync_committee
|
||||||
|
|
||||||
yield from run_epoch_processing_with(spec, state, 'process_final_updates')
|
yield from run_epoch_processing_with(spec, state, 'process_sync_committee_updates')
|
||||||
|
|
||||||
# Can compute the third committee having computed final balances in the last epoch
|
# Can compute the third committee having computed final balances in the last epoch
|
||||||
# of this `EPOCHS_PER_SYNC_COMMITTEE_PERIOD`
|
# of this `EPOCHS_PER_SYNC_COMMITTEE_PERIOD`
|
||||||
|
|
|
@ -2,45 +2,10 @@ from eth2spec.test.context import spec_state_test, with_all_phases
|
||||||
from eth2spec.test.helpers.epoch_processing import (
|
from eth2spec.test.helpers.epoch_processing import (
|
||||||
run_epoch_processing_with, run_epoch_processing_to
|
run_epoch_processing_with, run_epoch_processing_to
|
||||||
)
|
)
|
||||||
from eth2spec.test.helpers.state import transition_to
|
|
||||||
|
|
||||||
|
|
||||||
def run_process_final_updates(spec, state):
|
def run_process_effective_balances_updates(spec, state):
|
||||||
yield from run_epoch_processing_with(spec, state, 'process_final_updates')
|
yield from run_epoch_processing_with(spec, state, 'process_effective_balances_updates')
|
||||||
|
|
||||||
|
|
||||||
@with_all_phases
|
|
||||||
@spec_state_test
|
|
||||||
def test_eth1_vote_no_reset(spec, state):
|
|
||||||
assert spec.EPOCHS_PER_ETH1_VOTING_PERIOD > 1
|
|
||||||
# skip ahead to the end of the epoch
|
|
||||||
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,
|
|
||||||
deposit_count=state.eth1_deposit_index,
|
|
||||||
block_hash=b'\xbb' * 32))
|
|
||||||
|
|
||||||
yield from run_process_final_updates(spec, state)
|
|
||||||
|
|
||||||
assert len(state.eth1_data_votes) == spec.SLOTS_PER_EPOCH
|
|
||||||
|
|
||||||
|
|
||||||
@with_all_phases
|
|
||||||
@spec_state_test
|
|
||||||
def test_eth1_vote_reset(spec, state):
|
|
||||||
# skip ahead to the end of the voting period
|
|
||||||
state.slot = (spec.EPOCHS_PER_ETH1_VOTING_PERIOD * 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,
|
|
||||||
deposit_count=state.eth1_deposit_index,
|
|
||||||
block_hash=b'\xbb' * 32))
|
|
||||||
|
|
||||||
yield from run_process_final_updates(spec, state)
|
|
||||||
|
|
||||||
assert len(state.eth1_data_votes) == 0
|
|
||||||
|
|
||||||
|
|
||||||
@with_all_phases
|
@with_all_phases
|
||||||
|
@ -48,7 +13,7 @@ def test_eth1_vote_reset(spec, state):
|
||||||
def test_effective_balance_hysteresis(spec, state):
|
def test_effective_balance_hysteresis(spec, state):
|
||||||
# Prepare state up to the final-updates.
|
# Prepare state up to the final-updates.
|
||||||
# Then overwrite the balances, we only want to focus to be on the hysteresis based changes.
|
# Then overwrite the balances, we only want to focus to be on the hysteresis based changes.
|
||||||
run_epoch_processing_to(spec, state, 'process_final_updates')
|
run_epoch_processing_to(spec, state, 'process_effective_balances_updates')
|
||||||
# Set some edge cases for balances
|
# Set some edge cases for balances
|
||||||
max = spec.MAX_EFFECTIVE_BALANCE
|
max = spec.MAX_EFFECTIVE_BALANCE
|
||||||
min = spec.EJECTION_BALANCE
|
min = spec.EJECTION_BALANCE
|
||||||
|
@ -79,21 +44,7 @@ def test_effective_balance_hysteresis(spec, state):
|
||||||
state.validators[i].effective_balance = pre_eff
|
state.validators[i].effective_balance = pre_eff
|
||||||
state.balances[i] = bal
|
state.balances[i] = bal
|
||||||
|
|
||||||
yield 'pre', state
|
yield from run_process_effective_balances_updates(spec, state)
|
||||||
spec.process_final_updates(state)
|
|
||||||
yield 'post', state
|
|
||||||
|
|
||||||
for i, (_, _, post_eff, name) in enumerate(cases):
|
for i, (_, _, post_eff, name) in enumerate(cases):
|
||||||
assert state.validators[i].effective_balance == post_eff, name
|
assert state.validators[i].effective_balance == post_eff, name
|
||||||
|
|
||||||
|
|
||||||
@with_all_phases
|
|
||||||
@spec_state_test
|
|
||||||
def test_historical_root_accumulator(spec, state):
|
|
||||||
# skip ahead to near the end of the historical roots period (excl block before epoch processing)
|
|
||||||
state.slot = spec.SLOTS_PER_HISTORICAL_ROOT - 1
|
|
||||||
history_len = len(state.historical_roots)
|
|
||||||
|
|
||||||
yield from run_process_final_updates(spec, state)
|
|
||||||
|
|
||||||
assert len(state.historical_roots) == history_len + 1
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
from eth2spec.test.context import spec_state_test, with_all_phases
|
||||||
|
from eth2spec.test.helpers.epoch_processing import (
|
||||||
|
run_epoch_processing_with,
|
||||||
|
)
|
||||||
|
from eth2spec.test.helpers.state import transition_to
|
||||||
|
|
||||||
|
|
||||||
|
def run_process_eth1_data_votes_updates(spec, state):
|
||||||
|
yield from run_epoch_processing_with(spec, state, 'process_eth1_data_votes_updates')
|
||||||
|
|
||||||
|
|
||||||
|
@with_all_phases
|
||||||
|
@spec_state_test
|
||||||
|
def test_eth1_vote_no_reset(spec, state):
|
||||||
|
assert spec.EPOCHS_PER_ETH1_VOTING_PERIOD > 1
|
||||||
|
# skip ahead to the end of the epoch
|
||||||
|
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,
|
||||||
|
deposit_count=state.eth1_deposit_index,
|
||||||
|
block_hash=b'\xbb' * 32))
|
||||||
|
|
||||||
|
yield from run_process_eth1_data_votes_updates(spec, state)
|
||||||
|
|
||||||
|
assert len(state.eth1_data_votes) == spec.SLOTS_PER_EPOCH
|
||||||
|
|
||||||
|
|
||||||
|
@with_all_phases
|
||||||
|
@spec_state_test
|
||||||
|
def test_eth1_vote_reset(spec, state):
|
||||||
|
# skip ahead to the end of the voting period
|
||||||
|
state.slot = (spec.EPOCHS_PER_ETH1_VOTING_PERIOD * 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,
|
||||||
|
deposit_count=state.eth1_deposit_index,
|
||||||
|
block_hash=b'\xbb' * 32))
|
||||||
|
|
||||||
|
yield from run_process_eth1_data_votes_updates(spec, state)
|
||||||
|
|
||||||
|
assert len(state.eth1_data_votes) == 0
|
|
@ -0,0 +1,20 @@
|
||||||
|
from eth2spec.test.context import spec_state_test, with_all_phases
|
||||||
|
from eth2spec.test.helpers.epoch_processing import (
|
||||||
|
run_epoch_processing_with
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def run_process_historical_roots_updates(spec, state):
|
||||||
|
yield from run_epoch_processing_with(spec, state, 'process_historical_roots_updates')
|
||||||
|
|
||||||
|
|
||||||
|
@with_all_phases
|
||||||
|
@spec_state_test
|
||||||
|
def test_historical_root_accumulator(spec, state):
|
||||||
|
# skip ahead to near the end of the historical roots period (excl block before epoch processing)
|
||||||
|
state.slot = spec.SLOTS_PER_HISTORICAL_ROOT - 1
|
||||||
|
history_len = len(state.historical_roots)
|
||||||
|
|
||||||
|
yield from run_process_historical_roots_updates(spec, state)
|
||||||
|
|
||||||
|
assert len(state.historical_roots) == history_len + 1
|
|
@ -0,0 +1,21 @@
|
||||||
|
from eth2spec.test.context import spec_state_test, with_all_phases
|
||||||
|
from eth2spec.test.helpers.epoch_processing import (
|
||||||
|
run_epoch_processing_with
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def run_process_participation_record_updates(spec, state):
|
||||||
|
yield from run_epoch_processing_with(spec, state, 'process_participation_record_updates')
|
||||||
|
|
||||||
|
|
||||||
|
@with_all_phases
|
||||||
|
@spec_state_test
|
||||||
|
def test_updated_participation_record(spec, state):
|
||||||
|
state.previous_epoch_attestations = [spec.PendingAttestation(proposer_index=100)]
|
||||||
|
current_epoch_attestations = [spec.PendingAttestation(proposer_index=200)]
|
||||||
|
state.current_epoch_attestations = current_epoch_attestations
|
||||||
|
|
||||||
|
yield from run_process_participation_record_updates(spec, state)
|
||||||
|
|
||||||
|
assert state.previous_epoch_attestations == current_epoch_attestations
|
||||||
|
assert state.current_epoch_attestations == []
|
|
@ -0,0 +1,21 @@
|
||||||
|
from eth2spec.test.context import spec_state_test, with_all_phases
|
||||||
|
from eth2spec.test.helpers.epoch_processing import (
|
||||||
|
run_epoch_processing_with
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def run_process_randao_mixes_updates(spec, state):
|
||||||
|
yield from run_epoch_processing_with(spec, state, 'process_randao_mixes_updates')
|
||||||
|
|
||||||
|
|
||||||
|
@with_all_phases
|
||||||
|
@spec_state_test
|
||||||
|
def test_updated_randao_mixes(spec, state):
|
||||||
|
next_epoch = spec.get_current_epoch(state) + 1
|
||||||
|
state.randao_mixes[next_epoch % spec.EPOCHS_PER_HISTORICAL_VECTOR] = b'\x56' * 32
|
||||||
|
|
||||||
|
yield from run_process_randao_mixes_updates(spec, state)
|
||||||
|
|
||||||
|
assert state.randao_mixes[next_epoch % spec.EPOCHS_PER_HISTORICAL_VECTOR] == spec.get_randao_mix(
|
||||||
|
state, spec.get_current_epoch(state)
|
||||||
|
)
|
|
@ -0,0 +1,20 @@
|
||||||
|
from eth2spec.test.context import spec_state_test, with_all_phases
|
||||||
|
from eth2spec.test.helpers.epoch_processing import (
|
||||||
|
run_epoch_processing_with
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def run_process_slashings_updates(spec, state):
|
||||||
|
yield from run_epoch_processing_with(spec, state, 'process_slashings_updates')
|
||||||
|
|
||||||
|
|
||||||
|
@with_all_phases
|
||||||
|
@spec_state_test
|
||||||
|
def test_flush_slashings(spec, state):
|
||||||
|
next_epoch = spec.get_current_epoch(state) + 1
|
||||||
|
state.slashings[next_epoch % spec.EPOCHS_PER_SLASHINGS_VECTOR] = 100
|
||||||
|
assert state.slashings[next_epoch % spec.EPOCHS_PER_SLASHINGS_VECTOR] != 0
|
||||||
|
|
||||||
|
yield from run_process_slashings_updates(spec, state)
|
||||||
|
|
||||||
|
assert state.slashings[next_epoch % spec.EPOCHS_PER_SLASHINGS_VECTOR] == 0
|
|
@ -37,10 +37,17 @@ The provided pre-state is already transitioned to just before the specific sub-t
|
||||||
|
|
||||||
Sub-transitions:
|
Sub-transitions:
|
||||||
|
|
||||||
|
Sub-transitions:
|
||||||
|
|
||||||
- `justification_and_finalization`
|
- `justification_and_finalization`
|
||||||
- `rewards_and_penalties` (limited to `minimal` config)
|
- `rewards_and_penalties`
|
||||||
- `registry_updates`
|
- `registry_updates`
|
||||||
- `slashings`
|
- `slashings`
|
||||||
- `final_updates`
|
- `eth1_data_votes_updates`
|
||||||
|
- `effective_balances_updates`
|
||||||
|
- `slashings_updates`
|
||||||
|
- `randao_mixes_updates`
|
||||||
|
- `historical_roots_updates`
|
||||||
|
- `participation_record_updates`
|
||||||
|
|
||||||
The resulting state should match the expected `post` state.
|
The resulting state should match the expected `post` state.
|
||||||
|
|
Loading…
Reference in New Issue