From b0529843acb38f9e18cf31756be736f3c505aa24 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Thu, 5 Dec 2019 00:16:11 +0100 Subject: [PATCH] pytest: Add a plugin for custommsgs and check that they get the msgs This completes the custommsg epic, finally we are back where we began all that time ago (about 4 hours really...): in a plugin that implements some custom logic. --- tests/plugins/custommsg.py | 15 +++++++++++++++ tests/test_misc.py | 9 +++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100755 tests/plugins/custommsg.py diff --git a/tests/plugins/custommsg.py b/tests/plugins/custommsg.py new file mode 100755 index 000000000..3c99b0366 --- /dev/null +++ b/tests/plugins/custommsg.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python3 +from pyln.client import Plugin + +plugin = Plugin() + + +@plugin.hook('custommsg') +def on_custommsg(peer_id, message, plugin, **kwargs): + plugin.log("Got a custom message {msg} from peer {peer_id}".format( + msg=message, + peer_id=peer_id + )) + + +plugin.run() diff --git a/tests/test_misc.py b/tests/test_misc.py index fe2bd5a65..e55c9dddb 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -2072,8 +2072,10 @@ def test_sendcustommsg(node_factory): and we can't send to it. """ - l1, l2, l3 = node_factory.line_graph(3, opts={'log-level': 'io'}) - l4 = node_factory.get_node(options={'log-level': 'io'}) + plugin = os.path.join(os.path.dirname(__file__), "plugins", "custommsg.py") + opts = {'log-level': 'io', 'plugin': plugin} + l1, l2, l3 = node_factory.line_graph(3, opts=opts) + l4 = node_factory.get_node(options=opts) l2.connect(l4) l3.stop() msg = r'ff' * 32 @@ -2122,3 +2124,6 @@ def test_sendcustommsg(node_factory): ) ) l4.daemon.wait_for_log(r'\[IN\] {}'.format(serialized)) + l4.daemon.wait_for_log( + r'Got a custom message {serialized} from peer {peer_id}'.format( + serialized=serialized, peer_id=l2.info['id']))