Line data Source code
1 : /*
2 : This file is part of TALER
3 : Copyright (C) 2023 Taler Systems SA
4 :
5 : TALER is free software; you can redistribute it and/or modify
6 : it under the terms of the GNU General Public License as
7 : published by the Free Software Foundation; either version 3, or
8 : (at your option) any later version.
9 :
10 : TALER is distributed in the hope that it will be useful, but
11 : WITHOUT ANY WARRANTY; without even the implied warranty of
12 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 : GNU General Public License for more details.
14 :
15 : You should have received a copy of the GNU General Public
16 : License along with TALER; see the file COPYING. If not, see
17 : <http://www.gnu.org/licenses/>
18 : */
19 : /**
20 : * @file testing/testing_api_cmd_coin_history.c
21 : * @brief Implement the /coins/$COIN_PUB/history test command.
22 : * @author Christian Grothoff
23 : */
24 : #include "taler/taler_json_lib.h"
25 : #include <gnunet/gnunet_curl_lib.h>
26 : struct HistoryState;
27 : #define TALER_EXCHANGE_GET_COINS_HISTORY_RESULT_CLOSURE \
28 : struct HistoryState
29 : #include "taler/exchange/get-coins-COIN_PUB-history.h"
30 : #include "taler/taler_testing_lib.h"
31 :
32 :
33 : /**
34 : * State for a "history" CMD.
35 : */
36 : struct HistoryState
37 : {
38 :
39 : /**
40 : * Public key of the coin being analyzed.
41 : */
42 : struct TALER_CoinSpendPublicKeyP coin_pub;
43 :
44 : /**
45 : * Label to the command which created the coin to check,
46 : * needed to resort the coin key.
47 : */
48 : const char *coin_reference;
49 :
50 : /**
51 : * Handle to the "coin history" operation.
52 : */
53 : struct TALER_EXCHANGE_GetCoinsHistoryHandle *rsh;
54 :
55 : /**
56 : * Expected coin balance.
57 : */
58 : const char *expected_balance;
59 :
60 : /**
61 : * Private key of the coin being analyzed.
62 : */
63 : const struct TALER_CoinSpendPrivateKeyP *coin_priv;
64 :
65 : /**
66 : * Interpreter state.
67 : */
68 : struct TALER_TESTING_Interpreter *is;
69 :
70 : /**
71 : * Expected HTTP response code.
72 : */
73 : unsigned int expected_response_code;
74 :
75 : };
76 :
77 :
78 : /**
79 : * Closure for analysis_cb().
80 : */
81 : struct AnalysisContext
82 : {
83 : /**
84 : * Coin public key we are looking at.
85 : */
86 : const struct TALER_CoinSpendPublicKeyP *coin_pub;
87 :
88 : /**
89 : * Length of the @e history array.
90 : */
91 : unsigned int history_length;
92 :
93 : /**
94 : * Array of history items to match.
95 : */
96 : const struct TALER_EXCHANGE_CoinHistoryEntry *history;
97 :
98 : /**
99 : * Array of @e history_length of matched entries.
100 : */
101 : bool *found;
102 :
103 : /**
104 : * Set to true if an entry could not be found.
105 : */
106 : bool failure;
107 : };
108 :
109 :
110 : /**
111 : * Compare @a h1 and @a h2.
112 : *
113 : * @param h1 a history entry
114 : * @param h2 a history entry
115 : * @return 0 if @a h1 and @a h2 are equal
116 : */
117 : static int
118 15 : history_entry_cmp (
119 : const struct TALER_EXCHANGE_CoinHistoryEntry *h1,
120 : const struct TALER_EXCHANGE_CoinHistoryEntry *h2)
121 : {
122 15 : if (h1->type != h2->type)
123 0 : return 1;
124 15 : if (0 != TALER_amount_cmp (&h1->amount,
125 : &h2->amount))
126 : {
127 0 : GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
128 : "Amount mismatch (%s)\n",
129 : TALER_amount2s (&h1->amount));
130 0 : return 1;
131 : }
132 15 : switch (h1->type)
133 : {
134 0 : case TALER_EXCHANGE_CTT_NONE:
135 0 : GNUNET_break (0);
136 0 : break;
137 4 : case TALER_EXCHANGE_CTT_DEPOSIT:
138 4 : if (0 != GNUNET_memcmp (&h1->details.deposit.h_contract_terms,
139 : &h2->details.deposit.h_contract_terms))
140 0 : return 1;
141 4 : if (0 != GNUNET_memcmp (&h1->details.deposit.merchant_pub,
142 : &h2->details.deposit.merchant_pub))
143 0 : return 1;
144 4 : if (0 != GNUNET_memcmp (&h1->details.deposit.h_wire,
145 : &h2->details.deposit.h_wire))
146 0 : return 1;
147 4 : if (0 != GNUNET_memcmp (&h1->details.deposit.sig,
148 : &h2->details.deposit.sig))
149 0 : return 1;
150 4 : return 0;
151 4 : case TALER_EXCHANGE_CTT_MELT:
152 4 : if (0 != GNUNET_memcmp (&h1->details.melt.h_age_commitment,
153 : &h2->details.melt.h_age_commitment))
154 0 : return 1;
155 4 : if (0 != GNUNET_memcmp (&h1->details.melt.rc,
156 : &h2->details.melt.rc))
157 0 : return 1;
158 : /* presence of noreveal_index and transfer_pubs is checked,
159 : and transfer_pubs are verified, in check_melt_entries() */
160 4 : if ( (! h2->details.melt.no_noreveal_index) &&
161 4 : (h1->details.melt.noreveal_index != h2->details.melt.noreveal_index) )
162 0 : return 1;
163 : /* Note: most other fields are not initialized
164 : in the trait as they are hard to extract from
165 : the API */
166 4 : return 0;
167 0 : case TALER_EXCHANGE_CTT_REFUND:
168 0 : if (0 != GNUNET_memcmp (&h1->details.refund.sig,
169 : &h2->details.refund.sig))
170 0 : return 1;
171 0 : return 0;
172 4 : case TALER_EXCHANGE_CTT_RECOUP:
173 4 : if (0 != GNUNET_memcmp (&h1->details.recoup.coin_sig,
174 : &h2->details.recoup.coin_sig))
175 0 : return 1;
176 : /* Note: exchange_sig, exchange_pub and timestamp are
177 : fundamentally not available in the initiating command */
178 4 : return 0;
179 0 : case TALER_EXCHANGE_CTT_RECOUP_REFRESH:
180 0 : if (0 != GNUNET_memcmp (&h1->details.recoup_refresh.coin_sig,
181 : &h2->details.recoup_refresh.coin_sig))
182 0 : return 1;
183 : /* Note: exchange_sig, exchange_pub and timestamp are
184 : fundamentally not available in the initiating command */
185 0 : return 0;
186 0 : case TALER_EXCHANGE_CTT_OLD_COIN_RECOUP:
187 0 : if (0 != GNUNET_memcmp (&h1->details.old_coin_recoup.new_coin_pub,
188 : &h2->details.old_coin_recoup.new_coin_pub))
189 0 : return 1;
190 : /* Note: exchange_sig, exchange_pub and timestamp are
191 : fundamentally not available in the initiating command */
192 0 : return 0;
193 3 : case TALER_EXCHANGE_CTT_PURSE_DEPOSIT:
194 : /* coin_sig is not initialized */
195 3 : if (0 != GNUNET_memcmp (&h1->details.purse_deposit.purse_pub,
196 : &h2->details.purse_deposit.purse_pub))
197 : {
198 0 : GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
199 : "Purse public key mismatch\n");
200 0 : return 1;
201 : }
202 3 : if (0 != strcmp (h1->details.purse_deposit.exchange_base_url,
203 3 : h2->details.purse_deposit.exchange_base_url))
204 : {
205 0 : GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
206 : "Exchange base URL mismatch (%s/%s)\n",
207 : h1->details.purse_deposit.exchange_base_url,
208 : h2->details.purse_deposit.exchange_base_url);
209 0 : GNUNET_break (0);
210 0 : return 1;
211 : }
212 3 : return 0;
213 0 : case TALER_EXCHANGE_CTT_PURSE_REFUND:
214 : /* NOTE: not supported yet (trait not returned) */
215 0 : return 0;
216 0 : case TALER_EXCHANGE_CTT_RESERVE_OPEN_DEPOSIT:
217 : /* NOTE: not supported yet (trait not returned) */
218 0 : if (0 != GNUNET_memcmp (&h1->details.reserve_open_deposit.coin_sig,
219 : &h2->details.reserve_open_deposit.coin_sig))
220 0 : return 1;
221 0 : return 0;
222 : }
223 0 : GNUNET_assert (0);
224 : return -1;
225 : }
226 :
227 :
228 : /**
229 : * Check if @a cmd changed the coin, if so, find the
230 : * entry in our history and set the respective index in found
231 : * to true. If the entry is not found, set failure.
232 : *
233 : * @param cls our `struct AnalysisContext *`
234 : * @param cmd command to analyze for impact on history
235 : */
236 : static void
237 864 : analyze_command (void *cls,
238 : const struct TALER_TESTING_Command *cmd)
239 : {
240 864 : struct AnalysisContext *ac = cls;
241 864 : const struct TALER_CoinSpendPublicKeyP *coin_pub = ac->coin_pub;
242 864 : const struct TALER_EXCHANGE_CoinHistoryEntry *history = ac->history;
243 864 : unsigned int history_length = ac->history_length;
244 864 : bool *found = ac->found;
245 :
246 864 : if (TALER_TESTING_cmd_is_batch (cmd))
247 : {
248 : struct TALER_TESTING_Command *cur;
249 : struct TALER_TESTING_Command *bcmd;
250 :
251 57 : GNUNET_log (GNUNET_ERROR_TYPE_INFO,
252 : "Checking `%s' for history of coin `%s'\n",
253 : cmd->label,
254 : TALER_B2S (coin_pub));
255 57 : cur = TALER_TESTING_cmd_batch_get_current (cmd);
256 57 : if (GNUNET_OK !=
257 57 : TALER_TESTING_get_trait_batch_cmds (cmd,
258 : &bcmd))
259 : {
260 0 : GNUNET_break (0);
261 0 : ac->failure = true;
262 0 : return;
263 : }
264 728 : for (unsigned int i = 0; NULL != bcmd[i].label; i++)
265 : {
266 681 : struct TALER_TESTING_Command *step = &bcmd[i];
267 :
268 681 : analyze_command (ac,
269 : step);
270 681 : if (ac->failure)
271 : {
272 0 : GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
273 : "Entry for batch step `%s' missing in coin history\n",
274 : step->label);
275 0 : return;
276 : }
277 681 : if (step == cur)
278 10 : break; /* if *we* are in a batch, make sure not to analyze commands past 'now' */
279 : }
280 57 : return;
281 : }
282 :
283 807 : for (unsigned int j = 0; true; j++)
284 423 : {
285 : const struct TALER_CoinSpendPublicKeyP *rp;
286 : const struct TALER_EXCHANGE_CoinHistoryEntry *he;
287 1230 : bool matched = false;
288 :
289 1230 : if (GNUNET_OK !=
290 1230 : TALER_TESTING_get_trait_coin_pub (cmd,
291 : j,
292 : &rp))
293 : {
294 782 : GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
295 : "Command `%s#%u' has no public key for a coin\n",
296 : cmd->label,
297 : j);
298 782 : break; /* command does nothing for coins */
299 : }
300 854 : if (0 !=
301 448 : GNUNET_memcmp (rp,
302 : coin_pub))
303 : {
304 406 : GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
305 : "Command `%s#%u' is about another coin %s\n",
306 : cmd->label,
307 : j,
308 : TALER_B2S (rp));
309 408 : continue; /* command affects some _other_ coin */
310 : }
311 42 : if (GNUNET_OK !=
312 42 : TALER_TESTING_get_trait_coin_history (cmd,
313 : j,
314 : &he))
315 : {
316 : /* NOTE: only for debugging... */
317 25 : if (0 == j)
318 25 : GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
319 : "Command `%s' has the coin_pub, but lacks coin history trait\n",
320 : cmd->label);
321 25 : return; /* command does nothing for coins */
322 : }
323 17 : if (TALER_EXCHANGE_CTT_NONE == he->type)
324 2 : continue; /* operation was rejected, coin unaffected */
325 18 : for (unsigned int i = 0; i<history_length; i++)
326 : {
327 18 : if (found[i])
328 3 : continue; /* already found, skip */
329 15 : if (0 ==
330 15 : history_entry_cmp (he,
331 15 : &history[i]))
332 : {
333 15 : found[i] = true;
334 15 : matched = true;
335 15 : break;
336 : }
337 : }
338 15 : if (! matched)
339 : {
340 0 : GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
341 : "Command `%s' coin history entry #%u not found\n",
342 : cmd->label,
343 : j);
344 0 : ac->failure = true;
345 0 : return;
346 : }
347 : }
348 : }
349 :
350 :
351 : /**
352 : * Check the details of the melt entries of a coin history: they must
353 : * have a noreveal index and transfer public keys, and the latter must be
354 : * those the client derived for the batch at the noreveal index.
355 : *
356 : * @param ss our state, with the coin's private key
357 : * @param hlen length of @a rhist
358 : * @param rhist the parsed coin history
359 : * @return true if all melt entries are consistent
360 : */
361 : static bool
362 12 : check_melt_entries (
363 : const struct HistoryState *ss,
364 : unsigned int hlen,
365 : const struct TALER_EXCHANGE_CoinHistoryEntry rhist[static hlen])
366 12 : {
367 12 : const struct TALER_EXCHANGE_Keys *keys = TALER_TESTING_get_keys (ss->is);
368 : unsigned int protocol;
369 :
370 12 : GNUNET_assert (1 == sscanf (keys->version, "%u", &protocol));
371 27 : for (unsigned int i = 0; i < hlen; i++)
372 : {
373 15 : const struct TALER_EXCHANGE_CoinHistoryEntry *rh = &rhist[i];
374 15 : size_t n = rh->details.melt.num_fresh_coins;
375 :
376 15 : if (TALER_EXCHANGE_CTT_MELT != rh->type)
377 11 : continue;
378 4 : if ( (protocol < 46) &&
379 0 : rh->details.melt.no_noreveal_index &&
380 0 : (NULL == rh->details.melt.transfer_pubs) )
381 0 : continue;
382 4 : if ( (rh->details.melt.no_noreveal_index) ||
383 4 : (NULL == rh->details.melt.transfer_pubs) ||
384 : (0 == n) )
385 : {
386 0 : GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
387 : "Melt history entry lacks noreveal_index or transfer_pubs\n");
388 0 : return false;
389 : }
390 4 : {
391 : struct TALER_KappaPrivateRefreshBatchSeedsP kappa_seeds;
392 4 : struct TALER_PlanchetMasterSecretP ps[n];
393 4 : struct TALER_TransferPublicKeyP tp[n];
394 :
395 4 : TALER_refresh_expand_seed_to_kappa_batch_seeds (
396 : &rh->details.melt.refresh_seed,
397 4 : ss->coin_priv,
398 : &kappa_seeds);
399 4 : TALER_refresh_expand_batch_seed_to_transfer_data (
400 4 : &kappa_seeds.tuple[rh->details.melt.noreveal_index],
401 : &ss->coin_pub,
402 : n,
403 : ps,
404 : tp);
405 4 : if (0 != memcmp (tp,
406 4 : rh->details.melt.transfer_pubs,
407 : sizeof (tp)))
408 : {
409 0 : GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
410 : "Melt history has wrong transfer_pubs\n");
411 0 : return false;
412 : }
413 : }
414 : }
415 12 : return true;
416 : }
417 :
418 :
419 : /**
420 : * Check that the coin balance and HTTP response code are
421 : * both acceptable.
422 : *
423 : * @param ss closure.
424 : * @param rs HTTP response details
425 : */
426 : static void
427 14 : coin_history_cb (struct HistoryState *ss,
428 : const struct TALER_EXCHANGE_GetCoinsHistoryResponse *rs)
429 : {
430 14 : struct TALER_TESTING_Interpreter *is = ss->is;
431 : struct TALER_Amount eb;
432 : unsigned int hlen;
433 :
434 14 : ss->rsh = NULL;
435 14 : if (ss->expected_response_code != rs->hr.http_status)
436 : {
437 0 : TALER_TESTING_unexpected_status (ss->is,
438 : rs->hr.http_status,
439 : ss->expected_response_code);
440 2 : return;
441 : }
442 14 : if (MHD_HTTP_OK != rs->hr.http_status)
443 : {
444 2 : TALER_TESTING_interpreter_next (is);
445 2 : return;
446 : }
447 12 : GNUNET_assert (GNUNET_OK ==
448 : TALER_string_to_amount (ss->expected_balance,
449 : &eb));
450 :
451 12 : if (0 != TALER_amount_cmp (&eb,
452 : &rs->details.ok.balance))
453 : {
454 0 : GNUNET_break (0);
455 0 : GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
456 : "Unexpected balance for coin: %s\n",
457 : TALER_amount_to_string (&rs->details.ok.balance));
458 0 : GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
459 : "Expected balance of: %s\n",
460 : TALER_amount_to_string (&eb));
461 0 : TALER_TESTING_interpreter_fail (ss->is);
462 0 : return;
463 : }
464 12 : hlen = json_array_size (rs->details.ok.history);
465 12 : {
466 12 : bool found[GNUNET_NZL (hlen)];
467 12 : struct TALER_EXCHANGE_CoinHistoryEntry rhist[hlen + 1];
468 12 : struct AnalysisContext ac = {
469 12 : .coin_pub = &ss->coin_pub,
470 : .history = rhist,
471 : .history_length = hlen,
472 : .found = found
473 : };
474 : const struct TALER_EXCHANGE_DenomPublicKey *dk;
475 : struct TALER_Amount total_in;
476 : struct TALER_Amount total_out;
477 : struct TALER_Amount hbal;
478 12 : bool failed = false;
479 :
480 12 : dk = TALER_EXCHANGE_get_denomination_key_by_hash (
481 12 : TALER_TESTING_get_keys (is),
482 : &rs->details.ok.h_denom_pub);
483 12 : GNUNET_assert (NULL != dk);
484 12 : memset (found,
485 : 0,
486 12 : sizeof (found));
487 12 : memset (rhist,
488 : 0,
489 : sizeof (rhist));
490 : /* Exercise the public parse/free contract with spare capacity. */
491 12 : rhist[hlen].type = TALER_EXCHANGE_CTT_MELT;
492 12 : if (GNUNET_OK !=
493 12 : TALER_EXCHANGE_parse_coin_history (
494 12 : TALER_TESTING_get_keys (is),
495 : dk,
496 12 : rs->details.ok.history,
497 12 : &ss->coin_pub,
498 : &total_in,
499 : &total_out,
500 : hlen + 1,
501 : rhist))
502 : {
503 0 : GNUNET_break (0);
504 0 : json_dumpf (rs->hr.reply,
505 : stderr,
506 : JSON_INDENT (2));
507 0 : TALER_TESTING_interpreter_fail (ss->is);
508 0 : return;
509 : }
510 12 : GNUNET_assert (TALER_EXCHANGE_CTT_NONE == rhist[hlen].type);
511 12 : if (! check_melt_entries (ss,
512 : hlen,
513 : rhist))
514 : {
515 0 : failed = true;
516 0 : goto cleanup;
517 : }
518 12 : if (0 >
519 12 : TALER_amount_subtract (&hbal,
520 : &total_in,
521 : &total_out))
522 : {
523 0 : GNUNET_break (0);
524 0 : GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
525 : "Coin credits: %s\n",
526 : TALER_amount2s (&total_in));
527 0 : GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
528 : "Coin debits: %s\n",
529 : TALER_amount2s (&total_out));
530 0 : failed = true;
531 0 : goto cleanup;
532 : }
533 12 : if (0 != TALER_amount_cmp (&hbal,
534 : &rs->details.ok.balance))
535 : {
536 0 : GNUNET_break (0);
537 0 : failed = true;
538 0 : goto cleanup;
539 : }
540 : (void) ac;
541 12 : TALER_TESTING_iterate (is,
542 : true,
543 : &analyze_command,
544 : &ac);
545 12 : if (ac.failure)
546 : {
547 0 : json_dumpf (rs->hr.reply,
548 : stderr,
549 : JSON_INDENT (2));
550 0 : failed = true;
551 0 : goto cleanup;
552 : }
553 : #if 1
554 27 : for (unsigned int i = 0; i<hlen; i++)
555 : {
556 15 : if (found[i])
557 15 : continue;
558 0 : GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
559 : "History entry at index %u of type %d not justified by command history\n",
560 : i,
561 : rhist[i].type);
562 0 : json_dumpf (rs->hr.reply,
563 : stderr,
564 : JSON_INDENT (2));
565 0 : failed = true;
566 0 : goto cleanup;
567 : }
568 : #endif
569 12 : cleanup:
570 12 : TALER_EXCHANGE_free_coin_history (hlen + 1,
571 : rhist);
572 12 : if (failed)
573 : {
574 0 : TALER_TESTING_interpreter_fail (ss->is);
575 0 : return;
576 : }
577 : }
578 12 : TALER_TESTING_interpreter_next (is);
579 : }
580 :
581 :
582 : /**
583 : * Run the command.
584 : *
585 : * @param cls closure.
586 : * @param cmd the command being executed.
587 : * @param is the interpreter state.
588 : */
589 : static void
590 14 : history_run (void *cls,
591 : const struct TALER_TESTING_Command *cmd,
592 : struct TALER_TESTING_Interpreter *is)
593 : {
594 14 : struct HistoryState *ss = cls;
595 : const struct TALER_TESTING_Command *create_coin;
596 : char *cref;
597 : unsigned int idx;
598 :
599 14 : ss->is = is;
600 14 : GNUNET_assert (
601 : GNUNET_OK ==
602 : TALER_TESTING_parse_coin_reference (
603 : ss->coin_reference,
604 : &cref,
605 : &idx));
606 : create_coin
607 14 : = TALER_TESTING_interpreter_lookup_command (is,
608 : cref);
609 14 : GNUNET_free (cref);
610 14 : if (NULL == create_coin)
611 : {
612 0 : GNUNET_break (0);
613 0 : TALER_TESTING_interpreter_fail (is);
614 0 : return;
615 : }
616 14 : if (GNUNET_OK !=
617 14 : TALER_TESTING_get_trait_coin_priv (create_coin,
618 : idx,
619 : &ss->coin_priv))
620 : {
621 0 : GNUNET_break (0);
622 0 : TALER_LOG_ERROR ("Failed to find coin_priv for history query\n");
623 0 : TALER_TESTING_interpreter_fail (is);
624 0 : return;
625 : }
626 14 : GNUNET_CRYPTO_eddsa_key_get_public (&ss->coin_priv->eddsa_priv,
627 : &ss->coin_pub.eddsa_pub);
628 14 : ss->rsh = TALER_EXCHANGE_get_coins_history_create (
629 : TALER_TESTING_interpreter_get_context (is),
630 : TALER_TESTING_get_exchange_url (is),
631 : ss->coin_priv);
632 14 : GNUNET_assert (NULL != ss->rsh);
633 14 : GNUNET_assert (TALER_EC_NONE ==
634 : TALER_EXCHANGE_get_coins_history_start (ss->rsh,
635 : &coin_history_cb,
636 : ss));
637 : }
638 :
639 :
640 : /**
641 : * Offer internal data from a "history" CMD, to other commands.
642 : *
643 : * @param cls closure.
644 : * @param[out] ret result.
645 : * @param trait name of the trait.
646 : * @param index index number of the object to offer.
647 : * @return #GNUNET_OK on success.
648 : */
649 : static enum GNUNET_GenericReturnValue
650 49 : history_traits (void *cls,
651 : const void **ret,
652 : const char *trait,
653 : unsigned int index)
654 : {
655 49 : struct HistoryState *hs = cls;
656 : struct TALER_TESTING_Trait traits[] = {
657 49 : TALER_TESTING_make_trait_coin_pub (0,
658 49 : &hs->coin_pub),
659 49 : TALER_TESTING_trait_end ()
660 : };
661 :
662 49 : return TALER_TESTING_get_trait (traits,
663 : ret,
664 : trait,
665 : index);
666 : }
667 :
668 :
669 : /**
670 : * Cleanup the state from a "coin history" CMD, and possibly
671 : * cancel a pending operation thereof.
672 : *
673 : * @param cls closure.
674 : * @param cmd the command which is being cleaned up.
675 : */
676 : static void
677 14 : history_cleanup (void *cls,
678 : const struct TALER_TESTING_Command *cmd)
679 : {
680 14 : struct HistoryState *ss = cls;
681 :
682 14 : if (NULL != ss->rsh)
683 : {
684 0 : TALER_TESTING_command_incomplete (ss->is,
685 : cmd->label);
686 0 : TALER_EXCHANGE_get_coins_history_cancel (ss->rsh);
687 0 : ss->rsh = NULL;
688 : }
689 14 : GNUNET_free (ss);
690 14 : }
691 :
692 :
693 : struct TALER_TESTING_Command
694 14 : TALER_TESTING_cmd_coin_history (const char *label,
695 : const char *coin_reference,
696 : const char *expected_balance,
697 : unsigned int expected_response_code)
698 : {
699 : struct HistoryState *ss;
700 :
701 14 : GNUNET_assert (NULL != coin_reference);
702 14 : ss = GNUNET_new (struct HistoryState);
703 14 : ss->coin_reference = coin_reference;
704 14 : ss->expected_balance = expected_balance;
705 14 : ss->expected_response_code = expected_response_code;
706 : {
707 14 : struct TALER_TESTING_Command cmd = {
708 : .cls = ss,
709 : .label = label,
710 : .run = &history_run,
711 : .cleanup = &history_cleanup,
712 : .traits = &history_traits
713 : };
714 :
715 14 : return cmd;
716 : }
717 : }
|