Test various variants of waiting for the next invoice to complete.
(node_factory, executor)
| 502 | |
| 503 | |
| 504 | def test_waitanyinvoice(node_factory, executor): |
| 505 | """Test various variants of waiting for the next invoice to complete. |
| 506 | """ |
| 507 | l1, l2 = node_factory.line_graph(2) |
| 508 | inv1 = l2.rpc.invoice(1000, 'inv1', 'inv1') |
| 509 | inv2 = l2.rpc.invoice(1000, 'inv2', 'inv2') |
| 510 | inv3 = l2.rpc.invoice(1000, 'inv3', 'inv3') |
| 511 | inv4 = l2.rpc.invoice(1000, 'inv4', 'inv4') |
| 512 | |
| 513 | # Attempt to wait for the first invoice |
| 514 | f = executor.submit(l2.rpc.waitanyinvoice) |
| 515 | time.sleep(1) |
| 516 | |
| 517 | # The call to waitanyinvoice should not have returned just yet |
| 518 | assert not f.done() |
| 519 | |
| 520 | # Now pay the first two invoices and make sure we notice |
| 521 | l1.rpc.xpay(inv1['bolt11']) |
| 522 | l1.rpc.xpay(inv2['bolt11']) |
| 523 | r = f.result(timeout=5) |
| 524 | assert r['label'] == 'inv1' |
| 525 | pay_index = r['pay_index'] |
| 526 | |
| 527 | # This one should return immediately with inv2 |
| 528 | r = executor.submit(l2.rpc.waitanyinvoice, pay_index).result(timeout=5) |
| 529 | assert r['label'] == 'inv2' |
| 530 | pay_index = r['pay_index'] |
| 531 | |
| 532 | # Now spawn the next waiter |
| 533 | f = executor.submit(l2.rpc.waitanyinvoice, pay_index) |
| 534 | time.sleep(1) |
| 535 | assert not f.done() |
| 536 | l1.rpc.xpay(inv3['bolt11']) |
| 537 | r = f.result(timeout=5) |
| 538 | assert r['label'] == 'inv3' |
| 539 | pay_index = r['pay_index'] |
| 540 | |
| 541 | # If timeout is 0 and a paid invoice is not yet |
| 542 | # available, it should fail immediately. |
| 543 | with pytest.raises(RpcError): |
| 544 | l2.rpc.waitanyinvoice(pay_index, 0) |
| 545 | |
| 546 | # If timeout is 0 but a paid invoice is available |
| 547 | # anyway, it should return successfully immediately. |
| 548 | l1.rpc.xpay(inv4['bolt11']) |
| 549 | r = executor.submit(l2.rpc.waitanyinvoice, pay_index, 0).result(timeout=5) |
| 550 | assert r['label'] == 'inv4' |
| 551 | |
| 552 | l2.rpc.check_request_schemas = False |
| 553 | with pytest.raises(RpcError): |
| 554 | l2.rpc.waitanyinvoice('non-number') |
| 555 | |
| 556 | |
| 557 | def test_signinvoice(node_factory, executor): |
nothing calls this directly
no test coverage detected