Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Fix p2p_addr_relay.py #5967

Merged
5 commits merged into from
Apr 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions test/functional/p2p_addr_relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,13 @@
from test_framework.util import (
assert_equal,
)
import time

ADDRS = []
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can ADDRS remain outside?

In the last backport that modified p2p_addr_relay.py (bitcoin#19272), it has remained outside. Scope pollution shouldn't be much of a concern since tests don't include each other.

I mention this because a similar change was done for p2p_addrv2_relay.py (see develop vs bitcoin#19954, the backport that introduced this test) and I had to revert it in a WIP PR to make way for bitcoin#22211 because ADDRS was being accessed by both AddrReceiver and AddrTest in the changes introduced.

Also, ADDRS in p2p_addr_relay.py is anyways done away with in bitcoin#21707 (diff) so might be worthwhile to keep it in line with upstream to make the changes easier to follow when it is eventually done away with.

for i in range(10):
addr = CAddress()
addr.time = int(time.time()) + i
addr.nServices = NODE_NETWORK
addr.ip = "123.123.123.{}".format(i % 256)
addr.port = 8333 + i
ADDRS.append(addr)


class AddrReceiver(P2PInterface):
def on_addr(self, message):
for addr in message.addrs:
assert_equal(addr.nServices, 9)
assert_equal(addr.nServices, 1)
assert addr.ip.startswith('123.123.123.')
assert (8333 <= addr.port < 8343)

Expand All @@ -41,6 +32,14 @@ def set_test_params(self):
self.num_nodes = 1

def run_test(self):
for i in range(10):
addr = CAddress()
addr.time = int(self.mocktime) + i
addr.nServices = NODE_NETWORK
addr.ip = "123.123.123.{}".format(i % 256)
addr.port = 8333 + i
ADDRS.append(addr)

self.log.info('Create connection that sends addr messages')
addr_source = self.nodes[0].add_p2p_connection(P2PInterface())
msg = msg_addr()
Expand All @@ -56,9 +55,10 @@ def run_test(self):
with self.nodes[0].assert_debug_log([
'Added 10 addresses from 127.0.0.1: 0 tried',
'received: addr (301 bytes) peer=0',
'sending addr (301 bytes) peer=1',
]):
addr_source.send_and_ping(msg)
self.nodes[0].setmocktime(int(time.time()) + 30 * 60)
self.bump_mocktime(30 * 60)
addr_receiver.sync_with_ping()


Expand Down
Loading