File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -157,3 +157,13 @@ def num_validators(self) -> int:
157
157
@property
158
158
def num_crosslinks (self ) -> int :
159
159
return len (self .latest_crosslinks )
160
+
161
+ def update_validator (self ,
162
+ validator_index : int ,
163
+ validator : ValidatorRecord ) -> 'BeaconState' :
164
+ with self .build_changeset () as state_changeset :
165
+ validator_registry = list (state_changeset .validator_registry )
166
+ validator_registry [validator_index ] = validator
167
+ state_changeset .validator_registry = tuple (validator_registry )
168
+ self = state_changeset .commit ()
169
+ return self
Original file line number Diff line number Diff line change @@ -99,3 +99,24 @@ def test_num_crosslink_records(expected,
99
99
def test_hash (sample_beacon_state_params ):
100
100
state = BeaconState (** sample_beacon_state_params )
101
101
assert state .root == hash_eth2 (rlp .encode (state ))
102
+
103
+
104
+ def test_update_validator (sample_beacon_state_params , sample_validator_record_params , max_deposit ):
105
+ state = BeaconState (** sample_beacon_state_params ).copy (
106
+ validator_registry = [
107
+ mock_validator_record (
108
+ pubkey ,
109
+ max_deposit ,
110
+ )
111
+ for pubkey in range (10 )
112
+ ]
113
+ )
114
+
115
+ new_pubkey = 100
116
+ validator_index = 5
117
+ validator = state .validator_registry [validator_index ].copy (
118
+ pubkey = new_pubkey ,
119
+ )
120
+ result_state = state .update_validator (validator_index = validator_index , validator = validator )
121
+ assert result_state .validator_registry [validator_index ].pubkey == new_pubkey
122
+ assert state .validator_registry [validator_index ].pubkey != new_pubkey
You can’t perform that action at this time.
0 commit comments