mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-27 09:21:43 +02:00
test: ensure I2P addresses are relayed
This test would fail if `CNetAddr::IsRelayable()` returns `false` for I2P addresses, given that this test node does not have I2P connectivity.
This commit is contained in:
parent
e7468139a1
commit
7593b06bd1
@ -18,12 +18,19 @@ from test_framework.p2p import P2PInterface
|
|||||||
from test_framework.test_framework import BitcoinTestFramework
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
from test_framework.util import assert_equal
|
from test_framework.util import assert_equal
|
||||||
|
|
||||||
|
I2P_ADDR = "c4gfnttsuwqomiygupdqqqyy5y5emnk5c73hrfvatri67prd7vyq.b32.i2p"
|
||||||
|
|
||||||
ADDRS = []
|
ADDRS = []
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
addr = CAddress()
|
addr = CAddress()
|
||||||
addr.time = int(time.time()) + i
|
addr.time = int(time.time()) + i
|
||||||
addr.nServices = NODE_NETWORK | NODE_WITNESS
|
addr.nServices = NODE_NETWORK | NODE_WITNESS
|
||||||
addr.ip = "123.123.123.{}".format(i % 256)
|
# Add one I2P address at an arbitrary position.
|
||||||
|
if i == 5:
|
||||||
|
addr.net = addr.NET_I2P
|
||||||
|
addr.ip = I2P_ADDR
|
||||||
|
else:
|
||||||
|
addr.ip = f"123.123.123.{i % 256}"
|
||||||
addr.port = 8333 + i
|
addr.port = 8333 + i
|
||||||
ADDRS.append(addr)
|
ADDRS.append(addr)
|
||||||
|
|
||||||
@ -35,11 +42,8 @@ class AddrReceiver(P2PInterface):
|
|||||||
super().__init__(support_addrv2 = True)
|
super().__init__(support_addrv2 = True)
|
||||||
|
|
||||||
def on_addrv2(self, message):
|
def on_addrv2(self, message):
|
||||||
for addr in message.addrs:
|
if ADDRS == message.addrs:
|
||||||
assert_equal(addr.nServices, NODE_NETWORK | NODE_WITNESS)
|
self.addrv2_received_and_checked = True
|
||||||
assert addr.ip.startswith('123.123.123.')
|
|
||||||
assert (8333 <= addr.port < 8343)
|
|
||||||
self.addrv2_received_and_checked = True
|
|
||||||
|
|
||||||
def wait_for_addrv2(self):
|
def wait_for_addrv2(self):
|
||||||
self.wait_until(lambda: "addrv2" in self.last_message)
|
self.wait_until(lambda: "addrv2" in self.last_message)
|
||||||
@ -64,15 +68,18 @@ class AddrTest(BitcoinTestFramework):
|
|||||||
addr_receiver = self.nodes[0].add_p2p_connection(AddrReceiver())
|
addr_receiver = self.nodes[0].add_p2p_connection(AddrReceiver())
|
||||||
msg.addrs = ADDRS
|
msg.addrs = ADDRS
|
||||||
with self.nodes[0].assert_debug_log([
|
with self.nodes[0].assert_debug_log([
|
||||||
'Added 10 addresses from 127.0.0.1: 0 tried',
|
# The I2P address is not added to node's own addrman because it has no
|
||||||
'received: addrv2 (131 bytes) peer=0',
|
# I2P reachability (thus 10 - 1 = 9).
|
||||||
'sending addrv2 (131 bytes) peer=1',
|
'Added 9 addresses from 127.0.0.1: 0 tried',
|
||||||
|
'received: addrv2 (159 bytes) peer=0',
|
||||||
|
'sending addrv2 (159 bytes) peer=1',
|
||||||
]):
|
]):
|
||||||
addr_source.send_and_ping(msg)
|
addr_source.send_and_ping(msg)
|
||||||
self.nodes[0].setmocktime(int(time.time()) + 30 * 60)
|
self.nodes[0].setmocktime(int(time.time()) + 30 * 60)
|
||||||
addr_receiver.wait_for_addrv2()
|
addr_receiver.wait_for_addrv2()
|
||||||
|
|
||||||
assert addr_receiver.addrv2_received_and_checked
|
assert addr_receiver.addrv2_received_and_checked
|
||||||
|
assert_equal(len(self.nodes[0].getnodeaddresses(count=0, network="i2p")), 0)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user