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

Function test_sendonion_rpc

tests/test_pay.py:2997–3075  ·  view source on GitHub ↗
(node_factory)

Source from the content-addressed store, hash-verified

2995
2996
2997def test_sendonion_rpc(node_factory):
2998 l1, l2, l3, l4 = node_factory.line_graph(4, wait_for_announce=True)
2999 amt = 10**3
3000 route = l1.single_route(l4.info['id'], 10**3)
3001 inv = l4.rpc.invoice(amt, "lbl", "desc")
3002
3003 first_hop = {'id': route[0]['node_id_out'], 'amount_msat': route[0]['amount_out_msat'], 'delay': route[0]['cltv_out']}
3004 blockheight = l1.rpc.getinfo()['blockheight']
3005
3006 # Need to shift the parameters by one hop
3007 hops = []
3008 for h, n in zip(route[:-1], route[1:]):
3009 # We tell the node h about the parameters to use for n (a.k.a. h + 1)
3010 hops.append({
3011 "pubkey": h['node_id_out'],
3012 "payload": serialize_payload_tlv(n['amount_out_msat'], n['cltv_out'], n['short_channel_id_dir'].rsplit('/', 1)[0], blockheight).hex()
3013 })
3014
3015 # The last hop has a special payload:
3016 hops.append({
3017 "pubkey": route[-1]['node_id_out'],
3018 "payload": serialize_payload_final_tlv(route[-1]['amount_out_msat'], route[-1]['cltv_out'], route[-1]['amount_out_msat'], blockheight, inv['payment_secret']).hex()
3019 })
3020
3021 onion = l1.rpc.createonion(hops=hops, assocdata=inv['payment_hash'])
3022
3023 l1.rpc.sendonion(onion=onion['onion'], first_hop=first_hop,
3024 payment_hash=inv['payment_hash'])
3025
3026 l1.rpc.waitsendpay(payment_hash=inv['payment_hash'])
3027 invs = l4.rpc.listinvoices(label="lbl")['invoices']
3028 assert(len(invs) == 1 and invs[0]['status'] == 'paid')
3029
3030 pay = only_one(l1.rpc.listsendpays()['payments'])
3031 assert (pay['status'] == 'complete'
3032 and pay['payment_hash'] == inv['payment_hash'])
3033
3034 # listsendpays promised that amount would be missing if sendonion didn't
3035 # specify
3036 assert 'amount_msat' not in pay
3037
3038 # And now for a failing payment, using a payment_hash that doesn't match an
3039 # invoice
3040 payment_hash = "00" * 32
3041 onion = l1.rpc.createonion(hops=hops, assocdata=payment_hash)
3042 l1.rpc.sendonion(onion=onion['onion'], first_hop=first_hop,
3043 payment_hash=payment_hash, amount_msat=amt)
3044
3045 try:
3046 l1.rpc.waitsendpay(payment_hash=payment_hash)
3047 raise ValueError()
3048 except RpcError as e:
3049 assert(e.error['code'] == 202)
3050 assert(e.error['message'] == "Malformed error reply")
3051
3052 pay = only_one(l1.rpc.listsendpays(payment_hash=payment_hash)['payments'])
3053 assert(pay['status'] == 'failed'
3054 and pay['payment_hash'] == payment_hash)

Callers

nothing calls this directly

Calls 11

serialize_payload_tlvFunction · 0.90
only_oneFunction · 0.90
line_graphMethod · 0.80
single_routeMethod · 0.80
sendonionMethod · 0.80
waitsendpayMethod · 0.80
listsendpaysMethod · 0.80
invoiceMethod · 0.45
getinfoMethod · 0.45
listinvoicesMethod · 0.45

Tested by

no test coverage detected