|
14 | 14 | get_hashes_from_recent_block_hashes,
|
15 | 15 | get_hashes_to_sign,
|
16 | 16 | get_new_shuffling,
|
17 |
| - get_shards_committees_for_slot, |
| 17 | + _get_shard_committees_at_slot, |
18 | 18 | get_signed_parent_hashes,
|
19 | 19 | get_block_committees_info,
|
20 | 20 | )
|
|
24 | 24 | )
|
25 | 25 |
|
26 | 26 |
|
| 27 | +def get_sample_shard_committees_at_slots(num_slot, |
| 28 | + num_shard_committee_per_slot, |
| 29 | + sample_shard_committee_params): |
| 30 | + |
| 31 | + return tuple( |
| 32 | + [ |
| 33 | + [ |
| 34 | + ShardCommittee(**sample_shard_committee_params) |
| 35 | + for _ in range(num_shard_committee_per_slot) |
| 36 | + ] |
| 37 | + for _ in range(num_slot) |
| 38 | + ] |
| 39 | + ) |
| 40 | + |
| 41 | + |
27 | 42 | def generate_mock_recent_block_hashes(
|
28 | 43 | genesis_block,
|
29 | 44 | current_block_number,
|
@@ -202,39 +217,100 @@ def test_get_new_recent_block_hashes(genesis_block,
|
202 | 217 | #
|
203 | 218 | # Get shards_committees or indices
|
204 | 219 | #
|
205 |
| -@pytest.mark.xfail(reason="Need to be fixed") |
206 | 220 | @pytest.mark.parametrize(
|
207 | 221 | (
|
208 |
| - 'num_validators,slot,success' |
| 222 | + 'num_validators,' |
| 223 | + 'cycle_length,' |
| 224 | + 'latest_state_recalculation_slot,' |
| 225 | + 'num_slot,' |
| 226 | + 'num_shard_committee_per_slot,' |
| 227 | + 'slot,' |
| 228 | + 'success' |
209 | 229 | ),
|
210 | 230 | [
|
211 |
| - (100, 0, True), |
212 |
| - (100, 63, True), |
213 |
| - (100, 64, False), |
| 231 | + ( |
| 232 | + 100, |
| 233 | + 64, |
| 234 | + 0, |
| 235 | + 128, |
| 236 | + 10, |
| 237 | + 0, |
| 238 | + True, |
| 239 | + ), |
| 240 | + ( |
| 241 | + 100, |
| 242 | + 64, |
| 243 | + 64, |
| 244 | + 128, |
| 245 | + 10, |
| 246 | + 64, |
| 247 | + True, |
| 248 | + ), |
| 249 | + # The length of shard_committees_at_slots != epoch_length * 2 |
| 250 | + ( |
| 251 | + 100, |
| 252 | + 64, |
| 253 | + 64, |
| 254 | + 127, |
| 255 | + 10, |
| 256 | + 0, |
| 257 | + False, |
| 258 | + ), |
| 259 | + # slot is too small |
| 260 | + ( |
| 261 | + 100, |
| 262 | + 64, |
| 263 | + 128, |
| 264 | + 128, |
| 265 | + 10, |
| 266 | + 0, |
| 267 | + False, |
| 268 | + ), |
| 269 | + # slot is too large |
| 270 | + ( |
| 271 | + 100, |
| 272 | + 64, |
| 273 | + 0, |
| 274 | + 128, |
| 275 | + 10, |
| 276 | + 64, |
| 277 | + False, |
| 278 | + ), |
214 | 279 | ],
|
215 | 280 | )
|
216 | 281 | def test_get_shard_committee_for_slot(
|
217 |
| - genesis_crystallized_state, |
218 | 282 | num_validators,
|
| 283 | + cycle_length, |
| 284 | + latest_state_recalculation_slot, |
| 285 | + num_slot, |
| 286 | + num_shard_committee_per_slot, |
219 | 287 | slot,
|
220 | 288 | success,
|
221 |
| - epoch_length): |
222 |
| - crystallized_state = genesis_crystallized_state |
| 289 | + epoch_length, |
| 290 | + sample_shard_committee_params): |
| 291 | + |
| 292 | + shard_committees_at_slots = get_sample_shard_committees_at_slots( |
| 293 | + num_slot, |
| 294 | + num_shard_committee_per_slot, |
| 295 | + sample_shard_committee_params |
| 296 | + ) |
223 | 297 |
|
224 | 298 | if success:
|
225 |
| - shards_committees_for_slot = get_shards_committees_for_slot( |
226 |
| - crystallized_state, |
227 |
| - slot, |
228 |
| - epoch_length, |
| 299 | + shard_committees = _get_shard_committees_at_slot( |
| 300 | + latest_state_recalculation_slot=latest_state_recalculation_slot, |
| 301 | + shard_committees_at_slots=shard_committees_at_slots, |
| 302 | + slot=slot, |
| 303 | + epoch_length=epoch_length, |
229 | 304 | )
|
230 |
| - assert len(shards_committees_for_slot) > 0 |
231 |
| - assert len(shards_committees_for_slot[0].committee) > 0 |
| 305 | + assert len(shard_committees) > 0 |
| 306 | + assert len(shard_committees[0].committee) > 0 |
232 | 307 | else:
|
233 | 308 | with pytest.raises(ValueError):
|
234 |
| - get_shards_committees_for_slot( |
235 |
| - crystallized_state, |
236 |
| - slot, |
237 |
| - epoch_length, |
| 309 | + _get_shard_committees_at_slot( |
| 310 | + latest_state_recalculation_slot=latest_state_recalculation_slot, |
| 311 | + shard_committees_at_slots=shard_committees_at_slots, |
| 312 | + slot=slot, |
| 313 | + epoch_length=epoch_length, |
238 | 314 | )
|
239 | 315 |
|
240 | 316 |
|
@@ -363,17 +439,17 @@ def test_get_block_committees_info(monkeypatch,
|
363 | 439 | epoch_length):
|
364 | 440 | from eth.beacon import helpers
|
365 | 441 |
|
366 |
| - def mock_get_shards_committees_for_slot(parent_block, |
367 |
| - crystallized_state, |
368 |
| - epoch_length): |
| 442 | + def mock_get_shard_committees_at_slot(parent_block, |
| 443 | + crystallized_state, |
| 444 | + epoch_length): |
369 | 445 | return [
|
370 | 446 | ShardCommittee(shard_id=1, committee=committee),
|
371 | 447 | ]
|
372 | 448 |
|
373 | 449 | monkeypatch.setattr(
|
374 | 450 | helpers,
|
375 |
| - 'get_shards_committees_for_slot', |
376 |
| - mock_get_shards_committees_for_slot |
| 451 | + '_get_shard_committees_at_slot', |
| 452 | + mock__get_shard_committees_at_slot |
377 | 453 | )
|
378 | 454 |
|
379 | 455 | parent_block = genesis_block
|
|
0 commit comments