2019-08-13 06:00:22 +02:00
|
|
|
#include "config.h"
|
|
|
|
#include <assert.h>
|
|
|
|
#include <common/amount.h>
|
|
|
|
#include <common/bigsize.h>
|
2020-05-15 12:29:53 +02:00
|
|
|
#include <common/channel_id.h>
|
2020-01-26 13:07:50 +01:00
|
|
|
#include <common/json_stream.h>
|
|
|
|
#include <common/wireaddr.h>
|
2019-08-13 06:00:22 +02:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
int test_main(int argc, char *argv[]);
|
|
|
|
ssize_t test_read(int fd, void *buf, size_t len);
|
|
|
|
int test_socket(int domain, int type, int protocol);
|
|
|
|
int test_connect(int sockfd, const struct sockaddr *addr,
|
|
|
|
socklen_t addrlen);
|
|
|
|
int test_getpid(void);
|
|
|
|
int test_printf(const char *format, ...);
|
|
|
|
int test_fputc(int c, FILE *stream);
|
2019-11-23 02:46:40 +01:00
|
|
|
int test_chdir(const char *path);
|
2019-08-13 06:00:22 +02:00
|
|
|
|
|
|
|
#define main test_main
|
|
|
|
#define read test_read
|
|
|
|
#define socket test_socket
|
|
|
|
#define connect test_connect
|
|
|
|
#define getpid test_getpid
|
|
|
|
#define printf test_printf
|
|
|
|
#define fputc test_fputc
|
2019-11-23 02:46:40 +01:00
|
|
|
#define chdir test_chdir
|
2019-08-13 06:00:22 +02:00
|
|
|
|
|
|
|
#include "../lightning-cli.c"
|
|
|
|
#undef main
|
|
|
|
|
|
|
|
/* AUTOGENERATED MOCKS START */
|
2019-09-26 21:07:20 +02:00
|
|
|
/* Generated stub for amount_asset_is_main */
|
|
|
|
bool amount_asset_is_main(struct amount_asset *asset UNNEEDED)
|
|
|
|
{ fprintf(stderr, "amount_asset_is_main called!\n"); abort(); }
|
|
|
|
/* Generated stub for amount_asset_to_sat */
|
|
|
|
struct amount_sat amount_asset_to_sat(struct amount_asset *asset UNNEEDED)
|
|
|
|
{ fprintf(stderr, "amount_asset_to_sat called!\n"); abort(); }
|
2019-09-26 12:25:05 +02:00
|
|
|
/* Generated stub for amount_sat_add */
|
|
|
|
bool amount_sat_add(struct amount_sat *val UNNEEDED,
|
|
|
|
struct amount_sat a UNNEEDED,
|
|
|
|
struct amount_sat b UNNEEDED)
|
|
|
|
{ fprintf(stderr, "amount_sat_add called!\n"); abort(); }
|
|
|
|
/* Generated stub for amount_sat_eq */
|
|
|
|
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
|
|
|
|
{ fprintf(stderr, "amount_sat_eq called!\n"); abort(); }
|
|
|
|
/* Generated stub for amount_sat_sub */
|
|
|
|
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
|
|
|
|
struct amount_sat a UNNEEDED,
|
|
|
|
struct amount_sat b UNNEEDED)
|
|
|
|
{ fprintf(stderr, "amount_sat_sub called!\n"); abort(); }
|
2019-08-13 06:00:22 +02:00
|
|
|
/* Generated stub for bigsize_get */
|
|
|
|
size_t bigsize_get(const u8 *p UNNEEDED, size_t max UNNEEDED, bigsize_t *val UNNEEDED)
|
|
|
|
{ fprintf(stderr, "bigsize_get called!\n"); abort(); }
|
|
|
|
/* Generated stub for bigsize_put */
|
|
|
|
size_t bigsize_put(u8 buf[BIGSIZE_MAX_LEN] UNNEEDED, bigsize_t v UNNEEDED)
|
|
|
|
{ fprintf(stderr, "bigsize_put called!\n"); abort(); }
|
2020-05-15 12:29:53 +02:00
|
|
|
/* Generated stub for fromwire_channel_id */
|
|
|
|
void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
|
|
|
|
struct channel_id *channel_id UNNEEDED)
|
|
|
|
{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); }
|
2020-01-26 13:07:50 +01:00
|
|
|
/* Generated stub for json_add_member */
|
|
|
|
void json_add_member(struct json_stream *js UNNEEDED,
|
|
|
|
const char *fieldname UNNEEDED,
|
|
|
|
bool quote UNNEEDED,
|
|
|
|
const char *fmt UNNEEDED, ...)
|
|
|
|
{ fprintf(stderr, "json_add_member called!\n"); abort(); }
|
|
|
|
/* Generated stub for json_array_end */
|
|
|
|
void json_array_end(struct json_stream *js UNNEEDED)
|
|
|
|
{ fprintf(stderr, "json_array_end called!\n"); abort(); }
|
|
|
|
/* Generated stub for json_array_start */
|
|
|
|
void json_array_start(struct json_stream *js UNNEEDED, const char *fieldname UNNEEDED)
|
|
|
|
{ fprintf(stderr, "json_array_start called!\n"); abort(); }
|
|
|
|
/* Generated stub for json_member_direct */
|
|
|
|
char *json_member_direct(struct json_stream *js UNNEEDED,
|
|
|
|
const char *fieldname UNNEEDED, size_t extra UNNEEDED)
|
|
|
|
{ fprintf(stderr, "json_member_direct called!\n"); abort(); }
|
|
|
|
/* Generated stub for json_object_end */
|
|
|
|
void json_object_end(struct json_stream *js UNNEEDED)
|
|
|
|
{ fprintf(stderr, "json_object_end called!\n"); abort(); }
|
|
|
|
/* Generated stub for json_object_start */
|
|
|
|
void json_object_start(struct json_stream *ks UNNEEDED, const char *fieldname UNNEEDED)
|
|
|
|
{ fprintf(stderr, "json_object_start called!\n"); abort(); }
|
2020-05-15 12:29:53 +02:00
|
|
|
/* Generated stub for towire_channel_id */
|
|
|
|
void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id UNNEEDED)
|
|
|
|
{ fprintf(stderr, "towire_channel_id called!\n"); abort(); }
|
2019-08-13 06:00:22 +02:00
|
|
|
/* Generated stub for version_and_exit */
|
|
|
|
char *version_and_exit(const void *unused UNNEEDED)
|
|
|
|
{ fprintf(stderr, "version_and_exit called!\n"); abort(); }
|
|
|
|
/* AUTOGENERATED MOCKS END */
|
|
|
|
|
|
|
|
int test_socket(int domain UNUSED, int type UNUSED, int protocol UNUSED)
|
|
|
|
{
|
|
|
|
/* We give a real fd, as it writes to it */
|
|
|
|
return open("/dev/null", O_WRONLY);
|
|
|
|
}
|
|
|
|
|
|
|
|
int test_connect(int sockfd UNUSED, const struct sockaddr *addr UNUSED,
|
|
|
|
socklen_t addrlen UNUSED)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int test_getpid(void)
|
|
|
|
{
|
|
|
|
return 9999;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *response = "{\"id\": \"lightning-cli-9999\", \"jsonrpc\": \"2.0\", \"result\": {\"channels\": [\"\n\", \"├477308sat OUT/OURS ┼ IN/THEIRS 477308sat┤ SCID FLAG ALIAS\", \"├──────────────────────┼──────────────────────┤ 580612x1826x0 [__] BLUEIRON-v0.7.2rc1\"], \"my_address\": \"02b78caed0f45120acc48efe867aa506e8ea60f0712a23303178471da0ca2213f5@hdco6sxkbisc7s5t.onion\", \"format-hint\": \"simple\", \"avail_in\": \"0.00477308500btc (USD $54.37)\", \"num_utxos\": 0, \"num_gossipers\": 1, \"channels_flags\": \"P:private O:offline\", \"avail_out\": \"0.00477308500btc (USD $54.37)\", \"utxo_amount\": \"0.00000000btc (USD $0.00)\", \"num_channels\": 1, \"num_connected\": 1}}\n\n";
|
|
|
|
static size_t response_off;
|
|
|
|
|
|
|
|
ssize_t test_read(int fd UNUSED, void *buf, size_t len)
|
|
|
|
{
|
|
|
|
if (len > strlen(response + response_off))
|
|
|
|
len = strlen(response + response_off);
|
|
|
|
memcpy(buf, response + response_off, len);
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *output;
|
|
|
|
|
|
|
|
int test_printf(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
tal_append_vfmt(&output, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int test_fputc(int c, FILE *stream)
|
|
|
|
{
|
|
|
|
tal_append_fmt(&output, "%c", c);
|
|
|
|
return (unsigned)c;
|
|
|
|
}
|
|
|
|
|
2019-11-23 02:46:40 +01:00
|
|
|
int test_chdir(const char *path)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-08-13 06:00:22 +02:00
|
|
|
int main(int argc UNUSED, char *argv[])
|
|
|
|
{
|
|
|
|
setup_locale();
|
|
|
|
|
|
|
|
char *fake_argv[] = { argv[0], "--lightning-dir=/tmp/", "test", NULL };
|
|
|
|
|
|
|
|
output = tal_strdup(NULL, "");
|
|
|
|
assert(test_main(3, fake_argv) == 0);
|
|
|
|
|
|
|
|
assert(streq(output, "channels=\n"
|
|
|
|
"\n"
|
|
|
|
"├477308sat OUT/OURS ┼ IN/THEIRS 477308sat┤ SCID FLAG ALIAS\n"
|
|
|
|
"├──────────────────────┼──────────────────────┤ 580612x1826x0 [__] BLUEIRON-v0.7.2rc1\n"
|
|
|
|
"my_address=02b78caed0f45120acc48efe867aa506e8ea60f0712a23303178471da0ca2213f5@hdco6sxkbisc7s5t.onion\n"
|
|
|
|
"avail_in=0.00477308500btc (USD $54.37)\n"
|
|
|
|
"num_utxos=0\n"
|
|
|
|
"num_gossipers=1\n"
|
|
|
|
"channels_flags=P:private O:offline\n"
|
|
|
|
"avail_out=0.00477308500btc (USD $54.37)\n"
|
|
|
|
"utxo_amount=0.00000000btc (USD $0.00)\n"
|
|
|
|
"num_channels=1\n"
|
|
|
|
"num_connected=1\n"));
|
|
|
|
tal_free(output);
|
2019-11-23 02:46:40 +01:00
|
|
|
assert(!taken_any());
|
2019-11-23 02:45:53 +01:00
|
|
|
take_cleanup();
|
2019-08-13 06:00:22 +02:00
|
|
|
return 0;
|
|
|
|
}
|