From ede45821b601b1c98b3545831f8aea0dc03b616b Mon Sep 17 00:00:00 2001 From: darosior Date: Sat, 1 Feb 2020 18:25:49 +0100 Subject: [PATCH] pytest: test libplugin's send_outreq --- tests/plugins/test_libplugin.c | 38 ++++++++++++++++++++++++++++++++++ tests/test_plugin.py | 3 +++ 2 files changed, 41 insertions(+) diff --git a/tests/plugins/test_libplugin.c b/tests/plugins/test_libplugin.c index a432fae9bc96..2cc9c2a3ac10 100644 --- a/tests/plugins/test_libplugin.c +++ b/tests/plugins/test_libplugin.c @@ -1,4 +1,5 @@ #include +#include #include @@ -53,6 +54,36 @@ static void json_connected(struct command *cmd, json_strdup(tmpctx, buf, idtok)); } +static struct command_result *testrpc_cb(struct command *cmd, + const char *buf, + const jsmntok_t *params, + void *cb_arg UNUSED) +{ + int i = 0; + const jsmntok_t *t; + struct json_stream *response; + + response = jsonrpc_stream_success(cmd); + json_for_each_obj(i, t, params) + json_add_tok(response, json_strdup(tmpctx, buf, t), t+1, buf); + + return command_finished(cmd, response); +} + +static struct command_result *json_testrpc(struct command *cmd, + const char *buf, + const jsmntok_t *params) +{ + struct out_req *req; + + if (!param(cmd, buf, params, NULL)) + return command_param_failed(); + + req = jsonrpc_request_start(cmd->plugin, cmd, "getinfo", testrpc_cb, + testrpc_cb, NULL); + return send_outreq(cmd->plugin, req); +} + static void init(struct plugin *p, const char *buf UNUSED, const jsmntok_t *config UNUSED) { @@ -67,6 +98,13 @@ static const struct plugin_command commands[] = { { " option was set, and 'hello {name}' if the name parameter " "was passed (takes over the option)", json_helloworld, + }, + { + "testrpc", + "utils", + "Makes a simple getinfo call, to test rpc socket.", + "", + json_testrpc, } }; diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 832940c6641e..7c1850f4d783 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -819,3 +819,6 @@ def test_libplugin(node_factory): l2.connect(l1) assert l1.daemon.is_in_log("{} peer_connected".format(l2.info["id"])) l1.daemon.wait_for_log("{} connected".format(l2.info["id"])) + + # Test RPC calls FIXME: test concurrent ones ? + assert l1.rpc.call("testrpc") == l1.rpc.getinfo()