From e235aa82961e0143fa840c72b176cfa03162c71b Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Sun, 3 Oct 2021 22:20:53 +0800 Subject: [PATCH] Clean up. Add `execution_payload_header` to initialization `meta.yaml` --- specs/merge/beacon-chain.md | 6 +++--- .../eth2spec/test/merge/genesis/__init__.py | 0 .../test/merge/genesis/test_initialization.py | 21 +++++++++++-------- tests/formats/genesis/initialization.md | 5 +++-- tests/generators/genesis/main.py | 7 ++++++- 5 files changed, 24 insertions(+), 15 deletions(-) create mode 100644 tests/core/pyspec/eth2spec/test/merge/genesis/__init__.py diff --git a/specs/merge/beacon-chain.md b/specs/merge/beacon-chain.md index 29718b0ec1..3e2fd9753a 100644 --- a/specs/merge/beacon-chain.md +++ b/specs/merge/beacon-chain.md @@ -355,11 +355,11 @@ def process_execution_payload(state: BeaconState, payload: ExecutionPayload, exe *Note*: The function `initialize_beacon_state_from_eth1` is modified for pure Merge testing only. Modifications include: -1. Use `MERGE_FORK_VERSION` as the current fork version -2. Utilize the Merge `BeaconBlockBody` when constructing the initial `latest_block_header` +1. Use `MERGE_FORK_VERSION` as the current fork version. +2. Utilize the Merge `BeaconBlockBody` when constructing the initial `latest_block_header`. 3. Initialize `latest_execution_payload_header`. If `execution_payload_header == ExecutionPayloadHeader()`, then the Merge has not yet occurred. - Else, the Merge starts from genesis. + Else, the Merge starts from genesis and the transition is incomplete. ```python def initialize_beacon_state_from_eth1(eth1_block_hash: Bytes32, diff --git a/tests/core/pyspec/eth2spec/test/merge/genesis/__init__.py b/tests/core/pyspec/eth2spec/test/merge/genesis/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/core/pyspec/eth2spec/test/merge/genesis/test_initialization.py b/tests/core/pyspec/eth2spec/test/merge/genesis/test_initialization.py index 853d635c7f..384bf57c40 100644 --- a/tests/core/pyspec/eth2spec/test/merge/genesis/test_initialization.py +++ b/tests/core/pyspec/eth2spec/test/merge/genesis/test_initialization.py @@ -1,7 +1,9 @@ from eth2spec.test.context import ( + MERGE, single_phase, spec_test, with_presets, + with_phases, with_merge_and_later, ) from eth2spec.test.helpers.constants import MINIMAL @@ -17,7 +19,7 @@ def eth1_init_data(eth1_block_hash, eth1_timestamp): } -@with_merge_and_later +@with_phases([MERGE]) @spec_test @single_phase @with_presets([MINIMAL], reason="too slow") @@ -37,11 +39,11 @@ def test_initialize_pre_transition_no_param(spec): yield 'deposits', deposits # initialize beacon_state *without* an execution_payload_header + yield 'execution_payload_header', 'meta', False state = spec.initialize_beacon_state_from_eth1(eth1_block_hash, eth1_timestamp, deposits) - assert not spec.is_merge_comp(state) + assert not spec.is_merge_complete(state) - # yield state yield 'state', state @@ -64,19 +66,20 @@ def test_initialize_pre_transition_empty_payload(spec): yield from eth1_init_data(eth1_block_hash, eth1_timestamp) yield 'deposits', deposits - # initialize beacon_state *without* an execution_payload_header + # initialize beacon_state *with* an *empty* execution_payload_header + yield 'execution_payload_header', 'meta', True + execution_payload_header = spec.ExecutionPayloadHeader() state = spec.initialize_beacon_state_from_eth1( eth1_block_hash, eth1_timestamp, deposits, - spec.ExecutionPayloadHeader() + execution_payload_header=execution_payload_header, ) assert not spec.is_merge_complete(state) - yield 'execution_payload_header', spec.ExecutionPayloadHeader() + yield 'execution_payload_header', execution_payload_header - # yield state yield 'state', state @@ -100,6 +103,7 @@ def test_initialize_post_transition(spec): yield 'deposits', deposits # initialize beacon_state *with* an execution_payload_header + yield 'execution_payload_header', 'meta', True genesis_execution_payload_header = spec.ExecutionPayloadHeader( parent_hash=b'\x30' * 32, coinbase=b'\x42' * 20, @@ -118,12 +122,11 @@ def test_initialize_post_transition(spec): eth1_block_hash, eth1_timestamp, deposits, - genesis_execution_payload_header, + execution_payload_header=genesis_execution_payload_header, ) yield 'execution_payload_header', genesis_execution_payload_header assert spec.is_merge_complete(state) - # yield state yield 'state', state diff --git a/tests/formats/genesis/initialization.md b/tests/formats/genesis/initialization.md index e7edec173d..d0d453e5b6 100644 --- a/tests/formats/genesis/initialization.md +++ b/tests/formats/genesis/initialization.md @@ -17,8 +17,9 @@ eth1_timestamp: int -- An integer. The timestamp of the block, in seconds. A yaml file to help read the deposit count: ```yaml -description: string -- Optional. Description of test case, purely for debugging purposes. -deposits_count: int -- Amount of deposits. +description: string -- Optional. Description of test case, purely for debugging purposes. +deposits_count: int -- Amount of deposits. +execution_payload_header: bool -- `execution_payload_header` field is filled or not. If `true`, `execution_payload_header.ssz_snappy` file exists. ``` ### `deposits_.ssz_snappy` diff --git a/tests/generators/genesis/main.py b/tests/generators/genesis/main.py index 1f36afd4b9..a595db6120 100644 --- a/tests/generators/genesis/main.py +++ b/tests/generators/genesis/main.py @@ -9,7 +9,12 @@ ]} altair_mods = phase_0_mods # we have new unconditional lines in `initialize_beacon_state_from_eth1` and we want to test it - merge_mods = altair_mods + merge_mods = { + **{key: 'eth2spec.test.merge.genesis.test_' + key for key in [ + 'initialization', + ]}, + **altair_mods, + } all_mods = { PHASE0: phase_0_mods, ALTAIR: altair_mods,