test_taler_exchange_wirewatch.c (6205B)
1 /* 2 This file is part of TALER 3 (C) 2016-2020 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or modify it under the 6 terms of the GNU General Public License as published by the Free Software 7 Foundation; either version 3, or (at your option) any later version. 8 9 TALER is distributed in the hope that it will be useful, but WITHOUT ANY 10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 A PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License along with 14 TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 */ 16 17 /** 18 * @file testing/test_taler_exchange_wirewatch.c 19 * @brief Tests for taler-exchange-wirewatch and taler-exchange-aggregator logic; 20 * Performs an invalid wire transfer to the exchange, and then checks that 21 * wirewatch immediately sends the money back. 22 * Then performs a valid wire transfer, waits for the reserve to expire, 23 * and then checks that the aggregator sends the money back. 24 * @author Christian Grothoff <christian@grothoff.org> 25 */ 26 #include "taler/platform.h" 27 #include "taler/taler_util.h" 28 #include <gnunet/gnunet_json_lib.h> 29 #include <gnunet/gnunet_pq_lib.h> 30 #include "taler/taler_json_lib.h" 31 #include <microhttpd.h> 32 #include "taler/taler_fakebank_lib.h" 33 #include "taler/taler_testing_lib.h" 34 35 36 /** 37 * Our credentials. 38 */ 39 static struct TALER_TESTING_Credentials cred; 40 41 /** 42 * Name of the configuration file to use. 43 */ 44 static char *config_filename; 45 46 47 /** 48 * Execute the taler-exchange-aggregator, closer and transfer commands with 49 * our configuration file. 50 * 51 * @param label label to use for the command. 52 */ 53 #define CMD_EXEC_AGGREGATOR(label) \ 54 TALER_TESTING_cmd_exec_aggregator (label "-aggregator", config_filename) \ 55 , \ 56 TALER_TESTING_cmd_exec_transfer (label "-transfer", config_filename) 57 58 59 static struct TALER_TESTING_Command 60 transfer_to_exchange (const char *label, 61 const char *amount) 62 { 63 return TALER_TESTING_cmd_admin_add_incoming (label, 64 amount, 65 &cred.ba, 66 cred.user42_payto); 67 } 68 69 70 /** 71 * Main function that will tell the interpreter what commands to 72 * run. 73 * 74 * @param cls closure 75 */ 76 static void 77 run (void *cls, 78 struct TALER_TESTING_Interpreter *is) 79 { 80 struct TALER_TESTING_Command all[] = { 81 TALER_TESTING_cmd_run_fakebank ("run-fakebank", 82 cred.cfg, 83 "exchange-account-1"), 84 TALER_TESTING_cmd_system_start ("start-taler", 85 config_filename, 86 "-e", 87 "-u", "exchange-account-1", 88 NULL), 89 TALER_TESTING_cmd_get_exchange ("get-exchange", 90 cred.cfg, 91 NULL, 92 true, 93 true), 94 TALER_TESTING_cmd_check_bank_empty ("expect-empty-transactions-on-start"), 95 CMD_EXEC_AGGREGATOR ("run-aggregator-on-empty"), 96 TALER_TESTING_cmd_exec_wirewatch ("run-wirewatch-on-empty", 97 config_filename), 98 TALER_TESTING_cmd_check_bank_empty ("expect-transfers-empty-after-dry-run"), 99 100 transfer_to_exchange ("run-transfer-good-to-exchange", 101 "EUR:5"), 102 TALER_TESTING_cmd_exec_wirewatch ("run-wirewatch-on-good-transfer", 103 config_filename), 104 105 TALER_TESTING_cmd_check_bank_admin_transfer ( 106 "clear-good-transfer-to-the-exchange", 107 "EUR:5", 108 cred.user42_payto, // debit 109 cred.exchange_payto, // credit 110 "run-transfer-good-to-exchange"), 111 112 TALER_TESTING_cmd_exec_closer ("run-closer-non-expired-reserve", 113 config_filename, 114 NULL, 115 NULL, 116 NULL), 117 TALER_TESTING_cmd_exec_transfer ("do-idle-transfer", config_filename), 118 119 TALER_TESTING_cmd_check_bank_empty ("expect-empty-transactions-1"), 120 TALER_TESTING_cmd_sleep ("wait (5s)", 121 5), 122 TALER_TESTING_cmd_exec_closer ("run-closer-expired-reserve", 123 config_filename, 124 "EUR:4.99", 125 "EUR:0.01", 126 "run-transfer-good-to-exchange"), 127 TALER_TESTING_cmd_exec_transfer ("do-closing-transfer", 128 config_filename), 129 130 CMD_EXEC_AGGREGATOR ("run-closer-on-expired-reserve"), 131 TALER_TESTING_cmd_check_bank_transfer ("expect-deposit-1", 132 cred.exchange_url, 133 "EUR:4.99", 134 cred.exchange_payto, 135 cred.user42_payto), 136 TALER_TESTING_cmd_check_bank_empty ("expect-empty-transactions-2"), 137 TALER_TESTING_cmd_end () 138 }; 139 140 (void) cls; 141 TALER_TESTING_run (is, 142 all); 143 } 144 145 146 int 147 main (int argc, 148 char *const argv[]) 149 { 150 (void) argc; 151 { 152 const char *plugin_name; 153 154 plugin_name = strrchr (argv[0], (int) '-'); 155 if (NULL == plugin_name) 156 { 157 GNUNET_break (0); 158 return -1; 159 } 160 plugin_name++; 161 GNUNET_asprintf (&config_filename, 162 "test-taler-exchange-wirewatch-%s.conf", 163 plugin_name); 164 } 165 return TALER_TESTING_main (argv, 166 "INFO", 167 config_filename, 168 "exchange-account-1", 169 TALER_TESTING_BS_FAKEBANK, 170 &cred, 171 &run, 172 NULL); 173 } 174 175 176 /* end of test_taler_exchange_wirewatch.c */