mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
pytest: test libplugin's send_outreq
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
#include <ccan/array_size/array_size.h>
|
#include <ccan/array_size/array_size.h>
|
||||||
|
#include <common/json_stream.h>
|
||||||
#include <plugins/libplugin.h>
|
#include <plugins/libplugin.h>
|
||||||
|
|
||||||
|
|
||||||
@@ -53,6 +54,36 @@ static void json_connected(struct command *cmd,
|
|||||||
json_strdup(tmpctx, buf, idtok));
|
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,
|
static void init(struct plugin *p,
|
||||||
const char *buf UNUSED, const jsmntok_t *config UNUSED)
|
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 "
|
" option was set, and 'hello {name}' if the name parameter "
|
||||||
"was passed (takes over the option)",
|
"was passed (takes over the option)",
|
||||||
json_helloworld,
|
json_helloworld,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"testrpc",
|
||||||
|
"utils",
|
||||||
|
"Makes a simple getinfo call, to test rpc socket.",
|
||||||
|
"",
|
||||||
|
json_testrpc,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -819,3 +819,6 @@ def test_libplugin(node_factory):
|
|||||||
l2.connect(l1)
|
l2.connect(l1)
|
||||||
assert l1.daemon.is_in_log("{} peer_connected".format(l2.info["id"]))
|
assert l1.daemon.is_in_log("{} peer_connected".format(l2.info["id"]))
|
||||||
l1.daemon.wait_for_log("{} 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()
|
||||||
|
|||||||
Reference in New Issue
Block a user