We get much more descriptive errors from a self-payment than a remote payment, since we're not relying on a single WIRE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS but can share more useful information
(node_factory)
| 5607 | |
| 5608 | |
| 5609 | def test_self_sendpay(node_factory): |
| 5610 | """We get much more descriptive errors from a self-payment than a remote payment, since we're not relying on a single WIRE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS but can share more useful information""" |
| 5611 | l1 = node_factory.get_node() |
| 5612 | |
| 5613 | inv = l1.rpc.invoice('100000sat', 'test_selfpay', "Test of payment to self") |
| 5614 | assert only_one(l1.rpc.listinvoices()['invoices'])['status'] == 'unpaid' |
| 5615 | inv_expires = l1.rpc.invoice('1btc', 'test_selfpay-expires', "Test of payment to self", expiry=1) |
| 5616 | |
| 5617 | # Requires amount. |
| 5618 | with pytest.raises(RpcError, match="Self-payment requires amount_msat"): |
| 5619 | l1.rpc.sendpay([], inv['payment_hash'], label='selfpay', bolt11=inv['bolt11'], payment_secret=inv['payment_secret']) |
| 5620 | |
| 5621 | # Requires non-zero partid. |
| 5622 | with pytest.raises(RpcError, match=r"Self-payment does not allow \(non-zero\) partid"): |
| 5623 | l1.rpc.sendpay([], inv['payment_hash'], label='selfpay', bolt11=inv['bolt11'], payment_secret=inv['payment_secret'], amount_msat='100000sat', partid=1) |
| 5624 | |
| 5625 | # Bad payment_hash. |
| 5626 | with pytest.raises(RpcError, match="Unknown invoice"): |
| 5627 | l1.rpc.sendpay([], '00' * 32, label='selfpay-badimage', bolt11=inv['bolt11'], payment_secret=inv['payment_secret'], amount_msat='100000sat') |
| 5628 | |
| 5629 | # Missing payment_secret |
| 5630 | with pytest.raises(RpcError, match="Attempt to pay .* without secret"): |
| 5631 | l1.rpc.sendpay([], inv['payment_hash'], label='selfpay-badimage', bolt11=inv['bolt11'], amount_msat='100000sat') |
| 5632 | |
| 5633 | # Bad payment_secret |
| 5634 | with pytest.raises(RpcError, match="Attempt to pay .* with wrong payment_secret"): |
| 5635 | l1.rpc.sendpay([], inv['payment_hash'], label='selfpay-badimage', bolt11=inv['bolt11'], payment_secret='00' * 32, amount_msat='100000sat') |
| 5636 | |
| 5637 | # Expired |
| 5638 | time.sleep(2) |
| 5639 | with pytest.raises(RpcError, match="Already paid or expired invoice"): |
| 5640 | l1.rpc.sendpay([], inv_expires['payment_hash'], label='selfpay-badimage', bolt11=inv_expires['bolt11'], payment_secret=inv['payment_secret'], amount_msat='1btc') |
| 5641 | |
| 5642 | # This one works! |
| 5643 | l1.rpc.sendpay([], inv['payment_hash'], label='selfpay', bolt11=inv['bolt11'], payment_secret=inv['payment_secret'], amount_msat='100000sat') |
| 5644 | |
| 5645 | assert only_one(l1.rpc.listinvoices(payment_hash=inv['payment_hash'])['invoices'])['status'] == 'paid' |
| 5646 | # Only one is complete. |
| 5647 | assert [p['status'] for p in l1.rpc.listsendpays()['payments'] if p['status'] != 'failed'] == ['complete'] |
| 5648 | |
| 5649 | # Can't pay paid one already paid! |
| 5650 | with pytest.raises(RpcError, match="Already paid or expired invoice"): |
| 5651 | l1.rpc.sendpay([], inv['payment_hash'], label='selfpay', bolt11=inv['bolt11'], payment_secret=inv['payment_secret'], amount_msat='100000sat') |
| 5652 | |
| 5653 | |
| 5654 | def test_strip_lightning_suffix_from_inv(node_factory): |
nothing calls this directly
no test coverage detected