(node_factory)
| 24 | @pytest.mark.openchannel('v1') |
| 25 | @pytest.mark.openchannel('v2') |
| 26 | def test_pay(node_factory): |
| 27 | l1, l2 = node_factory.line_graph(2) |
| 28 | |
| 29 | inv = l2.rpc.invoice(123000, 'test_pay', 'description')['bolt11'] |
| 30 | before = int(time.time()) |
| 31 | details = l1.dev_pay(inv, dev_use_shadow=False) |
| 32 | after = time.time() |
| 33 | preimage = details['payment_preimage'] |
| 34 | assert details['status'] == 'complete' |
| 35 | assert details['amount_msat'] == Millisatoshi(123000) |
| 36 | assert details['destination'] == l2.info['id'] |
| 37 | assert details['created_at'] >= before |
| 38 | assert details['created_at'] <= after |
| 39 | |
| 40 | invoices = l2.rpc.listinvoices('test_pay')['invoices'] |
| 41 | assert len(invoices) == 1 |
| 42 | invoice = invoices[0] |
| 43 | assert invoice['status'] == 'paid' and invoice['paid_at'] >= before and invoice['paid_at'] <= after |
| 44 | |
| 45 | # Repeat payments are NOPs (if valid): we can hand null. |
| 46 | l1.dev_pay(inv, dev_use_shadow=False) |
| 47 | # This won't work: can't provide an amount (even if correct!) |
| 48 | with pytest.raises(RpcError): |
| 49 | l1.rpc.pay(inv, 123000) |
| 50 | with pytest.raises(RpcError): |
| 51 | l1.rpc.pay(inv, 122000) |
| 52 | |
| 53 | # Check pay_index is not null |
| 54 | outputs = l2.db_query('SELECT pay_index IS NOT NULL AS q FROM invoices WHERE label="label";') |
| 55 | assert len(outputs) == 1 and outputs[0]['q'] != 0 |
| 56 | |
| 57 | # Check payment of any-amount invoice. |
| 58 | for i in range(5): |
| 59 | label = "any{}".format(i) |
| 60 | inv2 = l2.rpc.invoice("any", label, 'description')['bolt11'] |
| 61 | # Must provide an amount! |
| 62 | with pytest.raises(RpcError): |
| 63 | l1.rpc.pay(inv2) |
| 64 | l1.dev_pay(inv2, random.randint(1000, 999999), dev_use_shadow=False) |
| 65 | |
| 66 | # Should see 6 completed payments |
| 67 | assert len(l1.rpc.listsendpays()['payments']) == 6 |
| 68 | |
| 69 | # Test listsendpays indexed by bolt11. |
| 70 | payments = l1.rpc.listsendpays(inv)['payments'] |
| 71 | assert len(payments) == 1 and payments[0]['payment_preimage'] == preimage |
| 72 | |
| 73 | # Make sure they're completely settled, so accounting correct. |
| 74 | wait_for(lambda: only_one(l1.rpc.listpeerchannels()['channels'])['htlcs'] == []) |
| 75 | |
| 76 | # Check channels apy summary view of channel activity |
| 77 | apys_1 = l1.rpc.bkpr_channelsapy()['channels_apy'] |
| 78 | apys_2 = l2.rpc.bkpr_channelsapy()['channels_apy'] |
| 79 | |
| 80 | assert apys_1[0]['channel_start_balance_msat'] == apys_2[0]['channel_start_balance_msat'] |
| 81 | assert apys_1[0]['channel_start_balance_msat'] == apys_1[0]['our_start_balance_msat'] |
| 82 | assert apys_2[0]['our_start_balance_msat'] == Millisatoshi(0) |
| 83 | assert apys_1[0]['routed_out_msat'] == apys_2[0]['routed_in_msat'] |
nothing calls this directly
no test coverage detected