From cc20b80103c8d55c05cb624e28b631eb852d9644 Mon Sep 17 00:00:00 2001 From: Mikhail Kalinin Date: Tue, 15 Jun 2021 14:55:06 +0600 Subject: [PATCH] Fix linter, add more test helpers --- setup.py | 2 +- specs/merge/validator.md | 4 +- .../test/helpers/execution_payload.py | 5 ++ .../test_process_execution_payload.py | 53 ++++++++++--------- 4 files changed, 36 insertions(+), 28 deletions(-) diff --git a/setup.py b/setup.py index 9ecf8261f..24ac6dd0c 100644 --- a/setup.py +++ b/setup.py @@ -532,7 +532,7 @@ class NoopExecutionEngine(ExecutionEngine): def finalize_block(self, block_hash: Hash32) -> bool: return True - def assemble_block(self, block_hash: Hash32, timestamp: uint64) -> ExecutionPayload: + def assemble_block(self, block_hash: Hash32, timestamp: uint64, randao: Bytes32) -> ExecutionPayload: raise NotImplementedError("no default block production") diff --git a/specs/merge/validator.md b/specs/merge/validator.md index d196d8fae..adbf63e84 100644 --- a/specs/merge/validator.md +++ b/specs/merge/validator.md @@ -95,9 +95,9 @@ def get_execution_payload(state: BeaconState, return ExecutionPayload() else: # Signify merge via producing on top of the last PoW block - return produce_execution_payload(state, pow_block.block_hash, randao_reveal) + return produce_execution_payload(state, pow_block.block_hash, randao_reveal, execution_engine) # Post-merge, normal payload parent_hash = state.latest_execution_payload_header.block_hash - return produce_execution_payload(state, parent_hash, randao_reveal) + return produce_execution_payload(state, parent_hash, randao_reveal, execution_engine) ``` diff --git a/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py b/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py index 661abe964..a84494e74 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py +++ b/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py @@ -1,3 +1,7 @@ +def build_empty_execution_payload_with_randao(spec, state): + return build_empty_execution_payload(spec, state, spec.Bytes32()) + + def build_empty_execution_payload(spec, state, randao_mix): """ Assuming a pre-state of the same slot, build a valid ExecutionPayload without any transactions. @@ -25,6 +29,7 @@ def build_empty_execution_payload(spec, state, randao_mix): return payload + def get_execution_payload_header(spec, execution_payload): return spec.ExecutionPayloadHeader( block_hash=execution_payload.block_hash, 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 04fb0df30..d5e3a796e 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,5 +1,5 @@ from eth2spec.test.helpers.execution_payload import ( - build_empty_execution_payload, + build_empty_execution_payload_with_randao, get_execution_payload_header, build_state_with_incomplete_transition, build_state_with_complete_transition, @@ -7,7 +7,8 @@ from eth2spec.test.helpers.execution_payload import ( from eth2spec.test.context import spec_state_test, expect_assertion_error, with_merge_and_later from eth2spec.test.helpers.state import next_slot -def run_execution_payload_processing(spec, state, execution_payload, randao_mix, valid=True, execution_valid=True): + +def run_execution_payload_processing(spec, state, execution_payload, valid=True, execution_valid=True): """ Run ``process_execution_payload``, yielding: - pre-state ('pre') @@ -21,6 +22,7 @@ def run_execution_payload_processing(spec, state, execution_payload, randao_mix, yield 'execution', {'execution_valid': execution_valid} yield 'execution_payload', execution_payload + randao_mix = spec.Bytes32() called_new_block = False class TestEngine(spec.NoopExecutionEngine): @@ -31,7 +33,8 @@ def run_execution_payload_processing(spec, state, execution_payload, randao_mix, return execution_valid if not valid: - expect_assertion_error(lambda: spec.process_execution_payload(state, execution_payload, randao_mix, TestEngine())) + expect_assertion_error( + lambda: spec.process_execution_payload(state, execution_payload, randao_mix, TestEngine())) yield 'post', None return @@ -53,9 +56,9 @@ def test_success_first_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload(spec, state, spec.Bytes32()) + execution_payload = build_empty_execution_payload_with_randao(spec, state) - yield from run_execution_payload_processing(spec, state, execution_payload, spec.Bytes32()) + yield from run_execution_payload_processing(spec, state, execution_payload) @with_merge_and_later @@ -66,9 +69,9 @@ def test_success_regular_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload(spec, state, spec.Bytes32()) + execution_payload = build_empty_execution_payload_with_randao(spec, state) - yield from run_execution_payload_processing(spec, state, execution_payload, spec.Bytes32()) + yield from run_execution_payload_processing(spec, state, execution_payload) @with_merge_and_later @@ -80,9 +83,9 @@ def test_success_first_payload_with_gap_slot(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload(spec, state, spec.Bytes32()) + execution_payload = build_empty_execution_payload_with_randao(spec, state) - yield from run_execution_payload_processing(spec, state, execution_payload, spec.Bytes32()) + yield from run_execution_payload_processing(spec, state, execution_payload) @with_merge_and_later @@ -94,9 +97,9 @@ def test_success_regular_payload_with_gap_slot(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload(spec, state, spec.Bytes32()) + execution_payload = build_empty_execution_payload_with_randao(spec, state) - yield from run_execution_payload_processing(spec, state, execution_payload, spec.Bytes32()) + yield from run_execution_payload_processing(spec, state, execution_payload) @with_merge_and_later @@ -109,9 +112,9 @@ def test_bad_execution_first_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload(spec, state, spec.Bytes32()) + execution_payload = build_empty_execution_payload_with_randao(spec, state) - yield from run_execution_payload_processing(spec, state, execution_payload, spec.Bytes32(), valid=False, execution_valid=False) + yield from run_execution_payload_processing(spec, state, execution_payload, valid=False, execution_valid=False) @with_merge_and_later @@ -124,9 +127,9 @@ def test_bad_execution_regular_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload(spec, state, spec.Bytes32()) + execution_payload = build_empty_execution_payload_with_randao(spec, state) - yield from run_execution_payload_processing(spec, state, execution_payload, spec.Bytes32(), valid=False, execution_valid=False) + yield from run_execution_payload_processing(spec, state, execution_payload, valid=False, execution_valid=False) @with_merge_and_later @@ -137,10 +140,10 @@ def test_bad_parent_hash_regular_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload(spec, state, spec.Bytes32()) + execution_payload = build_empty_execution_payload_with_randao(spec, state) execution_payload.parent_hash = spec.Hash32() - yield from run_execution_payload_processing(spec, state, execution_payload, spec.Bytes32(), valid=False) + yield from run_execution_payload_processing(spec, state, execution_payload, valid=False) @with_merge_and_later @@ -151,10 +154,10 @@ def test_bad_number_regular_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload(spec, state, spec.Bytes32()) + execution_payload = build_empty_execution_payload_with_randao(spec, state) execution_payload.number = execution_payload.number + 1 - yield from run_execution_payload_processing(spec, state, execution_payload, spec.Bytes32(), valid=False) + yield from run_execution_payload_processing(spec, state, execution_payload, valid=False) @with_merge_and_later @@ -165,11 +168,11 @@ def test_bad_everything_regular_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload(spec, state, spec.Bytes32()) + execution_payload = build_empty_execution_payload_with_randao(spec, state) execution_payload.parent_hash = spec.Hash32() execution_payload.number = execution_payload.number + 1 - yield from run_execution_payload_processing(spec, state, execution_payload, spec.Bytes32(), valid=False) + yield from run_execution_payload_processing(spec, state, execution_payload, valid=False) @with_merge_and_later @@ -180,10 +183,10 @@ def test_bad_timestamp_first_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload(spec, state, spec.Bytes32()) + execution_payload = build_empty_execution_payload_with_randao(spec, state) execution_payload.timestamp = execution_payload.timestamp + 1 - yield from run_execution_payload_processing(spec, state, execution_payload, spec.Bytes32(), valid=False) + yield from run_execution_payload_processing(spec, state, execution_payload, valid=False) @with_merge_and_later @@ -194,7 +197,7 @@ def test_bad_timestamp_regular_payload(spec, state): next_slot(spec, state) # execution payload - execution_payload = build_empty_execution_payload(spec, state, spec.Bytes32()) + execution_payload = build_empty_execution_payload_with_randao(spec, state) execution_payload.timestamp = execution_payload.timestamp + 1 - yield from run_execution_payload_processing(spec, state, execution_payload, spec.Bytes32(), valid=False) + yield from run_execution_payload_processing(spec, state, execution_payload, valid=False)