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

Function test_autoclean

tests/test_plugin.py:3315–3475  ·  view source on GitHub ↗
(node_factory)

Source from the content-addressed store, hash-verified

3313
3314
3315def test_autoclean(node_factory):
3316 l1, l2, l3 = node_factory.line_graph(3, opts={'may_reconnect': True},
3317 wait_for_announce=True)
3318
3319 # Under valgrind in CI, it can 50 seconds between creating invoice
3320 # and restarting.
3321 if VALGRIND:
3322 short_timeout = 10
3323 longer_timeout = 60
3324 else:
3325 short_timeout = 5
3326 longer_timeout = 20
3327
3328 assert l3.rpc.autoclean_status('expiredinvoices')['autoclean']['expiredinvoices']['enabled'] is False
3329 l3.rpc.invoice(amount_msat=12300, label='inv1', description='description1', expiry=short_timeout)
3330 l3.rpc.invoice(amount_msat=12300, label='inv2', description='description2', expiry=longer_timeout)
3331 l3.rpc.invoice(amount_msat=12300, label='inv3', description='description3', expiry=longer_timeout)
3332 inv4 = l3.rpc.invoice(amount_msat=12300, label='inv4', description='description4', expiry=2000)
3333 inv5 = l3.rpc.invoice(amount_msat=12300, label='inv5', description='description5', expiry=2000)
3334
3335 # It must be an integer!
3336 with pytest.raises(RpcError, match=r'is not a number'):
3337 l3.rpc.setconfig('autoclean-expiredinvoices-age', 'xxx')
3338
3339 # check gives the same answer.
3340 with pytest.raises(RpcError, match=r'is not a number'):
3341 l3.rpc.check('setconfig', config='autoclean-expiredinvoices-age', val='xxx')
3342
3343 # check does not actually set!
3344 l3.rpc.check('setconfig', config='autoclean-expiredinvoices-age', val=2) == {'command_to_check': 'setconfig'}
3345 assert l3.rpc.autoclean_status()['autoclean']['expiredinvoices']['enabled'] is False
3346
3347 l3.rpc.setconfig('autoclean-expiredinvoices-age', 2)
3348 assert l3.rpc.autoclean_status()['autoclean']['expiredinvoices']['enabled'] is True
3349 assert l3.rpc.autoclean_status()['autoclean']['expiredinvoices']['age'] == 2
3350
3351 # Both should still be there.
3352 assert l3.rpc.autoclean_status()['autoclean']['expiredinvoices']['cleaned'] == 0
3353 assert len(l3.rpc.listinvoices('inv1')['invoices']) == 1
3354 assert len(l3.rpc.listinvoices('inv2')['invoices']) == 1
3355 assert l3.rpc.listinvoices('inv1')['invoices'][0]['description'] == 'description1'
3356
3357 l3.rpc.setconfig('autoclean-cycle', 10)
3358
3359 # It will always go unpaid->expired->deleted, but we might miss it!
3360 was_expired = False
3361 while True:
3362 # Is it deleted yet?
3363 invs = l3.rpc.listinvoices('inv1')['invoices']
3364 if invs == []:
3365 break
3366 if was_expired:
3367 assert only_one(invs)['status'] == 'expired'
3368 else:
3369 if only_one(invs)['status'] == 'expired':
3370 was_expired = True
3371 else:
3372 assert only_one(invs)['status'] == 'unpaid'

Callers

nothing calls this directly

Calls 15

only_oneFunction · 0.90
wait_forFunction · 0.90
line_graphMethod · 0.80
autoclean_statusMethod · 0.80
restartMethod · 0.80
delinvoiceMethod · 0.80
listpaysMethod · 0.80
listsendpaysMethod · 0.80
listforwardsMethod · 0.80
invoiceMethod · 0.45
checkMethod · 0.45
listinvoicesMethod · 0.45

Tested by

no test coverage detected