Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
djrtwo committed Aug 8, 2022
1 parent 3dc29dc commit 6e5268d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from random import Random
from eth2spec.test.helpers.state import (
state_transition_and_sign_block
state_transition_and_sign_block,
next_slot,
)
from eth2spec.test.helpers.block import (
build_empty_block_for_next_slot
Expand Down Expand Up @@ -32,7 +34,9 @@ def test_empty_block_transition_randomized_payload(spec, state):
yield 'pre', state

block = build_empty_block_for_next_slot(spec, state)
block.body.execution_payload = build_randomized_execution_payload(spec, state)
next_slot_state = state.copy()
next_slot(spec, next_slot_state)
block.body.execution_payload = build_randomized_execution_payload(spec, next_slot_state, rng=Random(34433))

signed_block = state_transition_and_sign_block(spec, state, block)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ def test_sample_transition(state, fork_epoch, spec, post_spec, pre_tag, post_tag


@with_fork_metas([
ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=2) for pre, post in AFTER_BELLATRIX_PRE_POST_FORKS
ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=8) for pre, post in AFTER_BELLATRIX_PRE_POST_FORKS
])
def test_transition_randomized_state(state, fork_epoch, spec, post_spec, pre_tag, post_tag):
randomize_state(spec, state)
for validator in state.validators:
validator.slashed = False
transition_until_fork(spec, state, fork_epoch)

# check pre state
Expand Down
22 changes: 12 additions & 10 deletions tests/core/pyspec/eth2spec/test/helpers/execution_payload.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
from random import Random
from eth2spec.debug.random_value import get_random_bytes_list
from eth2spec.test.context import is_post_capella


Expand Down Expand Up @@ -40,24 +39,27 @@ def build_empty_execution_payload(spec, state, randao_mix=None):
return payload


def build_randomized_execution_payload(spec, state, rng=Random(4444)):
def build_randomized_execution_payload(spec, state, rng):
execution_payload = build_empty_execution_payload(spec, state)
execution_payload.fee_recipient = spec.ExecutionAddress(os.urandom(20))
execution_payload.state_root = spec.Bytes32(os.urandom(32))
execution_payload.receipts_root = spec.Bytes32(os.urandom(32))
execution_payload.logs_bloom = spec.ByteVector[spec.BYTES_PER_LOGS_BLOOM](os.urandom(spec.BYTES_PER_LOGS_BLOOM))
execution_payload.fee_recipient = spec.ExecutionAddress(get_random_bytes_list(rng, 20))
execution_payload.state_root = spec.Bytes32(get_random_bytes_list(rng, 32))
execution_payload.receipts_root = spec.Bytes32(get_random_bytes_list(rng, 32))
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.gas_limit = 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](
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.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)
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)
]

Expand Down

0 comments on commit 6e5268d

Please sign in to comment.