From 1fb1e0eec4616153c8f48063443d9d16a84281d4 Mon Sep 17 00:00:00 2001 From: Michael Schmoock Date: Wed, 21 Dec 2022 11:44:26 +0100 Subject: [PATCH] pytest: test ip discovery for custom port --- tests/test_connection.py | 52 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/tests/test_connection.py b/tests/test_connection.py index be23dd1bf..614a8b91b 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -188,6 +188,58 @@ def test_remote_addr_disabled(node_factory, bitcoind): assert not l2.daemon.is_in_log("Update our node_announcement for discovered address") +@pytest.mark.developer("needs DEVELOPER=1 for fast gossip and --dev-allow-localhost for local remote_addr") +def test_remote_addr_port(node_factory, bitcoind): + """Check address discovery (BOLT1 #917) can be done with non-default TCP ports + We perform logic tests on L2, setup same as above: + l1 --> [l2] <-- l3 + """ + port = 1234 + opts = {'dev-allow-localhost': None, + 'may_reconnect': True, + 'dev-no-reconnect': None, + 'announce-addr-discovered-port': port} + l1, l2, l3 = node_factory.get_nodes(3, opts=[opts, opts, opts]) + + # Disable announcing local autobind addresses with dev-allow-localhost. + # We need to have l2 opts 'bind-addr' to the (generated) value of 'addr'. + # So we stop, set 'bind-addr' option, delete 'addr' and restart first. + l2.stop() + l2.daemon.opts['bind-addr'] = l2.daemon.opts['addr'] + del l2.daemon.opts['addr'] + l2.start() + assert len(l2.rpc.getinfo()['address']) == 0 + + # l1->l2 + l2.rpc.connect(l1.info['id'], 'localhost', l1.port) + l2.daemon.wait_for_log("Peer says it sees our address as: 127.0.0.1:[0-9]{5}") + l1.fundchannel(l2) + bitcoind.generate_block(5) + l1.daemon.wait_for_log(f"Received node_announcement for node {l2.info['id']}") + # l2->l3 + l2.rpc.connect(l3.info['id'], 'localhost', l3.port) + l2.daemon.wait_for_log("Peer says it sees our address as: 127.0.0.1:[0-9]{5}") + l2.fundchannel(l3) + bitcoind.generate_block(5) + + # restart both and wait for channels to be ready + l1.restart() + l2.rpc.connect(l1.info['id'], 'localhost', l1.port) + l2.daemon.wait_for_log("Already have funding locked in") + l3.restart() + l2.rpc.connect(l3.info['id'], 'localhost', l3.port) + l2.daemon.wait_for_log("Already have funding locked in") + + # if ip discovery would have been enabled, we would have send an updated + # node_annoucement by now. Check we didn't... + assert l2.daemon.wait_for_log("Update our node_announcement for discovered address") + info = l2.rpc.getinfo() + assert len(info['address']) == 1 + assert info['address'][0]['type'] == 'ipv4' + assert info['address'][0]['address'] == '127.0.0.1' + assert info['address'][0]['port'] == port + + def test_connect_standard_addr(node_factory): """Test standard node@host:port address """