From 023d124e4f85e0c63edb7c6efefe987d3dbcbe56 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Tue, 10 Nov 2020 09:24:08 -0300 Subject: [PATCH] failure_onion: a test that only ensures lightningd doesn't crash. --- tests/plugins/htlc_accepted-failonion.py | 29 ++++++++++++++++++++++++ tests/test_plugin.py | 11 +++++++++ 2 files changed, 40 insertions(+) create mode 100755 tests/plugins/htlc_accepted-failonion.py diff --git a/tests/plugins/htlc_accepted-failonion.py b/tests/plugins/htlc_accepted-failonion.py new file mode 100755 index 000000000000..c6c1ec5fe96f --- /dev/null +++ b/tests/plugins/htlc_accepted-failonion.py @@ -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() diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 5fce24f62fe6..9243c6889fde 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -1928,3 +1928,14 @@ def test_htlc_accepted_hook_failcodes(node_factory): inv = l2.rpc.invoice(42, 'failcode{}'.format(failcode), '')['bolt11'] with pytest.raises(RpcError, match=r'failcodename.: .{}.'.format(expected)): l1.rpc.pay(inv) + + +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) + inv = l2.rpc.invoice(42, 'failonion000', '')['bolt11'] + with pytest.raises(RpcError): + l1.rpc.pay(inv)