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

Function test_remote_addr_port

tests/test_connection.py:189–237  ·  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

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