mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
pytest: Add a test for the event subscription and notification
Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
@@ -24,5 +24,15 @@ def init(options, configuration, plugin):
|
||||
plugin.log("Plugin helloworld.py initialized")
|
||||
|
||||
|
||||
@plugin.subscribe("connect")
|
||||
def on_connect(id, address, plugin):
|
||||
plugin.log("Received connect event for peer {}".format(id))
|
||||
|
||||
|
||||
@plugin.subscribe("disconnect")
|
||||
def on_disconnect(id, plugin):
|
||||
plugin.log("Received disconnect event for peer {}".format(id))
|
||||
|
||||
|
||||
plugin.add_option('greeting', 'Hello', 'The greeting I should use.')
|
||||
plugin.run()
|
||||
|
||||
@@ -83,6 +83,18 @@ def test_plugin_disable(node_factory):
|
||||
n.rpc.hello(name='Sun')
|
||||
|
||||
|
||||
def test_plugin_notifications(node_factory):
|
||||
l1, l2 = node_factory.get_nodes(2, opts={'plugin': 'contrib/plugins/helloworld.py'})
|
||||
|
||||
l1.connect(l2)
|
||||
l1.daemon.wait_for_log(r'Received connect event')
|
||||
l2.daemon.wait_for_log(r'Received connect event')
|
||||
|
||||
l2.rpc.disconnect(l1.info['id'])
|
||||
l1.daemon.wait_for_log(r'Received disconnect event')
|
||||
l2.daemon.wait_for_log(r'Received disconnect event')
|
||||
|
||||
|
||||
def test_failing_plugins():
|
||||
fail_plugins = [
|
||||
'contrib/plugins/fail/failtimeout.py',
|
||||
|
||||
@@ -385,11 +385,17 @@ class LightningNode(object):
|
||||
self.may_fail = may_fail
|
||||
self.may_reconnect = may_reconnect
|
||||
|
||||
def connect(self, remote_node):
|
||||
self.rpc.connect(remote_node.info['id'], '127.0.0.1', remote_node.daemon.port)
|
||||
|
||||
def is_connected(self, remote_node):
|
||||
return remote_node.info['id'] in [p['id'] for p in self.rpc.listpeers()['peers']]
|
||||
|
||||
def openchannel(self, remote_node, capacity, addrtype="p2sh-segwit", confirm=True, wait_for_announce=True, connect=True):
|
||||
addr, wallettxid = self.fundwallet(10 * capacity, addrtype)
|
||||
|
||||
if connect and remote_node.info['id'] not in [p['id'] for p in self.rpc.listpeers()['peers']]:
|
||||
self.rpc.connect(remote_node.info['id'], '127.0.0.1', remote_node.daemon.port)
|
||||
if connect and not self.is_connected(remote_node):
|
||||
self.connect(remote_node)
|
||||
|
||||
fundingtx = self.rpc.fundchannel(remote_node.info['id'], capacity)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user