Skip to content

Commit 17f6454

Browse files
committed
Add tests for process_registry_updates
1 parent 96b1d31 commit 17f6454

File tree

3 files changed

+101
-5
lines changed

3 files changed

+101
-5
lines changed

specs/electra/beacon-chain.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -778,23 +778,25 @@ def process_epoch(state: BeaconState) -> None:
778778

779779
#### Modified `process_registry_updates`
780780

781-
*Note*: The function `process_registry_updates` is modified to use the updated definition of `initiate_validator_exit`
781+
*Note*: The function `process_registry_updates` is modified to
782+
use the updated definitions of `initiate_validator_exit` and `is_eligible_for_activation_queue`
782783
and changes how the activation epochs are computed for eligible validators.
783784

784785
```python
785786
def process_registry_updates(state: BeaconState) -> None:
786787
# Process activation eligibility and ejections
787788
for index, validator in enumerate(state.validators):
788-
if is_eligible_for_activation_queue(validator):
789+
if is_eligible_for_activation_queue(validator): # [Modified in Electra:EIP7251]
789790
validator.activation_eligibility_epoch = get_current_epoch(state) + 1
790791

791792
if (
792793
is_active_validator(validator, get_current_epoch(state))
793794
and validator.effective_balance <= EJECTION_BALANCE
794795
):
795-
initiate_validator_exit(state, ValidatorIndex(index))
796+
initiate_validator_exit(state, ValidatorIndex(index)) # [Modified in Electra:EIP7251]
796797

797798
# Activate all eligible validators
799+
# [Modified in Electra:EIP7251]
798800
activation_epoch = compute_activation_exit_epoch(get_current_epoch(state))
799801
for validator in state.validators:
800802
if is_eligible_for_activation(state, validator):

tests/core/pyspec/eth2spec/test/deneb/epoch_processing/test_process_registry_updates.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ def run_test_activation_churn_limit(spec, state):
2323

2424
validator_count_0 = len(state.validators)
2525

26+
balance = spec.MIN_ACTIVATION_BALANCE if is_post_electra(spec) else spec.MAX_EFFECTIVE_BALANCE
27+
2628
for i in range(mock_activations):
2729
index = validator_count_0 + i
2830
validator = spec.Validator(
@@ -32,10 +34,10 @@ def run_test_activation_churn_limit(spec, state):
3234
activation_epoch=spec.FAR_FUTURE_EPOCH,
3335
exit_epoch=spec.FAR_FUTURE_EPOCH,
3436
withdrawable_epoch=spec.FAR_FUTURE_EPOCH,
35-
effective_balance=spec.MAX_EFFECTIVE_BALANCE,
37+
effective_balance=balance,
3638
)
3739
state.validators.append(validator)
38-
state.balances.append(spec.MAX_EFFECTIVE_BALANCE)
40+
state.balances.append(balance)
3941
state.previous_epoch_participation.append(spec.ParticipationFlags(0b0000_0000))
4042
state.current_epoch_participation.append(spec.ParticipationFlags(0b0000_0000))
4143
state.inactivity_scores.append(0)
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
from eth2spec.test.helpers.deposits import mock_deposit
2+
from eth2spec.test.helpers.state import next_epoch
3+
from eth2spec.test.context import spec_state_test, with_electra_and_later
4+
from eth2spec.test.helpers.epoch_processing import run_epoch_processing_with
5+
from eth2spec.test.helpers.withdrawals import (
6+
set_eth1_withdrawal_credential_with_balance,
7+
set_compounding_withdrawal_credential_with_balance
8+
)
9+
10+
11+
def run_test_activation_queue_eligibility(spec, state, validator_index, balance):
12+
# move past first two irregular epochs wrt finality
13+
next_epoch(spec, state)
14+
next_epoch(spec, state)
15+
16+
state.balances[validator_index] = balance
17+
state.validators[validator_index].effective_balance = balance
18+
19+
# ready for entrance into activation queue
20+
mock_deposit(spec, state, validator_index)
21+
22+
yield from run_epoch_processing_with(spec, state, 'process_registry_updates')
23+
24+
# validator moved into activation queue if eligible
25+
validator = state.validators[validator_index]
26+
if validator.effective_balance < spec.MIN_ACTIVATION_BALANCE:
27+
assert validator.activation_eligibility_epoch == spec.FAR_FUTURE_EPOCH
28+
else:
29+
assert validator.activation_eligibility_epoch < spec.FAR_FUTURE_EPOCH
30+
31+
32+
@with_electra_and_later
33+
@spec_state_test
34+
def test_activation_queue_eligibility__less_than_min_activation_balance(spec, state):
35+
# move past first two irregular epochs wrt finality
36+
next_epoch(spec, state)
37+
next_epoch(spec, state)
38+
39+
index = 3
40+
balance = spec.MIN_ACTIVATION_BALANCE - spec.EFFECTIVE_BALANCE_INCREMENT
41+
yield from run_test_activation_queue_eligibility(spec, state, index, balance)
42+
43+
44+
@with_electra_and_later
45+
@spec_state_test
46+
def test_activation_queue_eligibility__min_activation_balance(spec, state):
47+
# move past first two irregular epochs wrt finality
48+
next_epoch(spec, state)
49+
next_epoch(spec, state)
50+
51+
index = 5
52+
balance = spec.MIN_ACTIVATION_BALANCE
53+
yield from run_test_activation_queue_eligibility(spec, state, index, balance)
54+
55+
56+
@with_electra_and_later
57+
@spec_state_test
58+
def test_activation_queue_eligibility__min_activation_balance_eth1_creds(spec, state):
59+
# move past first two irregular epochs wrt finality
60+
next_epoch(spec, state)
61+
next_epoch(spec, state)
62+
63+
index = 7
64+
balance = spec.MIN_ACTIVATION_BALANCE
65+
set_eth1_withdrawal_credential_with_balance(spec, state, index)
66+
yield from run_test_activation_queue_eligibility(spec, state, index, balance)
67+
68+
69+
@with_electra_and_later
70+
@spec_state_test
71+
def test_activation_queue_eligibility__min_activation_balance_compounding_creds(spec, state):
72+
# move past first two irregular epochs wrt finality
73+
next_epoch(spec, state)
74+
next_epoch(spec, state)
75+
76+
index = 11
77+
balance = spec.MIN_ACTIVATION_BALANCE
78+
set_compounding_withdrawal_credential_with_balance(spec, state, index)
79+
yield from run_test_activation_queue_eligibility(spec, state, index, balance)
80+
81+
82+
@with_electra_and_later
83+
@spec_state_test
84+
def test_activation_queue_eligibility__greater_than_min_activation_balance(spec, state):
85+
# move past first two irregular epochs wrt finality
86+
next_epoch(spec, state)
87+
next_epoch(spec, state)
88+
89+
index = 13
90+
balance = spec.MIN_ACTIVATION_BALANCE + spec.EFFECTIVE_BALANCE_INCREMENT
91+
set_compounding_withdrawal_credential_with_balance(spec, state, index)
92+
yield from run_test_activation_queue_eligibility(spec, state, index, balance)

0 commit comments

Comments
 (0)