testing_api_cmd_bank_admin_check.c (6002B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2018-2020, 2024 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_admin_check.c 21 * @brief command to check if a particular admin/add-incoming transfer took 22 * place. 23 * @author Christian Grothoff 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 * State for a "bank check" CMD. 34 */ 35 struct BankAdminCheckState 36 { 37 38 /** 39 * Expected transferred amount. 40 */ 41 const char *amount; 42 43 /** 44 * Expected debit bank account. 45 */ 46 struct TALER_FullPayto debit_payto; 47 48 /** 49 * Expected credit bank account. 50 */ 51 struct TALER_FullPayto credit_payto; 52 53 /** 54 * Command providing the reserve public key trait to use. 55 */ 56 const char *reserve_pub_ref; 57 58 /** 59 * Interpreter state. 60 */ 61 struct TALER_TESTING_Interpreter *is; 62 63 }; 64 65 /** 66 * Run the command. 67 * 68 * @param cls closure. 69 * @param cmd the command to execute. 70 * @param is the interpreter state. 71 */ 72 static void 73 check_bank_admin_transfer_run (void *cls, 74 const struct TALER_TESTING_Command *cmd, 75 struct TALER_TESTING_Interpreter *is) 76 { 77 struct BankAdminCheckState *bcs = cls; 78 struct TALER_Amount amount; 79 char *debit_account; 80 char *credit_account; 81 struct TALER_FullPayto debit_payto; 82 struct TALER_FullPayto credit_payto; 83 const struct TALER_ReservePublicKeyP *reserve_pub; 84 const struct TALER_TESTING_Command *cmd_ref; 85 struct TALER_FAKEBANK_Handle *fakebank; 86 87 (void) cmd; 88 { 89 const struct TALER_TESTING_Command *fakebank_cmd; 90 91 fakebank_cmd 92 = TALER_TESTING_interpreter_get_command (is, 93 "fakebank"); 94 if (NULL == fakebank_cmd) 95 { 96 GNUNET_break (0); 97 TALER_TESTING_interpreter_fail (is); 98 return; 99 } 100 if (GNUNET_OK != 101 TALER_TESTING_get_trait_fakebank (fakebank_cmd, 102 &fakebank)) 103 { 104 GNUNET_break (0); 105 TALER_TESTING_interpreter_fail (is); 106 return; 107 } 108 } 109 cmd_ref 110 = TALER_TESTING_interpreter_lookup_command (is, 111 bcs->reserve_pub_ref); 112 if (NULL == cmd_ref) 113 { 114 GNUNET_break (0); 115 TALER_TESTING_interpreter_fail (is); 116 return; 117 } 118 if (GNUNET_OK != 119 TALER_TESTING_get_trait_reserve_pub (cmd_ref, 120 &reserve_pub)) 121 { 122 GNUNET_break (0); 123 TALER_LOG_ERROR ("Command reference fails to provide reserve public key\n"); 124 TALER_TESTING_interpreter_fail (is); 125 return; 126 } 127 debit_payto = bcs->debit_payto; 128 credit_payto = bcs->credit_payto; 129 if (GNUNET_OK != 130 TALER_string_to_amount (bcs->amount, 131 &amount)) 132 { 133 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 134 "Failed to parse amount `%s' at %s\n", 135 bcs->amount, 136 TALER_TESTING_interpreter_get_current_label (is)); 137 TALER_TESTING_interpreter_fail (is); 138 return; 139 } 140 debit_account = TALER_xtalerbank_account_from_payto (debit_payto); 141 credit_account = TALER_xtalerbank_account_from_payto (credit_payto); 142 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 143 "converted debit_payto (%s) to debit_account (%s)\n", 144 debit_payto.full_payto, 145 debit_account); 146 if (GNUNET_OK != 147 TALER_FAKEBANK_check_credit (fakebank, 148 &amount, 149 debit_account, 150 credit_account, 151 reserve_pub)) 152 { 153 GNUNET_break (0); 154 GNUNET_free (credit_account); 155 GNUNET_free (debit_account); 156 TALER_TESTING_interpreter_fail (is); 157 return; 158 } 159 GNUNET_free (credit_account); 160 GNUNET_free (debit_account); 161 TALER_TESTING_interpreter_next (is); 162 } 163 164 165 /** 166 * Free the state of a "bank check" CMD. 167 * 168 * @param cls closure. 169 * @param cmd the command which is being cleaned up. 170 */ 171 static void 172 check_bank_admin_transfer_cleanup (void *cls, 173 const struct TALER_TESTING_Command *cmd) 174 { 175 struct BankAdminCheckState *bcs = cls; 176 177 (void) cmd; 178 GNUNET_free (bcs); 179 } 180 181 182 /** 183 * Make a "bank check" CMD. It checks whether a particular wire transfer to 184 * the exchange (credit) has been made or not. 185 * 186 * @param label the command label. 187 * @param amount the amount expected to be transferred. 188 * @param debit_payto the account that gave money. 189 * @param credit_payto the account that received money. 190 * @param reserve_pub_ref command that provides the reserve public key to expect 191 * @return the command 192 */ 193 struct TALER_TESTING_Command 194 TALER_TESTING_cmd_check_bank_admin_transfer ( 195 const char *label, 196 const char *amount, 197 struct TALER_FullPayto debit_payto, 198 struct TALER_FullPayto credit_payto, 199 const char *reserve_pub_ref) 200 { 201 struct BankAdminCheckState *bcs; 202 203 bcs = GNUNET_new (struct BankAdminCheckState); 204 bcs->amount = amount; 205 bcs->debit_payto = debit_payto; 206 bcs->credit_payto = credit_payto; 207 bcs->reserve_pub_ref = reserve_pub_ref; 208 { 209 struct TALER_TESTING_Command cmd = { 210 .label = label, 211 .cls = bcs, 212 .run = &check_bank_admin_transfer_run, 213 .cleanup = &check_bank_admin_transfer_cleanup 214 }; 215 216 return cmd; 217 } 218 }