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

Function test_decode

common/test/run-bigsize.c:231–259  ·  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

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

Callers 2

mainFunction · 0.70
mainFunction · 0.50

Calls 7

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

Tested by

no test coverage detected