MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_decode

Function test_decode

common/test/run-bigsize.c:225–253  ·  view source on GitHub ↗

BOLT #1: * * A correct implementation should pass against these test vectors: * ```json * [ * { * "name": "zero", * "value": 0, * "bytes": "00" * }, * { * "name": "one byte high", * "value": 252, * "bytes": "fc" * }, * { * "name": "two byte low", * "value": 253, * "bytes": "fd00fd" *

Source from the content-addressed store, hash-verified

223 * ```
224 */
225static void test_decode(const char *json, const jsmntok_t toks[])
226{
227 size_t i;
228 const jsmntok_t *t;
229
230 json_for_each_arr(i, t, toks) {
231 const jsmntok_t *err = json_get_member(json, t, "exp_error");
232 const jsmntok_t *bytes = json_get_member(json, t, "bytes");
233 u64 num, expect;
234 const u8 *b;
235 size_t len;
236
237 if (!json_to_u64(json, json_get_member(json, t, "value"),
238 &expect))
239 abort();
240 b = tal_hexdata(tmpctx, json + bytes->start,
241 bytes->end - bytes->start);
242
243 reason = NULL;
244 len = bigsize_get(b, tal_bytelen(b), &num);
245 if (err) {
246 assert(len == 0);
247 assert(json_tok_streq(json, err, reason));
248 } else {
249 assert(len == tal_bytelen(b));
250 assert(num == expect);
251 }
252 }
253}
254
255/* BOLT #1:
256 *

Callers 2

mainFunction · 0.70
mainFunction · 0.50

Calls 7

abortFunction · 0.85
tal_hexdataFunction · 0.85
tal_bytelenFunction · 0.85
json_get_memberFunction · 0.70
bigsize_getFunction · 0.70
json_tok_streqFunction · 0.70
json_to_u64Function · 0.50

Tested by

no test coverage detected