testing_api_cmd_bank_check_empty.c (3234B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2018-2020 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_bank_check_empty.c 21 * @brief command to check if a particular wire transfer took 22 * place. 23 * @author Marcello Stanisci 24 */ 25 #include "taler/platform.h" 26 #include "taler/taler_json_lib.h" 27 #include <gnunet/gnunet_curl_lib.h> 28 #include "taler/taler_testing_lib.h" 29 #include "taler/taler_fakebank_lib.h" 30 31 32 /** 33 * Cleanup the state, only defined to respect the API. 34 * 35 * @param cls closure. 36 * @param cmd the command which is being cleaned up. 37 */ 38 static void 39 check_bank_empty_cleanup 40 (void *cls, 41 const struct TALER_TESTING_Command *cmd) 42 { 43 (void) cls; 44 (void) cmd; 45 return; 46 } 47 48 49 /** 50 * Run the command. 51 * 52 * @param cls closure. 53 * @param cmd the command to execute. 54 * @param is the interpreter state. 55 */ 56 static void 57 check_bank_empty_run ( 58 void *cls, 59 const struct TALER_TESTING_Command *cmd, 60 struct TALER_TESTING_Interpreter *is) 61 { 62 struct TALER_FAKEBANK_Handle *fakebank; 63 64 (void) cls; 65 (void) cmd; 66 { 67 const struct TALER_TESTING_Command *fakebank_cmd; 68 69 fakebank_cmd 70 = TALER_TESTING_interpreter_get_command (is, 71 "fakebank"); 72 if (NULL == fakebank_cmd) 73 { 74 GNUNET_break (0); 75 TALER_TESTING_interpreter_fail (is); 76 return; 77 } 78 if (GNUNET_OK != 79 TALER_TESTING_get_trait_fakebank (fakebank_cmd, 80 &fakebank)) 81 { 82 GNUNET_break (0); 83 TALER_TESTING_interpreter_fail (is); 84 return; 85 } 86 } 87 if (GNUNET_OK != 88 TALER_FAKEBANK_check_empty (fakebank)) 89 { 90 GNUNET_break (0); 91 TALER_TESTING_interpreter_fail (is); 92 return; 93 } 94 TALER_TESTING_interpreter_next (is); 95 } 96 97 98 /** 99 * Some commands (notably "bank history") could randomly 100 * look for traits; this way makes sure we don't segfault. 101 */ 102 static enum GNUNET_GenericReturnValue 103 check_bank_empty_traits (void *cls, 104 const void **ret, 105 const char *trait, 106 unsigned int index) 107 { 108 (void) cls; 109 (void) ret; 110 (void) trait; 111 (void) index; 112 return GNUNET_SYSERR; 113 } 114 115 116 /** 117 * Checks whether all the wire transfers got "checked" 118 * by the "bank check" CMD. 119 * 120 * @param label command label. 121 * 122 * @return the command 123 */ 124 struct TALER_TESTING_Command 125 TALER_TESTING_cmd_check_bank_empty (const char *label) 126 { 127 struct TALER_TESTING_Command cmd = { 128 .label = label, 129 .run = &check_bank_empty_run, 130 .cleanup = &check_bank_empty_cleanup, 131 .traits = &check_bank_empty_traits 132 }; 133 134 return cmd; 135 }