-
Notifications
You must be signed in to change notification settings - Fork 972
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1001 from ethereum/registry_test
Fix `process_registry_updates` and add `test_process_registry_updates`
- Loading branch information
Showing
4 changed files
with
79 additions
and
1 deletion.
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
67 changes: 67 additions & 0 deletions
67
test_libs/pyspec/tests/epoch_processing/test_process_registry_updates.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,67 @@ | ||
from copy import deepcopy | ||
|
||
import pytest | ||
|
||
import eth2spec.phase0.spec as spec | ||
|
||
from eth2spec.phase0.spec import ( | ||
get_current_epoch, | ||
is_active_validator, | ||
) | ||
from tests.helpers import ( | ||
next_epoch, | ||
) | ||
|
||
# mark entire file as 'state' | ||
pytestmark = pytest.mark.state | ||
|
||
|
||
def test_activation(state): | ||
index = 0 | ||
assert is_active_validator(state.validator_registry[index], get_current_epoch(state)) | ||
|
||
# Mock a new deposit | ||
state.validator_registry[index].activation_eligibility_epoch = spec.FAR_FUTURE_EPOCH | ||
state.validator_registry[index].activation_epoch = spec.FAR_FUTURE_EPOCH | ||
state.validator_registry[index].effective_balance = spec.MAX_EFFECTIVE_BALANCE | ||
assert not is_active_validator(state.validator_registry[index], get_current_epoch(state)) | ||
|
||
pre_state = deepcopy(state) | ||
|
||
blocks = [] | ||
for _ in range(spec.ACTIVATION_EXIT_DELAY + 1): | ||
block = next_epoch(state) | ||
blocks.append(block) | ||
|
||
assert state.validator_registry[index].activation_eligibility_epoch != spec.FAR_FUTURE_EPOCH | ||
assert state.validator_registry[index].activation_epoch != spec.FAR_FUTURE_EPOCH | ||
assert is_active_validator( | ||
state.validator_registry[index], | ||
get_current_epoch(state), | ||
) | ||
|
||
return pre_state, blocks, state | ||
|
||
|
||
def test_ejection(state): | ||
index = 0 | ||
assert is_active_validator(state.validator_registry[index], get_current_epoch(state)) | ||
assert state.validator_registry[index].exit_epoch == spec.FAR_FUTURE_EPOCH | ||
|
||
# Mock an ejection | ||
state.validator_registry[index].effective_balance = spec.EJECTION_BALANCE | ||
|
||
pre_state = deepcopy(state) | ||
|
||
blocks = [] | ||
for _ in range(spec.ACTIVATION_EXIT_DELAY + 1): | ||
block = next_epoch(state) | ||
blocks.append(block) | ||
|
||
assert state.validator_registry[index].exit_epoch != spec.FAR_FUTURE_EPOCH | ||
assert not is_active_validator( | ||
state.validator_registry[index], | ||
get_current_epoch(state), | ||
) | ||
|
||
return pre_state, blocks, state |
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