diff --git a/tests/plugins/fail_htlcs_invalid.py b/tests/plugins/fail_htlcs_invalid.py new file mode 100755 index 000000000..95881d8b7 --- /dev/null +++ b/tests/plugins/fail_htlcs_invalid.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 + +from pyln.client import Plugin + +plugin = Plugin() + + +@plugin.hook("htlc_accepted") +def on_htlc_accepted(onion, plugin, **kwargs): + plugin.log("Failing htlc on purpose with invalid onion failure") + plugin.log("onion: %r" % (onion)) + # WIRE_TEMPORARY_CHANNEL_FAILURE = 0x1007 + # This failure code should be followed by a + # `channel_update`; we deliberately return + # a 0-length `channel_update` to trigger + # issue #3757 reported by @sumBTC. + return {"result": "fail", "failure_message": "10070000"} + + +plugin.run() diff --git a/tests/test_pay.py b/tests/test_pay.py index 6c0190481..66dada0a9 100644 --- a/tests/test_pay.py +++ b/tests/test_pay.py @@ -3017,3 +3017,30 @@ def test_keysend(node_factory): inv = invs[0] assert(inv['msatoshi_received'] >= amt) + + +@pytest.mark.xfail(strict=True) +def test_invalid_onion_channel_update(node_factory): + ''' + Some onion failures "should" send a `channel_update`. + + This test checks to see if we handle things correctly + even if some remote node does not send the required + `channel_update`. + ''' + plugin = os.path.join(os.getcwd(), 'tests/plugins/fail_htlcs_invalid.py') + l1, l2, l3 = node_factory.line_graph(3, + opts=[{}, + {'plugin': plugin}, + {}], + wait_for_announce=True) + + l1id = l1.info['id'] + + inv = l3.rpc.invoice(12345, 'inv', 'inv')['bolt11'] + # Should fail, since l2 will always fail to forward. + with pytest.raises(RpcError): + l1.rpc.pay(inv) + + # l1 should still be alive afterwards. + assert l1.rpc.getinfo()['id'] == l1id