Skip to content

Commit 294db63

Browse files
authored
Merge pull request #4094 from bshastry/add-eip7251-test
[Tests] Add test cases for partially withdrawable validator scenarios
2 parents f17311c + e793b64 commit 294db63

File tree

2 files changed

+233
-0
lines changed

2 files changed

+233
-0
lines changed

tests/core/pyspec/eth2spec/test/capella/block_processing/test_process_withdrawals.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,3 +812,77 @@ def test_random_partial_withdrawals_4(spec, state):
812812
@spec_state_test
813813
def test_random_partial_withdrawals_5(spec, state):
814814
yield from run_random_partial_withdrawals_test(spec, state, random.Random(5))
815+
816+
817+
@with_capella_and_later
818+
@spec_state_test
819+
def test_partially_withdrawable_validator_legacy_max_plus_one(spec, state):
820+
"""Test legacy validator with balance just above MAX_EFFECTIVE_BALANCE"""
821+
validator_index = 0
822+
set_eth1_withdrawal_credential_with_balance(
823+
spec, state,
824+
validator_index,
825+
balance=spec.MAX_EFFECTIVE_BALANCE + 1
826+
)
827+
assert spec.is_partially_withdrawable_validator(
828+
state.validators[validator_index],
829+
state.balances[validator_index]
830+
)
831+
832+
next_slot(spec, state)
833+
execution_payload = build_empty_execution_payload(spec, state)
834+
yield from run_withdrawals_processing(
835+
spec, state,
836+
execution_payload,
837+
fully_withdrawable_indices=[],
838+
partial_withdrawals_indices=[validator_index]
839+
)
840+
841+
842+
@with_capella_and_later
843+
@spec_state_test
844+
def test_partially_withdrawable_validator_legacy_exact_max(spec, state):
845+
"""Test legacy validator whose balance is exactly MAX_EFFECTIVE_BALANCE"""
846+
validator_index = 0
847+
set_eth1_withdrawal_credential_with_balance(
848+
spec, state,
849+
validator_index
850+
)
851+
assert not spec.is_partially_withdrawable_validator(
852+
state.validators[validator_index],
853+
state.balances[validator_index]
854+
)
855+
856+
next_slot(spec, state)
857+
execution_payload = build_empty_execution_payload(spec, state)
858+
yield from run_withdrawals_processing(
859+
spec, state,
860+
execution_payload,
861+
fully_withdrawable_indices=[],
862+
partial_withdrawals_indices=[]
863+
)
864+
865+
866+
@with_capella_and_later
867+
@spec_state_test
868+
def test_partially_withdrawable_validator_legacy_max_minus_one(spec, state):
869+
"""Test legacy validator whose balance is below MAX_EFFECTIVE_BALANCE"""
870+
validator_index = 0
871+
set_eth1_withdrawal_credential_with_balance(
872+
spec, state,
873+
validator_index,
874+
balance=spec.MAX_EFFECTIVE_BALANCE - 1
875+
)
876+
assert not spec.is_partially_withdrawable_validator(
877+
state.validators[validator_index],
878+
state.balances[validator_index]
879+
)
880+
881+
next_slot(spec, state)
882+
execution_payload = build_empty_execution_payload(spec, state)
883+
yield from run_withdrawals_processing(
884+
spec, state,
885+
execution_payload,
886+
fully_withdrawable_indices=[],
887+
partial_withdrawals_indices=[]
888+
)

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

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,3 +442,162 @@ def test_pending_withdrawals_at_max_mixed_with_sweep_and_fully_withdrawable(spec
442442

443443
withdrawals_exceeding_max = pending_withdrawal_requests[spec.MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP:]
444444
assert state.pending_partial_withdrawals == withdrawals_exceeding_max
445+
446+
447+
@with_electra_and_later
448+
@spec_state_test
449+
def test_partially_withdrawable_validator_compounding_max_plus_one(spec, state):
450+
"""Test compounding validator with balance just above MAX_EFFECTIVE_BALANCE_ELECTRA"""
451+
validator_index = 0
452+
set_compounding_withdrawal_credential_with_balance(
453+
spec, state,
454+
validator_index,
455+
balance=spec.MAX_EFFECTIVE_BALANCE_ELECTRA + 1
456+
)
457+
assert spec.is_partially_withdrawable_validator(
458+
state.validators[validator_index],
459+
state.balances[validator_index]
460+
)
461+
462+
next_slot(spec, state)
463+
execution_payload = build_empty_execution_payload(spec, state)
464+
yield from run_withdrawals_processing(
465+
spec, state,
466+
execution_payload,
467+
fully_withdrawable_indices=[],
468+
partial_withdrawals_indices=[validator_index]
469+
)
470+
assert state.pending_partial_withdrawals == []
471+
472+
473+
@with_electra_and_later
474+
@spec_state_test
475+
def test_partially_withdrawable_validator_compounding_exact_max(spec, state):
476+
"""Test compounding validator with balance exactly equal to MAX_EFFECTIVE_BALANCE_ELECTRA"""
477+
validator_index = 0
478+
set_compounding_withdrawal_credential_with_balance(
479+
spec, state,
480+
validator_index
481+
)
482+
assert not spec.is_partially_withdrawable_validator(
483+
state.validators[validator_index],
484+
state.balances[validator_index]
485+
)
486+
487+
next_slot(spec, state)
488+
execution_payload = build_empty_execution_payload(spec, state)
489+
yield from run_withdrawals_processing(
490+
spec, state,
491+
execution_payload,
492+
fully_withdrawable_indices=[],
493+
partial_withdrawals_indices=[]
494+
)
495+
assert state.pending_partial_withdrawals == []
496+
497+
498+
@with_electra_and_later
499+
@spec_state_test
500+
def test_partially_withdrawable_validator_compounding_max_minus_one(spec, state):
501+
"""Test compounding validator whose balance is just below MAX_EFFECTIVE_BALANCE_ELECTRA"""
502+
validator_index = 0
503+
set_compounding_withdrawal_credential_with_balance(
504+
spec, state,
505+
validator_index,
506+
effective_balance=spec.MAX_EFFECTIVE_BALANCE_ELECTRA - spec.EFFECTIVE_BALANCE_INCREMENT,
507+
balance=spec.MAX_EFFECTIVE_BALANCE_ELECTRA - 1
508+
)
509+
assert not spec.is_partially_withdrawable_validator(
510+
state.validators[validator_index],
511+
state.balances[validator_index]
512+
)
513+
514+
next_slot(spec, state)
515+
execution_payload = build_empty_execution_payload(spec, state)
516+
yield from run_withdrawals_processing(
517+
spec, state,
518+
execution_payload,
519+
fully_withdrawable_indices=[],
520+
partial_withdrawals_indices=[]
521+
)
522+
assert state.pending_partial_withdrawals == []
523+
524+
525+
@with_electra_and_later
526+
@spec_state_test
527+
def test_partially_withdrawable_validator_compounding_min_plus_one(spec, state):
528+
"""Test compounding validator just above MIN_ACTIVATION_BALANCE"""
529+
validator_index = 0
530+
set_compounding_withdrawal_credential_with_balance(
531+
spec, state,
532+
validator_index,
533+
effective_balance=spec.MIN_ACTIVATION_BALANCE,
534+
balance=spec.MIN_ACTIVATION_BALANCE + 1
535+
)
536+
assert not spec.is_partially_withdrawable_validator(
537+
state.validators[validator_index],
538+
state.balances[validator_index]
539+
)
540+
541+
next_slot(spec, state)
542+
execution_payload = build_empty_execution_payload(spec, state)
543+
yield from run_withdrawals_processing(
544+
spec, state,
545+
execution_payload,
546+
fully_withdrawable_indices=[],
547+
partial_withdrawals_indices=[]
548+
)
549+
assert state.pending_partial_withdrawals == []
550+
551+
552+
@with_electra_and_later
553+
@spec_state_test
554+
def test_partially_withdrawable_validator_compounding_exact_min(spec, state):
555+
"""Test compounding validator with balance exactly equal to MIN_ACTIVATION_BALANCE"""
556+
validator_index = 0
557+
set_compounding_withdrawal_credential_with_balance(
558+
spec, state,
559+
validator_index,
560+
effective_balance=spec.MIN_ACTIVATION_BALANCE,
561+
balance=spec.MIN_ACTIVATION_BALANCE
562+
)
563+
assert not spec.is_partially_withdrawable_validator(
564+
state.validators[validator_index],
565+
state.balances[validator_index]
566+
)
567+
568+
next_slot(spec, state)
569+
execution_payload = build_empty_execution_payload(spec, state)
570+
yield from run_withdrawals_processing(
571+
spec, state,
572+
execution_payload,
573+
fully_withdrawable_indices=[],
574+
partial_withdrawals_indices=[]
575+
)
576+
assert state.pending_partial_withdrawals == []
577+
578+
579+
@with_electra_and_later
580+
@spec_state_test
581+
def test_partially_withdrawable_validator_compounding_min_minus_one(spec, state):
582+
"""Test compounding validator below MIN_ACTIVATION_BALANCE"""
583+
validator_index = 0
584+
set_compounding_withdrawal_credential_with_balance(
585+
spec, state,
586+
validator_index,
587+
effective_balance=spec.MIN_ACTIVATION_BALANCE - spec.EFFECTIVE_BALANCE_INCREMENT,
588+
balance=spec.MIN_ACTIVATION_BALANCE - 1
589+
)
590+
assert not spec.is_partially_withdrawable_validator(
591+
state.validators[validator_index],
592+
state.balances[validator_index]
593+
)
594+
595+
next_slot(spec, state)
596+
execution_payload = build_empty_execution_payload(spec, state)
597+
yield from run_withdrawals_processing(
598+
spec, state,
599+
execution_payload,
600+
fully_withdrawable_indices=[],
601+
partial_withdrawals_indices=[]
602+
)
603+
assert state.pending_partial_withdrawals == []

0 commit comments

Comments
 (0)