(node_factory, executor)
| 6232 | |
| 6233 | |
| 6234 | def 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 | |
| 6281 | def test_injectpaymentonion_mpp(node_factory, executor): |
nothing calls this directly
no test coverage detected