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"
| 301 | * ``` |
| 302 | */ |
| 303 | static 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 | |
| 326 | int main(int argc, char *argv[]) |
| 327 | { |
no test coverage detected