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" *
| 223 | * ``` |
| 224 | */ |
| 225 | static 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 | * |
no test coverage detected