pr feedback from @hwwhww
This commit is contained in:
parent
7e360240f9
commit
3d785dad7a
|
@ -1,6 +1,6 @@
|
||||||
import os
|
|
||||||
from random import Random
|
from random import Random
|
||||||
|
|
||||||
|
from eth2spec.debug.random_value import get_random_bytes_list
|
||||||
from eth2spec.test.helpers.execution_payload import (
|
from eth2spec.test.helpers.execution_payload import (
|
||||||
build_empty_execution_payload,
|
build_empty_execution_payload,
|
||||||
get_execution_payload_header,
|
get_execution_payload_header,
|
||||||
|
@ -60,7 +60,6 @@ def run_success_test(spec, state):
|
||||||
@spec_state_test
|
@spec_state_test
|
||||||
def test_success_first_payload(spec, state):
|
def test_success_first_payload(spec, state):
|
||||||
state = build_state_with_incomplete_transition(spec, state)
|
state = build_state_with_incomplete_transition(spec, state)
|
||||||
assert not spec.is_merge_transition_complete(state)
|
|
||||||
|
|
||||||
yield from run_success_test(spec, state)
|
yield from run_success_test(spec, state)
|
||||||
|
|
||||||
|
@ -69,7 +68,6 @@ def test_success_first_payload(spec, state):
|
||||||
@spec_state_test
|
@spec_state_test
|
||||||
def test_success_regular_payload(spec, state):
|
def test_success_regular_payload(spec, state):
|
||||||
state = build_state_with_complete_transition(spec, state)
|
state = build_state_with_complete_transition(spec, state)
|
||||||
assert spec.is_merge_transition_complete(state)
|
|
||||||
|
|
||||||
yield from run_success_test(spec, state)
|
yield from run_success_test(spec, state)
|
||||||
|
|
||||||
|
@ -311,22 +309,25 @@ def test_zero_length_transaction_regular_payload(spec, state):
|
||||||
|
|
||||||
def build_randomized_execution_payload(spec, state, rng):
|
def build_randomized_execution_payload(spec, state, rng):
|
||||||
execution_payload = build_empty_execution_payload(spec, state)
|
execution_payload = build_empty_execution_payload(spec, state)
|
||||||
execution_payload.fee_recipient = spec.ExecutionAddress(os.urandom(20))
|
execution_payload.fee_recipient = spec.ExecutionAddress(get_random_bytes_list(rng, 20))
|
||||||
execution_payload.state_root = spec.Bytes32(os.urandom(32))
|
execution_payload.state_root = spec.Bytes32(get_random_bytes_list(rng, 32))
|
||||||
execution_payload.receipts_root = spec.Bytes32(os.urandom(32))
|
execution_payload.receipts_root = spec.Bytes32(get_random_bytes_list(rng, 32))
|
||||||
execution_payload.logs_bloom = spec.ByteVector[spec.BYTES_PER_LOGS_BLOOM](os.urandom(spec.BYTES_PER_LOGS_BLOOM))
|
execution_payload.logs_bloom = spec.ByteVector[spec.BYTES_PER_LOGS_BLOOM](
|
||||||
|
get_random_bytes_list(rng, spec.BYTES_PER_LOGS_BLOOM)
|
||||||
|
)
|
||||||
execution_payload.block_number = rng.randint(0, 10e10)
|
execution_payload.block_number = rng.randint(0, 10e10)
|
||||||
execution_payload.gas_limit = rng.randint(0, 10e10)
|
execution_payload.gas_limit = rng.randint(0, 10e10)
|
||||||
execution_payload.gas_used = rng.randint(0, 10e10)
|
execution_payload.gas_used = rng.randint(0, 10e10)
|
||||||
|
extra_data_length = rng.randint(0, spec.MAX_EXTRA_DATA_BYTES)
|
||||||
execution_payload.extra_data = spec.ByteList[spec.MAX_EXTRA_DATA_BYTES](
|
execution_payload.extra_data = spec.ByteList[spec.MAX_EXTRA_DATA_BYTES](
|
||||||
os.urandom(rng.randint(0, spec.MAX_EXTRA_DATA_BYTES))
|
get_random_bytes_list(rng, extra_data_length)
|
||||||
)
|
)
|
||||||
execution_payload.base_fee_per_gas = rng.randint(0, 2**256 - 1)
|
execution_payload.base_fee_per_gas = rng.randint(0, 2**256 - 1)
|
||||||
execution_payload.block_hash = spec.Hash32(os.urandom(32))
|
execution_payload.block_hash = spec.Hash32(get_random_bytes_list(rng, 32))
|
||||||
|
|
||||||
num_transactions = rng.randint(0, 100)
|
num_transactions = rng.randint(0, 100)
|
||||||
execution_payload.transactions = [
|
execution_payload.transactions = [
|
||||||
spec.Transaction(os.urandom(rng.randint(0, 1000)))
|
spec.Transaction(get_random_bytes_list(rng, rng.randint(0, 1000)))
|
||||||
for _ in range(num_transactions)
|
for _ in range(num_transactions)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -61,14 +61,20 @@ def get_execution_payload_header(spec, execution_payload):
|
||||||
|
|
||||||
|
|
||||||
def build_state_with_incomplete_transition(spec, state):
|
def build_state_with_incomplete_transition(spec, state):
|
||||||
return build_state_with_execution_payload_header(spec, state, spec.ExecutionPayloadHeader())
|
state = build_state_with_execution_payload_header(spec, state, spec.ExecutionPayloadHeader())
|
||||||
|
assert not spec.is_merge_transition_complete(state)
|
||||||
|
|
||||||
|
return state
|
||||||
|
|
||||||
|
|
||||||
def build_state_with_complete_transition(spec, state):
|
def build_state_with_complete_transition(spec, state):
|
||||||
pre_state_payload = build_empty_execution_payload(spec, state)
|
pre_state_payload = build_empty_execution_payload(spec, state)
|
||||||
payload_header = get_execution_payload_header(spec, pre_state_payload)
|
payload_header = get_execution_payload_header(spec, pre_state_payload)
|
||||||
|
|
||||||
return build_state_with_execution_payload_header(spec, state, payload_header)
|
state = build_state_with_execution_payload_header(spec, state, payload_header)
|
||||||
|
assert spec.is_merge_transition_complete(state)
|
||||||
|
|
||||||
|
return state
|
||||||
|
|
||||||
|
|
||||||
def build_state_with_execution_payload_header(spec, state, execution_payload_header):
|
def build_state_with_execution_payload_header(spec, state, execution_payload_header):
|
||||||
|
|
Loading…
Reference in New Issue