Skip to content

Commit

Permalink
Add more test
Browse files Browse the repository at this point in the history
  • Loading branch information
hwwhww committed Apr 16, 2020
1 parent bb49c08 commit b440fe5
Showing 1 changed file with 51 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
run_crosslinks_processing,
)
from eth2spec.test.helpers.shard_block import build_shard_block
from eth2spec.test.helpers.state import next_epoch, next_slot
from eth2spec.test.helpers.state import next_epoch, next_slot, next_slots


@with_all_phases_except(['phase0'])
Expand All @@ -24,7 +24,8 @@ def test_basic_crosslinks(spec, state):

committee_index = spec.CommitteeIndex(0)
shard = spec.compute_shard_from_committee_index(state, committee_index, state.slot)
shard_block = build_shard_block(spec, state, shard, body=b'\x12' * 10, slot=state.slot, signed=True)
body = b'1' * spec.MAX_SHARD_BLOCK_SIZE
shard_block = build_shard_block(spec, state, shard, body=body, slot=state.slot, signed=True)
shard_blocks = [shard_block]

next_slot(spec, state)
Expand All @@ -43,10 +44,58 @@ def test_basic_crosslinks(spec, state):
)
attestations = [attestation]

pre_gasprice = state.shard_states[shard].gasprice
offset_slots = spec.get_offset_slots(state, shard)
assert len(offset_slots) == 1

yield from run_crosslinks_processing(spec, state, shard_transitions, attestations)

shard_state = state.shard_states[shard]
assert shard_state.slot == offset_slots[-1]
assert shard_state.latest_block_root == shard_block.message.hash_tree_root()
assert shard_state == shard_transition.shard_states[len(shard_transition.shard_states) - 1]
assert shard_state.gasprice > pre_gasprice


@with_all_phases_except(['phase0'])
@spec_state_test
@always_bls
def test_multiple_offset_slots(spec, state):
next_epoch(spec, state)
next_epoch(spec, state)
state = spec.upgrade_to_phase1(state)
next_slot(spec, state)

committee_index = spec.CommitteeIndex(0)
shard = spec.compute_shard_from_committee_index(state, committee_index, state.slot)
body = b'1' * spec.MAX_SHARD_BLOCK_SIZE
shard_block = build_shard_block(spec, state, shard, body=body, slot=state.slot, signed=True)
shard_blocks = [shard_block]

next_slots(spec, state, 3)

shard_transition = spec.get_shard_transition(state, shard, shard_blocks)
shard_transitions = [spec.ShardTransition()] * len(state.shard_states)
shard_transitions[shard] = shard_transition

attestation = get_valid_on_time_attestation(
spec,
state,
slot=state.slot,
index=committee_index,
shard_transition=shard_transition,
signed=True,
)
attestations = [attestation]

pre_gasprice = state.shard_states[shard].gasprice
offset_slots = spec.get_offset_slots(state, shard)
assert len(offset_slots) == 3

yield from run_crosslinks_processing(spec, state, shard_transitions, attestations)

shard_state = state.shard_states[shard]
assert shard_state.slot == offset_slots[-1]
assert shard_state.latest_block_root == shard_block.message.hash_tree_root()
assert shard_state == shard_transition.shard_states[len(shard_transition.shard_states) - 1]
assert shard_state.gasprice > pre_gasprice

0 comments on commit b440fe5

Please sign in to comment.