(node_factory)
| 497 | |
| 498 | |
| 499 | def test_sendpay(node_factory): |
| 500 | l1, l2 = node_factory.line_graph(2, fundamount=10**6) |
| 501 | |
| 502 | amt = 200000000 |
| 503 | inv = l2.rpc.invoice(amt, 'testpayment2', 'desc') |
| 504 | rhash = inv['payment_hash'] |
| 505 | |
| 506 | def invoice_unpaid(dst, label): |
| 507 | invoices = dst.rpc.listinvoices(label)['invoices'] |
| 508 | return len(invoices) == 1 and invoices[0]['status'] == 'unpaid' |
| 509 | |
| 510 | routestep = { |
| 511 | 'amount_msat': amt, |
| 512 | 'id': l2.info['id'], |
| 513 | 'delay': 5, |
| 514 | 'channel': first_scid(l1, l2) |
| 515 | } |
| 516 | |
| 517 | # Insufficient funds. |
| 518 | with pytest.raises(RpcError): |
| 519 | rs = copy.deepcopy(routestep) |
| 520 | rs['amount_msat'] = rs['amount_msat'] - 1 |
| 521 | l1.rpc.sendpay([rs], rhash, payment_secret=inv['payment_secret']) |
| 522 | l1.rpc.waitsendpay(rhash) |
| 523 | assert invoice_unpaid(l2, 'testpayment2') |
| 524 | |
| 525 | # Gross overpayment (more than factor of 2) |
| 526 | with pytest.raises(RpcError): |
| 527 | rs = copy.deepcopy(routestep) |
| 528 | rs['amount_msat'] = rs['amount_msat'] * 2 + 1 |
| 529 | l1.rpc.sendpay([rs], rhash, payment_secret=inv['payment_secret']) |
| 530 | l1.rpc.waitsendpay(rhash) |
| 531 | assert invoice_unpaid(l2, 'testpayment2') |
| 532 | |
| 533 | # Insufficient delay. |
| 534 | with pytest.raises(RpcError): |
| 535 | rs = copy.deepcopy(routestep) |
| 536 | rs['delay'] = rs['delay'] - 2 |
| 537 | l1.rpc.sendpay([rs], rhash, payment_secret=inv['payment_secret']) |
| 538 | l1.rpc.waitsendpay(rhash) |
| 539 | assert invoice_unpaid(l2, 'testpayment2') |
| 540 | |
| 541 | # Bad ID. |
| 542 | l1.rpc.check_request_schemas = False |
| 543 | with pytest.raises(RpcError): |
| 544 | rs = copy.deepcopy(routestep) |
| 545 | rs['id'] = '00000000000000000000000000000000' |
| 546 | l1.rpc.sendpay([rs], rhash, payment_secret=inv['payment_secret']) |
| 547 | assert invoice_unpaid(l2, 'testpayment2') |
| 548 | l1.rpc.check_request_schemas = True |
| 549 | |
| 550 | # Bad payment_secret |
| 551 | l1.rpc.sendpay([routestep], rhash, payment_secret="00" * 32) |
| 552 | with pytest.raises(RpcError): |
| 553 | l1.rpc.waitsendpay(rhash) |
| 554 | assert invoice_unpaid(l2, 'testpayment2') |
| 555 | |
| 556 | # Missing payment_secret |
nothing calls this directly
no test coverage detected