MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_remote_addr_port

Function test_remote_addr_port

tests/test_connection.py:196–244  ·  view source on GitHub ↗

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

(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

194
195
196def test_remote_addr_port(node_factory, bitcoind):
197 """Check address discovery (BOLT1 #917) can be done with non-default TCP ports
198 We perform logic tests on L2, setup same as above:
199 l1 --> [l2] <-- l3
200 """
201 port = 1234
202 opts = {'dev-allow-localhost': None,
203 'may_reconnect': True,
204 'dev-no-reconnect': None,
205 'announce-addr-discovered-port': port}
206 l1, l2, l3 = node_factory.get_nodes(3, opts=[opts, opts, opts])
207
208 # Disable announcing local autobind addresses with dev-allow-localhost.
209 # We need to have l2 opts 'bind-addr' to the (generated) value of 'addr'.
210 # So we stop, set 'bind-addr' option, delete 'addr' and restart first.
211 l2.stop()
212 l2.daemon.opts['bind-addr'] = l2.daemon.opts['addr']
213 del l2.daemon.opts['addr']
214 l2.start()
215 assert len(l2.rpc.getinfo()['address']) == 0
216
217 # l1->l2
218 l2.rpc.connect(l1.info['id'], 'localhost', l1.port)
219 l2.daemon.wait_for_log("Peer says it sees our address as: 127.0.0.1:[0-9]{5}")
220 l1.fundchannel(l2)
221 bitcoind.generate_block(5)
222 l1.daemon.wait_for_log(f"Received node_announcement for node {l2.info['id']}")
223 # l2->l3
224 l2.rpc.connect(l3.info['id'], 'localhost', l3.port)
225 l2.daemon.wait_for_log("Peer says it sees our address as: 127.0.0.1:[0-9]{5}")
226 l2.fundchannel(l3)
227 bitcoind.generate_block(5)
228
229 # restart both and wait for channels to be ready
230 l1.restart()
231 l2.rpc.connect(l1.info['id'], 'localhost', l1.port)
232 l2.daemon.wait_for_log("Already have funding locked in")
233 l3.restart()
234 l2.rpc.connect(l3.info['id'], 'localhost', l3.port)
235
236 # if ip discovery would have been enabled, we would have send an updated
237 # node_announcement by now. Check we didn't...
238 l2.daemon.wait_for_logs(["Already have funding locked in",
239 "Update our node_announcement for discovered address"])
240 info = l2.rpc.getinfo()
241 assert len(info['address']) == 1
242 assert info['address'][0]['type'] == 'ipv4'
243 assert info['address'][0]['address'] == '127.0.0.1'
244 assert info['address'][0]['port'] == port
245
246
247def test_connect_standard_addr(node_factory):

Callers

nothing calls this directly

Calls 10

get_nodesMethod · 0.80
wait_for_logMethod · 0.80
generate_blockMethod · 0.80
restartMethod · 0.80
wait_for_logsMethod · 0.80
stopMethod · 0.45
startMethod · 0.45
getinfoMethod · 0.45
connectMethod · 0.45
fundchannelMethod · 0.45

Tested by

no test coverage detected