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

Function test_plugin_command

tests/test_plugin.py:257–321  ·  view source on GitHub ↗

Tests the 'plugin' RPC command

(node_factory)

Source from the content-addressed store, hash-verified

255
256
257def test_plugin_command(node_factory):
258 """Tests the 'plugin' RPC command"""
259 n = node_factory.get_node()
260
261 # Make sure that the 'hello' command from the helloworld.py plugin
262 # is not available.
263 cmd = [hlp for hlp in n.rpc.help()["help"] if "hello" in hlp["command"]]
264 assert(len(cmd) == 0)
265
266 # Add the 'contrib/plugins' test dir
267 n.rpc.plugin_startdir(directory=os.path.join(os.getcwd(), "contrib/plugins"))
268 # Make sure that the 'hello' command from the helloworld.py plugin
269 # is now available.
270 cmd = [hlp for hlp in n.rpc.help()["help"] if "hello" in hlp["command"]]
271 assert(len(cmd) == 1)
272
273 # Make sure 'rescan' and 'list' subcommands dont crash
274 n.rpc.plugin_rescan()
275 n.rpc.plugin_list()
276
277 # Make sure the plugin behaves normally after stop and restart
278 assert("Successfully stopped helloworld.py."
279 == n.rpc.plugin_stop(plugin="helloworld.py")["result"])
280 n.daemon.wait_for_log(r"Killing plugin: stopped by lightningd via RPC")
281 n.rpc.plugin_start(plugin=os.path.join(os.getcwd(), "contrib/plugins/helloworld.py"))
282 n.daemon.wait_for_log(r"Plugin helloworld.py initialized")
283 assert("Hello world" == n.rpc.call(method="hello"))
284
285 # Now stop the helloworld plugin
286 assert("Successfully stopped helloworld.py."
287 == n.rpc.plugin_stop(plugin="helloworld.py")["result"])
288 n.daemon.wait_for_log(r"Killing plugin: stopped by lightningd via RPC")
289 # Make sure that the 'hello' command from the helloworld.py plugin
290 # is not available anymore.
291 cmd = [hlp for hlp in n.rpc.help()["help"] if "hello" in hlp["command"]]
292 assert(len(cmd) == 0)
293
294 # Test that we cannot start a plugin with 'dynamic' set to False in
295 # getmanifest
296 with pytest.raises(RpcError, match=r"Not a dynamic plugin"):
297 n.rpc.plugin_start(plugin=os.path.join(os.getcwd(), "tests/plugins/static.py"))
298
299 # Test that we cannot stop a started plugin with 'dynamic' flag set to
300 # False
301 n2 = node_factory.get_node(options={
302 "plugin": os.path.join(os.getcwd(), "tests/plugins/static.py")
303 })
304 with pytest.raises(RpcError, match=r"static.py cannot be managed when lightningd is up"):
305 n2.rpc.plugin_stop(plugin="static.py")
306
307 # Test that we don't crash when starting a broken plugin
308 with pytest.raises(RpcError, match=r": exited before replying to getmanifest"):
309 n2.rpc.plugin_start(plugin=os.path.join(os.getcwd(), "tests/plugins/broken.py"))
310
311 with pytest.raises(RpcError, match=r': timed out before replying to getmanifest'):
312 n2.rpc.plugin_start(os.path.join(os.getcwd(), 'contrib/plugins/fail/failtimeout.py'))
313
314 # Test that we can add a directory with more than one new plugin in it.

Callers

nothing calls this directly

Calls 11

plugin_startdirMethod · 0.80
joinMethod · 0.80
plugin_rescanMethod · 0.80
plugin_listMethod · 0.80
plugin_stopMethod · 0.80
wait_for_logMethod · 0.80
plugin_startMethod · 0.80
get_nodeMethod · 0.45
helpMethod · 0.45
callMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected