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

Function test_fetchinvoice_autoconnect

tests/test_pay.py:4889–4928  ·  view source on GitHub ↗

We should autoconnect if we need to, to route.

(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

4887
4888
4889def test_fetchinvoice_autoconnect(node_factory, bitcoind):
4890 """We should autoconnect if we need to, to route."""
4891
4892 l1, l2 = node_factory.line_graph(2, wait_for_announce=True,
4893 # No onion_message support in l1
4894 opts=[{'dev-force-features': -39},
4895 {'dev-allow-localhost': None}])
4896
4897 l3 = node_factory.get_node()
4898 l3.rpc.connect(l1.info['id'], 'localhost', l1.port)
4899 wait_for(lambda: ['addresses' in n for n in l3.rpc.listnodes(l2.info['id'])['nodes']] == [True])
4900
4901 offer = l2.rpc.call('offer', {'amount': '2msat',
4902 'description': 'simple test'})
4903 l3.rpc.call('fetchinvoice', {'offer': offer['bolt12']})
4904 assert l3.rpc.listpeers(l2.info['id'])['peers'] != []
4905
4906 # Similarly for an invoice_request.
4907 l3.rpc.disconnect(l2.info['id'])
4908 invreq = l2.rpc.call('invoicerequest', {'amount': '2msat',
4909 'description': 'simple test'})
4910 # Ofc l2 can't actually pay it!
4911 with pytest.raises(RpcError, match='pay attempt failed: "Failed: There is no connection between source and destination at all"'):
4912 l3.rpc.call('sendinvoice', {'invreq': invreq['bolt12'], 'label': 'payme!'})
4913
4914 assert l3.rpc.listpeers(l2.info['id'])['peers'] != []
4915
4916 # But if we create a channel l3->l1->l2 (and balance!), l2 can!
4917 node_factory.join_nodes([l3, l1], wait_for_announce=True)
4918 # Make sure l2 knows about it
4919 wait_for(lambda: l2.rpc.listnodes(l3.info['id'])['nodes'] != [])
4920
4921 l3.rpc.pay(l2.rpc.invoice(FUNDAMOUNT * 500, 'balancer', 'balancer')['bolt11'])
4922 # Make sure l2 has capacity (can be still resolving!).
4923 wait_for(lambda: only_one(l2.rpc.listpeerchannels(l1.info['id'])['channels'])['spendable_msat'] != Millisatoshi(0))
4924
4925 l3.rpc.disconnect(l2.info['id'])
4926 l3.rpc.call('sendinvoice', {'invreq': invreq['bolt12'], 'label': 'payme for real!'})
4927 # It will have autoconnected, to send invoice (since l1 says it doesn't do onion messages!)
4928 assert l3.rpc.listpeers(l2.info['id'])['peers'] != []
4929
4930
4931def test_fetchinvoice_autoconnect_if_disconnected(node_factory, bitcoind):

Callers

nothing calls this directly

Calls 14

wait_forFunction · 0.90
only_oneFunction · 0.90
MillisatoshiClass · 0.90
line_graphMethod · 0.80
join_nodesMethod · 0.80
listpeerchannelsMethod · 0.80
get_nodeMethod · 0.45
connectMethod · 0.45
listnodesMethod · 0.45
callMethod · 0.45
listpeersMethod · 0.45
disconnectMethod · 0.45

Tested by

no test coverage detected