(node_factory)
| 559 | |
| 560 | |
| 561 | def test_sendpay(node_factory): |
| 562 | l1, l2 = node_factory.line_graph(2, fundamount=10**6) |
| 563 | |
| 564 | amt = 200000000 |
| 565 | inv = l2.rpc.invoice(amt, 'testpayment2', 'desc') |
| 566 | rhash = inv['payment_hash'] |
| 567 | |
| 568 | def invoice_unpaid(dst, label): |
| 569 | invoices = dst.rpc.listinvoices(label)['invoices'] |
| 570 | return len(invoices) == 1 and invoices[0]['status'] == 'unpaid' |
| 571 | |
| 572 | routestep = { |
| 573 | 'amount_msat': amt, |
| 574 | 'id': l2.info['id'], |
| 575 | 'delay': 5, |
| 576 | 'channel': first_scid(l1, l2) |
| 577 | } |
| 578 | |
| 579 | # Insufficient funds. |
| 580 | with pytest.raises(RpcError): |
| 581 | rs = copy.deepcopy(routestep) |
| 582 | rs['amount_msat'] = rs['amount_msat'] - 1 |
| 583 | l1.rpc.sendpay([rs], rhash, payment_secret=inv['payment_secret']) |
| 584 | l1.rpc.waitsendpay(rhash) |
| 585 | assert invoice_unpaid(l2, 'testpayment2') |
| 586 | |
| 587 | # Gross overpayment (more than factor of 2) |
| 588 | with pytest.raises(RpcError): |
| 589 | rs = copy.deepcopy(routestep) |
| 590 | rs['amount_msat'] = rs['amount_msat'] * 2 + 1 |
| 591 | l1.rpc.sendpay([rs], rhash, payment_secret=inv['payment_secret']) |
| 592 | l1.rpc.waitsendpay(rhash) |
| 593 | assert invoice_unpaid(l2, 'testpayment2') |
| 594 | |
| 595 | # Insufficient delay. |
| 596 | with pytest.raises(RpcError): |
| 597 | rs = copy.deepcopy(routestep) |
| 598 | rs['delay'] = rs['delay'] - 2 |
| 599 | l1.rpc.sendpay([rs], rhash, payment_secret=inv['payment_secret']) |
| 600 | l1.rpc.waitsendpay(rhash) |
| 601 | assert invoice_unpaid(l2, 'testpayment2') |
| 602 | |
| 603 | # Bad ID. |
| 604 | l1.rpc.check_request_schemas = False |
| 605 | with pytest.raises(RpcError): |
| 606 | rs = copy.deepcopy(routestep) |
| 607 | rs['id'] = '00000000000000000000000000000000' |
| 608 | l1.rpc.sendpay([rs], rhash, payment_secret=inv['payment_secret']) |
| 609 | assert invoice_unpaid(l2, 'testpayment2') |
| 610 | l1.rpc.check_request_schemas = True |
| 611 | |
| 612 | # Bad payment_secret |
| 613 | l1.rpc.sendpay([routestep], rhash, payment_secret="00" * 32) |
| 614 | with pytest.raises(RpcError): |
| 615 | l1.rpc.waitsendpay(rhash) |
| 616 | assert invoice_unpaid(l2, 'testpayment2') |
| 617 | |
| 618 | # Missing payment_secret |
nothing calls this directly
no test coverage detected