|
27 | 27 | 'min_attestation_inclusion_delay,'
|
28 | 28 | 'target_committee_size,'
|
29 | 29 | 'shard_count,'
|
| 30 | + 'success,' |
30 | 31 | ),
|
31 | 32 | [
|
32 |
| - (10, 2, 1, 2, 2), |
33 |
| - (40, 4, 2, 3, 5), |
| 33 | + (10, 2, 1, 2, 2, True), |
| 34 | + (10, 2, 1, 2, 2, False), |
| 35 | + (40, 4, 2, 3, 5, True), |
34 | 36 | ]
|
35 | 37 | )
|
36 | 38 | def test_process_attestations(genesis_state,
|
37 | 39 | sample_attestation_data_params,
|
38 | 40 | sample_beacon_block_params,
|
39 | 41 | sample_beacon_block_body_params,
|
40 | 42 | config,
|
41 |
| - create_mock_signed_attestation): |
| 43 | + create_mock_signed_attestation, |
| 44 | + success): |
42 | 45 |
|
43 | 46 | attestation_slot = 0
|
44 | 47 | current_slot = attestation_slot + config.MIN_ATTESTATION_INCLUSION_DELAY
|
@@ -77,17 +80,40 @@ def test_process_attestations(genesis_state,
|
77 | 80 |
|
78 | 81 | assert len(attestations) > 0
|
79 | 82 |
|
| 83 | + if not success: |
| 84 | + # create invalid attestation in the future |
| 85 | + bad_attestation_data = AttestationData(**sample_attestation_data_params).copy( |
| 86 | + slot=state.slot + 10, |
| 87 | + ) |
| 88 | + attestations.append( |
| 89 | + create_mock_signed_attestation( |
| 90 | + state, |
| 91 | + state.shard_committees_at_slots[attestation_slot][0], |
| 92 | + [0], |
| 93 | + bad_attestation_data, |
| 94 | + ) |
| 95 | + ) |
| 96 | + |
80 | 97 | block_body = BeaconBlockBody(**sample_beacon_block_body_params).copy(
|
81 | 98 | attestations=attestations,
|
82 | 99 | )
|
83 | 100 | block = BaseBeaconBlock(**sample_beacon_block_params).copy(
|
84 | 101 | slot=current_slot,
|
85 | 102 | body=block_body
|
86 | 103 | )
|
87 |
| - new_state = process_attestations( |
88 |
| - state, |
89 |
| - block, |
90 |
| - config |
91 |
| - ) |
92 | 104 |
|
93 |
| - assert len(new_state.latest_attestations) == len(attestations) |
| 105 | + if success: |
| 106 | + new_state = process_attestations( |
| 107 | + state, |
| 108 | + block, |
| 109 | + config |
| 110 | + ) |
| 111 | + |
| 112 | + assert len(new_state.latest_attestations) == len(attestations) |
| 113 | + else: |
| 114 | + with pytest.raises(ValidationError): |
| 115 | + new_state = process_attestations( |
| 116 | + state, |
| 117 | + block, |
| 118 | + config |
| 119 | + ) |
0 commit comments