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

Function test_injectpaymentonion_selfpay

tests/test_pay.py:6371–6535  ·  view source on GitHub ↗
(node_factory, executor)

Source from the content-addressed store, hash-verified

6369
6370
6371def test_injectpaymentonion_selfpay(node_factory, executor):
6372 l1, l2 = node_factory.line_graph(2)
6373
6374 blockheight = l1.rpc.getinfo()['blockheight']
6375
6376 # Test simple self-pay.
6377 inv4 = l1.rpc.invoice(1000, "test_injectpaymentonion4", "test_injectpaymentonion4")
6378
6379 # First hop for injectpaymentonion is self.
6380 hops = [{'pubkey': l1.info['id'],
6381 'payload': serialize_payload_final_tlv(1000, 18, 1000, blockheight, inv4['payment_secret']).hex()}]
6382 onion = l1.rpc.createonion(hops=hops, assocdata=inv4['payment_hash'])
6383
6384 ret = l1.rpc.injectpaymentonion(onion=onion['onion'],
6385 payment_hash=inv4['payment_hash'],
6386 invstring=inv4['bolt11'],
6387 amount_msat=1000,
6388 cltv_expiry=blockheight + 18,
6389 partid=1,
6390 groupid=0)
6391 assert sha256(bytes.fromhex(ret['payment_preimage'])).hexdigest() == inv4['payment_hash']
6392 assert only_one(l1.rpc.listinvoices("test_injectpaymentonion4")['invoices'])['status'] == 'paid'
6393 lsp = only_one(l1.rpc.listsendpays(inv4['bolt11'])['payments'])
6394 assert lsp['groupid'] == 0
6395 assert lsp['partid'] == 1
6396 assert lsp['payment_hash'] == inv4['payment_hash']
6397 assert lsp['status'] == 'complete'
6398 assert lsp['destination'] == l1.info['id']
6399
6400 # Test self-pay with MPP.
6401 inv5 = l1.rpc.invoice(1000, "test_injectpaymentonion5", "test_injectpaymentonion5")
6402
6403 # First hop for injectpaymentonion is self.
6404 hops1 = [{'pubkey': l1.info['id'],
6405 'payload': serialize_payload_final_tlv(333, 18, 1000, blockheight, inv5['payment_secret']).hex()}]
6406 onion1 = l1.rpc.createonion(hops=hops1, assocdata=inv5['payment_hash'])
6407 hops2 = [{'pubkey': l1.info['id'],
6408 'payload': serialize_payload_final_tlv(667, 18, 1000, blockheight, inv5['payment_secret']).hex()}]
6409 onion2 = l1.rpc.createonion(hops=hops2, assocdata=inv5['payment_hash'])
6410
6411 fut1 = executor.submit(l1.rpc.injectpaymentonion,
6412 onion1['onion'],
6413 inv5['payment_hash'],
6414 333,
6415 blockheight + 18,
6416 1,
6417 0)
6418 fut2 = executor.submit(l1.rpc.injectpaymentonion,
6419 onion2['onion'],
6420 inv5['payment_hash'],
6421 667,
6422 blockheight + 18,
6423 2,
6424 0)
6425 # Now both should complete.
6426 ret = fut1.result(TIMEOUT)
6427 assert sha256(bytes.fromhex(ret['payment_preimage'])).hexdigest() == inv5['payment_hash']
6428

Callers

nothing calls this directly

Calls 15

add_fieldMethod · 0.95
to_bytesMethod · 0.95
only_oneFunction · 0.90
serialize_payload_tlvFunction · 0.90
first_scidFunction · 0.90
TlvPayloadClass · 0.90
tu64_encodeFunction · 0.90
line_graphMethod · 0.80
listsendpaysMethod · 0.80
listpaysMethod · 0.80
fetchinvoiceMethod · 0.80

Tested by

no test coverage detected