From 6e5268d2c8ac42891895253c637d53c1c3293d8d Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Thu, 4 Aug 2022 07:47:43 -0600 Subject: [PATCH] fix tests --- .../test/bellatrix/sanity/test_blocks.py | 8 +++++-- .../bellatrix/transition/test_transition.py | 4 +++- .../test/helpers/execution_payload.py | 22 ++++++++++--------- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/bellatrix/sanity/test_blocks.py b/tests/core/pyspec/eth2spec/test/bellatrix/sanity/test_blocks.py index 89a706ee5f..ef6bb75a9c 100644 --- a/tests/core/pyspec/eth2spec/test/bellatrix/sanity/test_blocks.py +++ b/tests/core/pyspec/eth2spec/test/bellatrix/sanity/test_blocks.py @@ -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 @@ -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) diff --git a/tests/core/pyspec/eth2spec/test/bellatrix/transition/test_transition.py b/tests/core/pyspec/eth2spec/test/bellatrix/transition/test_transition.py index f1c2955adf..fab74b2d4c 100644 --- a/tests/core/pyspec/eth2spec/test/bellatrix/transition/test_transition.py +++ b/tests/core/pyspec/eth2spec/test/bellatrix/transition/test_transition.py @@ -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 diff --git a/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py b/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py index 24323ceaa8..83162e1c2a 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py +++ b/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py @@ -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 @@ -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) ]