Skip to content

Commit 2d211d2

Browse files
committed
Initial commit
1 parent 0039e60 commit 2d211d2

File tree

3 files changed

+42
-41
lines changed

3 files changed

+42
-41
lines changed

tests/core/pubsub/test_gossipsub.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ async def test_sparse_connect():
604604
async def test_connect_some_with_fewer_hosts_than_degree():
605605
"""Test connect_some when there are fewer hosts than degree."""
606606
# Create 3 hosts with degree=5
607-
async with PubsubFactory.create_batch_with_floodsub(3) as pubsubs_fsub:
607+
async with PubsubFactory.create_batch_with_gossipsub(3) as pubsubs_fsub:
608608
hosts = [pubsub.host for pubsub in pubsubs_fsub]
609609
degree = 5
610610

@@ -625,7 +625,7 @@ async def test_connect_some_with_fewer_hosts_than_degree():
625625
async def test_connect_some_degree_limit_enforced():
626626
"""Test that connect_some enforces degree limits and creates expected topology."""
627627
# Test with small network where we can verify exact behavior
628-
async with PubsubFactory.create_batch_with_floodsub(6) as pubsubs_fsub:
628+
async with PubsubFactory.create_batch_with_gossipsub(6) as pubsubs_fsub:
629629
hosts = [pubsub.host for pubsub in pubsubs_fsub]
630630
degree = 2
631631

@@ -673,7 +673,7 @@ async def test_connect_some_degree_limit_enforced():
673673
async def test_connect_some_degree_zero():
674674
"""Test edge case: degree=0 should result in no connections."""
675675
# Create 5 hosts with degree=0
676-
async with PubsubFactory.create_batch_with_floodsub(5) as pubsubs_fsub:
676+
async with PubsubFactory.create_batch_with_gossipsub(5) as pubsubs_fsub:
677677
hosts = [pubsub.host for pubsub in pubsubs_fsub]
678678
degree = 0
679679

@@ -693,7 +693,7 @@ async def test_connect_some_degree_zero():
693693
async def test_connect_some_negative_degree():
694694
"""Test edge case: negative degree should be handled gracefully."""
695695
# Create 5 hosts with degree=-1
696-
async with PubsubFactory.create_batch_with_floodsub(5) as pubsubs_fsub:
696+
async with PubsubFactory.create_batch_with_gossipsub(5) as pubsubs_fsub:
697697
hosts = [pubsub.host for pubsub in pubsubs_fsub]
698698
degree = -1
699699

@@ -712,7 +712,7 @@ async def test_connect_some_negative_degree():
712712
@pytest.mark.trio
713713
async def test_sparse_connect_degree_zero():
714714
"""Test sparse_connect with degree=0."""
715-
async with PubsubFactory.create_batch_with_floodsub(8) as pubsubs_fsub:
715+
async with PubsubFactory.create_batch_with_gossipsub(8) as pubsubs_fsub:
716716
hosts = [pubsub.host for pubsub in pubsubs_fsub]
717717
degree = 0
718718

@@ -748,7 +748,7 @@ async def test_empty_host_list():
748748
@pytest.mark.trio
749749
async def test_single_host():
750750
"""Test edge case: single host should be handled gracefully."""
751-
async with PubsubFactory.create_batch_with_floodsub(1) as pubsubs_fsub:
751+
async with PubsubFactory.create_batch_with_gossipsub(1) as pubsubs_fsub:
752752
hosts = [pubsub.host for pubsub in pubsubs_fsub]
753753

754754
# All functions should handle single host gracefully

tests/core/pubsub/test_pubsub.py

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555

5656
@pytest.mark.trio
5757
async def test_subscribe_and_unsubscribe():
58-
async with PubsubFactory.create_batch_with_floodsub(1) as pubsubs_fsub:
58+
async with PubsubFactory.create_batch_with_gossipsub(1) as pubsubs_fsub:
5959
await pubsubs_fsub[0].subscribe(TESTING_TOPIC)
6060
assert TESTING_TOPIC in pubsubs_fsub[0].topic_ids
6161

@@ -65,7 +65,7 @@ async def test_subscribe_and_unsubscribe():
6565

6666
@pytest.mark.trio
6767
async def test_re_subscribe():
68-
async with PubsubFactory.create_batch_with_floodsub(1) as pubsubs_fsub:
68+
async with PubsubFactory.create_batch_with_gossipsub(1) as pubsubs_fsub:
6969
await pubsubs_fsub[0].subscribe(TESTING_TOPIC)
7070
assert TESTING_TOPIC in pubsubs_fsub[0].topic_ids
7171

