added some simple tests

This commit is contained in:
james-prysm 2024-07-01 15:26:56 -05:00
parent 8f6b1e0ba9
commit e1a4d8b60e
2 changed files with 133 additions and 92 deletions

View File

@ -8,97 +8,99 @@
<!-- START doctoc generated TOC please keep comment here to allow auto update --> <!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
- [Introduction](#introduction) - [Electra -- The Beacon Chain](#electra----the-beacon-chain)
- [Constants](#constants) - [Table of contents](#table-of-contents)
- [Misc](#misc) - [Introduction](#introduction)
- [Withdrawal prefixes](#withdrawal-prefixes) - [Constants](#constants)
- [Domains](#domains) - [Misc](#misc)
- [Preset](#preset) - [Withdrawal prefixes](#withdrawal-prefixes)
- [Gwei values](#gwei-values) - [Domains](#domains)
- [Rewards and penalties](#rewards-and-penalties) - [Preset](#preset)
- [State list lengths](#state-list-lengths) - [Gwei values](#gwei-values)
- [Max operations per block](#max-operations-per-block) - [Rewards and penalties](#rewards-and-penalties)
- [Execution](#execution) - [State list lengths](#state-list-lengths)
- [Withdrawals processing](#withdrawals-processing) - [Max operations per block](#max-operations-per-block)
- [Pending deposits processing](#pending-deposits-processing) - [Execution](#execution)
- [Configuration](#configuration) - [Withdrawals processing](#withdrawals-processing)
- [Validator cycle](#validator-cycle) - [Pending deposits processing](#pending-deposits-processing)
- [Containers](#containers) - [Configuration](#configuration)
- [New containers](#new-containers) - [Validator cycle](#validator-cycle)
- [`DepositRequest`](#depositrequest) - [Containers](#containers)
- [`PendingDeposit`](#pendingdeposit) - [New containers](#new-containers)
- [`PendingPartialWithdrawal`](#pendingpartialwithdrawal) - [`DepositRequest`](#depositrequest)
- [`WithdrawalRequest`](#withdrawalrequest) - [`PendingDeposit`](#pendingdeposit)
- [`ConsolidationRequest`](#consolidationrequest) - [`PendingPartialWithdrawal`](#pendingpartialwithdrawal)
- [`PendingConsolidation`](#pendingconsolidation) - [`WithdrawalRequest`](#withdrawalrequest)
- [Modified Containers](#modified-containers) - [`ConsolidationRequest`](#consolidationrequest)
- [`AttesterSlashing`](#attesterslashing) - [`PendingConsolidation`](#pendingconsolidation)
- [Extended Containers](#extended-containers) - [Modified Containers](#modified-containers)
- [`Attestation`](#attestation) - [`AttesterSlashing`](#attesterslashing)
- [`IndexedAttestation`](#indexedattestation) - [Extended Containers](#extended-containers)
- [`BeaconBlockBody`](#beaconblockbody) - [`Attestation`](#attestation)
- [`ExecutionPayload`](#executionpayload) - [`IndexedAttestation`](#indexedattestation)
- [`ExecutionPayloadHeader`](#executionpayloadheader) - [`BeaconBlockBody`](#beaconblockbody)
- [`BeaconState`](#beaconstate) - [`ExecutionPayload`](#executionpayload)
- [Helper functions](#helper-functions) - [`ExecutionPayloadHeader`](#executionpayloadheader)
- [Predicates](#predicates) - [`BeaconState`](#beaconstate)
- [Updated `compute_proposer_index`](#updated-compute_proposer_index) - [Helper functions](#helper-functions)
- [Updated `is_eligible_for_activation_queue`](#updated-is_eligible_for_activation_queue) - [Predicates](#predicates)
- [New `is_compounding_withdrawal_credential`](#new-is_compounding_withdrawal_credential) - [Updated `compute_proposer_index`](#updated-compute_proposer_index)
- [New `has_compounding_withdrawal_credential`](#new-has_compounding_withdrawal_credential) - [Updated `is_eligible_for_activation_queue`](#updated-is_eligible_for_activation_queue)
- [New `has_execution_withdrawal_credential`](#new-has_execution_withdrawal_credential) - [New `is_compounding_withdrawal_credential`](#new-is_compounding_withdrawal_credential)
- [Updated `is_fully_withdrawable_validator`](#updated-is_fully_withdrawable_validator) - [New `has_compounding_withdrawal_credential`](#new-has_compounding_withdrawal_credential)
- [Updated `is_partially_withdrawable_validator`](#updated-is_partially_withdrawable_validator) - [New `has_execution_withdrawal_credential`](#new-has_execution_withdrawal_credential)
- [Misc](#misc-1) - [Updated `is_fully_withdrawable_validator`](#updated-is_fully_withdrawable_validator)
- [`get_committee_indices`](#get_committee_indices) - [Updated `is_partially_withdrawable_validator`](#updated-is_partially_withdrawable_validator)
- [`get_validator_max_effective_balance`](#get_validator_max_effective_balance) - [Misc](#misc-1)
- [Beacon state accessors](#beacon-state-accessors) - [`get_committee_indices`](#get_committee_indices)
- [New `get_balance_churn_limit`](#new-get_balance_churn_limit) - [`get_validator_max_effective_balance`](#get_validator_max_effective_balance)
- [New `get_activation_exit_churn_limit`](#new-get_activation_exit_churn_limit) - [Beacon state accessors](#beacon-state-accessors)
- [New `get_consolidation_churn_limit`](#new-get_consolidation_churn_limit) - [New `get_balance_churn_limit`](#new-get_balance_churn_limit)
- [New `get_active_balance`](#new-get_active_balance) - [New `get_activation_exit_churn_limit`](#new-get_activation_exit_churn_limit)
- [New `get_pending_balance_to_withdraw`](#new-get_pending_balance_to_withdraw) - [New `get_consolidation_churn_limit`](#new-get_consolidation_churn_limit)
- [Modified `get_attesting_indices`](#modified-get_attesting_indices) - [New `get_active_balance`](#new-get_active_balance)
- [New `get_activation_churn_consumption`](#new-get_activation_churn_consumption) - [New `get_pending_balance_to_withdraw`](#new-get_pending_balance_to_withdraw)
- [Modified `get_next_sync_committee_indices`](#modified-get_next_sync_committee_indices) - [Modified `get_attesting_indices`](#modified-get_attesting_indices)
- [Beacon state mutators](#beacon-state-mutators) - [New `get_activation_churn_consumption`](#new-get_activation_churn_consumption)
- [Updated `initiate_validator_exit`](#updated--initiate_validator_exit) - [Modified `get_next_sync_committee_indices`](#modified-get_next_sync_committee_indices)
- [New `switch_to_compounding_validator`](#new-switch_to_compounding_validator) - [Beacon state mutators](#beacon-state-mutators)
- [New `queue_excess_active_balance`](#new-queue_excess_active_balance) - [Updated `initiate_validator_exit`](#updated--initiate_validator_exit)
- [New `queue_entire_balance_and_reset_validator`](#new-queue_entire_balance_and_reset_validator) - [New `switch_to_compounding_validator`](#new-switch_to_compounding_validator)
- [New `compute_exit_epoch_and_update_churn`](#new-compute_exit_epoch_and_update_churn) - [New `queue_excess_active_balance`](#new-queue_excess_active_balance)
- [New `compute_consolidation_epoch_and_update_churn`](#new-compute_consolidation_epoch_and_update_churn) - [New `queue_entire_balance_and_reset_validator`](#new-queue_entire_balance_and_reset_validator)
- [Updated `slash_validator`](#updated-slash_validator) - [New `compute_exit_epoch_and_update_churn`](#new-compute_exit_epoch_and_update_churn)
- [Beacon chain state transition function](#beacon-chain-state-transition-function) - [New `compute_consolidation_epoch_and_update_churn`](#new-compute_consolidation_epoch_and_update_churn)
- [Epoch processing](#epoch-processing) - [Updated `slash_validator`](#updated-slash_validator)
- [Updated `process_epoch`](#updated-process_epoch) - [Beacon chain state transition function](#beacon-chain-state-transition-function)
- [Updated `process_registry_updates`](#updated--process_registry_updates) - [Epoch processing](#epoch-processing)
- [New `apply_pending_deposit`](#new-apply_pending_deposit) - [Updated `process_epoch`](#updated-process_epoch)
- [New `process_pending_deposits`](#new-process_pending_deposits) - [Updated `process_registry_updates`](#updated--process_registry_updates)
- [New `process_pending_consolidations`](#new-process_pending_consolidations) - [New `apply_pending_deposit`](#new-apply_pending_deposit)
- [Updated `process_effective_balance_updates`](#updated-process_effective_balance_updates) - [New `process_pending_deposits`](#new-process_pending_deposits)
- [Block processing](#block-processing) - [New `process_pending_consolidations`](#new-process_pending_consolidations)
- [Withdrawals](#withdrawals) - [Updated `process_effective_balance_updates`](#updated-process_effective_balance_updates)
- [Updated `get_expected_withdrawals`](#updated-get_expected_withdrawals) - [Block processing](#block-processing)
- [Updated `process_withdrawals`](#updated-process_withdrawals) - [Withdrawals](#withdrawals)
- [Execution payload](#execution-payload) - [Updated `get_expected_withdrawals`](#updated-get_expected_withdrawals)
- [Modified `process_execution_payload`](#modified-process_execution_payload) - [Updated `process_withdrawals`](#updated-process_withdrawals)
- [Operations](#operations) - [Execution payload](#execution-payload)
- [Modified `process_operations`](#modified-process_operations) - [Modified `process_execution_payload`](#modified-process_execution_payload)
- [Attestations](#attestations) - [Operations](#operations)
- [Modified `process_attestation`](#modified-process_attestation) - [Modified `process_operations`](#modified-process_operations)
- [Deposits](#deposits) - [Attestations](#attestations)
- [Updated `apply_deposit`](#updated--apply_deposit) - [Modified `process_attestation`](#modified-process_attestation)
- [New `is_valid_deposit_signature`](#new-is_valid_deposit_signature) - [Deposits](#deposits)
- [Voluntary exits](#voluntary-exits) - [Updated `apply_deposit`](#updated--apply_deposit)
- [Updated `process_voluntary_exit`](#updated-process_voluntary_exit) - [New `is_valid_deposit_signature`](#new-is_valid_deposit_signature)
- [Execution layer withdrawal requests](#execution-layer-withdrawal-requests) - [Voluntary exits](#voluntary-exits)
- [New `process_withdrawal_request`](#new-process_withdrawal_request) - [Updated `process_voluntary_exit`](#updated-process_voluntary_exit)
- [Deposit requests](#deposit-requests) - [Execution layer withdrawal requests](#execution-layer-withdrawal-requests)
- [New `process_deposit_request`](#new-process_deposit_request) - [New `process_withdrawal_request`](#new-process_withdrawal_request)
- [Execution layer consolidation requests](#execution-layer-consolidation-requests) - [Deposit requests](#deposit-requests)
- [New `process_consolidation_request`](#new-process_consolidation_request) - [New `process_deposit_request`](#new-process_deposit_request)
- [Testing](#testing) - [Execution layer consolidation requests](#execution-layer-consolidation-requests)
- [New `process_consolidation_request`](#new-process_consolidation_request)
- [Testing](#testing)
<!-- END doctoc generated TOC please keep comment here to allow auto update --> <!-- END doctoc generated TOC please keep comment here to allow auto update -->
<!-- /TOC --> <!-- /TOC -->
@ -954,7 +956,7 @@ def process_pending_deposits(state: BeaconState) -> None:
break break
# Check if number of processed deposits has not reached the limit, otherwise, stop processing. # Check if number of processed deposits has not reached the limit, otherwise, stop processing.
if next_deposit_index > MAX_PENDING_DEPOSITS_PER_EPOCH_PROCESSING: if next_deposit_index > MAX_PENDING_DEPOSITS_PER_EPOCH_PROCESSING-1:
break break
# Check if deposit fits in the churn, otherwise, do no more deposit processing in this epoch. # Check if deposit fits in the churn, otherwise, do no more deposit processing in this epoch.

View File

@ -279,3 +279,42 @@ def test_processing_deposit_of_withdrawable_validator_does_not_get_churned(spec,
# First deposit does not consume any. # First deposit does not consume any.
assert state.deposit_balance_to_consume == spec.get_activation_exit_churn_limit(state) assert state.deposit_balance_to_consume == spec.get_activation_exit_churn_limit(state)
assert state.pending_deposits == [build_pending_deposit_top_up(spec, state, validator_index=1, amount=amount)] assert state.pending_deposits == [build_pending_deposit_top_up(spec, state, validator_index=1, amount=amount)]
@with_electra_and_later
@spec_state_test
def test_pending_deposit_over_max(spec, state):
# pick an amount that adds to less than churn limit
amount = 100
overmax = spec.MAX_PENDING_DEPOSITS_PER_EPOCH_PROCESSING + 1
for i in range(overmax):
state.pending_deposits.append(spec.PendingDeposit(
pubkey=state.validators[i].pubkey,
withdrawal_credentials=state.validators[i].withdrawal_credentials,
amount=amount,
slot=state.slot
))
assert len(state.pending_deposits) == overmax,"pending deposits is not over max"
yield from run_process_pending_deposits(spec, state)
# the remaining deposit over MAX_PENDING_DEPOSITS_PER_EPOCH_PROCESSING should remain in pending_deposits
assert len(state.pending_deposits) == 1
@with_electra_and_later
@spec_state_test
def test_pending_deposit_deposit_not_finalized(spec, state):
amount = spec.MIN_ACTIVATION_BALANCE
slot=spec.compute_start_slot_at_epoch(state.finalized_checkpoint.epoch)
# deposit is not finalized yet, so it is postponed
state.pending_deposits.append(spec.PendingDeposit(
pubkey=state.validators[0].pubkey,
withdrawal_credentials=state.validators[0].withdrawal_credentials,
amount=amount,
slot=slot,
))
# set deposit_balance_to_consume to some initial amount to see its removal later on in the test
state.deposit_balance_to_consume = amount
yield from run_process_pending_deposits(spec, state)
# deposit_balance_to_consume was reset to 0
assert state.deposit_balance_to_consume == 0
# deposit was postponed and not processed
assert len(state.pending_deposits) == 1