Line data Source code
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_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 "platform.h" 26 : #include "taler_json_lib.h" 27 : #include <gnunet/gnunet_curl_lib.h> 28 : #include "taler_testing_lib.h" 29 : #include "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 : const char *debit_payto; 47 : 48 : /** 49 : * Expected credit bank account. 50 : */ 51 : const char *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 0 : check_bank_admin_transfer_run (void *cls, 74 : const struct TALER_TESTING_Command *cmd, 75 : struct TALER_TESTING_Interpreter *is) 76 : { 77 0 : struct BankAdminCheckState *bcs = cls; 78 : struct TALER_Amount amount; 79 : char *debit_account; 80 : char *credit_account; 81 : const char *debit_payto; 82 : const char *credit_payto; 83 : const struct TALER_ReservePublicKeyP *reserve_pub; 84 : const struct TALER_TESTING_Command *cmd_ref; 85 : 86 : (void) cmd; 87 : cmd_ref 88 0 : = TALER_TESTING_interpreter_lookup_command (is, 89 : bcs->reserve_pub_ref); 90 0 : if (NULL == cmd_ref) 91 : { 92 0 : GNUNET_break (0); 93 0 : TALER_TESTING_interpreter_fail (is); 94 0 : return; 95 : } 96 0 : if (GNUNET_OK != 97 0 : TALER_TESTING_get_trait_reserve_pub (cmd_ref, 98 : &reserve_pub)) 99 : { 100 0 : GNUNET_break (0); 101 0 : TALER_LOG_ERROR ("Command reference fails to provide reserve public key\n"); 102 0 : TALER_TESTING_interpreter_fail (is); 103 0 : return; 104 : } 105 0 : debit_payto = bcs->debit_payto; 106 0 : credit_payto = bcs->credit_payto; 107 0 : if (GNUNET_OK != 108 0 : TALER_string_to_amount (bcs->amount, 109 : &amount)) 110 : { 111 0 : GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 112 : "Failed to parse amount `%s' at %u\n", 113 : bcs->amount, 114 : is->ip); 115 0 : TALER_TESTING_interpreter_fail (is); 116 0 : return; 117 : } 118 0 : debit_account = TALER_xtalerbank_account_from_payto (debit_payto); 119 0 : credit_account = TALER_xtalerbank_account_from_payto (credit_payto); 120 0 : GNUNET_log (GNUNET_ERROR_TYPE_INFO, 121 : "converted debit_payto (%s) to debit_account (%s)\n", 122 : debit_payto, 123 : debit_account); 124 0 : if (GNUNET_OK != 125 0 : TALER_FAKEBANK_check_credit (is->fakebank, 126 : &amount, 127 : debit_account, 128 : credit_account, 129 : reserve_pub)) 130 : { 131 0 : GNUNET_break (0); 132 0 : GNUNET_free (credit_account); 133 0 : GNUNET_free (debit_account); 134 0 : TALER_TESTING_interpreter_fail (is); 135 0 : return; 136 : } 137 0 : GNUNET_free (credit_account); 138 0 : GNUNET_free (debit_account); 139 0 : TALER_TESTING_interpreter_next (is); 140 : } 141 : 142 : 143 : /** 144 : * Free the state of a "bank check" CMD. 145 : * 146 : * @param cls closure. 147 : * @param cmd the command which is being cleaned up. 148 : */ 149 : static void 150 0 : check_bank_admin_transfer_cleanup (void *cls, 151 : const struct TALER_TESTING_Command *cmd) 152 : { 153 0 : struct BankAdminCheckState *bcs = cls; 154 : 155 : (void) cmd; 156 0 : GNUNET_free (bcs); 157 0 : } 158 : 159 : 160 : /** 161 : * Make a "bank check" CMD. It checks whether a particular wire transfer to 162 : * the exchange (credit) has been made or not. 163 : * 164 : * @param label the command label. 165 : * @param amount the amount expected to be transferred. 166 : * @param debit_payto the account that gave money. 167 : * @param credit_payto the account that received money. 168 : * @param reserve_pub_ref command that provides the reserve public key to expect 169 : * @return the command 170 : */ 171 : struct TALER_TESTING_Command 172 0 : TALER_TESTING_cmd_check_bank_admin_transfer 173 : (const char *label, 174 : const char *amount, 175 : const char *debit_payto, 176 : const char *credit_payto, 177 : const char *reserve_pub_ref) 178 : { 179 : struct BankAdminCheckState *bcs; 180 : 181 0 : bcs = GNUNET_new (struct BankAdminCheckState); 182 0 : bcs->amount = amount; 183 0 : bcs->debit_payto = debit_payto; 184 0 : bcs->credit_payto = credit_payto; 185 0 : bcs->reserve_pub_ref = reserve_pub_ref; 186 : { 187 0 : struct TALER_TESTING_Command cmd = { 188 : .label = label, 189 : .cls = bcs, 190 : .run = &check_bank_admin_transfer_run, 191 : .cleanup = &check_bank_admin_transfer_cleanup 192 : }; 193 : 194 0 : return cmd; 195 : } 196 : }