Skip to content

Commit edd0230

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 587a181 commit edd0230

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

tests/plugins/onionmessage-reply.py

+21
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

+30
Original file line numberDiff line numberDiff line change
@@ -2217,6 +2217,36 @@ def test_sendonionmessage(node_factory):
22172217
assert l3.daemon.wait_for_log('Got onionmsg')
22182218

22192219

2220+
@unittest.skipIf(not EXPERIMENTAL_FEATURES, "Needs sendonionmessage")
2221+
def test_sendonionmessage_reply(node_factory):
2222+
blindedpathtool = os.path.join(os.path.dirname(__file__), "..", "devtools", "blindedpath")
2223+
2224+
plugin = os.path.join(os.path.dirname(__file__), "plugins", "onionmessage-reply.py")
2225+
l1, l2, l3 = node_factory.line_graph(3, opts={'plugin': plugin})
2226+
2227+
# Make reply path
2228+
output = subprocess.check_output(
2229+
[blindedpathtool, '--simple-output', 'create', l2.info['id'], l1.info['id']]
2230+
).decode('ASCII').strip()
2231+
2232+
# First line is blinding, then <peerid> then <encblob>.
2233+
blinding, p1, p1enc, p2 = output.split('\n')
2234+
# First hop can't be blinded!
2235+
assert p1 == l2.info['id']
2236+
2237+
l1.rpc.call('sendonionmessage',
2238+
{'hops':
2239+
[{'id': l2.info['id']},
2240+
{'id': l3.info['id']}],
2241+
'reply_path':
2242+
{'blinding': blinding,
2243+
'path': [{'id': p1, 'enctlv': p1enc}, {'id': p2}]}})
2244+
2245+
assert l3.daemon.wait_for_log('Got onionmsg reply_blinding reply_path')
2246+
assert l3.daemon.wait_for_log('Sent reply via')
2247+
assert l1.daemon.wait_for_log('Got onionmsg')
2248+
2249+
22202250
@unittest.skipIf(not DEVELOPER, "needs --dev-force-privkey")
22212251
def test_getsharedsecret(node_factory):
22222252
"""

0 commit comments

Comments
 (0)