From f5dab5b6663afe61f669897a0128a4ab8def56b7 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Thu, 24 Feb 2022 15:06:31 -0700 Subject: [PATCH] fix fully withdrawal tests --- specs/capella/beacon-chain.md | 20 +++++++++--------- .../test_process_full_withdrawals.py} | 21 +++++++++++-------- 2 files changed, 22 insertions(+), 19 deletions(-) rename tests/core/pyspec/eth2spec/test/{altair/epoch_processing/test_process_withdrawals.py => capella/epoch_processing/test_process_full_withdrawals.py} (71%) diff --git a/specs/capella/beacon-chain.md b/specs/capella/beacon-chain.md index 8d5041970..a8f509a94 100644 --- a/specs/capella/beacon-chain.md +++ b/specs/capella/beacon-chain.md @@ -117,9 +117,9 @@ class ExecutionPayload(Container): parent_hash: Hash32 fee_recipient: ExecutionAddress # 'beneficiary' in the yellow paper state_root: Bytes32 - receipt_root: Bytes32 # 'receipts root' in the yellow paper + receipts_root: Bytes32 logs_bloom: ByteVector[BYTES_PER_LOGS_BLOOM] - random: Bytes32 # 'difficulty' in the yellow paper + prev_randao: Bytes32 # 'difficulty' in the yellow paper block_number: uint64 # 'number' in the yellow paper gas_limit: uint64 gas_used: uint64 @@ -140,9 +140,9 @@ class ExecutionPayloadHeader(Container): parent_hash: Hash32 fee_recipient: ExecutionAddress state_root: Bytes32 - receipt_root: Bytes32 + receipts_root: Bytes32 logs_bloom: ByteVector[BYTES_PER_LOGS_BLOOM] - random: Bytes32 + prev_randao: Bytes32 block_number: uint64 gas_limit: uint64 gas_used: uint64 @@ -165,7 +165,7 @@ followed by an SSZ encoding of the `WithdrawalTransaction` container comprising ```python class WithdrawalTransaction(Container): address: ExecutionAddress - value: Gwei + amount: Gwei ``` ## Helpers @@ -188,12 +188,12 @@ def withdraw(state: BeaconState, index: ValidatorIndex, amount: Gwei) -> None: ### Predicates -#### `is_withdrawable_validator` +#### `is_fully_withdrawable_validator` ```python -def is_withdrawable_validator(validator: Validator, epoch: Epoch) -> bool: +def is_fully_withdrawable_validator(validator: Validator, epoch: Epoch) -> bool: """ - Check if ``validator`` is withdrawable. + Check if ``validator`` is fully withdrawable. """ is_eth1_withdrawal_prefix = validator.withdrawal_credentials[0:1] == ETH1_ADDRESS_WITHDRAWAL_PREFIX return is_eth1_withdrawal_prefix and validator.withdrawable_epoch <= epoch < validator.withdrawn_epoch @@ -228,7 +228,7 @@ def process_epoch(state: BeaconState) -> None: def process_full_withdrawals(state: BeaconState) -> None: current_epoch = get_current_epoch(state) for index, validator in enumerate(state.validators): - if is_withdrawable_validator(validator, current_epoch): + if is_fully_withdrawable_validator(validator, current_epoch): # TODO, consider the zero-balance case withdraw(state, ValidatorIndex(index), state.balances[index]) validator.withdrawn_epoch = current_epoch @@ -297,6 +297,6 @@ def process_execution_payload(state: BeaconState, payload: ExecutionPayload, exe base_fee_per_gas=payload.base_fee_per_gas, block_hash=payload.block_hash, transactions_root=hash_tree_root(payload.transactions), - withdrawal_transactions=hash_tree_root(payload.withdrawal_transactions), + withdrawal_transactions_root=hash_tree_root(payload.withdrawal_transactions), ) ``` diff --git a/tests/core/pyspec/eth2spec/test/altair/epoch_processing/test_process_withdrawals.py b/tests/core/pyspec/eth2spec/test/capella/epoch_processing/test_process_full_withdrawals.py similarity index 71% rename from tests/core/pyspec/eth2spec/test/altair/epoch_processing/test_process_withdrawals.py rename to tests/core/pyspec/eth2spec/test/capella/epoch_processing/test_process_full_withdrawals.py index f1f8e084d..ef7b7c8ac 100644 --- a/tests/core/pyspec/eth2spec/test/altair/epoch_processing/test_process_withdrawals.py +++ b/tests/core/pyspec/eth2spec/test/capella/epoch_processing/test_process_full_withdrawals.py @@ -13,31 +13,34 @@ def set_validator_withdrawable(spec, state, index, withdrawable_epoch=None): validator.withdrawable_epoch = withdrawable_epoch validator.withdrawal_credentials = spec.ETH1_ADDRESS_WITHDRAWAL_PREFIX + validator.withdrawal_credentials[1:] - assert spec.is_withdrawable_validator(validator, withdrawable_epoch) + assert spec.is_fully_withdrawable_validator(validator, withdrawable_epoch) -def run_process_withdrawals(spec, state, num_expected_withdrawals=None): +def run_process_full_withdrawals(spec, state, num_expected_withdrawals=None): + pre_withdrawal_receipts = state.withdrawal_receipts to_be_withdrawn_indices = [ index for index, validator in enumerate(state.validators) - if spec.is_withdrawable_validator(validator, spec.get_current_epoch(state)) + if spec.is_fully_withdrawable_validator(validator, spec.get_current_epoch(state)) ] if num_expected_withdrawals is not None: assert len(to_be_withdrawn_indices) == num_expected_withdrawals - yield from run_epoch_processing_with(spec, state, 'process_withdrawals') + yield from run_epoch_processing_with(spec, state, 'process_full_withdrawals') for index in to_be_withdrawn_indices: validator = state.validators[index] assert validator.withdrawn_epoch == spec.get_current_epoch(state) assert state.balances[index] == 0 + assert len(state.withdrawal_receipts) == len(pre_withdrawal_receipts) + num_expected_withdrawals + @with_capella_and_later @spec_state_test def test_no_withdrawals(spec, state): pre_validators = state.validators.copy() - yield from run_process_withdrawals(spec, state, 0) + yield from run_process_full_withdrawals(spec, state, 0) assert pre_validators == state.validators @@ -51,7 +54,7 @@ def test_no_withdrawals_but_some_next_epoch(spec, state): for index in range(3): set_validator_withdrawable(spec, state, index, current_epoch + 1) - yield from run_process_withdrawals(spec, state, 0) + yield from run_process_full_withdrawals(spec, state, 0) @with_capella_and_later @@ -60,7 +63,7 @@ def test_single_withdrawal(spec, state): # Make one validator withdrawable set_validator_withdrawable(spec, state, 0) - yield from run_process_withdrawals(spec, state, 1) + yield from run_process_full_withdrawals(spec, state, 1) @with_capella_and_later @@ -70,7 +73,7 @@ def test_multi_withdrawal(spec, state): for index in range(3): set_validator_withdrawable(spec, state, index) - yield from run_process_withdrawals(spec, state, 3) + yield from run_process_full_withdrawals(spec, state, 3) @with_capella_and_later @@ -80,4 +83,4 @@ def test_all_withdrawal(spec, state): for index in range(len(state.validators)): set_validator_withdrawable(spec, state, index) - yield from run_process_withdrawals(spec, state, len(state.validators)) + yield from run_process_full_withdrawals(spec, state, len(state.validators))