mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
failure_onion: a test that only ensures lightningd doesn't crash.
This commit is contained in:
29
tests/plugins/htlc_accepted-failonion.py
Executable file
29
tests/plugins/htlc_accepted-failonion.py
Executable file
@@ -0,0 +1,29 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""A simply plugin that fails HTLCs with a meaningless onion.
|
||||||
|
|
||||||
|
"""
|
||||||
|
from pyln.client import Plugin
|
||||||
|
|
||||||
|
|
||||||
|
plugin = Plugin()
|
||||||
|
|
||||||
|
|
||||||
|
@plugin.hook("htlc_accepted")
|
||||||
|
def on_htlc_accepted(htlc, onion, plugin, **kwargs):
|
||||||
|
print('returning failonion', plugin.failonion)
|
||||||
|
return {"result": "fail", "failure_onion": plugin.failonion}
|
||||||
|
|
||||||
|
|
||||||
|
@plugin.method("setfailonion")
|
||||||
|
def setfailonion(plugin, onion):
|
||||||
|
"""Sets the failure_onion to return when receiving an incoming HTLC.
|
||||||
|
"""
|
||||||
|
plugin.failonion = onion
|
||||||
|
|
||||||
|
|
||||||
|
@plugin.init()
|
||||||
|
def on_init(**kwargs):
|
||||||
|
plugin.failonion = None
|
||||||
|
|
||||||
|
|
||||||
|
plugin.run()
|
||||||
@@ -2135,3 +2135,14 @@ def test_hook_dep_stable(node_factory):
|
|||||||
l2.daemon.wait_for_log(r"dep_d.py: htlc_accepted called")
|
l2.daemon.wait_for_log(r"dep_d.py: htlc_accepted called")
|
||||||
l2.daemon.wait_for_log(r"dep_e.py: htlc_accepted called")
|
l2.daemon.wait_for_log(r"dep_e.py: htlc_accepted called")
|
||||||
l2.daemon.wait_for_log(r"dep_b.py: htlc_accepted called")
|
l2.daemon.wait_for_log(r"dep_b.py: htlc_accepted called")
|
||||||
|
|
||||||
|
|
||||||
|
def test_htlc_accepted_hook_failonion(node_factory):
|
||||||
|
plugin = os.path.join(os.path.dirname(__file__), 'plugins/htlc_accepted-failonion.py')
|
||||||
|
l1, l2 = node_factory.line_graph(2, opts=[{}, {'plugin': plugin}])
|
||||||
|
|
||||||
|
# an invalid onion
|
||||||
|
l2.rpc.setfailonion('0' * (292 * 2))
|
||||||
|
inv = l2.rpc.invoice(42, 'failonion000', '')['bolt11']
|
||||||
|
with pytest.raises(RpcError):
|
||||||
|
l1.rpc.pay(inv)
|
||||||
|
|||||||
Reference in New Issue
Block a user