Skip to content

Commit 63b35de

Browse files
committed
pytest: test connecting to a DNS only announced node
1 parent f176b44 commit 63b35de

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

tests/test_gossip.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,52 @@ def test_announce_address(node_factory, bitcoind):
164164
assert addresses_dns[1]['port'] == 1236
165165

166166

167+
@pytest.mark.developer("gossip without DEVELOPER=1 is slow")
168+
def test_announce_and_connect_via_dns(node_factory, bitcoind):
169+
""" Test that DNS annoucements propagate and can be used when connecting.
170+
171+
- First node announces only a FQDN like 'localhost.localdomain'.
172+
- Second node gets a channel with first node.
173+
- Third node just connects to second node.
174+
- Wait fot gossip so third node sees first node.
175+
- Third node must be able to 'resolve' localhost and connect to first node.
176+
177+
Notes:
178+
- --disable-dns is needed so the first node does not announce 127.0.0.1 itself.
179+
- 'dev-allow-localhost' must not be set, so it does not resolve localhost anyway.
180+
"""
181+
opts = {'disable-dns': None,
182+
'announce-addr': ['localhost.localdomain:12345'], # announce dns
183+
'bind-addr': ['127.0.0.1:12345']} # and bind to ip
184+
l1, l2, l3 = node_factory.get_nodes(3, opts=[opts, {}, {}])
185+
186+
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
187+
l3.rpc.connect(l2.info['id'], 'localhost', l2.port)
188+
scid, _ = l1.fundchannel(l2, 10**6)
189+
bitcoind.generate_block(5)
190+
191+
# wait until l3 sees l1 in its gossip with announced addresses
192+
wait_for(lambda: len(l3.rpc.listnodes(l1.info['id'])['nodes']) == 1)
193+
wait_for(lambda: 'addresses' in l3.rpc.listnodes(l1.info['id'])['nodes'][0])
194+
addresses = l3.rpc.listnodes(l1.info['id'])['nodes'][0]['addresses']
195+
assert(len(addresses) == 1) # no other addresses must be announced for this
196+
assert(addresses[0]['type'] == 'dns')
197+
assert(addresses[0]['address'] == 'localhost.localdomain')
198+
assert(addresses[0]['port'] == 12345)
199+
200+
# now l3 must be able to use DNS to resolve and connect to l1
201+
result = l3.rpc.connect(l1.info['id'])
202+
assert result['id'] == l1.info['id']
203+
assert result['direction'] == 'out'
204+
assert result['address']['port'] == 12345
205+
if result['address']['type'] == 'ipv4':
206+
assert result['address']['address'] == '127.0.0.1'
207+
elif result['address']['type'] == 'ipv6':
208+
assert result['address']['address'] == '::1'
209+
else:
210+
assert False
211+
212+
167213
@pytest.mark.developer("needs DEVELOPER=1")
168214
def test_gossip_timestamp_filter(node_factory, bitcoind, chainparams):
169215
# Updates get backdated 5 seconds with --dev-fast-gossip.

0 commit comments

Comments
 (0)