test: fix addr relay test silent pass and wrong peerinfo index

the test silently passes on master because SetupAddressRelay
isn't called by default for inbound connections.
This commit is contained in:
stratospher 2026-03-05 17:29:39 +05:30
parent 7e91060ec7
commit ecb5ce6e76

View File

@ -178,6 +178,9 @@ class AddrTest(BitcoinTestFramework):
self.log.info('Check relay of addresses received from outbound peers')
inbound_peer = self.nodes[0].add_p2p_connection(AddrReceiver(test_addr_contents=True, send_getaddr=False))
# Send an empty ADDR message to initialize address relay on this connection.
inbound_peer.send_and_ping(msg_addr())
full_outbound_peer = self.nodes[0].add_outbound_p2p_connection(AddrReceiver(), p2p_idx=0, connection_type="outbound-full-relay")
msg = self.setup_addr_msg(2)
self.send_addr_msg(full_outbound_peer, msg, [inbound_peer])
@ -188,9 +191,6 @@ class AddrTest(BitcoinTestFramework):
# of the outbound peer which is often sent before the GETADDR response.
assert_equal(inbound_peer.num_ipv4_received, 0)
# Send an empty ADDR message to initialize address relay on this connection.
inbound_peer.send_and_ping(msg_addr())
self.log.info('Check that subsequent addr messages sent from an outbound peer are relayed')
msg2 = self.setup_addr_msg(2)
self.send_addr_msg(full_outbound_peer, msg2, [inbound_peer])
@ -248,8 +248,9 @@ class AddrTest(BitcoinTestFramework):
blackhole_peer.send_and_ping(msg_addr())
# Confirm node has now received addr-related messages from blackhole peer
assert_greater_than(self.sum_addr_messages(peerinfo[1]['bytesrecv_per_msg']), 0)
assert_equal(self.nodes[0].getpeerinfo()[2]['addr_relay_enabled'], True)
peerinfo = self.nodes[0].getpeerinfo()
assert_greater_than(self.sum_addr_messages(peerinfo[2]['bytesrecv_per_msg']), 0)
assert_equal(peerinfo[2]['addr_relay_enabled'], True)
msg = self.setup_addr_msg(2)
self.send_addr_msg(addr_source, msg, [receiver_peer, blackhole_peer])
@ -280,6 +281,7 @@ class AddrTest(BitcoinTestFramework):
inbound_peer = self.nodes[0].add_p2p_connection(AddrReceiver(send_getaddr=False))
inbound_peer.sync_with_ping()
assert_equal(inbound_peer.getaddr_received(), False)
assert_equal(inbound_peer.addr_received(), False)
self.log.info('Check that we answer getaddr messages only from inbound peers')
# Add some addresses to addrman