Browse Source
pytest: Add a test for the JSON-RPC passthrough
Tests JSON-RPC registration, as well as success and failures.
Signed-off-by: Christian Decker <decker.christian@gmail.com>
plugin-3
Christian Decker
6 years ago
No known key found for this signature in database
GPG Key ID: 1416D83DC4F0E86D
1 changed files with
24 additions and
0 deletions
-
tests/test_plugin.py
|
|
@ -1,5 +1,7 @@ |
|
|
|
from fixtures import * # noqa: F401,F403 |
|
|
|
from lightning import RpcError |
|
|
|
|
|
|
|
import pytest |
|
|
|
import subprocess |
|
|
|
|
|
|
|
|
|
|
@ -27,3 +29,25 @@ def test_option_passthrough(node_factory): |
|
|
|
# option didn't exist |
|
|
|
n = node_factory.get_node(options={'plugin': plugin_path, 'greeting': 'Mars'}) |
|
|
|
n.stop() |
|
|
|
|
|
|
|
|
|
|
|
def test_rpc_passthrough(node_factory): |
|
|
|
"""Starting with a plugin exposes its RPC methods. |
|
|
|
|
|
|
|
First check that the RPC method appears in the help output and |
|
|
|
then try to call it. |
|
|
|
|
|
|
|
""" |
|
|
|
plugin_path = 'contrib/plugins/helloworld.py' |
|
|
|
n = node_factory.get_node(options={'plugin': plugin_path, 'greeting': 'Mars'}) |
|
|
|
|
|
|
|
# Make sure that the 'hello' command that the helloworld.py plugin |
|
|
|
# has registered is available. |
|
|
|
cmd = [hlp for hlp in n.rpc.help()['help'] if 'hello' in hlp['command']] |
|
|
|
assert(len(cmd) == 1) |
|
|
|
|
|
|
|
# Now try to call it and see what it returns: |
|
|
|
greet = n.rpc.hello(name='Sun') |
|
|
|
assert(greet == "Hello Sun") |
|
|
|
with pytest.raises(RpcError): |
|
|
|
n.rpc.fail() |
|
|
|