MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_fetchinvoice_recurrence

Function test_fetchinvoice_recurrence

tests/test_pay.py:4775–4866  ·  view source on GitHub ↗

Test for our recurrence extension

(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

4773
4774
4775def test_fetchinvoice_recurrence(node_factory, bitcoind):
4776 """Test for our recurrence extension"""
4777 l1, l2, l3 = node_factory.line_graph(3, wait_for_announce=True,
4778 opts=[{}, {'dev-allow-localhost': None}, {}])
4779
4780 # Recurring offer.
4781 offer3 = l2.rpc.call('offer', {'amount': '1msat',
4782 'description': 'recurring test',
4783 'recurrence': '1minutes'})
4784 assert only_one(l2.rpc.call('listoffers', [offer3['offer_id']])['offers'])['used'] is False
4785
4786 ret = l1.rpc.call('fetchinvoice', {'offer': offer3['bolt12'],
4787 'recurrence_counter': 0,
4788 'recurrence_label': 'test recurrence'})
4789 period1 = ret['next_period']
4790 assert period1['counter'] == 1
4791 assert period1['endtime'] == period1['starttime'] + 59
4792 assert period1['paywindow_start'] == period1['starttime'] - 60
4793 assert period1['paywindow_end'] == period1['endtime']
4794 assert only_one(l2.rpc.call('listoffers', [offer3['offer_id']])['offers'])['used'] is False
4795
4796 l1.rpc.pay(ret['invoice'], label='test recurrence')
4797 assert only_one(l2.rpc.call('listoffers', [offer3['offer_id']])['offers'])['used'] is True
4798
4799 ret = l1.rpc.call('fetchinvoice', {'offer': offer3['bolt12'],
4800 'recurrence_counter': 1,
4801 'recurrence_label': 'test recurrence'})
4802 period2 = ret['next_period']
4803 assert period2['counter'] == 2
4804 assert period2['starttime'] == period1['endtime'] + 1
4805 assert period2['endtime'] == period2['starttime'] + 59
4806 assert period2['paywindow_start'] == period2['starttime'] - 60
4807 assert period2['paywindow_end'] == period2['endtime']
4808
4809 # Can't request 2 before paying 1.
4810 with pytest.raises(RpcError, match='previous invoice has not been paid'):
4811 l1.rpc.call('fetchinvoice', {'offer': offer3['bolt12'],
4812 'recurrence_counter': 2,
4813 'recurrence_label': 'test recurrence'})
4814
4815 l1.rpc.pay(ret['invoice'], label='test recurrence')
4816
4817 # Now we can, but it's too early:
4818 with pytest.raises(RpcError, match="Too early: can't send until time {}".format(period1['starttime'])):
4819 l1.rpc.call('fetchinvoice', {'offer': offer3['bolt12'],
4820 'recurrence_counter': 2,
4821 'recurrence_label': 'test recurrence'})
4822
4823 # Wait until the correct moment.
4824 while time.time() < period1['starttime']:
4825 time.sleep(1)
4826
4827 l1.rpc.call('fetchinvoice', {'offer': offer3['bolt12'],
4828 'recurrence_counter': 2,
4829 'recurrence_label': 'test recurrence'})
4830
4831 # Now try an offer with a more complex paywindow (only 10 seconds before)
4832 offer = l2.rpc.call('offer', {'amount': '1msat',

Callers

nothing calls this directly

Calls 4

only_oneFunction · 0.90
line_graphMethod · 0.80
callMethod · 0.45
payMethod · 0.45

Tested by

no test coverage detected