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

Function test_encode

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

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

Callers 2

mainFunction · 0.70
mainFunction · 0.50

Calls 7

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

Tested by

no test coverage detected