Skip to content

Commit

Permalink
failure_onion: a test that only ensures lightningd doesn't crash.
Browse files Browse the repository at this point in the history
  • Loading branch information
fiatjaf committed Nov 10, 2020
1 parent a200f02 commit 023d124
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/plugins/htlc_accepted-failonion.py
Original file line number Diff line number Diff line change
@@ -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()
11 changes: 11 additions & 0 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 023d124

Please sign in to comment.