Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 76 additions & 67 deletions plugins/bkpr/test/run-recorder.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@
#include "plugins/bkpr/rebalances.c"
#include "plugins/bkpr/sql.c"

#if HAVE_SQLITE3
#include <sqlite3.h>
#endif

/* AUTOGENERATED MOCKS START */
/* Generated stub for chain_event_description */
const char *chain_event_description(const struct bkpr *bkpr UNNEEDED,
Expand Down Expand Up @@ -89,6 +85,55 @@ void plugin_log(struct plugin *p UNNEEDED, enum log_level l UNNEEDED, const char
{ fprintf(stderr, "plugin_log called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */

struct command_result *jsonrpc_set_datastore_(struct command *cmd UNNEEDED,
const char *path UNNEEDED,
const void *value UNNEEDED,
int len_or_str UNNEEDED,
const char *mode UNNEEDED,
struct command_result *(*cb)(struct command *command,
const char *method,
const char *buf,
const jsmntok_t *result,
void *arg),
struct command_result *(*errcb)(struct command *command UNNEEDED,
const char *method UNNEEDED,
const char *buf UNNEEDED,
const jsmntok_t *result UNNEEDED,
void *arg) UNNEEDED,
void *arg)

{
return cb(cmd, NULL, NULL, NULL, arg);
}

struct command_result *ignore_datastore_reply(struct command *cmd,
const char *method UNNEEDED,
const char *buf UNNEEDED,
const jsmntok_t *result UNNEEDED,
void *arg UNNEEDED)
{
return NULL;
}

struct json_out *json_out_obj(const tal_t *ctx,
const char *fieldname,
const char *str)
{
struct json_out *jout = json_out_new(ctx);
json_out_start(jout, NULL, '{');
if (str)
json_out_addstr(jout, fieldname, str);
if (taken(str))
tal_free(str);
json_out_end(jout, '}');
json_out_finished(jout);

return jout;
}

#if HAVE_SQLITE3
#include <sqlite3.h>

static sqlite3 *bkpr_db;
static struct command *cmd;

Expand Down Expand Up @@ -425,59 +470,12 @@ static void log_channel_event(sqlite3 *db,
sqlite3_finalize(stmt);
}

struct command_result *jsonrpc_set_datastore_(struct command *cmd UNNEEDED,
const char *path UNNEEDED,
const void *value UNNEEDED,
int len_or_str UNNEEDED,
const char *mode UNNEEDED,
struct command_result *(*cb)(struct command *command,
const char *method,
const char *buf,
const jsmntok_t *result,
void *arg),
struct command_result *(*errcb)(struct command *command UNNEEDED,
const char *method UNNEEDED,
const char *buf UNNEEDED,
const jsmntok_t *result UNNEEDED,
void *arg) UNNEEDED,
void *arg)

{
return cb(cmd, NULL, NULL, NULL, arg);
}

struct command_result *ignore_datastore_reply(struct command *cmd,
const char *method UNNEEDED,
const char *buf UNNEEDED,
const jsmntok_t *result UNNEEDED,
void *arg UNNEEDED)
{
return NULL;
}

struct json_out *json_out_obj(const tal_t *ctx,
const char *fieldname,
const char *str)
{
struct json_out *jout = json_out_new(ctx);
json_out_start(jout, NULL, '{');
if (str)
json_out_addstr(jout, fieldname, str);
if (taken(str))
tal_free(str);
json_out_end(jout, '}');
json_out_finished(jout);

return jout;
}

const jsmntok_t *jsonrpc_request_sync(const tal_t *ctx,
struct command *cmd,
const char *method,
const struct json_out *params TAKES,
const char **resp)
{
#if HAVE_SQLITE3
sqlite3_stmt *s;
jsmntok_t *toks;
jsmn_parser parser;
Expand Down Expand Up @@ -551,9 +549,6 @@ const jsmntok_t *jsonrpc_request_sync(const tal_t *ctx,
tal_free(params);
*resp = buf;
return toks;
#else
return NULL;
#endif
}

static char *tmp_dsn(const tal_t *ctx)
Expand Down Expand Up @@ -1660,21 +1655,35 @@ int main(int argc, char *argv[])

common_setup(argv[0]);

if (HAVE_SQLITE3) {
/* UBSan insists cmd isn't NULL */
cmd = tal(tmpctx, struct command);
ok &= test_account_crud(tmpctx);
ok &= test_channel_event_crud(tmpctx);
ok &= test_chain_event_crud(tmpctx);
ok &= test_account_balances(tmpctx);
ok &= test_onchain_fee_chan_close(tmpctx);
ok &= test_onchain_fee_chan_open(tmpctx);
ok &= test_channel_rebalances(tmpctx);
ok &= test_onchain_fee_wallet_spend(tmpctx);
sqlite3_close(bkpr_db);
}
/* UBSan insists cmd isn't NULL */
cmd = tal(tmpctx, struct command);
ok &= test_account_crud(tmpctx);
ok &= test_channel_event_crud(tmpctx);
ok &= test_chain_event_crud(tmpctx);
ok &= test_account_balances(tmpctx);
ok &= test_onchain_fee_chan_close(tmpctx);
ok &= test_onchain_fee_chan_open(tmpctx);
ok &= test_channel_rebalances(tmpctx);
ok &= test_onchain_fee_wallet_spend(tmpctx);
sqlite3_close(bkpr_db);

common_shutdown();
trace_cleanup();
return !ok;
}
#else /* No sqlite, no test! */
const jsmntok_t *jsonrpc_request_sync(const tal_t *ctx,
struct command *cmd,
const char *method,
const struct json_out *params TAKES,
const char **resp)
{
abort();
}

int main(int argc, char *argv[])
{
common_setup(argv[0]);
common_shutdown();
}
#endif /* !HAVE_SQLITE3 */
Loading