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

Function test_injectpaymentonion_simple

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

Source from the content-addressed store, hash-verified

6232
6233
6234def test_injectpaymentonion_simple(node_factory, executor):
6235 l1, l2 = node_factory.line_graph(2)
6236
6237 blockheight = l1.rpc.getinfo()['blockheight']
6238 inv1 = l2.rpc.invoice(1000, "test_injectpaymentonion1", "test_injectpaymentonion1")
6239
6240 # First hop for injectpaymentonion is self.
6241 hops = [{'pubkey': l1.info['id'],
6242 'payload': serialize_payload_tlv(1000, 18 + 6, first_scid(l1, l2), blockheight).hex()},
6243 {'pubkey': l2.info['id'],
6244 'payload': serialize_payload_final_tlv(1000, 18, 1000, blockheight, inv1['payment_secret']).hex()}]
6245 onion = l1.rpc.createonion(hops=hops, assocdata=inv1['payment_hash'])
6246
6247 ret = l1.rpc.injectpaymentonion(onion=onion['onion'],
6248 payment_hash=inv1['payment_hash'],
6249 amount_msat=1000,
6250 cltv_expiry=blockheight + 18 + 6,
6251 partid=1,
6252 groupid=0)
6253 assert ret['completed_at'] >= ret['created_at']
6254 assert sha256(bytes.fromhex(ret['payment_preimage'])).hexdigest() == inv1['payment_hash']
6255 assert ret == {'payment_preimage': ret['payment_preimage'],
6256 'created_index': 1,
6257 'completed_at': ret['completed_at'],
6258 'created_at': ret['created_at']}
6259 assert only_one(l2.rpc.listinvoices("test_injectpaymentonion1")['invoices'])['status'] == 'paid'
6260 lsp = only_one(l1.rpc.listsendpays(inv1['bolt11'])['payments'])
6261 assert lsp['groupid'] == 0
6262 assert lsp['partid'] == 1
6263 assert lsp['payment_hash'] == inv1['payment_hash']
6264 assert lsp['status'] == 'complete'
6265 assert 'amount_msat' not in lsp
6266
6267 # We FAIL on reattempt
6268 with pytest.raises(RpcError, match="Already paid this invoice") as err:
6269 l1.rpc.injectpaymentonion(onion=onion['onion'],
6270 payment_hash=inv1['payment_hash'],
6271 amount_msat=1000,
6272 cltv_expiry=blockheight + 18 + 6,
6273 partid=1,
6274 groupid=0)
6275 # PAY_INJECTPAYMENTONION_ALREADY_PAID
6276 assert err.value.error['code'] == 219
6277 assert 'onionreply' not in err.value.error['data']
6278 assert err.value.error['data'] == lsp
6279
6280
6281def test_injectpaymentonion_mpp(node_factory, executor):

Callers

nothing calls this directly

Calls 10

serialize_payload_tlvFunction · 0.90
first_scidFunction · 0.90
only_oneFunction · 0.90
line_graphMethod · 0.80
listsendpaysMethod · 0.80
sha256Class · 0.50
getinfoMethod · 0.45
invoiceMethod · 0.45
listinvoicesMethod · 0.45

Tested by

no test coverage detected