test_bank_api_twisted.c (5409B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2014-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/test_bank_api_twisted.c 21 * @author Marcello Stanisci 22 * @author Sree Harsha Totakura <sreeharsha@totakura.in> 23 * @author Christian Grothoff 24 */ 25 #include "taler/platform.h" 26 #include "taler/taler_util.h" 27 #include "taler/taler_signatures.h" 28 #include "taler/taler_exchange_service.h" 29 #include "taler/taler_json_lib.h" 30 #include <gnunet/gnunet_util_lib.h> 31 #include <microhttpd.h> 32 #include "taler/taler_bank_service.h" 33 #include "taler/taler_fakebank_lib.h" 34 #include "taler/taler_testing_lib.h" 35 #include "taler/taler_twister_testing_lib.h" 36 #include <taler/taler_twister_service.h> 37 38 /** 39 * Configuration file we use. One (big) configuration is used 40 * for the various components for this test. 41 */ 42 #define CONFIG_FILE_FAKEBANK "test_bank_api_fakebank_twisted.conf" 43 44 /** 45 * Configuration file we use. 46 */ 47 static const char *cfgfile; 48 49 /** 50 * Our credentials. 51 */ 52 static struct TALER_TESTING_Credentials cred; 53 54 /** 55 * Which bank is the test running against? 56 * Set up at runtime. 57 */ 58 static enum TALER_TESTING_BankSystem bs; 59 60 /** 61 * (real) Twister URL. Used at startup time to check if it runs. 62 */ 63 static char *twister_url; 64 65 /** 66 * Twister process. 67 */ 68 static struct GNUNET_OS_Process *twisterd; 69 70 71 /** 72 * Main function that will tell 73 * the interpreter what commands to run. 74 * 75 * @param cls closure 76 */ 77 static void 78 run (void *cls, 79 struct TALER_TESTING_Interpreter *is) 80 { 81 struct TALER_WireTransferIdentifierRawP wtid; 82 /* Authentication data to route our commands through twister. */ 83 struct TALER_BANK_AuthenticationData exchange_auth_twisted; 84 const char *systype = NULL; 85 86 (void) cls; 87 memset (&wtid, 88 0x5a, 89 sizeof (wtid)); 90 GNUNET_memcpy (&exchange_auth_twisted, 91 &cred.ba, 92 sizeof (struct TALER_BANK_AuthenticationData)); 93 switch (bs) 94 { 95 case TALER_TESTING_BS_FAKEBANK: 96 exchange_auth_twisted.wire_gateway_url 97 = (char *) "http://localhost:8888/accounts/2/taler-wire-gateway/"; 98 systype = "-f"; 99 break; 100 case TALER_TESTING_BS_IBAN: 101 exchange_auth_twisted.wire_gateway_url 102 = (char *) "http://localhost:8888/accounts/Exchange/taler-wire-gateway/"; 103 systype = "-b"; 104 break; 105 } 106 GNUNET_assert (NULL != systype); 107 108 { 109 struct TALER_TESTING_Command commands[] = { 110 TALER_TESTING_cmd_system_start ("start-taler", 111 cfgfile, 112 systype, 113 NULL), 114 /* Test retrying transfer after failure. */ 115 TALER_TESTING_cmd_malform_response ("malform-transfer", 116 cfgfile), 117 TALER_TESTING_cmd_transfer_retry ( 118 TALER_TESTING_cmd_transfer ("debit-1", 119 "EUR:3.22", 120 &exchange_auth_twisted, 121 cred.exchange_payto, 122 cred.user42_payto, 123 &wtid, 124 "http://exchange.example.com/")), 125 TALER_TESTING_cmd_end () 126 }; 127 128 TALER_TESTING_run (is, 129 commands); 130 } 131 } 132 133 134 /** 135 * Kill, wait, and destroy convenience function. 136 * 137 * @param[in] process process to purge. 138 */ 139 static void 140 purge_process (struct GNUNET_OS_Process *process) 141 { 142 GNUNET_OS_process_kill (process, 143 SIGINT); 144 GNUNET_OS_process_wait (process); 145 GNUNET_OS_process_destroy (process); 146 } 147 148 149 int 150 main (int argc, 151 char *const *argv) 152 { 153 int ret; 154 155 (void) argc; 156 if (TALER_TESTING_has_in_name (argv[0], 157 "_with_fakebank")) 158 { 159 bs = TALER_TESTING_BS_FAKEBANK; 160 cfgfile = CONFIG_FILE_FAKEBANK; 161 } 162 else if (TALER_TESTING_has_in_name (argv[0], 163 "_with_nexus")) 164 { 165 GNUNET_assert (0); /* FIXME: test with nexus not yet implemented */ 166 bs = TALER_TESTING_BS_IBAN; 167 /* cfgfile = CONFIG_FILE_NEXUS; */ 168 } 169 else 170 { 171 /* no bank service was specified. */ 172 GNUNET_break (0); 173 return 77; 174 } 175 176 /* FIXME: introduce commands for twister! */ 177 twister_url = TALER_TWISTER_prepare_twister (cfgfile); 178 if (NULL == twister_url) 179 return 77; 180 twisterd = TALER_TWISTER_run_twister (cfgfile); 181 if (NULL == twisterd) 182 return 77; 183 ret = TALER_TESTING_main (argv, 184 "INFO", 185 cfgfile, 186 "exchange-account-2", 187 bs, 188 &cred, 189 &run, 190 NULL); 191 purge_process (twisterd); 192 GNUNET_free (twister_url); 193 return ret; 194 } 195 196 197 /* end of test_bank_api_twisted.c */