Browse Source

df-tests: test_openchannel_hook_chaining

ppa
niftynei 4 years ago
committed by Christian Decker
parent
commit
803d9701d3
  1. 3
      lightningd/dual_open_control.c
  2. 12
      tests/plugins/openchannel_hook_accept.py
  3. 12
      tests/plugins/openchannel_hook_reject.py
  4. 2
      tests/test_plugin.py

3
lightningd/dual_open_control.c

@ -373,6 +373,9 @@ openchannel2_hook_cb(struct openchannel2_payload *payload STEALS)
tal_del_destructor2(dualopend, openchannel2_remove_dualopend, payload);
if (payload->err_msg) {
log_debug(dualopend->ld->log,
"openchannel2_hook rejects and says '%s'",
payload->err_msg);
msg = towire_dualopend_fail(NULL, payload->err_msg);
return subd_send_msg(dualopend, take(msg));
}

12
tests/plugins/openchannel_hook_accept.py

@ -5,10 +5,14 @@ Will simply accept any channel. Useful fot testing chained hook.
"""
from pyln.client import Plugin
from pyln.testing.utils import env
plugin = Plugin()
EXPERIMENTAL_FEATURES = env("EXPERIMENTAL_FEATURES", "0") == "1"
@plugin.hook('openchannel')
def on_openchannel(openchannel, plugin, **kwargs):
msg = "accept on principle"
@ -16,4 +20,12 @@ def on_openchannel(openchannel, plugin, **kwargs):
return {'result': 'continue'}
if EXPERIMENTAL_FEATURES:
@plugin.hook('openchannel2')
def on_openchannel2(openchannel2, plugin, **kwargs):
msg = "accept on principle"
plugin.log(msg)
return {'result': 'continue'}
plugin.run()

12
tests/plugins/openchannel_hook_reject.py

@ -6,6 +6,10 @@ Useful fot testing chained hook.
"""
from pyln.client import Plugin
from pyln.testing.utils import env
EXPERIMENTAL_FEATURES = env("EXPERIMENTAL_FEATURES", "0") == "1"
plugin = Plugin()
@ -17,4 +21,12 @@ def on_openchannel(openchannel, plugin, **kwargs):
return {'result': 'reject', 'error_message': msg}
if EXPERIMENTAL_FEATURES:
@plugin.hook('openchannel2')
def on_openchannel2(openchannel2, plugin, **kwargs):
msg = "reject on principle"
plugin.log(msg)
return {'result': 'reject', 'error_message': msg}
plugin.run()

2
tests/test_plugin.py

@ -646,7 +646,7 @@ def test_openchannel_hook_chaining(node_factory, bitcoind):
l1, l2 = node_factory.line_graph(2, fundchannel=False, opts=opts)
l1.fundwallet(10**6)
hook_msg = "openchannel_hook rejects and says '"
hook_msg = "openchannel2?_hook rejects and says '"
# 100005sat fundchannel should fail fatal() for l2
# because hook_accepter.py rejects on that amount 'for a reason'
with pytest.raises(RpcError, match=r'They sent error channel'):

Loading…
Cancel
Save