`listpays` should be smart enough to group repeated `pay` calls. We always use slightly decreasing values for the payment, in order to avoid having to adjust the channel_hints that are being remembered across attempts. In case of a failure the `channel_hint` will be `attempted amoun
(node_factory, bitcoind)
| 5301 | |
| 5302 | |
| 5303 | def test_sendpay_grouping(node_factory, bitcoind): |
| 5304 | """`listpays` should be smart enough to group repeated `pay` calls. |
| 5305 | |
| 5306 | We always use slightly decreasing values for the payment, in order |
| 5307 | to avoid having to adjust the channel_hints that are being |
| 5308 | remembered across attempts. In case of a failure the |
| 5309 | `channel_hint` will be `attempted amount - 1msat` so use that as |
| 5310 | the next payment's amount. |
| 5311 | |
| 5312 | """ |
| 5313 | l1, l2, l3 = node_factory.line_graph( |
| 5314 | 3, |
| 5315 | wait_for_announce=True, |
| 5316 | opts=[ |
| 5317 | {}, |
| 5318 | {'may_reconnect': True}, |
| 5319 | {'may_reconnect': True}, |
| 5320 | ], |
| 5321 | ) |
| 5322 | wait_for(lambda: len(l1.rpc.listnodes()['nodes']) == 3) |
| 5323 | |
| 5324 | inv = l3.rpc.invoice(amount_msat='any', label='lbl1', description='desc')['bolt11'] |
| 5325 | l3.stop() # Stop recipient so the first attempt fails |
| 5326 | |
| 5327 | assert(len(l1.db.query("SELECT * FROM payments")) == 0) |
| 5328 | assert(len(l1.rpc.listpays()['pays']) == 0) |
| 5329 | |
| 5330 | with pytest.raises(RpcError, match=r'Failed after 1 attempts'): |
| 5331 | l1.rpc.xpay(inv, amount_msat='100002msat') |
| 5332 | |
| 5333 | # After this one invocation we have one entry in `listpays` |
| 5334 | assert(len(l1.rpc.listpays()['pays']) == 1) |
| 5335 | |
| 5336 | with pytest.raises(RpcError, match=r'Failed after 1 attempts'): |
| 5337 | l1.rpc.xpay(inv, amount_msat='100001msat') |
| 5338 | |
| 5339 | # Surprise: we should have 2 entries after 2 invocations |
| 5340 | assert(len(l1.rpc.listpays()['pays']) == 2) |
| 5341 | |
| 5342 | l3.start() |
| 5343 | invoices = l3.rpc.listinvoices()['invoices'] |
| 5344 | assert(len(invoices) == 1) |
| 5345 | assert(invoices[0]['status'] == 'unpaid') |
| 5346 | # Will reconnect automatically |
| 5347 | wait_for(lambda: only_one(l3.rpc.listpeers()['peers'])['connected'] is True) |
| 5348 | scid = l3.rpc.listpeerchannels()['channels'][0]['short_channel_id'] |
| 5349 | wait_for(lambda: [c['active'] for c in l1.rpc.listchannels(scid)['channels']] == [True, True]) |
| 5350 | l1.rpc.pay(inv, amount_msat='10000msat') |
| 5351 | |
| 5352 | # And finally we should have all 3 attempts to pay the invoice |
| 5353 | pays = l1.rpc.listpays()['pays'] |
| 5354 | assert(len(pays) == 3) |
| 5355 | assert([p['status'] for p in pays] == ['failed', 'failed', 'complete']) |
| 5356 | |
| 5357 | |
| 5358 | @pytest.mark.flaky(reruns=2) |
nothing calls this directly
no test coverage detected