(node_factory, executor)
| 6304 | |
| 6305 | |
| 6306 | def test_injectpaymentonion_simple(node_factory, executor): |
| 6307 | l1, l2 = node_factory.line_graph(2) |
| 6308 | |
| 6309 | blockheight = l1.rpc.getinfo()['blockheight'] |
| 6310 | inv1 = l2.rpc.invoice(1000, "test_injectpaymentonion1", "test_injectpaymentonion1") |
| 6311 | |
| 6312 | # First hop for injectpaymentonion is self. |
| 6313 | hops = [{'pubkey': l1.info['id'], |
| 6314 | 'payload': serialize_payload_tlv(1000, 18 + 6, first_scid(l1, l2), blockheight).hex()}, |
| 6315 | {'pubkey': l2.info['id'], |
| 6316 | 'payload': serialize_payload_final_tlv(1000, 18, 1000, blockheight, inv1['payment_secret']).hex()}] |
| 6317 | onion = l1.rpc.createonion(hops=hops, assocdata=inv1['payment_hash']) |
| 6318 | |
| 6319 | ret = l1.rpc.injectpaymentonion(onion=onion['onion'], |
| 6320 | payment_hash=inv1['payment_hash'], |
| 6321 | amount_msat=1000, |
| 6322 | cltv_expiry=blockheight + 18 + 6, |
| 6323 | partid=1, |
| 6324 | groupid=0) |
| 6325 | assert ret['completed_at'] >= ret['created_at'] |
| 6326 | assert sha256(bytes.fromhex(ret['payment_preimage'])).hexdigest() == inv1['payment_hash'] |
| 6327 | assert ret == {'payment_preimage': ret['payment_preimage'], |
| 6328 | 'created_index': 1, |
| 6329 | 'completed_at': ret['completed_at'], |
| 6330 | 'created_at': ret['created_at']} |
| 6331 | assert only_one(l2.rpc.listinvoices("test_injectpaymentonion1")['invoices'])['status'] == 'paid' |
| 6332 | lsp = only_one(l1.rpc.listsendpays(inv1['bolt11'])['payments']) |
| 6333 | assert lsp['groupid'] == 0 |
| 6334 | assert lsp['partid'] == 1 |
| 6335 | assert lsp['payment_hash'] == inv1['payment_hash'] |
| 6336 | assert lsp['status'] == 'complete' |
| 6337 | assert 'amount_msat' not in lsp |
| 6338 | |
| 6339 | # We FAIL on reattempt |
| 6340 | with pytest.raises(RpcError, match="Already paid this invoice") as err: |
| 6341 | l1.rpc.injectpaymentonion(onion=onion['onion'], |
| 6342 | payment_hash=inv1['payment_hash'], |
| 6343 | amount_msat=1000, |
| 6344 | cltv_expiry=blockheight + 18 + 6, |
| 6345 | partid=1, |
| 6346 | groupid=0) |
| 6347 | # PAY_INJECTPAYMENTONION_ALREADY_PAID |
| 6348 | assert err.value.error['code'] == 219 |
| 6349 | assert 'onionreply' not in err.value.error['data'] |
| 6350 | assert err.value.error['data'] == lsp |
| 6351 | |
| 6352 | |
| 6353 | def test_injectpaymentonion_mpp(node_factory, executor): |
nothing calls this directly
no test coverage detected