(node_factory, anchors)
| 721 | @unittest.skipIf(TEST_NETWORK != 'regtest', "The reserve computation is bitcoin specific") |
| 722 | @pytest.mark.parametrize("anchors", [False, True]) |
| 723 | def test_sendpay_cant_afford(node_factory, anchors): |
| 724 | # Set feerates the same so we don't have to wait for update. |
| 725 | opts = {'feerates': (15000, 15000, 15000, 15000), |
| 726 | 'commit-feerate-offset': 0} |
| 727 | if anchors is False: |
| 728 | opts['dev-force-features'] = "-23" |
| 729 | |
| 730 | l1, l2 = node_factory.line_graph(2, fundamount=10**6, opts=opts) |
| 731 | |
| 732 | # Can't pay more than channel capacity. |
| 733 | with pytest.raises(RpcError): |
| 734 | l1.pay(l2, 10**9 + 1) |
| 735 | |
| 736 | # Reserve is 1%. |
| 737 | reserve = 10**7 |
| 738 | |
| 739 | # This is how we recalc constants (v. v. slow!) |
| 740 | # minimum = 1 |
| 741 | # maximum = 10**9 |
| 742 | # while maximum - minimum > 1: |
| 743 | # l1, l2 = node_factory.line_graph(2, fundamount=10**6, opts=opts) |
| 744 | # try: |
| 745 | # l1.pay(l2, (minimum + maximum) // 2) |
| 746 | # print("XXX Pay {} WORKED!".format((minimum + maximum) // 2)) |
| 747 | # minimum = (minimum + maximum) // 2 |
| 748 | # except RpcError: |
| 749 | # print("XXX Pay {} FAILED!".format((minimum + maximum) // 2)) |
| 750 | # maximum = (minimum + maximum) // 2 |
| 751 | # print("{} - {}".format(minimum, maximum)) |
| 752 | |
| 753 | # assert False, "Max we can pay == {}".format(minimum) |
| 754 | # # Currently this gives: 962713000 for non-anchors, 951833000 for anchors |
| 755 | # # Add reserve to this result to derive `available` |
| 756 | |
| 757 | # This is the fee, which needs to be taken into account for l1. |
| 758 | if anchors: |
| 759 | available = 951833000 + reserve |
| 760 | else: |
| 761 | available = 962713000 + reserve |
| 762 | |
| 763 | # Can't pay past reserve. |
| 764 | with pytest.raises(RpcError): |
| 765 | l1.pay(l2, available) |
| 766 | with pytest.raises(RpcError): |
| 767 | l1.pay(l2, available - reserve + 1) |
| 768 | |
| 769 | # Can pay up to reserve (1%) |
| 770 | l1.pay(l2, available - reserve) |
| 771 | |
| 772 | # And now it can't pay back, due to its own reserve. |
| 773 | with pytest.raises(RpcError): |
| 774 | l2.pay(l1, available - reserve) |
| 775 | |
| 776 | # But this should work. |
| 777 | l2.pay(l1, available - reserve * 2) |
| 778 | |
| 779 | |
| 780 | def test_decode(node_factory): |
nothing calls this directly
no test coverage detected