Polishing merge tests

This commit is contained in:
Dmitrii Shmatko
2021-09-23 23:10:29 +03:00
parent 8ae078a4f5
commit 1ecfc4016c
10 changed files with 47 additions and 78 deletions

View File

@@ -1,2 +1,6 @@
class SkippedTest(Exception):
...
class BlockNotFoundException(Exception):
...

View File

@@ -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)
)

View File

@@ -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)

View File

@@ -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)
)

View File

@@ -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)

View File

@@ -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
)

View File

@@ -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:

View File

@@ -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()

View File

@@ -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_<number>.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`.