2019-08-09 18:12:01 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
2019-09-22 07:53:42 +02:00
|
|
|
#include "../queries.c"
|
2019-08-09 18:12:01 +02:00
|
|
|
#include <ccan/str/hex/hex.h>
|
2021-11-30 04:06:05 +01:00
|
|
|
#include <common/blinding.h>
|
2021-09-09 04:50:52 +02:00
|
|
|
#include <common/channel_type.h>
|
2021-11-30 04:06:05 +01:00
|
|
|
#include <common/ecdh.h>
|
2022-07-04 05:49:38 +02:00
|
|
|
#include <common/json_parse.h>
|
2020-02-27 03:17:01 +01:00
|
|
|
#include <common/json_stream.h>
|
2021-11-30 04:06:05 +01:00
|
|
|
#include <common/onionreply.h>
|
2021-11-14 18:52:46 +01:00
|
|
|
#include <common/setup.h>
|
2019-08-09 18:12:01 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#ifdef NDEBUG
|
|
|
|
#error "assert required for tests"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* AUTOGENERATED MOCKS START */
|
2021-11-30 04:06:05 +01:00
|
|
|
/* Generated stub for blinding_hash_e_and_ss */
|
|
|
|
void blinding_hash_e_and_ss(const struct pubkey *e UNNEEDED,
|
|
|
|
const struct secret *ss UNNEEDED,
|
|
|
|
struct sha256 *sha UNNEEDED)
|
|
|
|
{ fprintf(stderr, "blinding_hash_e_and_ss called!\n"); abort(); }
|
|
|
|
/* Generated stub for blinding_next_privkey */
|
|
|
|
bool blinding_next_privkey(const struct privkey *e UNNEEDED,
|
|
|
|
const struct sha256 *h UNNEEDED,
|
|
|
|
struct privkey *next UNNEEDED)
|
|
|
|
{ fprintf(stderr, "blinding_next_privkey called!\n"); abort(); }
|
|
|
|
/* Generated stub for blinding_next_pubkey */
|
|
|
|
bool blinding_next_pubkey(const struct pubkey *pk UNNEEDED,
|
|
|
|
const struct sha256 *h UNNEEDED,
|
|
|
|
struct pubkey *next UNNEEDED)
|
|
|
|
{ fprintf(stderr, "blinding_next_pubkey called!\n"); abort(); }
|
2019-08-29 07:53:07 +02:00
|
|
|
/* Generated stub for daemon_conn_wake */
|
|
|
|
void daemon_conn_wake(struct daemon_conn *dc UNNEEDED)
|
|
|
|
{ fprintf(stderr, "daemon_conn_wake called!\n"); abort(); }
|
2019-10-08 03:23:24 +02:00
|
|
|
/* Generated stub for decode_channel_update_timestamps */
|
|
|
|
struct channel_update_timestamps *decode_channel_update_timestamps(const tal_t *ctx UNNEEDED,
|
|
|
|
const struct tlv_reply_channel_range_tlvs_timestamps_tlv *timestamps_tlv UNNEEDED)
|
|
|
|
{ fprintf(stderr, "decode_channel_update_timestamps called!\n"); abort(); }
|
2019-08-29 07:53:07 +02:00
|
|
|
/* Generated stub for decode_scid_query_flags */
|
|
|
|
bigsize_t *decode_scid_query_flags(const tal_t *ctx UNNEEDED,
|
|
|
|
const struct tlv_query_short_channel_ids_tlvs_query_flags *qf UNNEEDED)
|
|
|
|
{ fprintf(stderr, "decode_scid_query_flags called!\n"); abort(); }
|
|
|
|
/* Generated stub for decode_short_ids */
|
|
|
|
struct short_channel_id *decode_short_ids(const tal_t *ctx UNNEEDED, const u8 *encoded UNNEEDED)
|
|
|
|
{ fprintf(stderr, "decode_short_ids called!\n"); abort(); }
|
2021-11-30 04:06:05 +01:00
|
|
|
/* Generated stub for ecdh */
|
|
|
|
void ecdh(const struct pubkey *point UNNEEDED, struct secret *ss UNNEEDED)
|
|
|
|
{ fprintf(stderr, "ecdh called!\n"); abort(); }
|
2020-08-25 04:05:45 +02:00
|
|
|
/* Generated stub for fromwire_gossipd_dev_set_max_scids_encode_size */
|
|
|
|
bool fromwire_gossipd_dev_set_max_scids_encode_size(const void *p UNNEEDED, u32 *max UNNEEDED)
|
|
|
|
{ fprintf(stderr, "fromwire_gossipd_dev_set_max_scids_encode_size called!\n"); abort(); }
|
2019-09-16 12:43:59 +02:00
|
|
|
/* Generated stub for get_cupdate_parts */
|
|
|
|
void get_cupdate_parts(const u8 *channel_update UNNEEDED,
|
|
|
|
const u8 *parts[2] UNNEEDED,
|
|
|
|
size_t sizes[2])
|
|
|
|
{ fprintf(stderr, "get_cupdate_parts called!\n"); abort(); }
|
2019-08-29 07:53:07 +02:00
|
|
|
/* Generated stub for get_node */
|
|
|
|
struct node *get_node(struct routing_state *rstate UNNEEDED,
|
|
|
|
const struct node_id *id UNNEEDED)
|
|
|
|
{ fprintf(stderr, "get_node called!\n"); abort(); }
|
|
|
|
/* Generated stub for gossip_store_get */
|
|
|
|
const u8 *gossip_store_get(const tal_t *ctx UNNEEDED,
|
|
|
|
struct gossip_store *gs UNNEEDED,
|
|
|
|
u64 offset UNNEEDED)
|
|
|
|
{ fprintf(stderr, "gossip_store_get called!\n"); abort(); }
|
|
|
|
/* Generated stub for master_badmsg */
|
|
|
|
void master_badmsg(u32 type_expected UNNEEDED, const u8 *msg)
|
|
|
|
{ fprintf(stderr, "master_badmsg called!\n"); abort(); }
|
2021-11-30 04:06:05 +01:00
|
|
|
/* Generated stub for new_onionreply */
|
|
|
|
struct onionreply *new_onionreply(const tal_t *ctx UNNEEDED, const u8 *contents TAKES UNNEEDED)
|
|
|
|
{ fprintf(stderr, "new_onionreply called!\n"); abort(); }
|
2019-10-08 03:26:24 +02:00
|
|
|
/* Generated stub for peer_supplied_good_gossip */
|
|
|
|
void peer_supplied_good_gossip(struct peer *peer UNNEEDED, size_t amount UNNEEDED)
|
|
|
|
{ fprintf(stderr, "peer_supplied_good_gossip called!\n"); abort(); }
|
2019-09-22 07:53:42 +02:00
|
|
|
/* Generated stub for queue_peer_from_store */
|
|
|
|
void queue_peer_from_store(struct peer *peer UNNEEDED,
|
|
|
|
const struct broadcastable *bcast UNNEEDED)
|
|
|
|
{ fprintf(stderr, "queue_peer_from_store called!\n"); abort(); }
|
|
|
|
/* Generated stub for queue_peer_msg */
|
|
|
|
void queue_peer_msg(struct peer *peer UNNEEDED, const u8 *msg TAKES UNNEEDED)
|
|
|
|
{ fprintf(stderr, "queue_peer_msg called!\n"); abort(); }
|
2021-02-03 03:51:41 +01:00
|
|
|
/* Generated stub for towire_warningfmt */
|
|
|
|
u8 *towire_warningfmt(const tal_t *ctx UNNEEDED,
|
|
|
|
const struct channel_id *channel UNNEEDED,
|
|
|
|
const char *fmt UNNEEDED, ...)
|
|
|
|
{ fprintf(stderr, "towire_warningfmt called!\n"); abort(); }
|
2019-08-09 18:12:01 +02:00
|
|
|
/* AUTOGENERATED MOCKS END */
|
|
|
|
|
2019-11-17 12:42:33 +01:00
|
|
|
void status_fmt(enum log_level level UNNEEDED,
|
|
|
|
const struct node_id *node_id UNNEEDED,
|
|
|
|
const char *fmt UNNEEDED, ...)
|
2019-08-09 18:12:01 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-05-18 02:50:16 +02:00
|
|
|
/* These we can reproduce */
|
|
|
|
static const char *test_vectors_nozlib[] = {
|
2019-08-09 18:12:01 +02:00
|
|
|
"{\n"
|
|
|
|
" \"msg\" : {\n"
|
|
|
|
" \"type\" : \"QueryChannelRange\",\n"
|
|
|
|
" \"chainHash\" : \"0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206\",\n"
|
|
|
|
" \"firstBlockNum\" : 100000,\n"
|
|
|
|
" \"numberOfBlocks\" : 1500,\n"
|
|
|
|
" \"extensions\" : [ ]\n"
|
|
|
|
" },\n"
|
|
|
|
" \"hex\" : \"01070f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206000186a0000005dc\"\n"
|
|
|
|
"}\n",
|
|
|
|
"{\n"
|
|
|
|
" \"msg\" : {\n"
|
|
|
|
" \"type\" : \"QueryChannelRange\",\n"
|
|
|
|
" \"chainHash\" : \"0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206\",\n"
|
|
|
|
" \"firstBlockNum\" : 35000,\n"
|
|
|
|
" \"numberOfBlocks\" : 100,\n"
|
|
|
|
" \"extensions\" : [ \"WANT_TIMESTAMPS | WANT_CHECKSUMS\" ]\n"
|
|
|
|
" },\n"
|
|
|
|
" \"hex\" : \"01070f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206000088b800000064010103\"\n"
|
|
|
|
"}\n",
|
|
|
|
"{\n"
|
|
|
|
" \"msg\" : {\n"
|
|
|
|
" \"type\" : \"ReplyChannelRange\",\n"
|
|
|
|
" \"chainHash\" : \"0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206\",\n"
|
|
|
|
" \"firstBlockNum\" : 122334,\n"
|
|
|
|
" \"numberOfBlocks\" : 1500,\n"
|
|
|
|
" \"complete\" : 1,\n"
|
|
|
|
" \"shortChannelIds\" : {\n"
|
|
|
|
" \"encoding\" : \"UNCOMPRESSED\",\n"
|
|
|
|
" \"array\" : [ \"0x0x12355\", \"0x7x30934\", \"0x70x57793\" ]\n"
|
|
|
|
" },\n"
|
|
|
|
" \"timestamps\" : {\n"
|
|
|
|
" \"encoding\" : \"UNCOMPRESSED\",\n"
|
|
|
|
" \"timestamps\" : [ {\n"
|
|
|
|
" \"timestamp1\" : 164545,\n"
|
|
|
|
" \"timestamp2\" : 948165\n"
|
|
|
|
" }, {\n"
|
|
|
|
" \"timestamp1\" : 489645,\n"
|
|
|
|
" \"timestamp2\" : 4786864\n"
|
|
|
|
" }, {\n"
|
|
|
|
" \"timestamp1\" : 46456,\n"
|
|
|
|
" \"timestamp2\" : 9788415\n"
|
|
|
|
" } ]\n"
|
|
|
|
" },\n"
|
|
|
|
" \"checksums\" : {\n"
|
|
|
|
" \"checksums\" : [ {\n"
|
|
|
|
" \"checksum1\" : 1111,\n"
|
|
|
|
" \"checksum2\" : 2222\n"
|
|
|
|
" }, {\n"
|
|
|
|
" \"checksum1\" : 3333,\n"
|
|
|
|
" \"checksum2\" : 4444\n"
|
|
|
|
" }, {\n"
|
|
|
|
" \"checksum1\" : 5555,\n"
|
|
|
|
" \"checksum2\" : 6666\n"
|
|
|
|
" } ]\n"
|
|
|
|
" }\n"
|
|
|
|
" },\n"
|
|
|
|
" \"hex\" : \"01080f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e22060001ddde000005dc01001900000000000000304300000000000778d6000000000046e1c1011900000282c1000e77c5000778ad00490ab00000b57800955bff031800000457000008ae00000d050000115c000015b300001a0a\"\n"
|
|
|
|
"}\n",
|
|
|
|
"{\n"
|
|
|
|
" \"msg\" : {\n"
|
|
|
|
" \"type\" : \"QueryShortChannelIds\",\n"
|
|
|
|
" \"chainHash\" : \"0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206\",\n"
|
|
|
|
" \"shortChannelIds\" : {\n"
|
|
|
|
" \"encoding\" : \"UNCOMPRESSED\",\n"
|
|
|
|
" \"array\" : [ \"0x0x142\", \"0x0x15465\", \"0x69x42692\" ]\n"
|
|
|
|
" },\n"
|
|
|
|
" \"extensions\" : [ ]\n"
|
|
|
|
" },\n"
|
|
|
|
" \"hex\" : \"01050f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206001900000000000000008e0000000000003c69000000000045a6c4\"\n"
|
|
|
|
"}\n",
|
|
|
|
};
|
|
|
|
|
|
|
|
static void get_chainhash(const char *test_vector,
|
|
|
|
const jsmntok_t *obj,
|
|
|
|
struct bitcoin_blkid *chain_hash)
|
|
|
|
{
|
|
|
|
const jsmntok_t *tok = json_get_member(test_vector, obj, "chainHash");
|
|
|
|
size_t hexlen = tok->end - tok->start;
|
|
|
|
assert(hex_decode(test_vector + tok->start, hexlen,
|
|
|
|
chain_hash, sizeof(*chain_hash)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static u8 *get_scid_array(const tal_t *ctx,
|
|
|
|
const char *test_vector,
|
|
|
|
const jsmntok_t *obj)
|
|
|
|
{
|
|
|
|
const jsmntok_t *scids, *arr, *encoding, *t;
|
|
|
|
size_t i;
|
|
|
|
u8 *encoded;
|
|
|
|
|
|
|
|
scids = json_get_member(test_vector, obj, "shortChannelIds");
|
|
|
|
arr = json_get_member(test_vector, scids, "array");
|
|
|
|
|
2022-05-18 02:51:16 +02:00
|
|
|
encoded = encoding_start(ctx, true);
|
2019-08-09 18:12:01 +02:00
|
|
|
encoding = json_get_member(test_vector, scids, "encoding");
|
|
|
|
json_for_each_arr(i, t, arr) {
|
|
|
|
struct short_channel_id scid;
|
2019-09-06 08:41:41 +02:00
|
|
|
assert(json_to_short_channel_id(test_vector, t, &scid));
|
2019-08-09 18:12:01 +02:00
|
|
|
encoding_add_short_channel_id(&encoded, &scid);
|
|
|
|
}
|
2022-05-18 02:50:16 +02:00
|
|
|
assert(json_tok_streq(test_vector, encoding, "UNCOMPRESSED"));
|
2019-08-09 18:12:01 +02:00
|
|
|
|
|
|
|
return encoded;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u8 *test_query_channel_range(const char *test_vector, const jsmntok_t *obj)
|
|
|
|
{
|
|
|
|
struct bitcoin_blkid chain_hash;
|
|
|
|
u32 firstBlockNum, numberOfBlocks;
|
|
|
|
const jsmntok_t *opt, *t;
|
|
|
|
struct tlv_query_channel_range_tlvs *tlvs
|
|
|
|
= tlv_query_channel_range_tlvs_new(NULL);
|
|
|
|
u8 *msg;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
get_chainhash(test_vector, obj, &chain_hash);
|
|
|
|
assert(json_to_number(test_vector, json_get_member(test_vector, obj, "firstBlockNum"), &firstBlockNum));
|
|
|
|
assert(json_to_number(test_vector, json_get_member(test_vector, obj, "numberOfBlocks"), &numberOfBlocks));
|
|
|
|
opt = json_get_member(test_vector, obj, "extensions");
|
|
|
|
json_for_each_arr(i, t, opt) {
|
|
|
|
assert(json_tok_streq(test_vector, t,
|
|
|
|
"WANT_TIMESTAMPS | WANT_CHECKSUMS"));
|
2020-09-23 00:49:53 +02:00
|
|
|
tlvs->query_option = tal(tlvs, bigsize_t);
|
2020-05-06 12:41:54 +02:00
|
|
|
*tlvs->query_option =
|
2019-08-09 18:12:01 +02:00
|
|
|
QUERY_ADD_TIMESTAMPS | QUERY_ADD_CHECKSUMS;
|
|
|
|
}
|
|
|
|
msg = towire_query_channel_range(NULL, &chain_hash, firstBlockNum, numberOfBlocks, tlvs);
|
|
|
|
|
2019-08-28 23:29:16 +02:00
|
|
|
tal_free(tlvs);
|
2019-08-09 18:12:01 +02:00
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u8 *test_reply_channel_range(const char *test_vector, const jsmntok_t *obj)
|
|
|
|
{
|
|
|
|
struct bitcoin_blkid chain_hash;
|
|
|
|
u32 firstBlockNum, numberOfBlocks, complete;
|
|
|
|
const jsmntok_t *opt, *t;
|
|
|
|
size_t i;
|
|
|
|
u8 *msg;
|
|
|
|
u8 *encoded_scids;
|
2019-08-28 23:29:16 +02:00
|
|
|
|
|
|
|
u8 *ctx = tal(NULL, u8);
|
2019-08-09 18:12:01 +02:00
|
|
|
struct tlv_reply_channel_range_tlvs *tlvs
|
2019-08-28 23:29:16 +02:00
|
|
|
= tlv_reply_channel_range_tlvs_new(ctx);
|
2019-08-09 18:12:01 +02:00
|
|
|
|
|
|
|
get_chainhash(test_vector, obj, &chain_hash);
|
|
|
|
assert(json_to_number(test_vector, json_get_member(test_vector, obj, "firstBlockNum"), &firstBlockNum));
|
|
|
|
assert(json_to_number(test_vector, json_get_member(test_vector, obj, "numberOfBlocks"), &numberOfBlocks));
|
|
|
|
assert(json_to_number(test_vector, json_get_member(test_vector, obj, "complete"), &complete));
|
|
|
|
|
2019-08-28 23:29:16 +02:00
|
|
|
encoded_scids = get_scid_array(ctx, test_vector, obj);
|
2019-08-09 18:12:01 +02:00
|
|
|
|
|
|
|
opt = json_get_member(test_vector, obj, "timestamps");
|
|
|
|
if (opt) {
|
|
|
|
const jsmntok_t *encodingtok, *tstok;
|
|
|
|
tlvs->timestamps_tlv
|
|
|
|
= tal(tlvs, struct tlv_reply_channel_range_tlvs_timestamps_tlv);
|
|
|
|
|
|
|
|
tlvs->timestamps_tlv->encoded_timestamps
|
2022-05-18 02:51:16 +02:00
|
|
|
= encoding_start(tlvs->timestamps_tlv, false);
|
2019-08-09 18:12:01 +02:00
|
|
|
encodingtok = json_get_member(test_vector, opt, "encoding");
|
|
|
|
tstok = json_get_member(test_vector, opt, "timestamps");
|
|
|
|
json_for_each_arr(i, t, tstok) {
|
|
|
|
struct channel_update_timestamps ts;
|
|
|
|
assert(json_to_number(test_vector,
|
|
|
|
json_get_member(test_vector, t,
|
|
|
|
"timestamp1"),
|
|
|
|
&ts.timestamp_node_id_1));
|
|
|
|
assert(json_to_number(test_vector,
|
|
|
|
json_get_member(test_vector, t,
|
|
|
|
"timestamp2"),
|
|
|
|
&ts.timestamp_node_id_2));
|
|
|
|
encoding_add_timestamps(&tlvs->timestamps_tlv->encoded_timestamps, &ts);
|
|
|
|
}
|
2022-05-18 02:50:16 +02:00
|
|
|
assert(json_tok_streq(test_vector, encodingtok, "UNCOMPRESSED"));
|
|
|
|
tlvs->timestamps_tlv->encoding_type = ARR_UNCOMPRESSED;
|
2019-08-09 18:12:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
opt = json_get_member(test_vector, obj, "checksums");
|
|
|
|
if (opt) {
|
|
|
|
const jsmntok_t *cstok;
|
|
|
|
tlvs->checksums_tlv
|
2020-05-06 12:41:54 +02:00
|
|
|
= tal_arr(tlvs, struct channel_update_checksums, 0);
|
2019-08-09 18:12:01 +02:00
|
|
|
|
|
|
|
cstok = json_get_member(test_vector, opt, "checksums");
|
|
|
|
json_for_each_arr(i, t, cstok) {
|
|
|
|
struct channel_update_checksums cs;
|
|
|
|
assert(json_to_number(test_vector,
|
|
|
|
json_get_member(test_vector, t,
|
|
|
|
"checksum1"),
|
|
|
|
&cs.checksum_node_id_1));
|
|
|
|
assert(json_to_number(test_vector,
|
|
|
|
json_get_member(test_vector, t,
|
|
|
|
"checksum2"),
|
|
|
|
&cs.checksum_node_id_2));
|
2020-05-06 12:41:54 +02:00
|
|
|
tal_arr_expand(&tlvs->checksums_tlv, cs);
|
2019-08-09 18:12:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
msg = towire_reply_channel_range(
|
|
|
|
NULL, &chain_hash, firstBlockNum, numberOfBlocks,
|
|
|
|
complete, encoded_scids, tlvs);
|
2019-08-28 23:29:16 +02:00
|
|
|
tal_free(ctx);
|
2019-08-09 18:12:01 +02:00
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct tlv_query_short_channel_ids_tlvs_query_flags *
|
|
|
|
get_query_flags_array(const tal_t *ctx,
|
|
|
|
const char *test_vector,
|
|
|
|
const jsmntok_t *opt)
|
|
|
|
{
|
|
|
|
const jsmntok_t *encoding, *arr, *t;
|
|
|
|
struct tlv_query_short_channel_ids_tlvs_query_flags *tlv
|
|
|
|
= tal(ctx, struct tlv_query_short_channel_ids_tlvs_query_flags);
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
arr = json_get_member(test_vector, opt, "array");
|
|
|
|
|
2022-05-18 02:51:16 +02:00
|
|
|
tlv->encoded_query_flags = encoding_start(tlv, false);
|
2019-08-09 18:12:01 +02:00
|
|
|
encoding = json_get_member(test_vector, opt, "encoding");
|
|
|
|
json_for_each_arr(i, t, arr) {
|
|
|
|
bigsize_t f;
|
|
|
|
assert(json_to_u64(test_vector, t, &f));
|
|
|
|
encoding_add_query_flag(&tlv->encoded_query_flags, f);
|
|
|
|
}
|
2022-05-18 02:50:16 +02:00
|
|
|
assert(json_tok_streq(test_vector, encoding, "UNCOMPRESSED"));
|
|
|
|
tlv->encoding_type = ARR_UNCOMPRESSED;
|
2019-08-09 18:12:01 +02:00
|
|
|
|
|
|
|
return tlv;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u8 *test_query_short_channel_ids(const char *test_vector,
|
|
|
|
const jsmntok_t *obj)
|
|
|
|
{
|
|
|
|
struct bitcoin_blkid chain_hash;
|
|
|
|
const jsmntok_t *opt;
|
|
|
|
u8 *encoded, *msg;
|
|
|
|
struct tlv_query_short_channel_ids_tlvs *tlvs;
|
|
|
|
|
|
|
|
get_chainhash(test_vector, obj, &chain_hash);
|
|
|
|
encoded = get_scid_array(NULL, test_vector, obj);
|
|
|
|
|
|
|
|
opt = json_get_member(test_vector, obj, "extensions");
|
|
|
|
if (opt && opt->size != 0) {
|
|
|
|
/* Only handle a single */
|
|
|
|
assert(opt->size == 1);
|
|
|
|
tlvs = tlv_query_short_channel_ids_tlvs_new(encoded);
|
|
|
|
tlvs->query_flags
|
|
|
|
= get_query_flags_array(tlvs, test_vector, opt + 1);
|
|
|
|
} else
|
|
|
|
tlvs = NULL;
|
|
|
|
msg = towire_query_short_channel_ids(NULL,
|
|
|
|
&chain_hash, encoded, tlvs);
|
|
|
|
|
|
|
|
tal_free(encoded);
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
2021-11-14 18:52:46 +01:00
|
|
|
int main(int argc, char *argv[])
|
2019-08-09 18:12:01 +02:00
|
|
|
{
|
|
|
|
jsmntok_t *toks = tal_arr(NULL, jsmntok_t, 1000);
|
|
|
|
|
2021-11-14 18:52:46 +01:00
|
|
|
common_setup(argv[0]);
|
2019-08-09 18:12:01 +02:00
|
|
|
|
2022-05-18 02:50:16 +02:00
|
|
|
for (size_t i = 0; i < ARRAY_SIZE(test_vectors_nozlib); i++) {
|
2019-08-09 18:12:01 +02:00
|
|
|
jsmn_parser parser;
|
|
|
|
u8 *m;
|
|
|
|
const char *hex_m;
|
|
|
|
const jsmntok_t *msg, *type, *hex;
|
|
|
|
|
|
|
|
jsmn_init(&parser);
|
|
|
|
assert(jsmn_parse(&parser,
|
2022-05-18 02:50:16 +02:00
|
|
|
test_vectors_nozlib[i], strlen(test_vectors_nozlib[i]),
|
2019-08-09 18:12:01 +02:00
|
|
|
toks, tal_count(toks)) > 0);
|
|
|
|
|
2022-05-18 02:50:16 +02:00
|
|
|
msg = json_get_member(test_vectors_nozlib[i], toks, "msg");
|
|
|
|
hex = json_get_member(test_vectors_nozlib[i], toks, "hex");
|
|
|
|
type = json_get_member(test_vectors_nozlib[i], msg, "type");
|
|
|
|
if (json_tok_streq(test_vectors_nozlib[i], type, "QueryChannelRange"))
|
|
|
|
m = test_query_channel_range(test_vectors_nozlib[i], msg);
|
|
|
|
else if (json_tok_streq(test_vectors_nozlib[i], type, "ReplyChannelRange"))
|
|
|
|
m = test_reply_channel_range(test_vectors_nozlib[i], msg);
|
|
|
|
else if (json_tok_streq(test_vectors_nozlib[i], type, "QueryShortChannelIds"))
|
|
|
|
m = test_query_short_channel_ids(test_vectors_nozlib[i], msg);
|
2019-08-09 18:12:01 +02:00
|
|
|
else
|
|
|
|
abort();
|
|
|
|
hex_m = tal_hex(m, m);
|
2022-05-18 02:50:16 +02:00
|
|
|
assert(json_tok_streq(test_vectors_nozlib[i], hex, hex_m));
|
2019-08-09 18:12:01 +02:00
|
|
|
tal_free(m);
|
|
|
|
}
|
|
|
|
tal_free(toks);
|
2021-11-14 18:52:46 +01:00
|
|
|
common_shutdown();
|
2019-08-09 18:12:01 +02:00
|
|
|
return 0;
|
|
|
|
}
|