def test_enr_partitioning(num_enr_records, max_payload_size): enrs = ENRFactory.create_batch(num_enr_records) batches = partition_enrs(enrs, max_payload_size) assert sum(len(batch) for batch in batches) == len(enrs) assert set(itertools.chain(*batches)) == set(enrs) for batch in batches: encoded_batch = rlp.encode(batch, sedes=rlp.sedes.CountableList(ENRSedes)) assert len(encoded_batch) <= max_payload_size for batch, next_batch in sliding_window(2, batches): overfull_batch = tuple(batch) + (next_batch[0], ) encoded_batch = rlp.encode(overfull_batch, sedes=rlp.sedes.CountableList(ENRSedes)) assert len(encoded_batch) > max_payload_size
@pytest.mark.trio async def test_client_send_find_nodes(alice, bob, alice_client, bob_client): with trio.fail_after(2): async with alice.events.find_nodes_sent.subscribe_and_wait(): async with bob.events.find_nodes_received.subscribe_and_wait(): await alice_client.send_find_nodes(bob.endpoint, bob.node_id, distances=[255]) @pytest.mark.parametrize( "enrs", ( ENRFactory.create_batch(1), ENRFactory.create_batch(2), ENRFactory.create_batch(10), ENRFactory.create_batch(50), ), ) @pytest.mark.trio async def test_client_send_found_nodes(alice, bob, alice_client, bob_client, enrs): with trio.fail_after(2): async with alice.events.found_nodes_sent.subscribe_and_wait(): async with bob.events.found_nodes_received.subscribe( ) as subscription: await alice_client.send_found_nodes( bob.endpoint, bob.node_id,