Skip to content

Commit e8a013b

Browse files
authored
Merge pull request #3947 from terencechain/withdrawal-request-balance-tests
Fix insufficient effective bal test and add a bal test
2 parents 85e2452 + e46ba7f commit e8a013b

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,8 @@ def test_insufficient_effective_balance(spec, state):
658658
state.validators[
659659
validator_index
660660
].effective_balance -= spec.EFFECTIVE_BALANCE_INCREMENT
661+
# Make sure validator has enough balance to withdraw
662+
state.balances[validator_index] += spec.EFFECTIVE_BALANCE_INCREMENT
661663

662664
set_compounding_withdrawal_credential(spec, state, validator_index, address=address)
663665
withdrawal_request = spec.WithdrawalRequest(
@@ -787,6 +789,30 @@ def test_partial_withdrawal_activation_epoch_less_than_shard_committee_period(
787789
)
788790

789791

792+
def test_insufficient_balance(spec, state):
793+
rng = random.Random(1361)
794+
state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH
795+
current_epoch = spec.get_current_epoch(state)
796+
validator_index = rng.choice(spec.get_active_validator_indices(state, current_epoch))
797+
validator_pubkey = state.validators[validator_index].pubkey
798+
address = b"\x22" * 20
799+
amount = spec.EFFECTIVE_BALANCE_INCREMENT
800+
801+
# Validator will not be able to partial withdrawal because MIN_ACTIVATION_BALANCE + amount > balance
802+
set_compounding_withdrawal_credential(spec, state, validator_index, address=address)
803+
withdrawal_request = spec.WithdrawalRequest(
804+
source_address=address,
805+
validator_pubkey=validator_pubkey,
806+
amount=amount,
807+
)
808+
809+
yield from run_withdrawal_request_processing(
810+
spec,
811+
state,
812+
withdrawal_request,
813+
success=False,
814+
)
815+
790816
#
791817
# Run processing
792818
#

0 commit comments

Comments
 (0)