mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 23:24:27 +01:00
pytest: test the 'rpc_command' hook
This commit is contained in:
committed by
Christian Decker
parent
a0df49718a
commit
95c6513ff3
27
tests/plugins/rpc_command.py
Executable file
27
tests/plugins/rpc_command.py
Executable file
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
This plugin is used to test the `rpc_command` hook.
|
||||
"""
|
||||
from lightning import Plugin
|
||||
|
||||
plugin = Plugin(dynamic=False)
|
||||
|
||||
|
||||
@plugin.hook("rpc_command")
|
||||
def on_rpc_command(plugin, rpc_command, **kwargs):
|
||||
request = rpc_command["rpc_command"]
|
||||
if request["method"] == "invoice":
|
||||
# Replace part of this command
|
||||
request["params"]["description"] = "A plugin modified this description"
|
||||
return {"replace": request}
|
||||
elif request["method"] == "listfunds":
|
||||
# Return a custom result to the command
|
||||
return {"return": {"result": ["Custom result"]}}
|
||||
elif request["method"] == "sendpay":
|
||||
# Don't allow this command to be executed
|
||||
return {"return": {"error": {"code": -1,
|
||||
"message": "You cannot do this"}}}
|
||||
return {"continue": True}
|
||||
|
||||
|
||||
plugin.run()
|
||||
Reference in New Issue
Block a user