From 52983836109fabd75e142245f3f105cf82c54293 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Fri, 27 Mar 2026 13:41:28 -0500 Subject: [PATCH] In networking tests, yield values after mutating them --- .../test_gossip_beacon_aggregate_and_proof.py | 42 +++++++++---------- .../test_gossip_beacon_attestation.py | 32 +++++++------- .../networking/test_gossip_beacon_block.py | 20 ++++----- .../networking/test_gossip_voluntary_exit.py | 16 ++++--- 4 files changed, 54 insertions(+), 56 deletions(-) diff --git a/tests/core/pyspec/eth_consensus_specs/test/phase0/networking/test_gossip_beacon_aggregate_and_proof.py b/tests/core/pyspec/eth_consensus_specs/test/phase0/networking/test_gossip_beacon_aggregate_and_proof.py index 55636f003ce..64c59a05124 100644 --- a/tests/core/pyspec/eth_consensus_specs/test/phase0/networking/test_gossip_beacon_aggregate_and_proof.py +++ b/tests/core/pyspec/eth_consensus_specs/test/phase0/networking/test_gossip_beacon_aggregate_and_proof.py @@ -98,7 +98,6 @@ def test_gossip_beacon_aggregate_and_proof__valid(spec, state): Test that a valid aggregate and proof passes gossip validation. """ yield "topic", "meta", "beacon_aggregate_and_proof" - yield "state", state seen = get_seen(spec) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -109,6 +108,7 @@ def test_gossip_beacon_aggregate_and_proof__valid(spec, state): yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] next_slot(spec, state) + yield "state", state attestation = get_valid_attestation(spec, state, signed=True, beacon_block_root=anchor_root) signed_agg = create_signed_aggregate_and_proof(spec, state, attestation) @@ -139,7 +139,6 @@ def test_gossip_beacon_aggregate_and_proof__reject_committee_index_out_of_range( Test that an aggregate with committee index out of range is rejected. """ yield "topic", "meta", "beacon_aggregate_and_proof" - yield "state", state seen = get_seen(spec) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -150,6 +149,7 @@ def test_gossip_beacon_aggregate_and_proof__reject_committee_index_out_of_range( yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] next_slot(spec, state) + yield "state", state attestation = get_valid_attestation(spec, state, signed=True, beacon_block_root=anchor_root) signed_agg = create_signed_aggregate_and_proof(spec, state, attestation) @@ -191,7 +191,6 @@ def test_gossip_beacon_aggregate_and_proof__ignore_slot_not_within_range(spec, s Test that an aggregate from a slot too far in the future is ignored. """ yield "topic", "meta", "beacon_aggregate_and_proof" - yield "state", state seen = get_seen(spec) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -202,6 +201,7 @@ def test_gossip_beacon_aggregate_and_proof__ignore_slot_not_within_range(spec, s yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] next_slot(spec, state) + yield "state", state attestation = get_valid_attestation(spec, state, signed=True, beacon_block_root=anchor_root) signed_agg = create_signed_aggregate_and_proof(spec, state, attestation) @@ -241,7 +241,6 @@ def test_gossip_beacon_aggregate_and_proof__valid_within_clock_disparity(spec, s Test that an aggregate at exactly the clock disparity boundary is valid. """ yield "topic", "meta", "beacon_aggregate_and_proof" - yield "state", state seen = get_seen(spec) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -252,6 +251,7 @@ def test_gossip_beacon_aggregate_and_proof__valid_within_clock_disparity(spec, s yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] next_slot(spec, state) + yield "state", state attestation = get_valid_attestation(spec, state, signed=True, beacon_block_root=anchor_root) signed_agg = create_signed_aggregate_and_proof(spec, state, attestation) @@ -290,7 +290,6 @@ def test_gossip_beacon_aggregate_and_proof__reject_epoch_mismatch(spec, state): Test that an aggregate whose epoch doesn't match target is rejected. """ yield "topic", "meta", "beacon_aggregate_and_proof" - yield "state", state seen = get_seen(spec) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -301,6 +300,7 @@ def test_gossip_beacon_aggregate_and_proof__reject_epoch_mismatch(spec, state): yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] next_slot(spec, state) + yield "state", state attestation = get_valid_attestation(spec, state, signed=True, beacon_block_root=anchor_root) signed_agg = create_signed_aggregate_and_proof(spec, state, attestation) @@ -341,7 +341,6 @@ def test_gossip_beacon_aggregate_and_proof__ignore_already_seen_aggregate(spec, Test that a duplicate aggregate data root is ignored. """ yield "topic", "meta", "beacon_aggregate_and_proof" - yield "state", state messages = [] seen = get_seen(spec) @@ -353,6 +352,7 @@ def test_gossip_beacon_aggregate_and_proof__ignore_already_seen_aggregate(spec, yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] next_slot(spec, state) + yield "state", state attestation = get_valid_attestation(spec, state, signed=True, beacon_block_root=anchor_root) signed_agg = create_signed_aggregate_and_proof(spec, state, attestation) @@ -396,7 +396,6 @@ def test_gossip_beacon_aggregate_and_proof__ignore_same_data_root_without_supers a prior aggregate has a non-strict superset of aggregation bits. """ yield "topic", "meta", "beacon_aggregate_and_proof" - yield "state", state messages = [] seen = get_seen(spec) @@ -408,6 +407,7 @@ def test_gossip_beacon_aggregate_and_proof__ignore_same_data_root_without_supers yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] next_slot(spec, state) + yield "state", state attestation = get_valid_attestation( spec, @@ -486,7 +486,6 @@ def test_gossip_beacon_aggregate_and_proof__valid_two_aggregators_same_data(spec is already in seen.aggregate_data_roots). """ yield "topic", "meta", "beacon_aggregate_and_proof" - yield "state", state messages = [] seen = get_seen(spec) @@ -498,6 +497,7 @@ def test_gossip_beacon_aggregate_and_proof__valid_two_aggregators_same_data(spec yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] next_slot(spec, state) + yield "state", state # Create two attestations with different single-participant aggregation bits # so neither is a superset of the other @@ -568,7 +568,6 @@ def test_gossip_beacon_aggregate_and_proof__ignore_block_not_seen(spec, state): Test that an aggregate for an unseen block is ignored. """ yield "topic", "meta", "beacon_aggregate_and_proof" - yield "state", state seen = get_seen(spec) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -582,6 +581,7 @@ def test_gossip_beacon_aggregate_and_proof__ignore_block_not_seen(spec, state): # Build and apply a block (but don't add to store) block = build_empty_block_for_next_slot(spec, state) signed_block = state_transition_and_sign_block(spec, state, block) + yield "state", state # Create an attestation referencing the unseen block attestation = get_valid_attestation( @@ -622,7 +622,6 @@ def test_gossip_beacon_aggregate_and_proof__reject_aggregation_bits_size_mismatc Test that an aggregate with wrong aggregation bits size is rejected. """ yield "topic", "meta", "beacon_aggregate_and_proof" - yield "state", state seen = get_seen(spec) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -633,6 +632,7 @@ def test_gossip_beacon_aggregate_and_proof__reject_aggregation_bits_size_mismatc yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] next_slot(spec, state) + yield "state", state attestation = get_valid_attestation(spec, state, signed=True, beacon_block_root=anchor_root) signed_agg = create_signed_aggregate_and_proof(spec, state, attestation) @@ -679,7 +679,6 @@ def test_gossip_beacon_aggregate_and_proof__reject_no_participants(spec, state): Test that an aggregate with no participants is rejected. """ yield "topic", "meta", "beacon_aggregate_and_proof" - yield "state", state seen = get_seen(spec) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -690,6 +689,7 @@ def test_gossip_beacon_aggregate_and_proof__reject_no_participants(spec, state): yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] next_slot(spec, state) + yield "state", state attestation = get_valid_attestation(spec, state, signed=True, beacon_block_root=anchor_root) signed_agg = create_signed_aggregate_and_proof(spec, state, attestation) @@ -734,7 +734,6 @@ def test_gossip_beacon_aggregate_and_proof__ignore_already_seen_aggregator(spec, Test that a second aggregate from the same aggregator in the same epoch is ignored. """ yield "topic", "meta", "beacon_aggregate_and_proof" - yield "state", state messages = [] seen = get_seen(spec) @@ -746,6 +745,7 @@ def test_gossip_beacon_aggregate_and_proof__ignore_already_seen_aggregator(spec, yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] next_slot(spec, state) + yield "state", state attestation1 = get_valid_attestation(spec, state, signed=True, beacon_block_root=anchor_root) signed_agg1 = create_signed_aggregate_and_proof(spec, state, attestation1) @@ -804,7 +804,6 @@ def test_gossip_beacon_aggregate_and_proof__reject_not_aggregator(spec, state): Test that an aggregate from a validator not selected as aggregator is rejected. """ yield "topic", "meta", "beacon_aggregate_and_proof" - yield "state", state seen = get_seen(spec) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -815,6 +814,7 @@ def test_gossip_beacon_aggregate_and_proof__reject_not_aggregator(spec, state): yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] next_slot(spec, state) + yield "state", state # Search for a non-aggregator at the current slot across all committees non_aggregator_index = None @@ -886,7 +886,6 @@ def test_gossip_beacon_aggregate_and_proof__reject_aggregator_not_in_committee(s Test that an aggregate from a validator not in the committee is rejected. """ yield "topic", "meta", "beacon_aggregate_and_proof" - yield "state", state seen = get_seen(spec) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -897,6 +896,7 @@ def test_gossip_beacon_aggregate_and_proof__reject_aggregator_not_in_committee(s yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] next_slot(spec, state) + yield "state", state attestation = get_valid_attestation(spec, state, signed=True, beacon_block_root=anchor_root) signed_agg = create_signed_aggregate_and_proof(spec, state, attestation) @@ -945,7 +945,6 @@ def test_gossip_beacon_aggregate_and_proof__reject_aggregator_index_out_of_range Test that an aggregate with out-of-range aggregator index is rejected. """ yield "topic", "meta", "beacon_aggregate_and_proof" - yield "state", state seen = get_seen(spec) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -956,6 +955,7 @@ def test_gossip_beacon_aggregate_and_proof__reject_aggregator_index_out_of_range yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] next_slot(spec, state) + yield "state", state attestation = get_valid_attestation(spec, state, signed=True, beacon_block_root=anchor_root) signed_agg = create_signed_aggregate_and_proof(spec, state, attestation) @@ -996,7 +996,6 @@ def test_gossip_beacon_aggregate_and_proof__reject_invalid_selection_proof(spec, Test that an aggregate with invalid selection proof signature is rejected. """ yield "topic", "meta", "beacon_aggregate_and_proof" - yield "state", state seen = get_seen(spec) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -1007,6 +1006,7 @@ def test_gossip_beacon_aggregate_and_proof__reject_invalid_selection_proof(spec, yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] next_slot(spec, state) + yield "state", state attestation = get_valid_attestation(spec, state, signed=True, beacon_block_root=anchor_root) signed_agg = create_signed_aggregate_and_proof(spec, state, attestation) @@ -1048,7 +1048,6 @@ def test_gossip_beacon_aggregate_and_proof__reject_invalid_aggregator_signature( Test that an aggregate with invalid aggregator signature is rejected. """ yield "topic", "meta", "beacon_aggregate_and_proof" - yield "state", state seen = get_seen(spec) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -1059,6 +1058,7 @@ def test_gossip_beacon_aggregate_and_proof__reject_invalid_aggregator_signature( yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] next_slot(spec, state) + yield "state", state attestation = get_valid_attestation(spec, state, signed=True, beacon_block_root=anchor_root) signed_agg = create_signed_aggregate_and_proof(spec, state, attestation) @@ -1100,7 +1100,6 @@ def test_gossip_beacon_aggregate_and_proof__reject_invalid_aggregate_signature(s Test that an aggregate with invalid aggregate attestation signature is rejected. """ yield "topic", "meta", "beacon_aggregate_and_proof" - yield "state", state seen = get_seen(spec) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -1111,6 +1110,7 @@ def test_gossip_beacon_aggregate_and_proof__reject_invalid_aggregate_signature(s yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] next_slot(spec, state) + yield "state", state # Create an attestation with INVALID signature BEFORE creating the aggregate attestation = get_valid_attestation(spec, state, signed=False, beacon_block_root=anchor_root) @@ -1151,7 +1151,6 @@ def test_gossip_beacon_aggregate_and_proof__reject_block_failed_validation(spec, Test that an aggregate for a block that failed validation is rejected. """ yield "topic", "meta", "beacon_aggregate_and_proof" - yield "state", state seen = get_seen(spec) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -1164,6 +1163,7 @@ def test_gossip_beacon_aggregate_and_proof__reject_block_failed_validation(spec, # Build and apply a block block = build_empty_block_for_next_slot(spec, state) signed_block = state_transition_and_sign_block(spec, state, block) + yield "state", state yield get_filename(signed_block), signed_block @@ -1215,7 +1215,6 @@ def test_gossip_beacon_aggregate_and_proof__reject_target_not_ancestor(spec, sta Test that an aggregate whose target is not an ancestor of the LMD vote block is rejected. """ yield "topic", "meta", "beacon_aggregate_and_proof" - yield "state", state seen = get_seen(spec) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -1226,6 +1225,7 @@ def test_gossip_beacon_aggregate_and_proof__reject_target_not_ancestor(spec, sta yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] next_slot(spec, state) + yield "state", state # Create an attestation with wrong target root BEFORE signing attestation = get_valid_attestation(spec, state, signed=False, beacon_block_root=anchor_root) @@ -1267,7 +1267,6 @@ def test_gossip_beacon_aggregate_and_proof__ignore_finalized_not_ancestor(spec, Test that an aggregate for a block not descending from finalized checkpoint is ignored. """ yield "topic", "meta", "beacon_aggregate_and_proof" - yield "state", state seen = get_seen(spec) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -1278,6 +1277,7 @@ def test_gossip_beacon_aggregate_and_proof__ignore_finalized_not_ancestor(spec, yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] next_slot(spec, state) + yield "state", state attestation = get_valid_attestation(spec, state, signed=True, beacon_block_root=anchor_root) signed_agg = create_signed_aggregate_and_proof(spec, state, attestation) diff --git a/tests/core/pyspec/eth_consensus_specs/test/phase0/networking/test_gossip_beacon_attestation.py b/tests/core/pyspec/eth_consensus_specs/test/phase0/networking/test_gossip_beacon_attestation.py index 751f9b8d9cf..60d8f48fe33 100644 --- a/tests/core/pyspec/eth_consensus_specs/test/phase0/networking/test_gossip_beacon_attestation.py +++ b/tests/core/pyspec/eth_consensus_specs/test/phase0/networking/test_gossip_beacon_attestation.py @@ -60,7 +60,6 @@ def test_gossip_beacon_attestation__valid(spec, state): Test that a valid unaggregated attestation passes gossip validation. """ yield "topic", "meta", "beacon_attestation" - yield "state", state seen = get_seen(spec) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -71,6 +70,7 @@ def test_gossip_beacon_attestation__valid(spec, state): yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] next_slot(spec, state) + yield "state", state # Create an unaggregated attestation (single validator) referencing anchor block attestation = get_valid_attestation( @@ -120,7 +120,6 @@ def test_gossip_beacon_attestation__reject_committee_index_out_of_range(spec, st Test that an attestation with committee index out of range is rejected. """ yield "topic", "meta", "beacon_attestation" - yield "state", state seen = get_seen(spec) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -131,6 +130,7 @@ def test_gossip_beacon_attestation__reject_committee_index_out_of_range(spec, st yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] next_slot(spec, state) + yield "state", state attestation = get_valid_attestation(spec, state, signed=True, beacon_block_root=anchor_root) @@ -173,7 +173,6 @@ def test_gossip_beacon_attestation__reject_wrong_subnet(spec, state): Test that an attestation sent to the wrong subnet is rejected. """ yield "topic", "meta", "beacon_attestation" - yield "state", state seen = get_seen(spec) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -184,6 +183,7 @@ def test_gossip_beacon_attestation__reject_wrong_subnet(spec, state): yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] next_slot(spec, state) + yield "state", state attestation = get_valid_attestation(spec, state, signed=True, beacon_block_root=anchor_root) @@ -224,7 +224,6 @@ def test_gossip_beacon_attestation__ignore_slot_not_in_range(spec, state): Test that an attestation with slot not in propagation range is ignored. """ yield "topic", "meta", "beacon_attestation" - yield "state", state seen = get_seen(spec) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -235,6 +234,7 @@ def test_gossip_beacon_attestation__ignore_slot_not_in_range(spec, state): yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] next_slot(spec, state) + yield "state", state # Create an unaggregated attestation referencing anchor block attestation = get_valid_attestation(spec, state, signed=False, beacon_block_root=anchor_root) @@ -285,7 +285,6 @@ def test_gossip_beacon_attestation__valid_within_clock_disparity(spec, state): Test that an attestation at exactly the clock disparity boundary is valid. """ yield "topic", "meta", "beacon_attestation" - yield "state", state seen = get_seen(spec) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -296,6 +295,7 @@ def test_gossip_beacon_attestation__valid_within_clock_disparity(spec, state): yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] next_slot(spec, state) + yield "state", state # Create an unaggregated attestation referencing anchor block attestation = get_valid_attestation(spec, state, signed=False, beacon_block_root=anchor_root) @@ -345,7 +345,6 @@ def test_gossip_beacon_attestation__valid_within_clock_disparity_old(spec, state Test that an attestation at exactly the old boundary (expiry + clock disparity) is still valid. """ yield "topic", "meta", "beacon_attestation" - yield "state", state seen = get_seen(spec) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -356,6 +355,7 @@ def test_gossip_beacon_attestation__valid_within_clock_disparity_old(spec, state yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] next_slot(spec, state) + yield "state", state # Create an unaggregated attestation referencing anchor block attestation = get_valid_attestation(spec, state, signed=False, beacon_block_root=anchor_root) @@ -407,7 +407,6 @@ def test_gossip_beacon_attestation__ignore_slot_too_old(spec, state): Test that an attestation that is too old (past propagation range + clock disparity) is ignored. """ yield "topic", "meta", "beacon_attestation" - yield "state", state seen = get_seen(spec) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -418,6 +417,7 @@ def test_gossip_beacon_attestation__ignore_slot_too_old(spec, state): yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] next_slot(spec, state) + yield "state", state # Create an unaggregated attestation referencing anchor block attestation = get_valid_attestation(spec, state, signed=False, beacon_block_root=anchor_root) @@ -470,7 +470,6 @@ def test_gossip_beacon_attestation__reject_epoch_mismatch(spec, state): Test that an attestation with mismatched epoch and target is rejected. """ yield "topic", "meta", "beacon_attestation" - yield "state", state seen = get_seen(spec) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -481,6 +480,7 @@ def test_gossip_beacon_attestation__reject_epoch_mismatch(spec, state): yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] next_slot(spec, state) + yield "state", state attestation = get_valid_attestation(spec, state, signed=True, beacon_block_root=anchor_root) @@ -522,7 +522,6 @@ def test_gossip_beacon_attestation__reject_not_unaggregated(spec, state): Test that an aggregated attestation (more than one bit set) is rejected. """ yield "topic", "meta", "beacon_attestation" - yield "state", state seen = get_seen(spec) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -533,6 +532,7 @@ def test_gossip_beacon_attestation__reject_not_unaggregated(spec, state): yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] next_slot(spec, state) + yield "state", state # Create an attestation with multiple bits set (aggregated) referencing anchor block attestation = get_valid_attestation(spec, state, signed=True, beacon_block_root=anchor_root) @@ -580,7 +580,6 @@ def test_gossip_beacon_attestation__reject_aggregation_bits_size_mismatch(spec, Test that an attestation with wrong aggregation bits size is rejected. """ yield "topic", "meta", "beacon_attestation" - yield "state", state seen = get_seen(spec) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -591,6 +590,7 @@ def test_gossip_beacon_attestation__reject_aggregation_bits_size_mismatch(spec, yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] next_slot(spec, state) + yield "state", state attestation = get_valid_attestation(spec, state, signed=True, beacon_block_root=anchor_root) @@ -636,7 +636,6 @@ def test_gossip_beacon_attestation__ignore_already_seen(spec, state): Test that a duplicate attestation from same validator/epoch is ignored. """ yield "topic", "meta", "beacon_attestation" - yield "state", state messages = [] seen = get_seen(spec) @@ -648,6 +647,7 @@ def test_gossip_beacon_attestation__ignore_already_seen(spec, state): yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] next_slot(spec, state) + yield "state", state # Create an unaggregated attestation referencing anchor block attestation = get_valid_attestation(spec, state, signed=False, beacon_block_root=anchor_root) @@ -709,7 +709,6 @@ def test_gossip_beacon_attestation__ignore_block_not_seen(spec, state): Test that an attestation for an unseen block is ignored. """ yield "topic", "meta", "beacon_attestation" - yield "state", state seen = get_seen(spec) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -723,6 +722,7 @@ def test_gossip_beacon_attestation__ignore_block_not_seen(spec, state): # Build and apply a block (but don't add to store) block = build_empty_block_for_next_slot(spec, state) state_transition_and_sign_block(spec, state, block) + yield "state", state # Create an attestation for the block that's not in store attestation = get_valid_attestation(spec, state, signed=False) @@ -771,7 +771,6 @@ def test_gossip_beacon_attestation__reject_block_failed_validation(spec, state): Test that an attestation for a block that failed validation is rejected. """ yield "topic", "meta", "beacon_attestation" - yield "state", state seen = get_seen(spec) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -784,6 +783,7 @@ def test_gossip_beacon_attestation__reject_block_failed_validation(spec, state): # Build and apply a block block = build_empty_block_for_next_slot(spec, state) signed_block = state_transition_and_sign_block(spec, state, block) + yield "state", state yield get_filename(signed_block), signed_block @@ -847,7 +847,6 @@ def test_gossip_beacon_attestation__reject_invalid_signature(spec, state): Test that an attestation with invalid signature is rejected. """ yield "topic", "meta", "beacon_attestation" - yield "state", state seen = get_seen(spec) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -858,6 +857,7 @@ def test_gossip_beacon_attestation__reject_invalid_signature(spec, state): yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] next_slot(spec, state) + yield "state", state # Create an attestation without signing, referencing anchor block attestation = get_valid_attestation(spec, state, signed=False, beacon_block_root=anchor_root) @@ -905,7 +905,6 @@ def test_gossip_beacon_attestation__reject_target_not_ancestor(spec, state): Test that an attestation whose target is not an ancestor of LMD vote is rejected. """ yield "topic", "meta", "beacon_attestation" - yield "state", state seen = get_seen(spec) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -916,6 +915,7 @@ def test_gossip_beacon_attestation__reject_target_not_ancestor(spec, state): yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] next_slot(spec, state) + yield "state", state # Create an attestation with wrong target root, referencing anchor block attestation = get_valid_attestation(spec, state, signed=False, beacon_block_root=anchor_root) @@ -966,7 +966,6 @@ def test_gossip_beacon_attestation__ignore_finalized_not_ancestor(spec, state): Test that an attestation for a block not descending from finalized checkpoint is ignored. """ yield "topic", "meta", "beacon_attestation" - yield "state", state seen = get_seen(spec) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -979,6 +978,7 @@ def test_gossip_beacon_attestation__ignore_finalized_not_ancestor(spec, state): # Build and apply a block block = build_empty_block_for_next_slot(spec, state) signed_block = state_transition_and_sign_block(spec, state, block) + yield "state", state yield get_filename(signed_block), signed_block diff --git a/tests/core/pyspec/eth_consensus_specs/test/phase0/networking/test_gossip_beacon_block.py b/tests/core/pyspec/eth_consensus_specs/test/phase0/networking/test_gossip_beacon_block.py index 6e21d2c8085..2e153dbb049 100644 --- a/tests/core/pyspec/eth_consensus_specs/test/phase0/networking/test_gossip_beacon_block.py +++ b/tests/core/pyspec/eth_consensus_specs/test/phase0/networking/test_gossip_beacon_block.py @@ -44,7 +44,6 @@ def test_gossip_beacon_block__valid_block(spec, state): Test that a valid block passes gossip validation. """ yield "topic", "meta", "beacon_block" - yield "state", state seen = get_seen(spec) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -55,6 +54,7 @@ def test_gossip_beacon_block__valid_block(spec, state): block = build_empty_block_for_next_slot(spec, state) signed_block = state_transition_and_sign_block(spec, state, block) + yield "state", state yield get_filename(signed_block), signed_block @@ -82,7 +82,6 @@ def test_gossip_beacon_block__ignore_future_slot(spec, state): Test that a block from a future slot is ignored. """ yield "topic", "meta", "beacon_block" - yield "state", state seen = get_seen(spec) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -93,6 +92,7 @@ def test_gossip_beacon_block__ignore_future_slot(spec, state): block = build_empty_block_for_next_slot(spec, state) signed_block = state_transition_and_sign_block(spec, state, block) + yield "state", state yield get_filename(signed_block), signed_block @@ -128,7 +128,6 @@ def test_gossip_beacon_block__valid_within_clock_disparity(spec, state): Test that a block from a slightly future slot is valid within clock disparity. """ yield "topic", "meta", "beacon_block" - yield "state", state seen = get_seen(spec) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -139,6 +138,7 @@ def test_gossip_beacon_block__valid_within_clock_disparity(spec, state): block = build_empty_block_for_next_slot(spec, state) signed_block = state_transition_and_sign_block(spec, state, block) + yield "state", state yield get_filename(signed_block), signed_block @@ -167,7 +167,6 @@ def test_gossip_beacon_block__ignore_already_seen_proposer_slot(spec, state): Test that a duplicate block for the same proposer/slot is ignored. """ yield "topic", "meta", "beacon_block" - yield "state", state messages = [] seen = get_seen(spec) @@ -179,6 +178,7 @@ def test_gossip_beacon_block__ignore_already_seen_proposer_slot(spec, state): block = build_empty_block_for_next_slot(spec, state) signed_block = state_transition_and_sign_block(spec, state, block) + yield "state", state yield get_filename(signed_block), signed_block @@ -291,7 +291,6 @@ def test_gossip_beacon_block__ignore_parent_not_seen(spec, state): Test that a block whose parent is not in the store is ignored. """ yield "topic", "meta", "beacon_block" - yield "state", state seen = get_seen(spec) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -302,6 +301,7 @@ def test_gossip_beacon_block__ignore_parent_not_seen(spec, state): block = build_empty_block_for_next_slot(spec, state) signed_block = state_transition_and_sign_block(spec, state, block) + yield "state", state # Modify parent_root to something unknown signed_block.message.parent_root = b"\x12" * 32 @@ -347,7 +347,6 @@ def test_gossip_beacon_block__reject_parent_failed_validation(spec, state): This happens when parent is in store.blocks but not in store.block_states. """ yield "topic", "meta", "beacon_block" - yield "state", state seen = get_seen(spec) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -357,6 +356,7 @@ def test_gossip_beacon_block__reject_parent_failed_validation(spec, state): block = build_empty_block_for_next_slot(spec, state) signed_block = state_transition_and_sign_block(spec, state, block) + yield "state", state yield get_filename(signed_block), signed_block @@ -420,7 +420,6 @@ def test_gossip_beacon_block__reject_slot_not_higher_than_parent(spec, state): Test that a block with slot <= parent slot is rejected. """ yield "topic", "meta", "beacon_block" - yield "state", state seen = get_seen(spec) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -431,6 +430,7 @@ def test_gossip_beacon_block__reject_slot_not_higher_than_parent(spec, state): # First, build and add a valid block at slot 1 to be our parent parent_block = build_empty_block_for_next_slot(spec, state) signed_parent = state_transition_and_sign_block(spec, state, parent_block) + yield "state", state yield get_filename(signed_parent), signed_parent @@ -492,7 +492,6 @@ def test_gossip_beacon_block__reject_finalized_checkpoint_not_ancestor(spec, sta Test that a block whose finalized checkpoint is not an ancestor is rejected. """ yield "topic", "meta", "beacon_block" - yield "state", state seen = get_seen(spec) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -502,6 +501,7 @@ def test_gossip_beacon_block__reject_finalized_checkpoint_not_ancestor(spec, sta block = build_empty_block_for_next_slot(spec, state) signed_block = state_transition_and_sign_block(spec, state, block) + yield "state", state yield get_filename(signed_block), signed_block @@ -576,7 +576,6 @@ def test_gossip_beacon_block__reject_invalid_proposer_signature(spec, state): Test that a block with an invalid proposer signature is rejected. """ yield "topic", "meta", "beacon_block" - yield "state", state seen = get_seen(spec) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -587,6 +586,7 @@ def test_gossip_beacon_block__reject_invalid_proposer_signature(spec, state): block = build_empty_block_for_next_slot(spec, state) signed_block = state_transition_and_sign_block(spec, state, block) + yield "state", state # Corrupt the signature signed_block.signature = b"\x00" * 96 @@ -624,7 +624,6 @@ def test_gossip_beacon_block__reject_invalid_proposer_index(spec, state): Test that a block with an out-of-range proposer_index is rejected. """ yield "topic", "meta", "beacon_block" - yield "state", state seen = get_seen(spec) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) @@ -635,6 +634,7 @@ def test_gossip_beacon_block__reject_invalid_proposer_index(spec, state): block = build_empty_block_for_next_slot(spec, state) signed_block = state_transition_and_sign_block(spec, state, block) + yield "state", state # Set proposer index to an invalid value. signed_block.message.proposer_index = len(state.validators) diff --git a/tests/core/pyspec/eth_consensus_specs/test/phase0/networking/test_gossip_voluntary_exit.py b/tests/core/pyspec/eth_consensus_specs/test/phase0/networking/test_gossip_voluntary_exit.py index 53dfa307b3b..a472d385c5c 100644 --- a/tests/core/pyspec/eth_consensus_specs/test/phase0/networking/test_gossip_voluntary_exit.py +++ b/tests/core/pyspec/eth_consensus_specs/test/phase0/networking/test_gossip_voluntary_exit.py @@ -53,9 +53,8 @@ def test_gossip_voluntary_exit__valid(spec, state): seen = get_seen(spec) - # Advance state past SHARD_COMMITTEE_PERIOD so validators can exit + # Advance state past SHARD_COMMITTEE_PERIOD state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH - yield "state", state # Pick a validator to exit @@ -86,7 +85,6 @@ def test_gossip_voluntary_exit__ignore_already_seen(spec, state): # Advance state past SHARD_COMMITTEE_PERIOD state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH - yield "state", state # Pick a validator to exit @@ -119,12 +117,12 @@ def test_gossip_voluntary_exit__reject_validator_index_out_of_range(spec, state) Test that a voluntary exit with validator index out of range is rejected. """ yield "topic", "meta", "voluntary_exit" - yield "state", state seen = get_seen(spec) # Advance state past SHARD_COMMITTEE_PERIOD state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH + yield "state", state # Create voluntary exit with invalid validator index invalid_index = len(state.validators) + 100 @@ -155,7 +153,6 @@ def test_gossip_voluntary_exit__reject_validator_not_active(spec, state): Test that a voluntary exit for a non-active validator is rejected. """ yield "topic", "meta", "voluntary_exit" - yield "state", state seen = get_seen(spec) @@ -165,6 +162,7 @@ def test_gossip_voluntary_exit__reject_validator_not_active(spec, state): # Pick a validator and make it inactive by setting activation_epoch to far future validator_index = 0 state.validators[validator_index].activation_epoch = spec.FAR_FUTURE_EPOCH + yield "state", state # Create voluntary exit signed_exit = create_signed_voluntary_exit(spec, state, validator_index) @@ -189,7 +187,6 @@ def test_gossip_voluntary_exit__reject_already_initiated_exit(spec, state): Test that a voluntary exit for a validator that has already initiated exit is rejected. """ yield "topic", "meta", "voluntary_exit" - yield "state", state seen = get_seen(spec) @@ -199,6 +196,7 @@ def test_gossip_voluntary_exit__reject_already_initiated_exit(spec, state): # Pick a validator and set their exit_epoch (simulating already initiated exit) validator_index = 0 state.validators[validator_index].exit_epoch = spec.get_current_epoch(state) + 10 + yield "state", state # Create voluntary exit signed_exit = create_signed_voluntary_exit(spec, state, validator_index) @@ -223,12 +221,12 @@ def test_gossip_voluntary_exit__reject_epoch_in_future(spec, state): Test that a voluntary exit with epoch in the future is rejected. """ yield "topic", "meta", "voluntary_exit" - yield "state", state seen = get_seen(spec) # Advance state past SHARD_COMMITTEE_PERIOD state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH + yield "state", state # Pick a validator validator_index = 0 @@ -257,7 +255,6 @@ def test_gossip_voluntary_exit__reject_not_active_long_enough(spec, state): Test that a voluntary exit for a validator not active long enough is rejected. """ yield "topic", "meta", "voluntary_exit" - yield "state", state seen = get_seen(spec) @@ -265,6 +262,7 @@ def test_gossip_voluntary_exit__reject_not_active_long_enough(spec, state): # Just advance a few epochs next_epoch_via_block(spec, state) next_epoch_via_block(spec, state) + yield "state", state # Pick a validator validator_index = 0 @@ -293,12 +291,12 @@ def test_gossip_voluntary_exit__reject_invalid_signature(spec, state): Test that a voluntary exit with invalid signature is rejected. """ yield "topic", "meta", "voluntary_exit" - yield "state", state seen = get_seen(spec) # Advance state past SHARD_COMMITTEE_PERIOD state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH + yield "state", state # Pick a validator validator_index = 0