Browse Source

pytest: custommsg chainable tests

master
Michael Schmoock 4 years ago
committed by Rusty Russell
parent
commit
67f2939540
  1. 2
      tests/plugins/custommsg_a.py
  2. 16
      tests/plugins/custommsg_b.py
  3. 24
      tests/test_misc.py

2
tests/plugins/custommsg.py → tests/plugins/custommsg_a.py

@ -6,7 +6,7 @@ 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(
plugin.log("Got custommessage_a {msg} from peer {peer_id}".format(
msg=message,
peer_id=peer_id
))

16
tests/plugins/custommsg_b.py

@ -0,0 +1,16 @@
#!/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 custommessage_b {msg} from peer {peer_id}".format(
msg=message,
peer_id=peer_id
))
return {'result': 'continue'}
plugin.run()

24
tests/test_misc.py

@ -2239,8 +2239,10 @@ def test_sendcustommsg(node_factory):
and we can't send to it.
"""
plugin = os.path.join(os.path.dirname(__file__), "plugins", "custommsg.py")
opts = {'log-level': 'io', 'plugin': plugin}
opts = {'log-level': 'io', 'plugin': [
os.path.join(os.path.dirname(__file__), "plugins", "custommsg_b.py"),
os.path.join(os.path.dirname(__file__), "plugins", "custommsg_a.py")
]}
l1, l2, l3, l4 = node_factory.get_nodes(4, opts=opts)
node_factory.join_nodes([l1, l2, l3])
l2.connect(l4)
@ -2279,9 +2281,12 @@ def test_sendcustommsg(node_factory):
)
)
l1.daemon.wait_for_log(r'\[IN\] {}'.format(serialized))
l1.daemon.wait_for_log(
r'Got a custom message {serialized} from peer {peer_id}'.format(
serialized=serialized, peer_id=l2.info['id']))
l1.daemon.wait_for_logs([
r'Got custommessage_a {serialized} from peer {peer_id}'.format(
serialized=serialized, peer_id=l2.info['id']),
r'Got custommessage_b {serialized} from peer {peer_id}'.format(
serialized=serialized, peer_id=l2.info['id'])
])
# This should work since the peer is currently owned by `openingd`
l2.rpc.dev_sendcustommsg(l4.info['id'], msg)
@ -2291,9 +2296,12 @@ 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']))
l4.daemon.wait_for_logs([
r'Got custommessage_a {serialized} from peer {peer_id}'.format(
serialized=serialized, peer_id=l2.info['id']),
r'Got custommessage_b {serialized} from peer {peer_id}'.format(
serialized=serialized, peer_id=l2.info['id']),
])
def test_sendonionmessage(node_factory):

Loading…
Cancel
Save