MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_rpc_passthrough

Function test_rpc_passthrough

tests/test_plugin.py:204–234  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

202
203
204def 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
237def test_plugin_dir(node_factory):

Callers

nothing calls this directly

Calls 6

only_oneFunction · 0.90
joinMethod · 0.80
is_in_logMethod · 0.80
failMethod · 0.80
get_nodeMethod · 0.45
helpMethod · 0.45

Tested by

no test coverage detected