Skip to content

Commit

Permalink
pytest: test the reply functionality (via blinded path) using a plugin.
Browse files Browse the repository at this point in the history
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell committed Mar 29, 2020
1 parent e4a379b commit 9d1848e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/plugins/onionmessage-reply.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python3
"""
This plugin is used to test the `onion_message` hook.
"""
from lightning import Plugin

plugin = Plugin()


@plugin.hook("onion_message")
def on_onion_message(plugin, onion_message, **kwargs):
if 'reply_path' not in onion_message:
plugin.log("no reply path")
return

plugin.rpc.call('sendonionmessage', [onion_message['reply_path']])
plugin.log("Sent reply via {}".format(onion_message['reply_path']))
return {"result": "continue"}


plugin.run()
30 changes: 30 additions & 0 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2198,6 +2198,36 @@ def test_sendonionmessage(node_factory):
assert l3.daemon.wait_for_log('Got onionmsg')


@unittest.skipIf(not EXPERIMENTAL_FEATURES, "Needs sendonionmessage")
def test_sendonionmessage_reply(node_factory):
blindedpathtool = os.path.join(os.path.dirname(__file__), "..", "devtools", "blindedpath")

plugin = os.path.join(os.path.dirname(__file__), "plugins", "onionmessage-reply.py")
l1, l2, l3 = node_factory.line_graph(3, opts={'plugin': plugin})

# Make reply path
output = subprocess.check_output(
[blindedpathtool, '--simple-output', 'create', l2.info['id'], l1.info['id']]
).decode('ASCII').strip()

# First line is blinding, then <peerid> then <encblob>.
blinding, p1, p1enc, p2 = output.split('\n')
# First hop can't be blinded!
assert p1 == l2.info['id']

l1.rpc.call('sendonionmessage',
{'hops':
[{'id': l2.info['id']},
{'id': l3.info['id']}],
'reply_path':
{'blinding': blinding,
'path': [{'id': p1, 'enctlv': p1enc}, {'id': p2}]}})

assert l3.daemon.wait_for_log('Got onionmsg reply_blinding reply_path')
assert l3.daemon.wait_for_log('Sent reply via')
assert l1.daemon.wait_for_log('Got onionmsg')


@unittest.skipIf(not DEVELOPER, "needs --dev-force-privkey")
def test_getsharedsecret(node_factory):
"""
Expand Down

0 comments on commit 9d1848e

Please sign in to comment.