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

Function test_offer_paths

tests/test_pay.py:5970–6022  ·  view source on GitHub ↗
(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

5968
5969
5970def test_offer_paths(node_factory, bitcoind):
5971 opts = {'dev-allow-localhost': None}
5972
5973 # Need to announce channels to use their scid in offers anyway!
5974 l1, l2, l3, l4 = node_factory.line_graph(4,
5975 opts=opts,
5976 wait_for_announce=True)
5977
5978 chan = only_one(l1.rpc.listpeerchannels()['channels'])
5979 scidd = "{}/{}".format(chan['short_channel_id'], chan['direction'])
5980 offer = l2.rpc.call('offer', {'amount': '100sat',
5981 'description': 'test_offer_paths',
5982 'dev_paths': [[scidd, l2.info['id']],
5983 [l3.info['id'], l2.info['id']]]})
5984
5985 paths = l1.rpc.decode(offer['bolt12'])['offer_paths']
5986 assert len(paths) == 2
5987 assert paths[0]['first_scid'] == chan['short_channel_id']
5988 assert paths[0]['first_scid_dir'] == chan['direction']
5989 assert paths[1]['first_node_id'] == l3.info['id']
5990
5991 l5 = node_factory.get_node(options=opts)
5992
5993 # Get all the gossip, so we have addresses
5994 l5.rpc.connect(l1.info['id'], 'localhost', l1.port)
5995 wait_for(lambda: len(l5.rpc.listnodes()['nodes']) == 4 and all(['addresses' in n for n in l5.rpc.listnodes()['nodes']]))
5996
5997 # We have a path ->l1 (head of blinded path), so we can use that without connecting.
5998 l5.rpc.fetchinvoice(offer=offer['bolt12'])
5999 assert not l5.daemon.is_in_log('connecting directly to')
6000
6001 # Make scid path invalid by closing it
6002 close = l1.rpc.close(paths[0]['first_scid'])
6003 bitcoind.generate_block(73, wait_for_mempool=only_one(close['txids']))
6004 wait_for(lambda: l5.rpc.listchannels(paths[0]['first_scid']) == {'channels': []})
6005
6006 # Now connect l5->l4, and it will be able to reach l3 via that, and join blinded path.
6007 l5.rpc.connect(l4.info['id'], 'localhost', l4.port)
6008 l5.rpc.fetchinvoice(offer=offer['bolt12'])
6009 assert not l5.daemon.is_in_log('connecting')
6010
6011 # This will make us connect straight to l3 to use blinded path from there.
6012 l5.rpc.disconnect(l4.info['id'])
6013 l5.rpc.fetchinvoice(offer=offer['bolt12'])
6014 assert l5.daemon.is_in_log('connecting')
6015
6016 # Restart l5 with fetchinvoice-noconnect and it will fail.
6017 l5.stop()
6018 l5.daemon.opts['fetchinvoice-noconnect'] = None
6019 l5.start()
6020
6021 with pytest.raises(RpcError, match=f"Failed: could not route or connect directly to blinded path at {l3.info['id']}: fetchinvoice-noconnect set: not initiating a new connection"):
6022 l5.rpc.fetchinvoice(offer=offer['bolt12'])
6023
6024
6025# CI is so slow under valgrind that this does not reach the ratelimit!

Callers

nothing calls this directly

Calls 15

only_oneFunction · 0.90
wait_forFunction · 0.90
line_graphMethod · 0.80
listpeerchannelsMethod · 0.80
fetchinvoiceMethod · 0.80
is_in_logMethod · 0.80
generate_blockMethod · 0.80
callMethod · 0.45
decodeMethod · 0.45
get_nodeMethod · 0.45
connectMethod · 0.45
listnodesMethod · 0.45

Tested by

no test coverage detected