Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finish state tests intro #1114

Merged
merged 22 commits into from
May 27, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
6cd681e
update docs on operation testing
protolambda May 23, 2019
e218c4f
update operations readme, fix wording
protolambda May 23, 2019
754d972
implement epoch processing test-gen, bugfix tests
protolambda May 23, 2019
c11f963
cleanup generator code, use helper pkg to load and generate test case…
protolambda May 23, 2019
e1b04f4
sanity tests generator
protolambda May 23, 2019
3500bde
only sign in test_double_late_crosslink when necessary
djrtwo May 23, 2019
f0c9e7a
ignore just the one crosslinks case that is incompatible with mainnet
protolambda May 23, 2019
1bbab9a
more direct in what is happening in test utils
protolambda May 23, 2019
21c48b5
move sanity tests, separate slot tests
protolambda May 23, 2019
f98a8d5
update epoch processing tests to conform to processing pattern, add d…
protolambda May 23, 2019
902059d
fix operations readme
protolambda May 23, 2019
4ccd304
docs for sanity tests
protolambda May 23, 2019
57dd9fc
fix syntax
protolambda May 23, 2019
f52b228
Update specs/test_formats/operations/README.md
protolambda May 24, 2019
4690bcf
Update specs/test_formats/operations/README.md
protolambda May 24, 2019
f2e3cd0
Update test_libs/pyspec/eth2spec/test/epoch_processing/test_process_c…
protolambda May 24, 2019
73f0f74
run process yield-from test pattern
protolambda May 24, 2019
321baf7
fix missing imports from earlier code suggestion
protolambda May 24, 2019
b6b5787
Update specs/test_formats/epoch_processing/README.md
protolambda May 24, 2019
b12031b
not signed by default
protolambda May 24, 2019
e9a01a2
epoch processing formatting
protolambda May 24, 2019
8d420c0
fix prestate for process registry updates
djrtwo May 27, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions specs/test_formats/operations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ Operations:

| *`operation-name`* | *`operation-object`* | *`input name`* | *`processing call`* |
|-------------------------|----------------------|----------------------|--------------------------------------------------------|
| `attestation` | `Attestation` | `attestation` | `process_deposit(state, attestation)` |
| `attester_slashing` | `AttesterSlashing` | `attester_slashing` | `process_deposit(state, attester_slashing)` |
| `attestation` | `Attestation` | `attestation` | `process_attestation(state, attestation)` |
| `attester_slashing` | `AttesterSlashing` | `attester_slashing` | `process_attester_slashing(state, attester_slashing)` |
| `block_header` | `Block` | `block` | `process_block_header(state, block)` |
| `deposit` | `Deposit` | `deposit` | `process_deposit(state, deposit)` |
| `proposer_slashing` | `ProposerSlashing` | `proposer_slashing` | `process_proposer_slashing(state, proposer_slashing)` |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def test_single_crosslink_update_from_previous_epoch(state):

@spec_state_test
def test_double_late_crosslink(state):
if spec.SLOTS_PER_EPOCH < spec.SHARD_COUNT:
if spec.get_epoch_committee_count(state, spec.get_current_epoch(state)) < spec.SHARD_COUNT:
print("warning: ignoring test, test-assumptions are incompatible with configuration")
return

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,34 @@
is_active_validator,
process_registry_updates
)
from eth2spec.phase0.state_transition import state_transition
from eth2spec.test.helpers.block import build_empty_block_for_next_slot, sign_block
from eth2spec.test.helpers.state import next_epoch
from eth2spec.test.context import spec_state_test


def run_process_registry_updates(state, valid=True):
"""
Run ``process_crosslinks``, yielding:
- pre-state ('pre')
- post-state ('post').
If ``valid == False``, run expecting ``AssertionError``
"""
# 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, signed=False)
block.slot = slot
sign_block(state, block)
state_transition(state, block)

# cache state before epoch transition
spec.cache_state(state)

djrtwo marked this conversation as resolved.
Show resolved Hide resolved
yield 'pre', state
process_registry_updates(state)
yield 'post', state


@spec_state_test
def test_activation(state):
index = 0
Expand All @@ -23,11 +47,7 @@ def test_activation(state):
for _ in range(spec.ACTIVATION_EXIT_DELAY + 1):
next_epoch(state)

yield 'pre', state

process_registry_updates(state)

yield 'post', state
yield from run_process_registry_updates(state)

assert state.validator_registry[index].activation_eligibility_epoch != spec.FAR_FUTURE_EPOCH
assert state.validator_registry[index].activation_epoch != spec.FAR_FUTURE_EPOCH
Expand All @@ -49,11 +69,7 @@ def test_ejection(state):
for _ in range(spec.ACTIVATION_EXIT_DELAY + 1):
next_epoch(state)

yield 'pre', state

process_registry_updates(state)

yield 'post', state
yield from run_process_registry_updates(state)

assert state.validator_registry[index].exit_epoch != spec.FAR_FUTURE_EPOCH
assert not is_active_validator(
Expand Down