Skip to content

Commit 2a06d91

Browse files
committed
Add more process_pending_consolidations tests
1 parent 17f6454 commit 2a06d91

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

tests/core/pyspec/eth2spec/test/electra/epoch_processing/test_process_pending_consolidations.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,3 +302,67 @@ def test_pending_consolidation_with_pending_deposit(spec, state):
302302
# Pending deposit to the source was not processed.
303303
# It should only be processed in the next epoch transition
304304
assert state.pending_deposits == [pending_deposit]
305+
306+
307+
@with_electra_and_later
308+
@spec_state_test
309+
def test_pending_consolidation_source_balance_less_than_effective(spec, state):
310+
current_epoch = spec.get_current_epoch(state)
311+
source_index = spec.get_active_validator_indices(state, current_epoch)[0]
312+
target_index = spec.get_active_validator_indices(state, current_epoch)[1]
313+
# append pending consolidation
314+
state.pending_consolidations.append(
315+
spec.PendingConsolidation(source_index=source_index, target_index=target_index)
316+
)
317+
# Set withdrawable epoch to current epoch to allow processing
318+
state.validators[source_index].withdrawable_epoch = current_epoch
319+
# Set the target withdrawal credential to eth1
320+
eth1_withdrawal_credential = (
321+
spec.ETH1_ADDRESS_WITHDRAWAL_PREFIX + b"\x00" * 11 + b"\x11" * 20
322+
)
323+
state.validators[target_index].withdrawal_credentials = eth1_withdrawal_credential
324+
# Set the source balance to be less than effective_balance
325+
pre_balance_source = state.validators[source_index].effective_balance - spec.EFFECTIVE_BALANCE_INCREMENT // 8
326+
state.balances[source_index] = pre_balance_source
327+
328+
pre_balance_target = state.balances[target_index]
329+
330+
yield from run_epoch_processing_with(spec, state, "process_pending_consolidations")
331+
332+
# Pending consolidation was successfully processed
333+
assert state.balances[target_index] == pre_balance_target + pre_balance_source
334+
assert state.balances[source_index] == 0
335+
assert state.pending_consolidations == []
336+
337+
338+
@with_electra_and_later
339+
@spec_state_test
340+
def test_pending_consolidation_source_balance_greater_than_effective(spec, state):
341+
current_epoch = spec.get_current_epoch(state)
342+
source_index = spec.get_active_validator_indices(state, current_epoch)[0]
343+
target_index = spec.get_active_validator_indices(state, current_epoch)[1]
344+
# append pending consolidation
345+
state.pending_consolidations.append(
346+
spec.PendingConsolidation(source_index=source_index, target_index=target_index)
347+
)
348+
# Set withdrawable epoch to current epoch to allow processing
349+
state.validators[source_index].withdrawable_epoch = current_epoch
350+
# Set the target withdrawal credential to eth1
351+
eth1_withdrawal_credential = (
352+
spec.ETH1_ADDRESS_WITHDRAWAL_PREFIX + b"\x00" * 11 + b"\x11" * 20
353+
)
354+
state.validators[target_index].withdrawal_credentials = eth1_withdrawal_credential
355+
# Set the source balance to be greater than effective_balance
356+
pre_balance_source = state.validators[source_index].effective_balance + spec.EFFECTIVE_BALANCE_INCREMENT // 8
357+
state.balances[source_index] = pre_balance_source
358+
359+
pre_balance_target = state.balances[target_index]
360+
361+
yield from run_epoch_processing_with(spec, state, "process_pending_consolidations")
362+
363+
# Pending consolidation was successfully processed
364+
assert state.balances[target_index] == (
365+
pre_balance_target + spec.get_max_effective_balance(state.validators[source_index]))
366+
assert state.balances[source_index] == (
367+
pre_balance_source - spec.get_max_effective_balance(state.validators[source_index]))
368+
assert state.pending_consolidations == []

0 commit comments

Comments
 (0)