-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathtest_validator_exit_bus_happy_path.py
232 lines (190 loc) · 10.6 KB
/
test_validator_exit_bus_happy_path.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
import dataclasses
from brownie.convert.datatypes import HexString
from utils.config import contracts
from utils.test.exit_bus_data import LidoValidator
from utils.test.oracle_report_helpers import (
wait_to_next_available_report_time,
reach_consensus,
prepare_exit_bus_report,
)
from utils.test.simple_dvt_helpers import simple_dvt_add_node_operators, simple_dvt_add_keys, simple_dvt_vet_keys
@dataclasses.dataclass
class ProcessingState:
current_frame_ref_slot: int
processing_deadline_slot: int
data_hash: HexString
data_submitted: bool
data_format: int
requests_count: int
requests_submitted: int
def _wait_for_next_ref_slot():
wait_to_next_available_report_time(contracts.hash_consensus_for_validators_exit_bus_oracle)
ref_slot, _ = contracts.hash_consensus_for_validators_exit_bus_oracle.getCurrentFrame()
return ref_slot
def send_report_with_consensus(ref_slot, report, report_hash):
consensus_version = contracts.validators_exit_bus_oracle.getConsensusVersion()
contract_version = contracts.validators_exit_bus_oracle.getContractVersion()
submitter = reach_consensus(
ref_slot, report_hash, consensus_version, contracts.hash_consensus_for_validators_exit_bus_oracle
)
return contracts.validators_exit_bus_oracle.submitReportData(report, contract_version, {"from": submitter})
def test_send_zero_validators_to_exit(helpers):
ref_slot = _wait_for_next_ref_slot()
report, report_hash = prepare_exit_bus_report([], ref_slot)
report_hash_hex = HexString(report_hash, "bytes")
# Collect state before
total_requests_before = contracts.validators_exit_bus_oracle.getTotalRequestsProcessed()
last_processing_ref_slot_before = contracts.validators_exit_bus_oracle.getLastProcessingRefSlot()
processing_state_before = ProcessingState(*contracts.validators_exit_bus_oracle.getProcessingState())
tx = send_report_with_consensus(ref_slot, report, report_hash)
# Collect state after
total_requests_after = contracts.validators_exit_bus_oracle.getTotalRequestsProcessed()
last_processing_ref_slot_after = contracts.validators_exit_bus_oracle.getLastProcessingRefSlot()
processing_state_after = ProcessingState(*contracts.validators_exit_bus_oracle.getProcessingState())
# Asserts
helpers.assert_single_event_named("ProcessingStarted", tx, {"refSlot": ref_slot, "hash": report_hash_hex})
helpers.assert_event_not_emitted("ValidatorExitRequest", tx)
assert total_requests_after == total_requests_before
assert last_processing_ref_slot_after != last_processing_ref_slot_before
assert last_processing_ref_slot_after == ref_slot
assert processing_state_before != processing_state_after
assert processing_state_after.data_hash == report_hash_hex
assert processing_state_after.data_submitted
assert processing_state_after.data_format == contracts.validators_exit_bus_oracle.DATA_FORMAT_LIST()
assert processing_state_after.requests_count == processing_state_before.requests_count
assert processing_state_after.requests_submitted == processing_state_before.requests_submitted
def test_send_validator_to_exit(helpers, web3):
unreachable_cl_validator_index = 100_000_000
no_global_index = (module_id, no_id) = (1, 33)
validator_key = contracts.node_operators_registry.getSigningKey(no_id, 1)[0]
validator = LidoValidator(index=unreachable_cl_validator_index, pubkey=validator_key)
ref_slot = _wait_for_next_ref_slot()
report, report_hash = prepare_exit_bus_report([(no_global_index, validator)], ref_slot)
report_hash_hex = HexString(report_hash, "bytes")
# Collect state before
total_requests_before = contracts.validators_exit_bus_oracle.getTotalRequestsProcessed()
last_processing_ref_slot_before = contracts.validators_exit_bus_oracle.getLastProcessingRefSlot()
processing_state_before = ProcessingState(*contracts.validators_exit_bus_oracle.getProcessingState())
tx = send_report_with_consensus(ref_slot, report, report_hash)
# Collect state after
total_requests_after = contracts.validators_exit_bus_oracle.getTotalRequestsProcessed()
last_processing_ref_slot_after = contracts.validators_exit_bus_oracle.getLastProcessingRefSlot()
processing_state_after = ProcessingState(*contracts.validators_exit_bus_oracle.getProcessingState())
last_requested_validator_index_after = contracts.validators_exit_bus_oracle.getLastRequestedValidatorIndices(
module_id, [no_id]
)
# Asserts
helpers.assert_single_event_named("ProcessingStarted", tx, {"refSlot": ref_slot, "hash": report_hash_hex})
helpers.assert_single_event_named(
"ValidatorExitRequest",
tx,
{
"stakingModuleId": module_id,
"nodeOperatorId": no_id,
"validatorIndex": unreachable_cl_validator_index,
"validatorPubkey": validator_key,
"timestamp": web3.eth.get_block(tx.block_number).timestamp,
},
)
assert total_requests_after == total_requests_before + 1
assert last_requested_validator_index_after == (unreachable_cl_validator_index,)
assert last_processing_ref_slot_after != last_processing_ref_slot_before
assert last_processing_ref_slot_after == ref_slot
assert processing_state_before != processing_state_after
assert processing_state_after.data_hash == report_hash_hex
assert processing_state_after.data_submitted
assert processing_state_after.data_format == contracts.validators_exit_bus_oracle.DATA_FORMAT_LIST()
assert processing_state_after.requests_count == processing_state_before.requests_count + 1
assert processing_state_after.requests_submitted == processing_state_before.requests_submitted + 1
def test_send_multiple_validators_to_exit(helpers, web3, stranger):
"""
The same as test above but with multiple validators on different node operators and modules
"""
unreachable_cl_validator_index = 100_000_000
# Fill SDVT
simple_dvt_add_node_operators(
contracts.simple_dvt, stranger, [("SDVT Operator", f"0xab{'1' * 38}", f"0xcd{'1' * 38}")]
)
simple_dvt_add_keys(contracts.simple_dvt, 0, 2)
simple_dvt_vet_keys(0, stranger)
first_no_global_index = (first_module_id, first_no_id) = (1, 30)
second_no_global_index = (second_module_id, second_no_id) = (1, 33)
third_no_global_index = (third_module_id, third_no_id) = (2, 0)
first_validator_id = 2
second_validator_id = 3
third_validator_id = 0
first_validator_index = unreachable_cl_validator_index
second_validator_index = unreachable_cl_validator_index + 1
third_validator_index = unreachable_cl_validator_index + 2
first_validator_key = contracts.node_operators_registry.getSigningKey(first_no_id, first_validator_id)[0]
second_validator_key = contracts.node_operators_registry.getSigningKey(second_no_id, second_validator_id)[0]
third_validator_key = contracts.simple_dvt.getSigningKey(third_no_id, third_validator_id)[0]
first_validator = LidoValidator(index=first_validator_index, pubkey=first_validator_key)
second_validator = LidoValidator(index=second_validator_index, pubkey=second_validator_key)
third_validator = LidoValidator(index=third_validator_index, pubkey=third_validator_key)
ref_slot = _wait_for_next_ref_slot()
report, report_hash = prepare_exit_bus_report(
[
(first_no_global_index, first_validator),
(second_no_global_index, second_validator),
(third_no_global_index, third_validator),
],
ref_slot,
)
report_hash_hex = HexString(report_hash, "bytes")
# Collect state before
total_requests_before = contracts.validators_exit_bus_oracle.getTotalRequestsProcessed()
last_processing_ref_slot_before = contracts.validators_exit_bus_oracle.getLastProcessingRefSlot()
processing_state_before = ProcessingState(*contracts.validators_exit_bus_oracle.getProcessingState())
tx = send_report_with_consensus(ref_slot, report, report_hash)
# Collect state after
total_requests_after = contracts.validators_exit_bus_oracle.getTotalRequestsProcessed()
last_processing_ref_slot_after = contracts.validators_exit_bus_oracle.getLastProcessingRefSlot()
processing_state_after = ProcessingState(*contracts.validators_exit_bus_oracle.getProcessingState())
first_last_requested_validator_index_after = contracts.validators_exit_bus_oracle.getLastRequestedValidatorIndices(
first_module_id, [first_no_id]
)
second_last_requested_validator_index_after = contracts.validators_exit_bus_oracle.getLastRequestedValidatorIndices(
second_module_id, [second_no_id]
)
third_last_requested_validator_index_after = contracts.validators_exit_bus_oracle.getLastRequestedValidatorIndices(
third_module_id, [third_no_id]
)
# Asserts
helpers.assert_single_event_named("ProcessingStarted", tx, {"refSlot": ref_slot, "hash": report_hash_hex})
events = helpers.filter_events_from(tx.receiver, tx.events["ValidatorExitRequest"])
timestamp = web3.eth.get_block(tx.block_number).timestamp
assert len(events) == 3
assert dict(events[0]) == {
"stakingModuleId": first_module_id,
"nodeOperatorId": first_no_id,
"validatorIndex": first_validator_index,
"validatorPubkey": first_validator_key,
"timestamp": timestamp,
}
assert dict(events[1]) == {
"stakingModuleId": second_module_id,
"nodeOperatorId": second_no_id,
"validatorIndex": second_validator_index,
"validatorPubkey": second_validator_key,
"timestamp": timestamp,
}
assert dict(events[2]) == {
"stakingModuleId": third_module_id,
"nodeOperatorId": third_no_id,
"validatorIndex": third_validator_index,
"validatorPubkey": third_validator_key,
"timestamp": timestamp,
}
assert total_requests_after == total_requests_before + 3
assert first_last_requested_validator_index_after == (first_validator_index,)
assert second_last_requested_validator_index_after == (second_validator_index,)
assert third_last_requested_validator_index_after == (third_validator_index,)
assert last_processing_ref_slot_after != last_processing_ref_slot_before
assert last_processing_ref_slot_after == ref_slot
assert processing_state_before != processing_state_after
assert processing_state_after.data_hash == report_hash_hex
assert processing_state_after.data_submitted
assert processing_state_after.data_format == contracts.validators_exit_bus_oracle.DATA_FORMAT_LIST()
assert processing_state_after.requests_count == processing_state_before.requests_count + 3
assert processing_state_after.requests_submitted == processing_state_before.requests_submitted + 3