diff --git a/tests/core/pyspec/eth2spec/test/exceptions.py b/tests/core/pyspec/eth2spec/test/exceptions.py index c553ec374..fcabd88f3 100644 --- a/tests/core/pyspec/eth2spec/test/exceptions.py +++ b/tests/core/pyspec/eth2spec/test/exceptions.py @@ -1,2 +1,6 @@ class SkippedTest(Exception): ... + + +class BlockNotFoundException(Exception): + ... diff --git a/tests/core/pyspec/eth2spec/test/helpers/block.py b/tests/core/pyspec/eth2spec/test/helpers/block.py index edbe43c13..78b90b165 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/block.py +++ b/tests/core/pyspec/eth2spec/test/helpers/block.py @@ -4,7 +4,6 @@ from eth2spec.test.helpers.keys import privkeys from eth2spec.utils import bls from eth2spec.utils.bls import only_with_bls from eth2spec.utils.ssz.ssz_impl import hash_tree_root -from eth2spec.utils.ssz.ssz_typing import uint256 def get_proposer_index_maybe(spec, state, slot, proposer_index=None): @@ -122,12 +121,3 @@ def get_state_and_beacon_parent_root_at_slot(spec, state, slot): previous_block_header.state_root = hash_tree_root(state) beacon_parent_root = hash_tree_root(previous_block_header) return state, beacon_parent_root - - -def prepare_empty_pow_block(spec): - return spec.PowBlock( - block_hash=spec.Hash32(), - parent_hash=spec.Hash32(), - total_difficulty=uint256(0), - difficulty=uint256(0) - ) diff --git a/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py b/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py index 453c49d3e..6126346a9 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py +++ b/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py @@ -1,6 +1,3 @@ -from remerkleable.byte_arrays import ByteVector - - def build_empty_execution_payload(spec, state, randao_mix=None): """ Assuming a pre-state of the same slot, build a valid ExecutionPayload without any transactions. @@ -69,12 +66,3 @@ def build_state_with_execution_payload_header(spec, state, execution_payload_hea pre_state.latest_execution_payload_header = execution_payload_header return pre_state - - -# damages last byte of the data by changing one bit -def screw_up_bytes(data: ByteVector): - assert len(data) > 0 - length = data.vector_length() - raw_data = data.encode_bytes() - raw_data = raw_data[0:len(raw_data) - 1] + bytes([(raw_data[len(raw_data) - 1] ^ 1)]) - return ByteVector[length](*raw_data) diff --git a/tests/core/pyspec/eth2spec/test/helpers/fork_choice.py b/tests/core/pyspec/eth2spec/test/helpers/fork_choice.py index 65d6975f2..aaaf5c23b 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/fork_choice.py +++ b/tests/core/pyspec/eth2spec/test/helpers/fork_choice.py @@ -1,4 +1,5 @@ from eth_utils import encode_hex +from eth2spec.utils.ssz.ssz_typing import uint256 from eth2spec.test.helpers.attestations import ( next_epoch_with_attestations, next_slots_with_attestations, @@ -227,3 +228,12 @@ def apply_next_slots_with_attestations(spec, assert store.block_states[block_root].hash_tree_root() == post_state.hash_tree_root() return post_state, store, last_signed_block + + +def prepare_empty_pow_block(spec): + return spec.PowBlock( + block_hash=spec.Hash32(), + parent_hash=spec.Hash32(), + total_difficulty=uint256(0), + difficulty=uint256(0) + ) diff --git a/tests/core/pyspec/eth2spec/test/merge/block_processing/test_process_execution_payload.py b/tests/core/pyspec/eth2spec/test/merge/block_processing/test_process_execution_payload.py index 525e42d9a..572326711 100644 --- a/tests/core/pyspec/eth2spec/test/merge/block_processing/test_process_execution_payload.py +++ b/tests/core/pyspec/eth2spec/test/merge/block_processing/test_process_execution_payload.py @@ -1,12 +1,9 @@ -from remerkleable.byte_arrays import Bytes32 from eth2spec.utils.ssz.ssz_typing import uint64 - from eth2spec.test.helpers.execution_payload import ( build_empty_execution_payload, get_execution_payload_header, build_state_with_incomplete_transition, - build_state_with_complete_transition, - screw_up_bytes + build_state_with_complete_transition ) from eth2spec.test.context import spec_state_test, expect_assertion_error, with_merge_and_later from eth2spec.test.helpers.state import next_slot @@ -233,39 +230,6 @@ def test_bad_timestamp_regular_payload(spec, state): yield from run_execution_payload_processing(spec, state, execution_payload, valid=False) -@with_merge_and_later -@spec_state_test -def test_bad_randao_first_payload(spec, state): - # pre-state - state = build_state_with_incomplete_transition(spec, state) - next_slot(spec, state) - - # execution payload - execution_payload = build_empty_execution_payload(spec, state) - good_randao: Bytes32 = execution_payload.random - bad_randao = screw_up_bytes(good_randao) - # still valid because randao is ignored on this stage - execution_payload.random = bad_randao - - yield from run_execution_payload_processing(spec, state, execution_payload, valid=False) - - -@with_merge_and_later -@spec_state_test -def test_bad_randao_regular_payload(spec, state): - # pre-state - state = build_state_with_complete_transition(spec, state) - next_slot(spec, state) - - # execution payload - execution_payload = build_empty_execution_payload(spec, state) - good_randao: Bytes32 = execution_payload.random - bad_randao = screw_up_bytes(good_randao) - execution_payload.random = bad_randao - - yield from run_execution_payload_processing(spec, state, execution_payload, valid=False) - - @with_merge_and_later @spec_state_test def test_gaslimit_zero_first_payload(spec, state): @@ -303,8 +267,10 @@ def test_gaslimit_upper_plus_regular_payload(spec, state): # execution payload execution_payload = build_empty_execution_payload(spec, state) - execution_payload.gas_limit = execution_payload.gas_limit + \ + execution_payload.gas_limit = ( + execution_payload.gas_limit + execution_payload.gas_limit // spec.GAS_LIMIT_DENOMINATOR + ) yield from run_execution_payload_processing(spec, state, execution_payload, valid=False) @@ -318,8 +284,10 @@ def test_gaslimit_upper_regular_payload(spec, state): # execution payload execution_payload = build_empty_execution_payload(spec, state) - execution_payload.gas_limit = execution_payload.gas_limit + \ + execution_payload.gas_limit = ( + execution_payload.gas_limit + execution_payload.gas_limit // spec.GAS_LIMIT_DENOMINATOR - uint64(1) + ) yield from run_execution_payload_processing(spec, state, execution_payload) @@ -333,8 +301,10 @@ def test_gaslimit_lower_minus_regular_payload(spec, state): # execution payload execution_payload = build_empty_execution_payload(spec, state) - execution_payload.gas_limit = execution_payload.gas_limit - \ + execution_payload.gas_limit = ( + execution_payload.gas_limit - execution_payload.gas_limit // spec.GAS_LIMIT_DENOMINATOR + ) yield from run_execution_payload_processing(spec, state, execution_payload, valid=False) @@ -348,8 +318,10 @@ def test_gaslimit_lower_regular_payload(spec, state): # execution payload execution_payload = build_empty_execution_payload(spec, state) - execution_payload.gas_limit = execution_payload.gas_limit - \ + execution_payload.gas_limit = ( + execution_payload.gas_limit - execution_payload.gas_limit // spec.GAS_LIMIT_DENOMINATOR + uint64(1) + ) yield from run_execution_payload_processing(spec, state, execution_payload) diff --git a/tests/core/pyspec/eth2spec/test/merge/fork_choice/test_on_merge_block.py b/tests/core/pyspec/eth2spec/test/merge/fork_choice/test_on_merge_block.py index f7bd0341c..f3e4129b3 100644 --- a/tests/core/pyspec/eth2spec/test/merge/fork_choice/test_on_merge_block.py +++ b/tests/core/pyspec/eth2spec/test/merge/fork_choice/test_on_merge_block.py @@ -11,7 +11,7 @@ from eth2spec.test.helpers.fork_choice import ( from eth2spec.test.helpers.state import ( state_transition_and_sign_block, ) -from eth2spec.test.helpers.block import ( +from eth2spec.test.helpers.fork_choice import ( prepare_empty_pow_block ) diff --git a/tests/core/pyspec/eth2spec/test/merge/unit/__init__.py b/tests/core/pyspec/eth2spec/test/merge/unittests/__init__.py similarity index 100% rename from tests/core/pyspec/eth2spec/test/merge/unit/__init__.py rename to tests/core/pyspec/eth2spec/test/merge/unittests/__init__.py diff --git a/tests/core/pyspec/eth2spec/test/merge/fork_choice/test_terminal_validity.py b/tests/core/pyspec/eth2spec/test/merge/unittests/test_terminal_validity.py similarity index 96% rename from tests/core/pyspec/eth2spec/test/merge/fork_choice/test_terminal_validity.py rename to tests/core/pyspec/eth2spec/test/merge/unittests/test_terminal_validity.py index 605375880..87ee190cc 100644 --- a/tests/core/pyspec/eth2spec/test/merge/fork_choice/test_terminal_validity.py +++ b/tests/core/pyspec/eth2spec/test/merge/unittests/test_terminal_validity.py @@ -1,16 +1,13 @@ +from eth2spec.test.exceptions import BlockNotFoundException from eth2spec.utils.ssz.ssz_typing import uint256 -from eth2spec.test.helpers.block import ( +from eth2spec.test.helpers.fork_choice import ( prepare_empty_pow_block ) from eth2spec.test.context import spec_state_test, with_merge_and_later -class BlockNotFoundException(Exception): - pass - - # Copy of conditional merge part of `on_block(store: Store, signed_block: SignedBeaconBlock)` handler -def process_merge_execution_payload(spec, execution_payload): +def validate_transition_execution_payload(spec, execution_payload): pow_block = spec.get_pow_block(execution_payload.parent_hash) pow_parent = spec.get_pow_block(pow_block.parent_hash) assert spec.is_valid_terminal_pow_block(pow_block, pow_parent) @@ -45,7 +42,7 @@ def run_process_merge_execution_payload(spec, block, parent_block, payload, exception_caught = False block_not_found_exception_caught = False try: - process_merge_execution_payload(spec, payload) + validate_transition_execution_payload(spec, payload) except BlockNotFoundException: block_not_found_exception_caught = True except AssertionError: diff --git a/tests/core/pyspec/eth2spec/test/merge/unit/test_unit.py b/tests/core/pyspec/eth2spec/test/merge/unittests/test_transition.py similarity index 88% rename from tests/core/pyspec/eth2spec/test/merge/unit/test_unit.py rename to tests/core/pyspec/eth2spec/test/merge/unittests/test_transition.py index bd968474e..03e6ae874 100644 --- a/tests/core/pyspec/eth2spec/test/merge/unit/test_unit.py +++ b/tests/core/pyspec/eth2spec/test/merge/unittests/test_transition.py @@ -22,7 +22,7 @@ def test_success_merge_complete(spec, state): @with_merge_and_later @spec_state_test -def test_fail_merge_block_false_false(spec, state): +def test_fail_merge_block(spec, state): state = build_state_with_complete_transition(spec, state) execution_payload = spec.ExecutionPayload() body = spec.BeaconBlockBody() @@ -32,7 +32,7 @@ def test_fail_merge_block_false_false(spec, state): @with_merge_and_later @spec_state_test -def test_fail_merge_block_false_true(spec, state): +def test_fail_merge_block_complete_transition(spec, state): state = build_state_with_complete_transition(spec, state) execution_payload = build_empty_execution_payload(spec, state) body = spec.BeaconBlockBody() @@ -42,7 +42,7 @@ def test_fail_merge_block_false_true(spec, state): @with_merge_and_later @spec_state_test -def test_fail_merge_block_true_false(spec, state): +def test_fail_merge_block_no_execution_payload(spec, state): state = build_state_with_incomplete_transition(spec, state) execution_payload = spec.ExecutionPayload() body = spec.BeaconBlockBody() @@ -62,7 +62,7 @@ def test_success_merge_block(spec, state): @with_merge_and_later @spec_state_test -def test_fail_execution_enabled_false_false(spec, state): +def test_failed_execution_enabled(spec, state): state = build_state_with_incomplete_transition(spec, state) execution_payload = spec.ExecutionPayload() body = spec.BeaconBlockBody() @@ -72,7 +72,7 @@ def test_fail_execution_enabled_false_false(spec, state): @with_merge_and_later @spec_state_test -def test_success_execution_enabled_true_false(spec, state): +def test_success_execution_enabled_before_terminal(spec, state): state = build_state_with_incomplete_transition(spec, state) execution_payload = build_empty_execution_payload(spec, state) body = spec.BeaconBlockBody() @@ -82,7 +82,7 @@ def test_success_execution_enabled_true_false(spec, state): @with_merge_and_later @spec_state_test -def test_success_execution_enabled_false_true(spec, state): +def test_success_execution_enabled_no_execution_payload(spec, state): state = build_state_with_complete_transition(spec, state) execution_payload = spec.ExecutionPayload() body = spec.BeaconBlockBody() @@ -92,7 +92,7 @@ def test_success_execution_enabled_false_true(spec, state): @with_merge_and_later @spec_state_test -def test_success_execution_enabled_true_true(spec, state): +def test_success_execution_enabled(spec, state): state = build_state_with_complete_transition(spec, state) execution_payload = build_empty_execution_payload(spec, state) body = spec.BeaconBlockBody() diff --git a/tests/formats/fork_choice/README.md b/tests/formats/fork_choice/README.md index cfc86776d..2f006b07e 100644 --- a/tests/formats/fork_choice/README.md +++ b/tests/formats/fork_choice/README.md @@ -69,6 +69,14 @@ The file is located in the same folder (see below). After this step, the `store` object may have been updated. +#### `on_merge_block` execution + +Adds `PowBlock` data which is required for executing `on_block(store, block)`. +Number of blocks is stored in `meta.yaml`, block file names are `pow_block_.ssz_snappy`. +The file is located in the same folder. +PowBlocks should be used as return values for `get_pow_block(hash: Hash32) -> PowBlock` function if hashes match. + + #### Checks step The checks to verify the current status of `store`.