@@ -75,7 +75,7 @@ async def test_re_subscribe():
7575

7676
@pytest.mark.trio
7777
async def test_re_unsubscribe():
78-
async with PubsubFactory.create_batch_with_floodsub(1) as pubsubs_fsub:
78+
async with PubsubFactory.create_batch_with_gossipsub(1) as pubsubs_fsub:
7979
# Unsubscribe from topic we didn't even subscribe to
8080
assert "NOT_MY_TOPIC" not in pubsubs_fsub[0].topic_ids
8181
await pubsubs_fsub[0].unsubscribe("NOT_MY_TOPIC")
@@ -93,7 +93,7 @@ async def test_re_unsubscribe():
9393

9494
@pytest.mark.trio
9595
async def test_reissue_when_listen_addrs_change():
96-
async with PubsubFactory.create_batch_with_floodsub(2) as pubsubs_fsub:
96+
async with PubsubFactory.create_batch_with_gossipsub(2) as pubsubs_fsub:
9797
await connect(pubsubs_fsub[0].host, pubsubs_fsub[1].host)
9898
await pubsubs_fsub[0].subscribe(TESTING_TOPIC)
9999
# Yield to let 0 notify 1
@@ -132,7 +132,7 @@ async def test_reissue_when_listen_addrs_change():
132132

133133
@pytest.mark.trio
134134
async def test_peers_subscribe():
135-
async with PubsubFactory.create_batch_with_floodsub(2) as pubsubs_fsub:
135+
async with PubsubFactory.create_batch_with_gossipsub(2) as pubsubs_fsub:
136136
await connect(pubsubs_fsub[0].host, pubsubs_fsub[1].host)
137137
await pubsubs_fsub[0].subscribe(TESTING_TOPIC)
138138
# Yield to let 0 notify 1
@@ -166,7 +166,7 @@ async def test_peers_subscribe():
166166

167167
@pytest.mark.trio
168168
async def test_peer_subscribe_fail_upon_invald_record_transfer():
169-
async with PubsubFactory.create_batch_with_floodsub(2) as pubsubs_fsub:
169+
async with PubsubFactory.create_batch_with_gossipsub(2) as pubsubs_fsub:
170170
await connect(pubsubs_fsub[0].host, pubsubs_fsub[1].host)
171171

172172
# Corrupt host_a's local peer record
@@ -206,7 +206,7 @@ async def test_peer_subscribe_fail_upon_invald_record_transfer():
206206

207207
@pytest.mark.trio
208208
async def test_get_hello_packet():
209-
async with PubsubFactory.create_batch_with_floodsub(1) as pubsubs_fsub:
209+
async with PubsubFactory.create_batch_with_gossipsub(1) as pubsubs_fsub:
210210

211211
def _get_hello_packet_topic_ids():
212212
packet = pubsubs_fsub[0].get_hello_packet()
@@ -227,7 +227,7 @@ def _get_hello_packet_topic_ids():
227227

228228
@pytest.mark.trio
229229
async def test_set_and_remove_topic_validator():
230-
async with PubsubFactory.create_batch_with_floodsub(1) as pubsubs_fsub:
230+
async with PubsubFactory.create_batch_with_gossipsub(1) as pubsubs_fsub:
231231
is_sync_validator_called = False
232232

233233
def sync_validator(peer_id: ID, msg: rpc_pb2.Message) -> bool:
@@ -311,7 +311,7 @@ async def async_validator(peer_id: ID, msg: rpc_pb2.Message) -> bool:
311311
await trio.lowlevel.checkpoint()
312312
return True
313313

