Skip to content

Commit 815485b

Browse files
authored
Merge pull request #3690 from fradamt/dev
Fix broken exit tests due to change in the churn computation
2 parents 6845546 + 715e754 commit 815485b

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

tests/core/pyspec/eth2spec/test/electra/block_processing/test_process_voluntary_exit.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ def test_min_balance_exit(spec, state):
4545
# Check exit queue churn is set correctly
4646
assert state.exit_balance_to_consume == churn_limit - spec.MIN_ACTIVATION_BALANCE
4747
# Check exit epoch and withdrawable epoch
48-
assert state.validators[0].exit_epoch == expected_exit_epoch
49-
assert state.validators[0].withdrawable_epoch == expected_withdrawable_epoch
48+
assert state.validators[validator_index].exit_epoch == expected_exit_epoch
49+
assert state.validators[validator_index].withdrawable_epoch == expected_withdrawable_epoch
5050
# Check earliest_exit_epoch
5151
assert state.earliest_exit_epoch == expected_exit_epoch
5252

@@ -178,13 +178,15 @@ def test_max_balance_exit(spec, state):
178178
spec.VoluntaryExit(epoch=current_epoch, validator_index=validator_index),
179179
privkey,
180180
)
181+
181182
yield from run_voluntary_exit_processing(spec, state, signed_voluntary_exit)
182183

183184
# Check exit epoch and withdrawable epoch
184-
expected_exit_epoch = spec.compute_activation_exit_epoch(
185+
earliest_exit_epoch = spec.compute_activation_exit_epoch(
185186
spec.get_current_epoch(state)
186187
)
187-
expected_exit_epoch += to_exit // churn_limit
188+
additional_epochs = (to_exit - 1) // churn_limit
189+
expected_exit_epoch = earliest_exit_epoch + additional_epochs
188190
expected_withdrawable_epoch = (
189191
expected_exit_epoch + spec.config.MIN_VALIDATOR_WITHDRAWABILITY_DELAY
190192
)
@@ -194,8 +196,7 @@ def test_max_balance_exit(spec, state):
194196
== expected_withdrawable_epoch
195197
)
196198
# Check exit_balance_to_consume
197-
remainder = to_exit % churn_limit
198-
assert state.exit_balance_to_consume == churn_limit - remainder
199+
assert state.exit_balance_to_consume == (additional_epochs + 1) * churn_limit - to_exit
199200
# Check earliest_exit_epoch
200201
assert state.earliest_exit_epoch == expected_exit_epoch
201202

@@ -254,7 +255,7 @@ def test_exit_with_balance_multiple_of_churn_limit(spec, state):
254255
validator_index = spec.get_active_validator_indices(state, current_epoch)[0]
255256
# Set validator effective balance to a multiple of churn_limit
256257
epochs_to_consume = 3
257-
state.validators[0].effective_balance = epochs_to_consume * churn_limit
258+
state.validators[validator_index].effective_balance = epochs_to_consume * churn_limit
258259

259260
privkey = pubkey_to_privkey[state.validators[validator_index].pubkey]
260261
signed_voluntary_exit = sign_voluntary_exit(
@@ -265,10 +266,10 @@ def test_exit_with_balance_multiple_of_churn_limit(spec, state):
265266
)
266267
yield from run_voluntary_exit_processing(spec, state, signed_voluntary_exit)
267268

268-
# Validator consumes churn limit fully in the next 3 epochs (current included)
269+
# Validator consumes churn limit fully in epochs_to_consume epochs
269270
expected_exit_epoch = (
270271
spec.compute_activation_exit_epoch(spec.get_current_epoch(state))
271-
+ epochs_to_consume
272+
+ epochs_to_consume - 1
272273
)
273274
expected_withdrawable_epoch = (
274275
expected_exit_epoch + spec.config.MIN_VALIDATOR_WITHDRAWABILITY_DELAY
@@ -279,7 +280,7 @@ def test_exit_with_balance_multiple_of_churn_limit(spec, state):
279280
== expected_withdrawable_epoch
280281
)
281282
# Check exit_balance_to_consume
282-
assert state.exit_balance_to_consume == churn_limit
283+
assert state.exit_balance_to_consume == 0
283284
# Check earliest_exit_epoch
284285
assert state.earliest_exit_epoch == expected_exit_epoch
285286

0 commit comments

Comments
 (0)