mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-22 16:44:20 +01:00
pytest: Add a test for htlc_accepted hook replay on startup
This commit is contained in:
committed by
Rusty Russell
parent
6db1e76156
commit
dd26a01c54
27
tests/plugins/hold_htlcs.py
Executable file
27
tests/plugins/hold_htlcs.py
Executable file
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Plugin that holds on to HTLCs for 10 seconds.
|
||||
|
||||
Used to test restarts / crashes while HTLCs were accepted, but not yet
|
||||
settled/forwarded/
|
||||
|
||||
"""
|
||||
|
||||
|
||||
from lightning import Plugin
|
||||
import time
|
||||
|
||||
|
||||
plugin = Plugin()
|
||||
|
||||
|
||||
@plugin.hook("htlc_accepted")
|
||||
def on_htlc_accepted(htlc, onion, plugin):
|
||||
plugin.log("Holding onto an incoming htlc for 10 seconds")
|
||||
time.sleep(10)
|
||||
|
||||
# Give the tester something to look for
|
||||
plugin.log("htlc_accepted hook called")
|
||||
return {'result': 'continue'}
|
||||
|
||||
|
||||
plugin.run()
|
||||
@@ -384,3 +384,38 @@ def test_htlc_accepted_hook_resolve(node_factory):
|
||||
# And the invoice must still be unpaid
|
||||
inv = l3.rpc.listinvoices("lbl")['invoices']
|
||||
assert len(inv) == 1 and inv[0]['status'] == 'unpaid'
|
||||
|
||||
|
||||
def test_htlc_accepted_hook_direct_restart(node_factory, executor):
|
||||
"""l2 restarts while it is pondering what to do with an HTLC.
|
||||
"""
|
||||
l1, l2 = node_factory.line_graph(2, opts=[
|
||||
{'may_reconnect': True},
|
||||
{'may_reconnect': True, 'plugin': 'tests/plugins/hold_htlcs.py'}
|
||||
])
|
||||
|
||||
i1 = l2.rpc.invoice(msatoshi=1000, label="direct", description="desc")['bolt11']
|
||||
f1 = executor.submit(l1.rpc.pay, i1)
|
||||
|
||||
l2.daemon.wait_for_log(r'Holding onto an incoming htlc for 10 seconds')
|
||||
l2.restart()
|
||||
|
||||
f1.result()
|
||||
|
||||
|
||||
def test_htlc_accepted_hook_forward_restart(node_factory, executor):
|
||||
"""l2 restarts while it is pondering what to do with an HTLC.
|
||||
"""
|
||||
l1, l2, l3 = node_factory.line_graph(3, opts=[
|
||||
{'may_reconnect': True},
|
||||
{'may_reconnect': True, 'plugin': 'tests/plugins/hold_htlcs.py'},
|
||||
{'may_reconnect': True},
|
||||
], wait_for_announce=True)
|
||||
|
||||
i1 = l3.rpc.invoice(msatoshi=1000, label="direct", description="desc")['bolt11']
|
||||
f1 = executor.submit(l1.rpc.pay, i1)
|
||||
|
||||
l2.daemon.wait_for_log(r'Holding onto an incoming htlc for 10 seconds')
|
||||
l2.restart()
|
||||
|
||||
f1.result()
|
||||
|
||||
Reference in New Issue
Block a user