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

Function test_encode

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

BOLT #1: * * A correct implementation should pass against the following 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

307 * ```
308 */
309static void test_encode(const char *json, const jsmntok_t toks[])
310{
311 size_t i;
312 const jsmntok_t *t;
313 u8 buf[BIGSIZE_MAX_LEN];
314
315 json_for_each_arr(i, t, toks) {
316 const jsmntok_t *bytes = json_get_member(json, t, "bytes");
317 u64 num;
318 const u8 *expect;
319 size_t len;
320
321 if (!json_to_u64(json, json_get_member(json, t, "value"),
322 &num))
323 abort();
324 expect = tal_hexdata(tmpctx, json + bytes->start,
325 bytes->end - bytes->start);
326
327 len = bigsize_put(buf, num);
328 assert(memeq(buf, len, expect, tal_bytelen(expect)));
329 }
330}
331
332int main(int argc, char *argv[])
333{

Callers 2

mainFunction · 0.70
mainFunction · 0.50

Calls 7

json_get_memberFunction · 0.85
abortFunction · 0.85
tal_hexdataFunction · 0.85
memeqFunction · 0.85
tal_bytelenFunction · 0.85
json_to_u64Function · 0.70
bigsize_putFunction · 0.70

Tested by

no test coverage detected