diff --git a/tests/core/pyspec/eth2spec/test/helpers/fork_choice.py b/tests/core/pyspec/eth2spec/test/helpers/fork_choice.py index aaaf5c23b..b26417e8f 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/fork_choice.py +++ b/tests/core/pyspec/eth2spec/test/helpers/fork_choice.py @@ -1,3 +1,4 @@ +from random import Random from eth_utils import encode_hex from eth2spec.utils.ssz.ssz_typing import uint256 from eth2spec.test.helpers.attestations import ( @@ -23,9 +24,12 @@ def add_block_to_store(spec, store, signed_block): spec.on_block(store, signed_block) -def tick_and_add_block(spec, store, signed_block, test_steps, valid=True, allow_invalid_attestations=False): +def tick_and_add_block(spec, store, signed_block, test_steps, valid=True, allow_invalid_attestations=False, + merge_block=False): pre_state = store.block_states[signed_block.message.parent_root] block_time = pre_state.genesis_time + signed_block.message.slot * spec.config.SECONDS_PER_SLOT + if merge_block: + assert spec.is_merge_block(pre_state, signed_block.message.body) if store.time < block_time: on_tick_and_append_step(spec, store, block_time, test_steps) @@ -230,10 +234,10 @@ def apply_next_slots_with_attestations(spec, return post_state, store, last_signed_block -def prepare_empty_pow_block(spec): +def prepare_empty_pow_block(spec, rng=Random(3131)): return spec.PowBlock( - block_hash=spec.Hash32(), - parent_hash=spec.Hash32(), + block_hash=spec.Hash32(spec.hash(rng.randbytes(32))), + parent_hash=spec.Hash32(spec.hash(rng.randbytes(32))), total_difficulty=uint256(0), difficulty=uint256(0) ) diff --git a/tests/core/pyspec/eth2spec/test/merge/unittests/test_terminal_validity.py b/tests/core/pyspec/eth2spec/test/merge/unittests/test_terminal_validity.py index 6c2a623b2..42d83b4a0 100644 --- a/tests/core/pyspec/eth2spec/test/merge/unittests/test_terminal_validity.py +++ b/tests/core/pyspec/eth2spec/test/merge/unittests/test_terminal_validity.py @@ -102,7 +102,6 @@ def test_valid_terminal_pow_block_fail_just_after_terminal(spec, state): @spec_state_test def test_process_merge_execution_payload_success(spec, state): parent_block = prepare_empty_pow_block(spec) - parent_block.block_hash = spec.Hash32(spec.hash(b'01')) parent_block.total_difficulty = spec.config.TERMINAL_TOTAL_DIFFICULTY - uint256(1) block = prepare_empty_pow_block(spec) block.parent_hash = parent_block.block_hash @@ -116,13 +115,11 @@ def test_process_merge_execution_payload_success(spec, state): @spec_state_test def test_process_merge_execution_payload_fail_block_lookup(spec, state): parent_block = prepare_empty_pow_block(spec) - parent_block.block_hash = spec.Hash32(spec.hash(b'01')) parent_block.total_difficulty = spec.config.TERMINAL_TOTAL_DIFFICULTY - uint256(1) block = prepare_empty_pow_block(spec) block.parent_hash = parent_block.block_hash block.total_difficulty = spec.config.TERMINAL_TOTAL_DIFFICULTY payload = spec.ExecutionPayload() - payload.parent_hash = spec.Hash32(spec.hash(b'02')) yield from run_process_merge_execution_payload(spec, block, parent_block, payload, block_lookup_success=False) @@ -131,10 +128,8 @@ def test_process_merge_execution_payload_fail_block_lookup(spec, state): @spec_state_test def test_process_merge_execution_payload_fail_parent_block_lookup(spec, state): parent_block = prepare_empty_pow_block(spec) - parent_block.block_hash = spec.Hash32(spec.hash(b'01')) parent_block.total_difficulty = spec.config.TERMINAL_TOTAL_DIFFICULTY - uint256(1) block = prepare_empty_pow_block(spec) - block.parent_hash = spec.Hash32(spec.hash(b'00')) block.total_difficulty = spec.config.TERMINAL_TOTAL_DIFFICULTY payload = spec.ExecutionPayload() payload.parent_hash = block.block_hash @@ -146,7 +141,6 @@ def test_process_merge_execution_payload_fail_parent_block_lookup(spec, state): @spec_state_test def test_process_merge_execution_payload_fail_after_terminal(spec, state): parent_block = prepare_empty_pow_block(spec) - parent_block.block_hash = spec.Hash32(spec.hash(b'01')) parent_block.total_difficulty = spec.config.TERMINAL_TOTAL_DIFFICULTY block = prepare_empty_pow_block(spec) block.parent_hash = parent_block.block_hash