314-
async with PubsubFactory.create_batch_with_floodsub(1) as pubsubs_fsub:
314+
async with PubsubFactory.create_batch_with_gossipsub(1) as pubsubs_fsub:
315315
topic_1 = "TEST_VALIDATOR_1"
316316
topic_2 = "TEST_VALIDATOR_2"
317317
topic_3 = "TEST_VALIDATOR_3"
@@ -379,7 +379,7 @@ async def mock_run_async_validator(
379379
async with lock:
380380
state["concurrency_counter"] -= 1
381381

382-
async with PubsubFactory.create_batch_with_floodsub(1) as pubsubs_fsub:
382+
async with PubsubFactory.create_batch_with_gossipsub(1) as pubsubs_fsub:
383383

384384
def passed_sync_validator(peer_id: ID, msg: rpc_pb2.Message) -> bool:
385385
return True
@@ -466,7 +466,7 @@ async def mock_handle_rpc(rpc, sender_peer_id):
466466
yield Events(event_push_msg, event_handle_subscription, event_handle_rpc)
467467

468468
async with (
469-
PubsubFactory.create_batch_with_floodsub(
469+
PubsubFactory.create_batch_with_gossipsub(
470470
1, security_protocol=security_protocol
471471
) as pubsubs_fsub,
472472
net_stream_pair_factory(security_protocol=security_protocol) as stream_pair,
@@ -541,7 +541,7 @@ async def mock_handle_rpc(rpc, sender_peer_id):
541541

542542
@pytest.mark.trio
543543
async def test_handle_subscription():
544-
async with PubsubFactory.create_batch_with_floodsub(1) as pubsubs_fsub:
544+
async with PubsubFactory.create_batch_with_gossipsub(1) as pubsubs_fsub:
545545
assert len(pubsubs_fsub[0].peer_topics) == 0
546546
sub_msg_0 = rpc_pb2.RPC.SubOpts(subscribe=True, topicid=TESTING_TOPIC)
547547
peer_ids = [IDFactory() for _ in range(2)]
@@ -573,7 +573,7 @@ async def test_handle_subscription():
573573

574574
@pytest.mark.trio
575575
async def test_handle_talk():
576-
async with PubsubFactory.create_batch_with_floodsub(1) as pubsubs_fsub:
576+
async with PubsubFactory.create_batch_with_gossipsub(1) as pubsubs_fsub:
577577
sub = await pubsubs_fsub[0].subscribe(TESTING_TOPIC)
578578
msg_0 = make_pubsub_msg(
579579
origin_id=pubsubs_fsub[0].my_id,
@@ -599,7 +599,7 @@ async def test_handle_talk():
599599
@pytest.mark.trio
600600
async def test_message_all_peers(monkeypatch, security_protocol):
601601
async with (
602-
PubsubFactory.create_batch_with_floodsub(
602+
PubsubFactory.create_batch_with_gossipsub(
603603
1, security_protocol=security_protocol
604604
) as pubsubs_fsub,
605605
net_stream_pair_factory(security_protocol=security_protocol) as stream_pair,
@@ -620,7 +620,7 @@ async def test_message_all_peers(monkeypatch, security_protocol):
620620

621621
@pytest.mark.trio
622622
async def test_subscribe_and_publish():
623-
async with PubsubFactory.create_batch_with_floodsub(1) as pubsubs_fsub:
623+
async with PubsubFactory.create_batch_with_gossipsub(1) as pubsubs_fsub:
624624
pubsub = pubsubs_fsub[0]
625625

626626
list_data = [b"d0", b"d1"]
@@ -652,7 +652,7 @@ async def receive_data(topic):
652652

653653
@pytest.mark.trio
654654
async def test_subscribe_and_publish_full_channel():
655-
async with PubsubFactory.create_batch_with_floodsub(1) as pubsubs_fsub:
655+
async with PubsubFactory.create_batch_with_gossipsub(1) as pubsubs_fsub:
656656
pubsub = pubsubs_fsub[0]
657657

658658
extra_data_0 = b"extra_data_0"
@@ -693,7 +693,7 @@ async def push_msg(msg_forwarder, msg):
693693
msgs.append(msg)
694694
await trio.lowlevel.checkpoint()
695695

696-
async with PubsubFactory.create_batch_with_floodsub(1) as pubsubs_fsub:
696+
async with PubsubFactory.create_batch_with_gossipsub(1) as pubsubs_fsub:
697697
with monkeypatch.context() as m:
698698
m.setattr(pubsubs_fsub[0], "push_msg", push_msg)
699699

@@ -713,7 +713,7 @@ async def push_msg(msg_forwarder, msg):
713713

714714
@pytest.mark.trio
715715
async def test_push_msg(monkeypatch):
716-
async with PubsubFactory.create_batch_with_floodsub(2) as pubsubs_fsub:
716+
async with PubsubFactory.create_batch_with_gossipsub(2) as pubsubs_fsub:
717717
msg_0 = make_pubsub_msg(
718718
origin_id=pubsubs_fsub[0].my_id,
719719
topic_ids=[TESTING_TOPIC],
@@ -802,7 +802,7 @@ def failed_sync_validator(peer_id: ID, msg: rpc_pb2.Message) -> bool:
802802

803803
@pytest.mark.trio
804804
async def test_strict_signing():
805-
async with PubsubFactory.create_batch_with_floodsub(
805+
async with PubsubFactory.create_batch_with_gossipsub(
806806
2, strict_signing=True
807807
) as pubsubs_fsub:
808808
await connect(pubsubs_fsub[0].host, pubsubs_fsub[1].host)
@@ -819,7 +819,7 @@ async def test_strict_signing():
819819

820820
@pytest.mark.trio
821821
async def test_strict_signing_failed_validation(monkeypatch):
822-
async with PubsubFactory.create_batch_with_floodsub(
822+
async with PubsubFactory.create_batch_with_gossipsub(
823823
2, strict_signing=True
824824
) as pubsubs_fsub:
825825
msg = make_pubsub_msg(
@@ -880,7 +880,7 @@ async def router_publish(*args, **kwargs):
880880
@pytest.mark.trio
881881
async def test_blacklist_basic_operations():
882882
"""Test basic blacklist operations: add, remove, check, clear."""
883-
async with PubsubFactory.create_batch_with_floodsub(1) as pubsubs_fsub:
883+
async with PubsubFactory.create_batch_with_gossipsub(1) as pubsubs_fsub:
884884
pubsub = pubsubs_fsub[0]
885885

886886
# Create test peer IDs
@@ -936,7 +936,7 @@ async def test_blacklist_basic_operations():
936936
@pytest.mark.trio
937937
async def test_blacklist_blocks_new_peer_connections(monkeypatch):
938938
"""Test that blacklisted peers are rejected when trying to connect."""
939-
async with PubsubFactory.create_batch_with_floodsub(1) as pubsubs_fsub:
939+
async with PubsubFactory.create_batch_with_gossipsub(1) as pubsubs_fsub:
940940
pubsub = pubsubs_fsub[0]
941941

942942
# Create a blacklisted peer ID
@@ -990,7 +990,7 @@ def mock_add_peer(*args, **kwargs):
990990
@pytest.mark.trio
991991
async def test_blacklist_blocks_messages_from_blacklisted_originator():
992992
"""Test that messages from blacklisted originator (from field) are rejected."""
993-
async with PubsubFactory.create_batch_with_floodsub(2) as pubsubs_fsub:
993+
async with PubsubFactory.create_batch_with_gossipsub(2) as pubsubs_fsub:
994994
pubsub = pubsubs_fsub[0]
995995
blacklisted_originator = pubsubs_fsub[1].my_id # Use existing peer ID
996996

@@ -1038,7 +1038,7 @@ async def mock_router_publish(msg_forwarder: ID, pubsub_msg: rpc_pb2.Message):
10381038
@pytest.mark.trio
10391039
async def test_blacklist_allows_non_blacklisted_peers():
10401040
"""Test that non-blacklisted peers can send messages normally."""
1041-
async with PubsubFactory.create_batch_with_floodsub(3) as pubsubs_fsub:
1041+
async with PubsubFactory.create_batch_with_gossipsub(3) as pubsubs_fsub:
10421042
pubsub = pubsubs_fsub[0]
10431043
allowed_peer = pubsubs_fsub[1].my_id
10441044
blacklisted_peer = pubsubs_fsub[2].my_id
@@ -1103,7 +1103,7 @@ async def mock_router_publish(msg_forwarder: ID, pubsub_msg: rpc_pb2.Message):
11031103
@pytest.mark.trio
11041104
async def test_blacklist_integration_with_existing_functionality():
11051105
"""Test that blacklisting works correctly with existing pubsub functionality."""
1106-
async with PubsubFactory.create_batch_with_floodsub(2) as pubsubs_fsub:
1106+
async with PubsubFactory.create_batch_with_gossipsub(2) as pubsubs_fsub:
11071107
pubsub = pubsubs_fsub[0]
11081108
other_peer = pubsubs_fsub[1].my_id
11091109

@@ -1153,7 +1153,7 @@ async def mock_router_publish(msg_forwarder: ID, pubsub_msg: rpc_pb2.Message):
11531153
@pytest.mark.trio
11541154
async def test_blacklist_blocks_messages_from_blacklisted_source():
11551155
"""Test that messages from blacklisted source (forwarder) are rejected."""
1156-
async with PubsubFactory.create_batch_with_floodsub(2) as pubsubs_fsub:
1156+
async with PubsubFactory.create_batch_with_gossipsub(2) as pubsubs_fsub:
11571157
pubsub = pubsubs_fsub[0]
11581158
blacklisted_forwarder = pubsubs_fsub[1].my_id
11591159

@@ -1205,8 +1205,9 @@ async def test_blacklist_tears_down_existing_connection():
12051205
calling add_to_blacklist(peer_id) immediately resets its stream and
12061206
removes it from both places.
12071207
"""
1208-
# Create two pubsub instances (floodsub), so they can connect to each other
1209-
async with PubsubFactory.create_batch_with_floodsub(2) as pubsubs_fsub:
1208+
# Create two pubsub instances (gosscreate_batch_with_gossipsub),
1209+
# so they can connect to each other
1210+
async with PubsubFactory.create_batch_with_gossipsub(2) as pubsubs_fsub:
12101211
pubsub0, pubsub1 = pubsubs_fsub
12111212

12121213
# 1) Connect peer1 to peer0
@@ -1246,7 +1247,7 @@ async def test_blacklist_tears_down_existing_connection():
12461247
@pytest.mark.trio
12471248
async def test_get_message_id():
12481249
"""Test that the get_message_id method provides correct message ID construction."""
1249-
async with PubsubFactory.create_batch_with_floodsub(1) as pubsubs_fsub:
1250+
async with PubsubFactory.create_batch_with_gossipsub(1) as pubsubs_fsub:
12501251
pubsub = pubsubs_fsub[0]
12511252

12521253
# Create a test message
@@ -1268,7 +1269,7 @@ def custom_msg_id_constructor(msg):
12681269
return msg.data + msg.from_id
12691270

12701271
# Create a new pubsub instance with custom constructor
1271-
async with PubsubFactory.create_batch_with_floodsub(
1272+
async with PubsubFactory.create_batch_with_gossipsub(
12721273
1, msg_id_constructor=custom_msg_id_constructor
12731274
) as custom_pubsubs:
12741275
custom_pubsub = custom_pubsubs[0]

tests/core/pubsub/test_pubsub_notifee_integration.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
@pytest.mark.trio
1111
async def test_connected_enqueues_and_adds_peer():
12-
async with PubsubFactory.create_batch_with_floodsub(2) as (p0, p1):
12+
async with PubsubFactory.create_batch_with_gossipsub(2) as (p0, p1):
1313
await connect(p0.host, p1.host)
1414
await p0.wait_until_ready()
1515
# Wait until peer is added via queue processing
@@ -21,7 +21,7 @@ async def test_connected_enqueues_and_adds_peer():
2121

2222
@pytest.mark.trio
2323
async def test_disconnected_enqueues_and_removes_peer():
24-
async with PubsubFactory.create_batch_with_floodsub(2) as (p0, p1):
24+
async with PubsubFactory.create_batch_with_gossipsub(2) as (p0, p1):
2525
await connect(p0.host, p1.host)
2626
await p0.wait_until_ready()
2727
# Ensure present first
@@ -39,7 +39,7 @@ async def test_disconnected_enqueues_and_removes_peer():
3939
@pytest.mark.trio
4040
async def test_channel_closed_is_swallowed_in_notifee(monkeypatch) -> None:
4141
# Ensure PubsubNotifee catches BrokenResourceError from its send channel
42-
async with PubsubFactory.create_batch_with_floodsub(2) as (p0, p1):
42+
async with PubsubFactory.create_batch_with_gossipsub(2) as (p0, p1):
4343
# Find the PubsubNotifee registered on the network
4444
from libp2p.pubsub.pubsub_notifee import PubsubNotifee
4545

@@ -66,7 +66,7 @@ async def failing_send(_peer_id): # type: ignore[no-redef]
6666

6767
@pytest.mark.trio
6868
async def test_duplicate_connection_does_not_duplicate_peer_state():
69-
async with PubsubFactory.create_batch_with_floodsub(2) as (p0, p1):
69+
async with PubsubFactory.create_batch_with_gossipsub(2) as (p0, p1):
7070
await connect(p0.host, p1.host)
7171
await p0.wait_until_ready()
7272
with trio.fail_after(1.0):
@@ -80,7 +80,7 @@ async def test_duplicate_connection_does_not_duplicate_peer_state():
8080

8181
@pytest.mark.trio
8282
async def test_blacklist_blocks_peer_added_by_notifee():
83-
async with PubsubFactory.create_batch_with_floodsub(2) as (p0, p1):
83+
async with PubsubFactory.create_batch_with_gossipsub(2) as (p0, p1):
8484
# Blacklist before connecting
8585
p0.add_to_blacklist(p1.my_id)
8686
await connect(p0.host, p1.host)

0 commit comments

Comments
 (0)