mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-03 18:57:06 +01:00
pytest: peer_connected chainable tests
This commit is contained in:
parent
91bdb6d2d9
commit
bc40287ade
3 changed files with 57 additions and 7 deletions
17
tests/plugins/peer_connected_logger_a.py
Executable file
17
tests/plugins/peer_connected_logger_a.py
Executable file
|
@ -0,0 +1,17 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Simple plugin to log the connected_hook.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
from pyln.client import Plugin
|
||||||
|
|
||||||
|
plugin = Plugin()
|
||||||
|
|
||||||
|
|
||||||
|
@plugin.hook('peer_connected')
|
||||||
|
def on_connected(peer, plugin, **kwargs):
|
||||||
|
print("peer_connected_logger_a {}".format(peer['id']))
|
||||||
|
return {'result': 'continue'}
|
||||||
|
|
||||||
|
|
||||||
|
plugin.run()
|
17
tests/plugins/peer_connected_logger_b.py
Executable file
17
tests/plugins/peer_connected_logger_b.py
Executable file
|
@ -0,0 +1,17 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Simple plugin to log the connected_hook.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
from pyln.client import Plugin
|
||||||
|
|
||||||
|
plugin = Plugin()
|
||||||
|
|
||||||
|
|
||||||
|
@plugin.hook('peer_connected')
|
||||||
|
def on_connected(peer, plugin, **kwargs):
|
||||||
|
print("peer_connected_logger_b {}".format(peer['id']))
|
||||||
|
return {'result': 'continue'}
|
||||||
|
|
||||||
|
|
||||||
|
plugin.run()
|
|
@ -392,31 +392,47 @@ def test_pay_plugin(node_factory):
|
||||||
assert only_one(l1.rpc.help('pay')['help'])['command'] == msg
|
assert only_one(l1.rpc.help('pay')['help'])['command'] == msg
|
||||||
|
|
||||||
|
|
||||||
def test_plugin_connected_hook(node_factory):
|
def test_plugin_connected_hook_chaining(node_factory):
|
||||||
""" l1 uses the reject plugin to reject connections.
|
""" l1 uses the logger_a, reject and logger_b plugin.
|
||||||
|
|
||||||
l1 is configured to accept connections from l2, but not from l3.
|
l1 is configured to accept connections from l2, but not from l3.
|
||||||
|
we check that logger_a is always called and logger_b only for l2.
|
||||||
"""
|
"""
|
||||||
opts = [{'plugin': os.path.join(os.getcwd(), 'tests/plugins/reject.py')}, {}, {}]
|
opts = [{'plugin': [
|
||||||
|
os.path.join(os.getcwd(), 'tests/plugins/peer_connected_logger_a.py'),
|
||||||
|
os.path.join(os.getcwd(), 'tests/plugins/reject.py'),
|
||||||
|
os.path.join(os.getcwd(), 'tests/plugins/peer_connected_logger_b.py'),
|
||||||
|
]}, {}, {}]
|
||||||
|
|
||||||
l1, l2, l3 = node_factory.get_nodes(3, opts=opts)
|
l1, l2, l3 = node_factory.get_nodes(3, opts=opts)
|
||||||
|
l2id = l2.info['id']
|
||||||
|
l3id = l3.info['id']
|
||||||
l1.rpc.reject(l3.info['id'])
|
l1.rpc.reject(l3.info['id'])
|
||||||
|
|
||||||
l2.connect(l1)
|
l2.connect(l1)
|
||||||
l1.daemon.wait_for_log(r"{} is allowed".format(l2.info['id']))
|
l1.daemon.wait_for_logs([
|
||||||
assert len(l1.rpc.listpeers(l2.info['id'])['peers']) == 1
|
f"peer_connected_logger_a {l2id}",
|
||||||
|
f"{l2id} is allowed",
|
||||||
|
f"peer_connected_logger_b {l2id}"
|
||||||
|
])
|
||||||
|
assert len(l1.rpc.listpeers(l2id)['peers']) == 1
|
||||||
|
|
||||||
l3.connect(l1)
|
l3.connect(l1)
|
||||||
l1.daemon.wait_for_log(r"{} is in reject list".format(l3.info['id']))
|
l1.daemon.wait_for_logs([
|
||||||
|
f"peer_connected_logger_a {l3id}",
|
||||||
|
f"{l3id} is in reject list"
|
||||||
|
])
|
||||||
|
|
||||||
# FIXME: this error occurs *after* connection, so we connect then drop.
|
# FIXME: this error occurs *after* connection, so we connect then drop.
|
||||||
l3.daemon.wait_for_log(r"chan#1: peer_in WIRE_ERROR")
|
l3.daemon.wait_for_log(r"chan#1: peer_in WIRE_ERROR")
|
||||||
l3.daemon.wait_for_log(r"You are in reject list")
|
l3.daemon.wait_for_log(r"You are in reject list")
|
||||||
|
|
||||||
def check_disconnect():
|
def check_disconnect():
|
||||||
peers = l1.rpc.listpeers(l3.info['id'])['peers']
|
peers = l1.rpc.listpeers(l3id)['peers']
|
||||||
return peers == [] or not peers[0]['connected']
|
return peers == [] or not peers[0]['connected']
|
||||||
|
|
||||||
wait_for(check_disconnect)
|
wait_for(check_disconnect)
|
||||||
|
assert not l3.daemon.is_in_log(f"peer_connected_logger_b {l3id}")
|
||||||
|
|
||||||
|
|
||||||
def test_async_rpcmethod(node_factory, executor):
|
def test_async_rpcmethod(node_factory, executor):
|
||||||
|
|
Loading…
Add table
Reference in a new issue