mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
pytest: Add a simple test for the hooks
This uses the `htlc_accepted` hook to delay payment acceptance. Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
committed by
Rusty Russell
parent
7499f7ddd4
commit
b54577041a
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from lightning import Plugin
|
from lightning import Plugin
|
||||||
|
import time
|
||||||
|
|
||||||
plugin = Plugin()
|
plugin = Plugin()
|
||||||
|
|
||||||
@@ -34,5 +34,12 @@ def on_disconnect(plugin, id):
|
|||||||
plugin.log("Received disconnect event for peer {}".format(id))
|
plugin.log("Received disconnect event for peer {}".format(id))
|
||||||
|
|
||||||
|
|
||||||
|
@plugin.hook("htlc_accepted")
|
||||||
|
def on_htlc_accepted(plugin):
|
||||||
|
plugin.log('on_htlc_accepted called')
|
||||||
|
time.sleep(20)
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
plugin.add_option('greeting', 'Hello', 'The greeting I should use.')
|
plugin.add_option('greeting', 'Hello', 'The greeting I should use.')
|
||||||
plugin.run()
|
plugin.run()
|
||||||
|
|||||||
@@ -107,6 +107,26 @@ def test_plugin_disable(node_factory):
|
|||||||
n.rpc.hello(name='Sun')
|
n.rpc.hello(name='Sun')
|
||||||
|
|
||||||
|
|
||||||
|
def test_plugin_hook(node_factory, executor):
|
||||||
|
"""The helloworld plugin registers a htlc_accepted hook.
|
||||||
|
|
||||||
|
The hook will sleep for a few seconds and log a
|
||||||
|
message. `lightningd` should wait for the response and only then
|
||||||
|
complete the payment.
|
||||||
|
|
||||||
|
"""
|
||||||
|
l1, l2 = node_factory.line_graph(2, opts={'plugin': 'contrib/plugins/helloworld.py'})
|
||||||
|
start_time = time.time()
|
||||||
|
f = executor.submit(l1.pay, l2, 100000)
|
||||||
|
l2.daemon.wait_for_log(r'on_htlc_accepted called')
|
||||||
|
|
||||||
|
# The hook will sleep for 20 seconds before answering, so `f`
|
||||||
|
# should take at least that long.
|
||||||
|
f.result()
|
||||||
|
end_time = time.time()
|
||||||
|
assert(end_time >= start_time + 20)
|
||||||
|
|
||||||
|
|
||||||
def test_plugin_notifications(node_factory):
|
def test_plugin_notifications(node_factory):
|
||||||
l1, l2 = node_factory.get_nodes(2, opts={'plugin': 'contrib/plugins/helloworld.py'})
|
l1, l2 = node_factory.get_nodes(2, opts={'plugin': 'contrib/plugins/helloworld.py'})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user