Skip to content

Commit

Permalink
pytest: test libplugin's send_outreq
Browse files Browse the repository at this point in the history
  • Loading branch information
darosior committed Feb 1, 2020
1 parent 47cff2d commit 5e8e9ca
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tests/plugins/test_libplugin.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <ccan/array_size/array_size.h>
#include <common/json_stream.h>
#include <plugins/libplugin.h>


Expand Down Expand Up @@ -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)
{
Expand All @@ -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,
}
};

Expand Down
3 changes: 3 additions & 0 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -838,3 +838,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()

0 comments on commit 5e8e9ca

Please sign in to comment.