From 087f785ee924edba32a8a7a598ed7133b649ca23 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Wed, 9 Nov 2022 17:15:00 -0500 Subject: [PATCH] PR feedback from @djrtwo --- .../test_process_withdrawals.py | 42 ++++++++++++------- .../test/capella/sanity/test_blocks.py | 6 +-- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/capella/block_processing/test_process_withdrawals.py b/tests/core/pyspec/eth2spec/test/capella/block_processing/test_process_withdrawals.py index fbf0387b4..ae8e5af3c 100644 --- a/tests/core/pyspec/eth2spec/test/capella/block_processing/test_process_withdrawals.py +++ b/tests/core/pyspec/eth2spec/test/capella/block_processing/test_process_withdrawals.py @@ -46,7 +46,8 @@ def verify_post_state(state, spec, expected_withdrawals, assert state.balances[index] > spec.MAX_EFFECTIVE_BALANCE -def run_withdrawals_processing(spec, state, execution_payload, num_expected_withdrawals=None, valid=True): +def run_withdrawals_processing(spec, state, execution_payload, num_expected_withdrawals=None, + fully_withdrawable_indices=None, partial_withdrawals_indices=None, valid=True): """ Run ``process_execution_payload``, yielding: - pre-state ('pre') @@ -79,6 +80,9 @@ def run_withdrawals_processing(spec, state, execution_payload, num_expected_with elif len(expected_withdrawals) > spec.MAX_WITHDRAWALS_PER_PAYLOAD: raise ValueError('len(expected_withdrawals) should not be greater than MAX_WITHDRAWALS_PER_PAYLOAD') + if fully_withdrawable_indices is not None or partial_withdrawals_indices is not None: + verify_post_state(state, spec, expected_withdrawals, fully_withdrawable_indices, partial_withdrawals_indices) + return expected_withdrawals @@ -104,9 +108,10 @@ def test_success_one_full_withdrawal(spec, state): next_slot(spec, state) execution_payload = build_empty_execution_payload(spec, state) - expected_withdrawals = yield from run_withdrawals_processing(spec, state, execution_payload) - - verify_post_state(state, spec, expected_withdrawals, fully_withdrawable_indices, partial_withdrawals_indices) + yield from run_withdrawals_processing( + spec, state, execution_payload, + fully_withdrawable_indices=fully_withdrawable_indices, + partial_withdrawals_indices=partial_withdrawals_indices) @with_capella_and_later @@ -122,9 +127,11 @@ def test_success_one_partial_withdrawal(spec, state): next_slot(spec, state) execution_payload = build_empty_execution_payload(spec, state) - expected_withdrawals = yield from run_withdrawals_processing(spec, state, execution_payload) - - verify_post_state(state, spec, expected_withdrawals, fully_withdrawable_indices, partial_withdrawals_indices) + yield from run_withdrawals_processing( + spec, state, execution_payload, + fully_withdrawable_indices=fully_withdrawable_indices, + partial_withdrawals_indices=partial_withdrawals_indices + ) @with_capella_and_later @@ -139,9 +146,10 @@ def test_success_max_per_slot(spec, state): next_slot(spec, state) execution_payload = build_empty_execution_payload(spec, state) - expected_withdrawals = yield from run_withdrawals_processing(spec, state, execution_payload) - - verify_post_state(state, spec, expected_withdrawals, fully_withdrawable_indices, partial_withdrawals_indices) + yield from run_withdrawals_processing( + spec, state, execution_payload, + fully_withdrawable_indices=fully_withdrawable_indices, + partial_withdrawals_indices=partial_withdrawals_indices) @with_capella_and_later @@ -153,9 +161,10 @@ def test_success_all_fully_withdrawable(spec, state): next_slot(spec, state) execution_payload = build_empty_execution_payload(spec, state) - expected_withdrawals = yield from run_withdrawals_processing(spec, state, execution_payload) - - verify_post_state(state, spec, expected_withdrawals, fully_withdrawable_indices, partial_withdrawals_indices) + yield from run_withdrawals_processing( + spec, state, execution_payload, + fully_withdrawable_indices=fully_withdrawable_indices, + partial_withdrawals_indices=partial_withdrawals_indices) @with_capella_and_later @@ -167,9 +176,10 @@ def test_success_all_partially_withdrawable(spec, state): next_slot(spec, state) execution_payload = build_empty_execution_payload(spec, state) - expected_withdrawals = yield from run_withdrawals_processing(spec, state, execution_payload) - - verify_post_state(state, spec, expected_withdrawals, fully_withdrawable_indices, partial_withdrawals_indices) + yield from run_withdrawals_processing( + spec, state, execution_payload, + fully_withdrawable_indices=fully_withdrawable_indices, + partial_withdrawals_indices=partial_withdrawals_indices) # diff --git a/tests/core/pyspec/eth2spec/test/capella/sanity/test_blocks.py b/tests/core/pyspec/eth2spec/test/capella/sanity/test_blocks.py index 0636dd58f..f3ad843b1 100644 --- a/tests/core/pyspec/eth2spec/test/capella/sanity/test_blocks.py +++ b/tests/core/pyspec/eth2spec/test/capella/sanity/test_blocks.py @@ -141,7 +141,7 @@ def test_exit_and_bls_change(spec, state): assert spec.is_fully_withdrawable_validator(validator, balance, validator.withdrawable_epoch) -def _valid_withdrawal(spec, state): +def _perform_valid_withdrawal(spec, state): fully_withdrawable_indices, partial_withdrawals_indices = prepare_expected_withdrawals( spec, state, num_partial_withdrawals=spec.MAX_WITHDRAWALS_PER_PAYLOAD * 4, num_full_withdrawals=spec.MAX_WITHDRAWALS_PER_PAYLOAD * 4) @@ -173,7 +173,7 @@ def _valid_withdrawal(spec, state): @with_capella_and_later @spec_state_test def test_withdrawal_success_two_blocks(spec, state): - pre_state, signed_block_1, pre_next_withdrawal_index = _valid_withdrawal(spec, state) + pre_state, signed_block_1, pre_next_withdrawal_index = _perform_valid_withdrawal(spec, state) yield 'pre', pre_state @@ -190,7 +190,7 @@ def test_withdrawal_success_two_blocks(spec, state): @with_capella_and_later @spec_state_test def test_withdrawal_fail_second_block_payload_isnt_compatible(spec, state): - _valid_withdrawal(spec, state) + _perform_valid_withdrawal(spec, state) # Block 2 block = build_empty_block_for_next_slot(spec, state)