-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
105 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
tests/core/pyspec/eth2spec/test/capella/epoch_processing/test_process_partial_withdrawals.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from eth2spec.test.context import ( | ||
with_capella_and_later, | ||
spec_state_test, | ||
) | ||
from eth2spec.test.helpers.epoch_processing import run_epoch_processing_with | ||
|
||
|
||
def set_validator_partiall_withdrawable(spec, state, index): | ||
validator = state.validators[index] | ||
validator.withdrawal_credentials = spec.ETH1_ADDRESS_WITHDRAWAL_PREFIX + validator.withdrawal_credentials[1:] | ||
validator.effective_balance = spec.MAX_EFFECTIVE_BALANCE | ||
state.balances[index] = spec.MAX_EFFECTIVE_BALANCE + 500 # make a random increase | ||
|
||
assert spec.partially_withdrawable_indices(validator, state.balances[index]) | ||
|
||
|
||
def run_process_partial_withdrawals(spec, state, num_expected_withdrawals=None): | ||
pre_withdrawal_index = state.withdrawal_index | ||
pre_withdrawals_queue = state.withdrawals_queue | ||
partially_withdrawable_indices = [ | ||
index for index, validator in enumerate(state.validators) | ||
if spec.is_partially_withdrawable_validator(validator, state.balances[index]) | ||
] | ||
num_partial_withdrawals = min(len(partially_withdrawable_indices), spec.MAX_PARTIAL_WITHDRAWALS_PER_EPOCH) | ||
|
||
if num_expected_withdrawals is not None: | ||
assert num_partial_withdrawals == num_expected_withdrawals | ||
else: | ||
num_expected_withdrawals = num_partial_withdrawals | ||
|
||
yield from run_epoch_processing_with(spec, state, 'process_partial_withdrawals') | ||
|
||
post_partially_withdrawable_indices = [ | ||
index for index, validator in enumerate(state.validators) | ||
if spec.is_partially_withdrawable_validator(validator, state.balances[index]) | ||
] | ||
|
||
assert len(partially_withdrawable_indices) - num_partial_withdrawals == len(post_partially_withdrawable_indices) | ||
|
||
assert len(state.withdrawals_queue) == len(pre_withdrawals_queue) + num_expected_withdrawals | ||
assert state.withdrawal_index == pre_withdrawal_index + num_expected_withdrawals | ||
|
||
|
||
@with_capella_and_later | ||
@spec_state_test | ||
def test_no_partial_withdrawals(spec, state): | ||
pre_validators = state.validators.copy() | ||
yield from run_process_partial_withdrawals(spec, state, 0) | ||
|
||
assert pre_validators == state.validators |