Browse Source

pytest: Add a test for htlc_accepted hook replay on startup

htlc_accepted_hook
Christian Decker 6 years ago
committed by Rusty Russell
parent
commit
dd26a01c54
  1. 27
      tests/plugins/hold_htlcs.py
  2. 35
      tests/test_plugin.py

27
tests/plugins/hold_htlcs.py

@ -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()

35
tests/test_plugin.py

@ -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()

Loading…
Cancel
Save