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

Function test_cancel_recurrence

tests/test_pay.py:7167–7212  ·  view source on GitHub ↗

Test handling of invoice cancellation

(node_factory)

Source from the content-addressed store, hash-verified

7165
7166
7167def test_cancel_recurrence(node_factory):
7168 """Test handling of invoice cancellation"""
7169 l1, l2 = node_factory.line_graph(2)
7170
7171 # Recurring offer.
7172 offer = l2.rpc.offer(amount='1msat',
7173 description='test_cancel_recurrence',
7174 recurrence='1minutes')
7175 # Check it decodes ok!
7176 l1.rpc.decode(offer['bolt12'])
7177
7178 # We cannot cancel if we never got the first one.
7179 with pytest.raises(RpcError, match="recurrence_counter: Must be non-zero"):
7180 l1.rpc.cancelrecurringinvoice(offer['bolt12'], 0, 'test_cancel_recurrence')
7181
7182 with pytest.raises(RpcError, match="No previous payment attempted for this label and offer"):
7183 l1.rpc.cancelrecurringinvoice(offer['bolt12'], 1, 'test_cancel_recurrence')
7184
7185 # Fetch and pay first one
7186 ret = l1.rpc.fetchinvoice(offer=offer['bolt12'],
7187 recurrence_counter=0,
7188 recurrence_label='test_cancel_recurrence')
7189 l1.rpc.pay(ret['invoice'], label='test_cancel_recurrence')
7190 m = re.search(r'invoice_request: "([a-z0-9]*)"', l1.daemon.wait_for_log('plugin-offers: invoice_request:'))
7191 decoded = l1.rpc.decode(m.group(1))
7192 assert 'invreq_recurrence_cancel' not in decoded
7193
7194 # Cancel counter must be correct!
7195 with pytest.raises(RpcError, match=r"previous invoice has not been paid \(last was 0\)"):
7196 l1.rpc.cancelrecurringinvoice(offer['bolt12'], 2, 'test_cancel_recurrence')
7197
7198 # Cancel second one.
7199 l1.rpc.cancelrecurringinvoice(offer=offer['bolt12'],
7200 recurrence_counter=1,
7201 recurrence_label='test_cancel_recurrence')
7202
7203 # Get invoice request: it will have invreq_recurrence_cancel
7204 m = re.search(r'invoice_request: "([a-z0-9]*)"', l1.daemon.wait_for_log('plugin-offers: invoice_request:'))
7205 decoded = l1.rpc.decode(m.group(1))
7206 assert decoded['invreq_recurrence_cancel'] is True
7207
7208 # Now we cannot fetch second one!
7209 with pytest.raises(RpcError, match=r"invoice expired \(cancelled\?\)"):
7210 l1.rpc.fetchinvoice(offer=offer['bolt12'],
7211 recurrence_counter=1,
7212 recurrence_label='test_cancel_recurrence')
7213
7214
7215def test_htlc_tlv_crash(node_factory):

Callers

nothing calls this directly

Calls 6

line_graphMethod · 0.80
fetchinvoiceMethod · 0.80
wait_for_logMethod · 0.80
offerMethod · 0.45
decodeMethod · 0.45
payMethod · 0.45

Tested by

no test coverage detected