| 152 | } |
| 153 | |
| 154 | int main(int argc, char *argv[]) |
| 155 | { |
| 156 | char *json; |
| 157 | size_t i; |
| 158 | jsmn_parser parser; |
| 159 | jsmntok_t toks[5000]; |
| 160 | const jsmntok_t *t, *hops_tok; |
| 161 | struct pubkey *ids; |
| 162 | u8 **enctlvs; |
| 163 | struct privkey blinding; |
| 164 | |
| 165 | common_setup(argv[0]); |
| 166 | |
| 167 | if (argv[1]) |
| 168 | json = grab_file(tmpctx, argv[1]); |
| 169 | else { |
| 170 | char *dir = getenv("BOLTDIR"); |
| 171 | json = grab_file(tmpctx, |
| 172 | path_join(tmpctx, |
| 173 | dir ? dir : "../bolts", |
| 174 | "bolt04/route-blinding-test.json")); |
| 175 | if (!json) { |
| 176 | printf("test file not found, skipping\n"); |
| 177 | goto out; |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | jsmn_init(&parser); |
| 182 | if (jsmn_parse(&parser, json, strlen(json), toks, ARRAY_SIZE(toks)) < 0) |
| 183 | abort(); |
| 184 | |
| 185 | hops_tok = json_get_member(json, json_get_member(json, toks, "route"), "hops"); |
| 186 | ids = tal_arr(tmpctx, struct pubkey, hops_tok->size); |
| 187 | enctlvs = tal_arr(tmpctx, u8 *, hops_tok->size); |
| 188 | |
| 189 | json_for_each_arr(i, t, hops_tok) { |
| 190 | u8 *expected; |
| 191 | assert(json_to_pubkey(json, json_get_member(json, t, "node_id"), |
| 192 | &ids[i])); |
| 193 | enctlvs[i] = json_tok_bin_from_hex(enctlvs, json, |
| 194 | json_get_member(json, t, "encoded_tlvs")); |
| 195 | expected = json_to_enctlvs(tmpctx, json, |
| 196 | json_get_member(json, t, "tlvs")); |
| 197 | assert(memeq(expected, tal_bytelen(expected), |
| 198 | enctlvs[i], tal_bytelen(enctlvs[i]))); |
| 199 | } |
| 200 | |
| 201 | /* Now do the blinding. */ |
| 202 | hops_tok = json_get_member(json, json_get_member(json, toks, "blinding"), "hops"); |
| 203 | assert(hops_tok->size == tal_count(ids)); |
| 204 | |
| 205 | json_for_each_arr(i, t, hops_tok) { |
| 206 | struct secret s; |
| 207 | struct pubkey pubkey, expected_pubkey; |
| 208 | u8 *enctlv, *expected_enctlv; |
| 209 | struct pubkey alias, expected_alias; |
| 210 | |
| 211 | assert(json_to_secret(json, |
nothing calls this directly
no test coverage detected