diff --git a/tests/core/pyspec/eth2spec/test/fork_choice/test_on_shard_head.py b/tests/core/pyspec/eth2spec/test/fork_choice/test_on_shard_head.py index c84f073b2..f7b888a2e 100644 --- a/tests/core/pyspec/eth2spec/test/fork_choice/test_on_shard_head.py +++ b/tests/core/pyspec/eth2spec/test/fork_choice/test_on_shard_head.py @@ -72,7 +72,7 @@ def apply_shard_and_beacon(spec, state, store, shard_store, shard_blocks_buffer) shard_transitions = get_shard_transitions( spec, state, - shard_blocks={shard: shard_blocks_buffer}, + shard_block_dict={shard: shard_blocks_buffer}, ) shard_transition = shard_transitions[shard] attestation = get_valid_on_time_attestation( diff --git a/tests/core/pyspec/eth2spec/test/helpers/shard_block.py b/tests/core/pyspec/eth2spec/test/helpers/shard_block.py index 6957f2283..1193f05e5 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/shard_block.py +++ b/tests/core/pyspec/eth2spec/test/helpers/shard_block.py @@ -30,7 +30,7 @@ def build_shard_block(spec, slot = shard_parent_state.slot + 1 if body is None: - body = b'\x56' * 128 + body = get_sample_shard_block_body() beacon_state, beacon_parent_root = get_state_and_beacon_parent_root_at_slot(spec, beacon_state, slot) proposer_index = spec.get_shard_proposer_index(beacon_state, slot, shard) @@ -52,10 +52,10 @@ def build_shard_block(spec, return signed_block -def get_shard_transitions(spec, parent_beacon_state, shard_blocks): +def get_shard_transitions(spec, parent_beacon_state, shard_block_dict): shard_transitions = [spec.ShardTransition()] * spec.MAX_SHARDS on_time_slot = parent_beacon_state.slot + 1 - for shard, blocks in shard_blocks.items(): + for shard, blocks in shard_block_dict.items(): shard_transition = spec.get_shard_transition(parent_beacon_state, shard, blocks) offset_slots = spec.compute_offset_slots( spec.get_latest_slot_for_shard(parent_beacon_state, shard), @@ -81,3 +81,7 @@ def get_committee_index_of_shard(spec, state, slot, shard): # Optional[Committe if (start_shard + committee_index) % active_shard_count == shard: return committee_index return None + + +def get_sample_shard_block_body(): + return b'\x56' * 128 diff --git a/tests/core/pyspec/eth2spec/test/phase1/block_processing/test_process_shard_transition.py b/tests/core/pyspec/eth2spec/test/phase1/block_processing/test_process_shard_transition.py index 6d8878177..0c9293b74 100644 --- a/tests/core/pyspec/eth2spec/test/phase1/block_processing/test_process_shard_transition.py +++ b/tests/core/pyspec/eth2spec/test/phase1/block_processing/test_process_shard_transition.py @@ -16,7 +16,7 @@ def run_basic_crosslink_tests(spec, state, target_len_offset_slot, valid=True): state = transition_to_valid_shard_slot(spec, state) committee_index = spec.CommitteeIndex(0) init_slot = state.slot - shard_slot = state.slot + target_len_offset_slot - 1 + shard_slot = init_slot + target_len_offset_slot - 1 shard = spec.compute_shard_from_committee_index(state, committee_index, shard_slot) assert state.shard_states[shard].slot == init_slot - 1 @@ -31,7 +31,7 @@ def run_basic_crosslink_tests(spec, state, target_len_offset_slot, valid=True): shard_transitions = get_shard_transitions( spec, state, - shard_blocks={shard: shard_blocks}, + shard_block_dict={shard: shard_blocks}, ) shard_transition = shard_transitions[shard] attestation = get_valid_on_time_attestation( diff --git a/tests/core/pyspec/eth2spec/test/phase1/sanity/test_blocks.py b/tests/core/pyspec/eth2spec/test/phase1/sanity/test_blocks.py index 33b0beac7..aa24bfc1e 100644 --- a/tests/core/pyspec/eth2spec/test/phase1/sanity/test_blocks.py +++ b/tests/core/pyspec/eth2spec/test/phase1/sanity/test_blocks.py @@ -19,9 +19,9 @@ def run_beacon_block_with_shard_blocks(spec, state, target_len_offset_slot, comm body = b'\x56' * spec.MAX_SHARD_BLOCK_SIZE shard_block = build_shard_block(spec, state, shard, body=body, slot=state.slot, signed=True) - shard_blocks: Dict[spec.Shard, Sequence[spec.SignedShardBlock]] = {shard: [shard_block]} + shard_block_dict: Dict[spec.Shard, Sequence[spec.SignedShardBlock]] = {shard: [shard_block]} - shard_transitions = get_shard_transitions(spec, state, shard_blocks) + shard_transitions = get_shard_transitions(spec, state, shard_block_dict) attestations = [ get_valid_on_time_attestation( spec, @@ -30,7 +30,7 @@ def run_beacon_block_with_shard_blocks(spec, state, target_len_offset_slot, comm shard_transition=shard_transitions[shard], signed=True, ) - for shard in shard_blocks.keys() + for shard in shard_block_dict.keys() ] beacon_block = build_empty_block(spec, state, slot=state.slot + 1) @@ -50,16 +50,16 @@ def run_beacon_block_with_shard_blocks(spec, state, target_len_offset_slot, comm for shard in range(spec.get_active_shard_count(state)): post_shard_state = state.shard_states[shard] - if shard in shard_blocks: + if shard in shard_block_dict: # Shard state has been changed to state_transition result assert post_shard_state == shard_transitions[shard].shard_states[ len(shard_transitions[shard].shard_states) - 1 ] assert post_shard_state.slot == state.slot - 1 - if len(shard_blocks[shard]) == 0: + if len((shard_block_dict[shard])) == 0: # `latest_block_root` is the same assert post_shard_state.latest_block_root == pre_shard_states[shard].latest_block_root - if target_len_offset_slot == 1 and len(shard_blocks) > 0: + if target_len_offset_slot == 1 and len(shard_block_dict[shard]) > 0: assert post_shard_state.gasprice > pre_gasprice