Skip to content

Commit 4bf22ed

Browse files
committed
test failure of process_attestations
1 parent 0fe34a3 commit 4bf22ed

File tree

1 file changed

+35
-9
lines changed

1 file changed

+35
-9
lines changed

tests/beacon/state_machines/test_serenity_operations.py

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,21 @@
2727
'min_attestation_inclusion_delay,'
2828
'target_committee_size,'
2929
'shard_count,'
30+
'success,'
3031
),
3132
[
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),
3436
]
3537
)
3638
def test_process_attestations(genesis_state,
3739
sample_attestation_data_params,
3840
sample_beacon_block_params,
3941
sample_beacon_block_body_params,
4042
config,
41-
create_mock_signed_attestation):
43+
create_mock_signed_attestation,
44+
success):
4245

4346
attestation_slot = 0
4447
current_slot = attestation_slot + config.MIN_ATTESTATION_INCLUSION_DELAY
@@ -77,17 +80,40 @@ def test_process_attestations(genesis_state,
7780

7881
assert len(attestations) > 0
7982

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+
8097
block_body = BeaconBlockBody(**sample_beacon_block_body_params).copy(
8198
attestations=attestations,
8299
)
83100
block = BaseBeaconBlock(**sample_beacon_block_params).copy(
84101
slot=current_slot,
85102
body=block_body
86103
)
87-
new_state = process_attestations(
88-
state,
89-
block,
90-
config
91-
)
92104

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

Comments
 (0)