mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-02-07 16:24:05 +00:00
Merge pull request #1938 from ethereum/hwwhww/shard-block-tests-part2
Add more tests for `shard_state_transition`
This commit is contained in:
commit
a681163305
@ -10,7 +10,7 @@ from eth2spec.test.helpers.shard_block import (
|
|||||||
sign_shard_block,
|
sign_shard_block,
|
||||||
)
|
)
|
||||||
from eth2spec.test.helpers.shard_transitions import is_full_crosslink
|
from eth2spec.test.helpers.shard_transitions import is_full_crosslink
|
||||||
from eth2spec.test.helpers.state import transition_to_valid_shard_slot
|
from eth2spec.test.helpers.state import next_slot, transition_to_valid_shard_slot, transition_to
|
||||||
|
|
||||||
|
|
||||||
def run_shard_blocks(spec, shard_state, signed_shard_block, beacon_parent_state, valid=True):
|
def run_shard_blocks(spec, shard_state, signed_shard_block, beacon_parent_state, valid=True):
|
||||||
@ -138,6 +138,67 @@ def test_invalid_proposer_index(spec, state):
|
|||||||
yield from run_shard_blocks(spec, shard_state, signed_shard_block, beacon_state, valid=False)
|
yield from run_shard_blocks(spec, shard_state, signed_shard_block, beacon_state, valid=False)
|
||||||
|
|
||||||
|
|
||||||
|
@with_all_phases_except([PHASE0])
|
||||||
|
@spec_state_test
|
||||||
|
@always_bls
|
||||||
|
def test_out_of_bound_offset(spec, state):
|
||||||
|
# TODO: Handle this edge case properly
|
||||||
|
if not is_full_crosslink(spec, state):
|
||||||
|
# skip
|
||||||
|
return
|
||||||
|
|
||||||
|
beacon_state = transition_to_valid_shard_slot(spec, state)
|
||||||
|
shard = 0
|
||||||
|
slot = (
|
||||||
|
beacon_state.shard_states[shard].slot
|
||||||
|
+ spec.SHARD_BLOCK_OFFSETS[spec.MAX_SHARD_BLOCKS_PER_ATTESTATION - 1]
|
||||||
|
+ 1 # out-of-bound
|
||||||
|
)
|
||||||
|
transition_to(spec, beacon_state, slot)
|
||||||
|
|
||||||
|
shard_state = beacon_state.shard_states[shard]
|
||||||
|
signed_shard_block = build_shard_block(spec, beacon_state, shard, slot=beacon_state.slot, signed=True)
|
||||||
|
|
||||||
|
yield from run_shard_blocks(spec, shard_state, signed_shard_block, beacon_state, valid=False)
|
||||||
|
|
||||||
|
|
||||||
|
@with_all_phases_except([PHASE0])
|
||||||
|
@spec_state_test
|
||||||
|
@always_bls
|
||||||
|
def test_invalid_offset(spec, state):
|
||||||
|
if not is_full_crosslink(spec, state):
|
||||||
|
# skip
|
||||||
|
return
|
||||||
|
|
||||||
|
beacon_state = transition_to_valid_shard_slot(spec, state)
|
||||||
|
# 4 is not in `SHARD_BLOCK_OFFSETS`
|
||||||
|
shard = 0
|
||||||
|
slot = beacon_state.shard_states[shard].slot + 4
|
||||||
|
assert slot not in spec.SHARD_BLOCK_OFFSETS
|
||||||
|
transition_to(spec, beacon_state, slot)
|
||||||
|
|
||||||
|
shard_state = beacon_state.shard_states[shard]
|
||||||
|
signed_shard_block = build_shard_block(spec, beacon_state, shard, slot=beacon_state.slot, signed=True)
|
||||||
|
|
||||||
|
yield from run_shard_blocks(spec, shard_state, signed_shard_block, beacon_state, valid=False)
|
||||||
|
|
||||||
|
|
||||||
|
@with_all_phases_except([PHASE0])
|
||||||
|
@spec_state_test
|
||||||
|
@always_bls
|
||||||
|
def test_empty_block_body(spec, state):
|
||||||
|
if not is_full_crosslink(spec, state):
|
||||||
|
# skip
|
||||||
|
return
|
||||||
|
|
||||||
|
beacon_state = transition_to_valid_shard_slot(spec, state)
|
||||||
|
shard = 0
|
||||||
|
shard_state = beacon_state.shard_states[shard]
|
||||||
|
signed_shard_block = build_shard_block(spec, beacon_state, shard, slot=beacon_state.slot, body=b'', signed=True)
|
||||||
|
|
||||||
|
yield from run_shard_blocks(spec, shard_state, signed_shard_block, beacon_state, valid=False)
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# verify_shard_block_signature
|
# verify_shard_block_signature
|
||||||
#
|
#
|
||||||
@ -157,3 +218,54 @@ def test_invalid_signature(spec, state):
|
|||||||
signed_shard_block = build_shard_block(spec, beacon_state, shard, slot=beacon_state.slot, signed=False)
|
signed_shard_block = build_shard_block(spec, beacon_state, shard, slot=beacon_state.slot, signed=False)
|
||||||
|
|
||||||
yield from run_shard_blocks(spec, shard_state, signed_shard_block, beacon_state, valid=False)
|
yield from run_shard_blocks(spec, shard_state, signed_shard_block, beacon_state, valid=False)
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Other cases
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
|
@with_all_phases_except([PHASE0])
|
||||||
|
@spec_state_test
|
||||||
|
@always_bls
|
||||||
|
def test_max_offset(spec, state):
|
||||||
|
if not is_full_crosslink(spec, state):
|
||||||
|
# skip
|
||||||
|
return
|
||||||
|
|
||||||
|
beacon_state = transition_to_valid_shard_slot(spec, state)
|
||||||
|
shard = 0
|
||||||
|
slot = beacon_state.shard_states[shard].slot + spec.SHARD_BLOCK_OFFSETS[spec.MAX_SHARD_BLOCKS_PER_ATTESTATION - 1]
|
||||||
|
transition_to(spec, beacon_state, slot)
|
||||||
|
|
||||||
|
shard_state = beacon_state.shard_states[shard]
|
||||||
|
signed_shard_block = build_shard_block(spec, beacon_state, shard, slot=beacon_state.slot, signed=True)
|
||||||
|
|
||||||
|
yield from run_shard_blocks(spec, shard_state, signed_shard_block, beacon_state)
|
||||||
|
|
||||||
|
|
||||||
|
@with_all_phases_except([PHASE0])
|
||||||
|
@spec_state_test
|
||||||
|
@always_bls
|
||||||
|
def test_pending_shard_parent_block(spec, state):
|
||||||
|
if not is_full_crosslink(spec, state):
|
||||||
|
# skip
|
||||||
|
return
|
||||||
|
|
||||||
|
# Block N
|
||||||
|
beacon_state = transition_to_valid_shard_slot(spec, state)
|
||||||
|
shard = 0
|
||||||
|
shard_state = beacon_state.shard_states[shard]
|
||||||
|
signed_shard_block_1 = build_shard_block(spec, beacon_state, shard, slot=beacon_state.slot, signed=True)
|
||||||
|
_, _, _, _ = run_shard_blocks(spec, shard_state, signed_shard_block_1, beacon_state)
|
||||||
|
|
||||||
|
# Block N+1
|
||||||
|
next_slot(spec, beacon_state)
|
||||||
|
signed_shard_block_2 = build_shard_block(
|
||||||
|
spec, beacon_state, shard,
|
||||||
|
slot=beacon_state.slot, shard_parent_state=shard_state, signed=True
|
||||||
|
)
|
||||||
|
|
||||||
|
assert signed_shard_block_2.message.shard_parent_root == shard_state.latest_block_root
|
||||||
|
assert signed_shard_block_2.message.slot == signed_shard_block_1.message.slot + 1
|
||||||
|
yield from run_shard_blocks(spec, shard_state, signed_shard_block_2, beacon_state)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user