Skip to content

Commit

Permalink
pytest: test connecting to a DNS only announced node
Browse files Browse the repository at this point in the history
  • Loading branch information
m-schmoock committed Oct 9, 2021
1 parent aa1ce5f commit b7d098f
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/test_gossip.py
Expand Up @@ -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.
Expand Down

0 comments on commit b7d098f

Please sign in to comment.