fix tests. add new generator

This commit is contained in:
Danny Ryan 2021-10-03 16:16:59 +03:00
parent af262bec07
commit 789eea0060
No known key found for this signature in database
GPG Key ID: 2765A792E42CE07A
3 changed files with 138 additions and 2 deletions

View File

@ -365,7 +365,8 @@ Modifications include:
def initialize_beacon_state_from_eth1(eth1_block_hash: Bytes32,
eth1_timestamp: uint64,
deposits: Sequence[Deposit],
execution_payload_header: ExecutionPayloadHeader) -> BeaconState:
execution_payload_header: ExecutionPayloadHeader=ExecutionPayloadHeader()
) -> BeaconState:
fork = Fork(
previous_version=MERGE_FORK_VERSION, # [Modified in Merge] for testing only
current_version=MERGE_FORK_VERSION, # [Modified in Merge]
@ -403,6 +404,7 @@ def initialize_beacon_state_from_eth1(eth1_block_hash: Bytes32,
state.next_sync_committee = get_next_sync_committee(state)
# [New in Merge] Initialize the execution payload header
# If empty, will initialize a chain that has not yet gone through the Merge transition
state.latest_execution_payload_header = execution_payload_header
return state

View File

@ -0,0 +1,129 @@
from eth2spec.test.context import (
single_phase,
spec_test,
with_presets,
with_merge_and_later,
)
from eth2spec.test.helpers.constants import MINIMAL
from eth2spec.test.helpers.deposits import (
prepare_full_genesis_deposits,
)
def eth1_init_data(eth1_block_hash, eth1_timestamp):
yield 'eth1', {
'eth1_block_hash': '0x' + eth1_block_hash.hex(),
'eth1_timestamp': int(eth1_timestamp),
}
@with_merge_and_later
@spec_test
@single_phase
@with_presets([MINIMAL], reason="too slow")
def test_initialize_pre_transition_no_param(spec):
deposit_count = spec.config.MIN_GENESIS_ACTIVE_VALIDATOR_COUNT
deposits, deposit_root, _ = prepare_full_genesis_deposits(
spec,
spec.MAX_EFFECTIVE_BALANCE,
deposit_count,
signed=True,
)
eth1_block_hash = b'\x12' * 32
eth1_timestamp = spec.config.MIN_GENESIS_TIME
yield from eth1_init_data(eth1_block_hash, eth1_timestamp)
yield 'deposits', deposits
# initialize beacon_state *without* an execution_payload_header
state = spec.initialize_beacon_state_from_eth1(eth1_block_hash, eth1_timestamp, deposits)
assert not spec.is_merge_comp(state)
# yield state
yield 'state', state
@with_merge_and_later
@spec_test
@single_phase
@with_presets([MINIMAL], reason="too slow")
def test_initialize_pre_transition_empty_payload(spec):
deposit_count = spec.config.MIN_GENESIS_ACTIVE_VALIDATOR_COUNT
deposits, deposit_root, _ = prepare_full_genesis_deposits(
spec,
spec.MAX_EFFECTIVE_BALANCE,
deposit_count,
signed=True,
)
eth1_block_hash = b'\x12' * 32
eth1_timestamp = spec.config.MIN_GENESIS_TIME
yield from eth1_init_data(eth1_block_hash, eth1_timestamp)
yield 'deposits', deposits
# initialize beacon_state *without* an execution_payload_header
state = spec.initialize_beacon_state_from_eth1(
eth1_block_hash,
eth1_timestamp,
deposits,
spec.ExecutionPayloadHeader()
)
assert not spec.is_merge_complete(state)
yield 'execution_payload_header', spec.ExecutionPayloadHeader()
# yield state
yield 'state', state
@with_merge_and_later
@spec_test
@single_phase
@with_presets([MINIMAL], reason="too slow")
def test_initialize_post_transition(spec):
deposit_count = spec.config.MIN_GENESIS_ACTIVE_VALIDATOR_COUNT
deposits, deposit_root, _ = prepare_full_genesis_deposits(
spec,
spec.MAX_EFFECTIVE_BALANCE,
deposit_count,
signed=True,
)
eth1_block_hash = b'\x12' * 32
eth1_timestamp = spec.config.MIN_GENESIS_TIME
yield from eth1_init_data(eth1_block_hash, eth1_timestamp)
yield 'deposits', deposits
# initialize beacon_state *with* an execution_payload_header
genesis_execution_payload_header = spec.ExecutionPayloadHeader(
parent_hash=b'\x30' * 32,
coinbase=b'\x42' * 20,
state_root=b'\x20' * 32,
receipt_root=b'\x20' * 32,
logs_bloom=b'\x35' * spec.BYTES_PER_LOGS_BLOOM,
random=b'\x55' * 32,
block_number=0,
gas_limit=30000000,
base_fee_per_gas=b'\x10' * 32,
block_hash=b'\x99' * 32,
transactions_root=spec.Root(b'\x56' * 32),
)
state = spec.initialize_beacon_state_from_eth1(
eth1_block_hash,
eth1_timestamp,
deposits,
genesis_execution_payload_header,
)
yield 'execution_payload_header', genesis_execution_payload_header
assert spec.is_merge_complete(state)
# yield state
yield 'state', state

View File

@ -26,11 +26,16 @@ deposits_count: int -- Amount of deposits.
A series of files, with `<index>` in range `[0, deposits_count)`. Deposits need to be processed in order.
Each file is a SSZ-snappy encoded `Deposit` object.
### `execution_payload_header.ssz_snappy`
*Note*: Param added only for the Merge and subsequent forks.
The execution payload header that state is initialized with. An SSZ-snappy encoded `BeaconState` object.
### `state.ssz_snappy`
The expected genesis state. An SSZ-snappy encoded `BeaconState` object.
## Processing
To process this test, build a genesis state with the provided `eth1_block_hash`, `eth1_timestamp` and `deposits`: