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.
(node_factory)
| 202 | |
| 203 | |
| 204 | def test_rpc_passthrough(node_factory): |
| 205 | """Starting with a plugin exposes its RPC methods. |
| 206 | |
| 207 | First check that the RPC method appears in the help output and |
| 208 | then try to call it. |
| 209 | |
| 210 | """ |
| 211 | plugin_path = os.path.join(os.getcwd(), 'contrib/plugins/helloworld.py') |
| 212 | n = node_factory.get_node(options={'plugin': plugin_path, 'greeting': 'Ciao'}) |
| 213 | |
| 214 | # Make sure that the 'hello' command that the helloworld.py plugin |
| 215 | # has registered is available. |
| 216 | cmd = [hlp for hlp in n.rpc.help()['help'] if 'hello' in hlp['command']] |
| 217 | assert(len(cmd) == 1) |
| 218 | |
| 219 | # Make sure usage message is present. |
| 220 | assert only_one(n.rpc.help('hello')['help'])['command'].startswith('hello [name]') |
| 221 | # While we're at it, let's check that helloworld.py is logging |
| 222 | # correctly via the notifications plugin->lightningd |
| 223 | assert n.daemon.is_in_log('Plugin helloworld.py initialized') |
| 224 | |
| 225 | # Now try to call it and see what it returns: |
| 226 | greet = n.rpc.hello(name='World') |
| 227 | assert(greet == "Ciao World") |
| 228 | with pytest.raises(RpcError): |
| 229 | n.rpc.fail() |
| 230 | |
| 231 | # Try to call a method without enough arguments |
| 232 | with pytest.raises(RpcError, match="processing bye: missing a required" |
| 233 | " argument"): |
| 234 | n.rpc.bye() |
| 235 | |
| 236 | |
| 237 | def test_plugin_dir(node_factory): |