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

Function main

common/test/run-bolt12-offer-decode.c:126–216  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

124/* AUTOGENERATED MOCKS END */
125
126int main(int argc, char *argv[])
127{
128 char *json;
129 size_t i;
130 jsmn_parser parser;
131 jsmntok_t toks[5000];
132 const jsmntok_t *t;
133 struct feature_set *feature_set;
134 common_setup(argv[0]);
135
136 if (argv[1])
137 json = grab_file_str(tmpctx, argv[1]);
138 else {
139 char *dir = getenv("BOLTDIR");
140 json = grab_file_str(tmpctx,
141 path_join(tmpctx,
142 dir ? dir : ".tmp.lightningrfc",
143 "bolt12/offers-test.json"));
144 if (!json) {
145 printf("test file not found, skipping\n");
146 goto out;
147 }
148 }
149
150 jsmn_init(&parser);
151 if (jsmn_parse(&parser, json, strlen(json), toks, ARRAY_SIZE(toks)) < 0)
152 abort();
153
154 /* This gives an empty bolt12 feature set. */
155 feature_set = feature_set_for_feature(tmpctx, OPT_VAR_ONION);
156 json_for_each_arr(i, t, toks) {
157 bool valid;
158 const char *desc, *bolt12;
159 const char *fail;
160 struct tlv_offer *offer;
161
162 assert(json_scan(tmpctx, json, t,
163 "{description:%,valid:%,bolt12:%}",
164 JSON_SCAN_TAL(tmpctx, json_strdup, &desc),
165 JSON_SCAN(json_to_bool, &valid),
166 JSON_SCAN_TAL(tmpctx, json_strdup, &bolt12)) == NULL);
167 printf("%s: ", desc);
168 offer = offer_decode(tmpctx, bolt12, strlen(bolt12),
169 feature_set, NULL, &fail);
170 if (!valid) {
171 if (offer) {
172 printf("ERROR should be invalid!\n");
173 abort();
174 }
175 printf("XFAIL %s\n", fail);
176 } else {
177 size_t j;
178 const jsmntok_t *f, *fields = json_get_member(json, t, "fields");
179 bool have_unknown = false;
180 if (!offer) {
181 printf("ERROR should be valid, but %s!\n", fail);
182 abort();
183 }

Callers

nothing calls this directly

Calls 10

common_setupFunction · 0.85
grab_file_strFunction · 0.85
path_joinFunction · 0.85
abortFunction · 0.85
feature_set_for_featureFunction · 0.85
offer_decodeFunction · 0.85
json_get_memberFunction · 0.85
memeqFunction · 0.85
common_shutdownFunction · 0.85
json_scanFunction · 0.70

Tested by

no test coverage detected