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

Function main

common/test/run-bolt12_decode.c:163–210  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

161/* AUTOGENERATED MOCKS END */
162
163int main(int argc, char *argv[])
164{
165 char *json;
166 size_t i;
167 jsmn_parser parser;
168 jsmntok_t toks[5000];
169 const jsmntok_t *t;
170
171 common_setup(argv[0]);
172
173 if (argv[1])
174 json = grab_file_str(tmpctx, argv[1]);
175 else {
176 char *dir = getenv("BOLTDIR");
177 json = grab_file_str(tmpctx,
178 path_join(tmpctx,
179 dir ? dir : ".tmp.lightningrfc",
180 "bolt12/format-string-test.json"));
181 if (!json) {
182 printf("test file not found, skipping\n");
183 goto out;
184 }
185 }
186
187 jsmn_init(&parser);
188 if (jsmn_parse(&parser, json, strlen(json), toks, ARRAY_SIZE(toks)) < 0)
189 abort();
190
191 json_for_each_arr(i, t, toks) {
192 bool valid, actual;
193 const jsmntok_t *strtok;
194 const char *fail;
195 const char *str;
196 size_t dlen;
197
198 assert(json_to_bool(json, json_get_member(json, t, "valid"), &valid));
199 strtok = json_get_member(json, t, "string");
200 str = json_escape_unescape_len(tmpctx, json + strtok->start,
201 strtok->end - strtok->start);
202 actual = (b12_string_to_data(tmpctx, str, strlen(str),
203 "lno", &dlen, &fail) != NULL);
204 assert(actual == valid);
205 printf("%s %s\n", str, valid ? "OK": "INVALID");
206 }
207out:
208 common_shutdown();
209 return 0;
210}

Callers

nothing calls this directly

Calls 9

common_setupFunction · 0.85
grab_file_strFunction · 0.85
path_joinFunction · 0.85
abortFunction · 0.85
json_get_memberFunction · 0.85
json_escape_unescape_lenFunction · 0.85
b12_string_to_dataFunction · 0.85
common_shutdownFunction · 0.85
json_to_boolFunction · 0.70

Tested by

no test coverage detected