From b7d098f36a43d2c4a5b2e069746d6da6d76b3f88 Mon Sep 17 00:00:00 2001 From: Michael Schmoock Date: Fri, 8 Oct 2021 15:37:56 +0200 Subject: [PATCH] pytest: test connecting to a DNS only announced node --- tests/test_gossip.py | 46 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tests/test_gossip.py b/tests/test_gossip.py index ca95359e18a8..403db7f6f8f7 100644 --- a/tests/test_gossip.py +++ b/tests/test_gossip.py @@ -164,6 +164,52 @@ def test_announce_address(node_factory, bitcoind): assert addresses_dns[1]['port'] == 1236 +@pytest.mark.developer("gossip without DEVELOPER=1 is slow") +def test_announce_and_connect_via_dns(node_factory, bitcoind): + """ Test that DNS annoucements propagate and can be used when connecting. + + - First node announces only a FQDN like 'localhost.localdomain'. + - Second node gets a channel with first node. + - Third node just connects to second node. + - Wait fot gossip so third node sees first node. + - Third node must be able to 'resolve' localhost and connect to first node. + + Notes: + - --disable-dns is needed so the first node does not announce 127.0.0.1 itself. + - 'dev-allow-localhost' must not be set, so it does not resolve localhost anyway. + """ + opts = {'disable-dns': None, + 'announce-addr': ['localhost.localdomain:12345'], # announce dns + 'bind-addr': ['127.0.0.1:12345']} # and bind to ip + l1, l2, l3 = node_factory.get_nodes(3, opts=[opts, {}, {}]) + + l1.rpc.connect(l2.info['id'], 'localhost', l2.port) + l3.rpc.connect(l2.info['id'], 'localhost', l2.port) + scid, _ = l1.fundchannel(l2, 10**6) + bitcoind.generate_block(5) + + # wait until l3 sees l1 in its gossip with announced addresses + wait_for(lambda: len(l3.rpc.listnodes(l1.info['id'])['nodes']) == 1) + wait_for(lambda: 'addresses' in l3.rpc.listnodes(l1.info['id'])['nodes'][0]) + addresses = l3.rpc.listnodes(l1.info['id'])['nodes'][0]['addresses'] + assert(len(addresses) == 1) # no other addresses must be announced for this + assert(addresses[0]['type'] == 'dns') + assert(addresses[0]['address'] == 'localhost.localdomain') + assert(addresses[0]['port'] == 12345) + + # now l3 must be able to use DNS to resolve and connect to l1 + result = l3.rpc.connect(l1.info['id']) + assert result['id'] == l1.info['id'] + assert result['direction'] == 'out' + assert result['address']['port'] == 12345 + if result['address']['type'] == 'ipv4': + assert result['address']['address'] == '127.0.0.1' + elif result['address']['type'] == 'ipv6': + assert result['address']['address'] == '::1' + else: + assert False + + @pytest.mark.developer("needs DEVELOPER=1") def test_gossip_timestamp_filter(node_factory, bitcoind, chainparams): # Updates get backdated 5 seconds with --dev-fast-gossip.