mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-21 14:24:09 +01:00
test: move run-bigsize into common to match common/bigsize.
And make it use bigsize accessors directly, not via fromwire/towire. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
8349c1a0c2
commit
2241e25cb4
1 changed files with 14 additions and 22 deletions
|
@ -4,14 +4,17 @@
|
|||
#include <ccan/tal/str/str.h>
|
||||
#include <common/json.c>
|
||||
#include <common/utils.h>
|
||||
#include <wire/wire.h>
|
||||
|
||||
static const char *reason;
|
||||
#define SUPERVERBOSE(r) do { if (!reason) reason = (r); } while(0)
|
||||
|
||||
#include <wire/fromwire.c>
|
||||
#include <wire/towire.c>
|
||||
#include <common/bigsize.c>
|
||||
|
||||
/* AUTOGENERATED MOCKS START */
|
||||
/* Generated stub for fromwire_fail */
|
||||
const void *fromwire_fail(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
|
||||
{ fprintf(stderr, "fromwire_fail called!\n"); abort(); }
|
||||
/* AUTOGENERATED MOCKS END */
|
||||
|
||||
/* BOLT-EXPERIMENTAL #1:
|
||||
|
@ -132,7 +135,7 @@ static void test_decode(const char *json, const jsmntok_t toks[])
|
|||
const jsmntok_t *bytes = json_get_member(json, t, "bytes");
|
||||
u64 num, expect;
|
||||
const u8 *b;
|
||||
size_t max;
|
||||
size_t len;
|
||||
|
||||
if (!json_to_u64(json, json_get_member(json, t, "value"),
|
||||
&expect))
|
||||
|
@ -140,25 +143,14 @@ static void test_decode(const char *json, const jsmntok_t toks[])
|
|||
b = tal_hexdata(tmpctx, json + bytes->start,
|
||||
bytes->end - bytes->start);
|
||||
|
||||
max = tal_bytelen(b);
|
||||
reason = NULL;
|
||||
num = fromwire_bigsize(&b, &max);
|
||||
len = bigsize_get(b, tal_bytelen(b), &num);
|
||||
if (err) {
|
||||
assert(b == NULL);
|
||||
assert(max == 0);
|
||||
/* Map our errors to the test strings. */
|
||||
if (json_tok_streq(json, err,
|
||||
"decoded varint is not canonical"))
|
||||
assert(streq(reason, "not minimal encoded"));
|
||||
else if (json_tok_streq(json, err, "unexpected EOF")
|
||||
|| json_tok_streq(json, err, "EOF"))
|
||||
assert(streq(reason, "less than encoding length"));
|
||||
else
|
||||
abort();
|
||||
assert(len == 0);
|
||||
assert(json_tok_streq(json, err, reason));
|
||||
} else {
|
||||
assert(b != NULL);
|
||||
assert(len == tal_bytelen(b));
|
||||
assert(num == expect);
|
||||
assert(max == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -215,12 +207,13 @@ static void test_encode(const char *json, const jsmntok_t toks[])
|
|||
{
|
||||
size_t i;
|
||||
const jsmntok_t *t;
|
||||
u8 buf[BIGSIZE_MAX_LEN];
|
||||
|
||||
json_for_each_arr(i, t, toks) {
|
||||
const jsmntok_t *bytes = json_get_member(json, t, "bytes");
|
||||
u64 num;
|
||||
const u8 *expect;
|
||||
u8 *b;
|
||||
size_t len;
|
||||
|
||||
if (!json_to_u64(json, json_get_member(json, t, "value"),
|
||||
&num))
|
||||
|
@ -228,9 +221,8 @@ static void test_encode(const char *json, const jsmntok_t toks[])
|
|||
expect = tal_hexdata(tmpctx, json + bytes->start,
|
||||
bytes->end - bytes->start);
|
||||
|
||||
b = tal_arr(tmpctx, u8, 0);
|
||||
towire_bigsize(&b, num);
|
||||
assert(memeq(b, tal_bytelen(b), expect, tal_bytelen(expect)));
|
||||
len = bigsize_put(buf, num);
|
||||
assert(memeq(buf, len, expect, tal_bytelen(expect)));
|
||||
}
|
||||
}
|
||||
|
Loading…
Add table
Reference in a new issue