added some simple tests
This commit is contained in:
parent
8f6b1e0ba9
commit
e1a4d8b60e
|
@ -8,12 +8,14 @@
|
||||||
<!-- 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)
|
||||||
|
- [Introduction](#introduction)
|
||||||
|
- [Constants](#constants)
|
||||||
- [Misc](#misc)
|
- [Misc](#misc)
|
||||||
- [Withdrawal prefixes](#withdrawal-prefixes)
|
- [Withdrawal prefixes](#withdrawal-prefixes)
|
||||||
- [Domains](#domains)
|
- [Domains](#domains)
|
||||||
- [Preset](#preset)
|
- [Preset](#preset)
|
||||||
- [Gwei values](#gwei-values)
|
- [Gwei values](#gwei-values)
|
||||||
- [Rewards and penalties](#rewards-and-penalties)
|
- [Rewards and penalties](#rewards-and-penalties)
|
||||||
- [State list lengths](#state-list-lengths)
|
- [State list lengths](#state-list-lengths)
|
||||||
|
@ -21,9 +23,9 @@
|
||||||
- [Execution](#execution)
|
- [Execution](#execution)
|
||||||
- [Withdrawals processing](#withdrawals-processing)
|
- [Withdrawals processing](#withdrawals-processing)
|
||||||
- [Pending deposits processing](#pending-deposits-processing)
|
- [Pending deposits processing](#pending-deposits-processing)
|
||||||
- [Configuration](#configuration)
|
- [Configuration](#configuration)
|
||||||
- [Validator cycle](#validator-cycle)
|
- [Validator cycle](#validator-cycle)
|
||||||
- [Containers](#containers)
|
- [Containers](#containers)
|
||||||
- [New containers](#new-containers)
|
- [New containers](#new-containers)
|
||||||
- [`DepositRequest`](#depositrequest)
|
- [`DepositRequest`](#depositrequest)
|
||||||
- [`PendingDeposit`](#pendingdeposit)
|
- [`PendingDeposit`](#pendingdeposit)
|
||||||
|
@ -40,7 +42,7 @@
|
||||||
- [`ExecutionPayload`](#executionpayload)
|
- [`ExecutionPayload`](#executionpayload)
|
||||||
- [`ExecutionPayloadHeader`](#executionpayloadheader)
|
- [`ExecutionPayloadHeader`](#executionpayloadheader)
|
||||||
- [`BeaconState`](#beaconstate)
|
- [`BeaconState`](#beaconstate)
|
||||||
- [Helper functions](#helper-functions)
|
- [Helper functions](#helper-functions)
|
||||||
- [Predicates](#predicates)
|
- [Predicates](#predicates)
|
||||||
- [Updated `compute_proposer_index`](#updated-compute_proposer_index)
|
- [Updated `compute_proposer_index`](#updated-compute_proposer_index)
|
||||||
- [Updated `is_eligible_for_activation_queue`](#updated-is_eligible_for_activation_queue)
|
- [Updated `is_eligible_for_activation_queue`](#updated-is_eligible_for_activation_queue)
|
||||||
|
@ -69,7 +71,7 @@
|
||||||
- [New `compute_exit_epoch_and_update_churn`](#new-compute_exit_epoch_and_update_churn)
|
- [New `compute_exit_epoch_and_update_churn`](#new-compute_exit_epoch_and_update_churn)
|
||||||
- [New `compute_consolidation_epoch_and_update_churn`](#new-compute_consolidation_epoch_and_update_churn)
|
- [New `compute_consolidation_epoch_and_update_churn`](#new-compute_consolidation_epoch_and_update_churn)
|
||||||
- [Updated `slash_validator`](#updated-slash_validator)
|
- [Updated `slash_validator`](#updated-slash_validator)
|
||||||
- [Beacon chain state transition function](#beacon-chain-state-transition-function)
|
- [Beacon chain state transition function](#beacon-chain-state-transition-function)
|
||||||
- [Epoch processing](#epoch-processing)
|
- [Epoch processing](#epoch-processing)
|
||||||
- [Updated `process_epoch`](#updated-process_epoch)
|
- [Updated `process_epoch`](#updated-process_epoch)
|
||||||
- [Updated `process_registry_updates`](#updated--process_registry_updates)
|
- [Updated `process_registry_updates`](#updated--process_registry_updates)
|
||||||
|
@ -98,7 +100,7 @@
|
||||||
- [New `process_deposit_request`](#new-process_deposit_request)
|
- [New `process_deposit_request`](#new-process_deposit_request)
|
||||||
- [Execution layer consolidation requests](#execution-layer-consolidation-requests)
|
- [Execution layer consolidation requests](#execution-layer-consolidation-requests)
|
||||||
- [New `process_consolidation_request`](#new-process_consolidation_request)
|
- [New `process_consolidation_request`](#new-process_consolidation_request)
|
||||||
- [Testing](#testing)
|
- [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.
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue