Skip to content

Commit 29f3948

Browse files
authored
Merge pull request #3814 from ethereum/update-consolidation-tests
Update `test_incorrect_not_enough_consolidation_churn_available` and add assertions to test cases
2 parents fed320c + f30a3a3 commit 29f3948

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

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

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,9 @@ def test_incorrect_source_equals_target(spec, state):
421421
target_pubkey=state.validators[source_index].pubkey,
422422
)
423423

424+
# Check the the return condition
425+
assert consolidation.source_pubkey == consolidation.target_pubkey
426+
424427
yield from run_consolidation_processing(
425428
spec, state, consolidation, success=False
426429
)
@@ -454,6 +457,9 @@ def test_incorrect_exceed_pending_consolidations_limit(spec, state):
454457
)
455458
set_eth1_withdrawal_credential_with_balance(spec, state, target_index)
456459

460+
# Check the the return condition
461+
assert len(state.pending_consolidations) == spec.PENDING_CONSOLIDATIONS_LIMIT
462+
457463
yield from run_consolidation_processing(
458464
spec, state, consolidation, success=False
459465
)
@@ -463,7 +469,6 @@ def test_incorrect_exceed_pending_consolidations_limit(spec, state):
463469
@spec_state_test
464470
@single_phase
465471
def test_incorrect_not_enough_consolidation_churn_available(spec, state):
466-
state.validators = state.validators[0:2]
467472
state.pending_consolidations = [
468473
spec.PendingConsolidation(source_index=0, target_index=1)
469474
]
@@ -481,7 +486,12 @@ def test_incorrect_not_enough_consolidation_churn_available(spec, state):
481486
source_pubkey=state.validators[source_index].pubkey,
482487
target_pubkey=state.validators[target_index].pubkey,
483488
)
489+
484490
set_eth1_withdrawal_credential_with_balance(spec, state, target_index)
491+
492+
# Check the the return condition
493+
assert spec.get_consolidation_churn_limit(state) <= spec.MIN_ACTIVATION_BALANCE
494+
485495
yield from run_consolidation_processing(
486496
spec, state, consolidation, success=False
487497
)
@@ -514,6 +524,9 @@ def test_incorrect_exited_source(spec, state):
514524
# exit source
515525
spec.initiate_validator_exit(state, source_index)
516526

527+
# Check the the return condition
528+
assert state.validators[source_index].exit_epoch != spec.FAR_FUTURE_EPOCH
529+
517530
yield from run_consolidation_processing(
518531
spec, state, consolidation, success=False
519532
)
@@ -544,6 +557,10 @@ def test_incorrect_exited_target(spec, state):
544557
set_eth1_withdrawal_credential_with_balance(spec, state, target_index)
545558
# exit target
546559
spec.initiate_validator_exit(state, 1)
560+
561+
# Check the the return condition
562+
assert state.validators[target_index].exit_epoch != spec.FAR_FUTURE_EPOCH
563+
547564
yield from run_consolidation_processing(
548565
spec, state, consolidation, success=False
549566
)
@@ -576,6 +593,9 @@ def test_incorrect_inactive_source(spec, state):
576593
# set source validator as not yet activated
577594
state.validators[source_index].activation_epoch = spec.FAR_FUTURE_EPOCH
578595

596+
# Check the the return condition
597+
assert not spec.is_active_validator(state.validators[source_index], current_epoch)
598+
579599
yield from run_consolidation_processing(
580600
spec, state, consolidation, success=False
581601
)
@@ -607,6 +627,10 @@ def test_incorrect_inactive_target(spec, state):
607627

608628
# set target validator as not yet activated
609629
state.validators[1].activation_epoch = spec.FAR_FUTURE_EPOCH
630+
631+
# Check the the return condition
632+
assert not spec.is_active_validator(state.validators[target_index], current_epoch)
633+
610634
yield from run_consolidation_processing(
611635
spec, state, consolidation, success=False
612636
)
@@ -633,6 +657,10 @@ def test_incorrect_no_source_execution_withdrawal_credential(spec, state):
633657
target_pubkey=state.validators[target_index].pubkey,
634658
)
635659
set_eth1_withdrawal_credential_with_balance(spec, state, target_index)
660+
661+
# Check the the return condition
662+
assert not spec.has_execution_withdrawal_credential(state.validators[source_index])
663+
636664
yield from run_consolidation_processing(
637665
spec, state, consolidation, success=False
638666
)
@@ -661,6 +689,10 @@ def test_incorrect_no_target_execution_withdrawal_credential(spec, state):
661689
source_pubkey=state.validators[source_index].pubkey,
662690
target_pubkey=state.validators[target_index].pubkey,
663691
)
692+
693+
# Check the the return condition
694+
assert not spec.has_execution_withdrawal_credential(state.validators[target_index])
695+
664696
yield from run_consolidation_processing(
665697
spec, state, consolidation, success=False
666698
)
@@ -691,6 +723,9 @@ def test_incorrect_incorrect_source_address(spec, state):
691723
)
692724
set_eth1_withdrawal_credential_with_balance(spec, state, target_index)
693725

726+
# Check the the return condition
727+
assert not state.validators[source_index].withdrawal_credentials[12:] == consolidation.source_address
728+
694729
yield from run_consolidation_processing(
695730
spec, state, consolidation, success=False
696731
)
@@ -721,6 +756,9 @@ def test_incorrect_unknown_source_pubkey(spec, state):
721756
)
722757
set_eth1_withdrawal_credential_with_balance(spec, state, target_index)
723758

759+
# Check the the return condition
760+
assert not state.validators[source_index].pubkey == consolidation.source_pubkey
761+
724762
yield from run_consolidation_processing(
725763
spec, state, consolidation, success=False
726764
)
@@ -751,6 +789,9 @@ def test_incorrect_unknown_target_pubkey(spec, state):
751789
)
752790
set_eth1_withdrawal_credential_with_balance(spec, state, target_index)
753791

792+
# Check the the return condition
793+
assert not state.validators[target_index].pubkey == consolidation.target_pubkey
794+
754795
yield from run_consolidation_processing(
755796
spec, state, consolidation, success=False
756797
)
@@ -762,7 +803,7 @@ def run_consolidation_processing(spec, state, consolidation, success=True):
762803
- pre-state ('pre')
763804
- consolidation_request ('consolidation_request')
764805
- post-state ('post').
765-
If ``valid == False``, run expecting ``AssertionError``
806+
If ``success == False``, ``process_consolidation_request`` would return without any state change.
766807
"""
767808

768809
if success:

0 commit comments

Comments
 (0)