Skip to content

Commit 9d1848e

Browse files
committed
pytest: test the reply functionality (via blinded path) using a plugin.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent e4a379b commit 9d1848e

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env python3
2+
"""
3+
This plugin is used to test the `onion_message` hook.
4+
"""
5+
from lightning import Plugin
6+
7+
plugin = Plugin()
8+
9+
10+
@plugin.hook("onion_message")
11+
def on_onion_message(plugin, onion_message, **kwargs):
12+
if 'reply_path' not in onion_message:
13+
plugin.log("no reply path")
14+
return
15+
16+
plugin.rpc.call('sendonionmessage', [onion_message['reply_path']])
17+
plugin.log("Sent reply via {}".format(onion_message['reply_path']))
18+
return {"result": "continue"}
19+
20+
21+
plugin.run()

tests/test_misc.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,6 +2198,36 @@ def test_sendonionmessage(node_factory):
21982198
assert l3.daemon.wait_for_log('Got onionmsg')
21992199

22002200

2201+
@unittest.skipIf(not EXPERIMENTAL_FEATURES, "Needs sendonionmessage")
2202+
def test_sendonionmessage_reply(node_factory):
2203+
blindedpathtool = os.path.join(os.path.dirname(__file__), "..", "devtools", "blindedpath")
2204+
2205+
plugin = os.path.join(os.path.dirname(__file__), "plugins", "onionmessage-reply.py")
2206+
l1, l2, l3 = node_factory.line_graph(3, opts={'plugin': plugin})
2207+
2208+
# Make reply path
2209+
output = subprocess.check_output(
2210+
[blindedpathtool, '--simple-output', 'create', l2.info['id'], l1.info['id']]
2211+
).decode('ASCII').strip()
2212+
2213+
# First line is blinding, then <peerid> then <encblob>.
2214+
blinding, p1, p1enc, p2 = output.split('\n')
2215+
# First hop can't be blinded!
2216+
assert p1 == l2.info['id']
2217+
2218+
l1.rpc.call('sendonionmessage',
2219+
{'hops':
2220+
[{'id': l2.info['id']},
2221+
{'id': l3.info['id']}],
2222+
'reply_path':
2223+
{'blinding': blinding,
2224+
'path': [{'id': p1, 'enctlv': p1enc}, {'id': p2}]}})
2225+
2226+
assert l3.daemon.wait_for_log('Got onionmsg reply_blinding reply_path')
2227+
assert l3.daemon.wait_for_log('Sent reply via')
2228+
assert l1.daemon.wait_for_log('Got onionmsg')
2229+
2230+
22012231
@unittest.skipIf(not DEVELOPER, "needs --dev-force-privkey")
22022232
def test_getsharedsecret(node_factory):
22032233
"""

0 commit comments

Comments
 (0)