File tree Expand file tree Collapse file tree 3 files changed +43
-4
lines changed Expand file tree Collapse file tree 3 files changed +43
-4
lines changed Original file line number Diff line number Diff line change 27
27
clamp ,
28
28
)
29
29
30
- from eth .beacon .block_committees_info import BlockCommitteesInfo
31
- from eth .beacon .enums import (
32
- ValidatorStatusCode ,
30
+ from eth .beacon .block_committees_info import (
31
+ BlockCommitteesInfo ,
33
32
)
34
33
from eth .beacon .types .shard_committees import (
35
34
ShardCommittee ,
@@ -156,7 +155,7 @@ def get_active_validator_indices(validators: Sequence['ValidatorRecord']) -> Tup
156
155
"""
157
156
return tuple (
158
157
i for i , v in enumerate (validators )
159
- if v .status in [ ValidatorStatusCode . ACTIVE , ValidatorStatusCode . ACTIVE_PENDING_EXIT ]
158
+ if v .is_active
160
159
)
161
160
162
161
Original file line number Diff line number Diff line change 3
3
)
4
4
import rlp
5
5
6
+ from eth .beacon .enums import (
7
+ ValidatorStatusCode ,
8
+ )
6
9
from eth .rlp .sedes import (
7
10
uint64 ,
8
11
uint256 ,
@@ -52,3 +55,13 @@ def __init__(self,
52
55
latest_status_change_slot = latest_status_change_slot ,
53
56
exit_count = exit_count ,
54
57
)
58
+
59
+ @property
60
+ def is_active (self ) -> bool :
61
+ """
62
+ Returns ``True`` if the validator is active.
63
+ """
64
+ return self .status in [
65
+ ValidatorStatusCode .ACTIVE ,
66
+ ValidatorStatusCode .ACTIVE_PENDING_EXIT
67
+ ]
Original file line number Diff line number Diff line change
1
+ from eth .beacon .enums import (
2
+ ValidatorStatusCode ,
3
+ )
1
4
from eth .beacon .types .validator_records import (
2
5
ValidatorRecord ,
3
6
)
@@ -7,3 +10,27 @@ def test_defaults(sample_validator_record_params):
7
10
validator = ValidatorRecord (** sample_validator_record_params )
8
11
assert validator .pubkey == sample_validator_record_params ['pubkey' ]
9
12
assert validator .withdrawal_credentials == sample_validator_record_params ['withdrawal_credentials' ] # noqa: E501
13
+
14
+
15
+ def test_is_active (sample_validator_record_params ):
16
+ validator_record_params = {
17
+ ** sample_validator_record_params ,
18
+ 'status' : ValidatorStatusCode .ACTIVE
19
+ }
20
+ validator = ValidatorRecord (** validator_record_params )
21
+ assert validator .is_active
22
+
23
+ validator_record_params = {
24
+ ** sample_validator_record_params ,
25
+ 'status' : ValidatorStatusCode .ACTIVE_PENDING_EXIT
26
+ }
27
+ validator = ValidatorRecord (** validator_record_params )
28
+ assert validator .is_active
29
+
30
+
31
+ validator_record_params = {
32
+ ** sample_validator_record_params ,
33
+ 'status' : ValidatorStatusCode .EXITED_WITHOUT_PENALTY
34
+ }
35
+ validator = ValidatorRecord (** validator_record_params )
36
+ assert not validator .is_active
You can’t perform that action at this time.
0 commit comments