diff options
Diffstat (limited to 'src/bank-lib/test_bank_api_twisted_NEW.c')
-rw-r--r-- | src/bank-lib/test_bank_api_twisted_NEW.c | 219 |
1 files changed, 219 insertions, 0 deletions
diff --git a/src/bank-lib/test_bank_api_twisted_NEW.c b/src/bank-lib/test_bank_api_twisted_NEW.c new file mode 100644 index 000000000..e971584f6 --- /dev/null +++ b/src/bank-lib/test_bank_api_twisted_NEW.c | |||
@@ -0,0 +1,219 @@ | |||
1 | /* | ||
2 | This file is part of TALER | ||
3 | Copyright (C) 2014-2018 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 exchange/test_bank_api_with_fakebank_twisted.c | ||
21 | * @author Marcello Stanisci | ||
22 | * @author Sree Harsha Totakura <sreeharsha@totakura.in> | ||
23 | * @author Christian Grothoff | ||
24 | */ | ||
25 | #include "platform.h" | ||
26 | #include "taler_util.h" | ||
27 | #include "taler_signatures.h" | ||
28 | #include "taler_exchange_service.h" | ||
29 | #include "taler_json_lib.h" | ||
30 | #include <gnunet/gnunet_util_lib.h> | ||
31 | #include <microhttpd.h> | ||
32 | #include "taler_bank_service.h" | ||
33 | #include "taler_fakebank_lib.h" | ||
34 | #include "taler_testing_lib.h" | ||
35 | #include <taler/taler_twister_testing_lib.h> | ||
36 | #include "taler_testing_bank_lib.h" | ||
37 | #include <taler/taler_twister_service.h> | ||
38 | |||
39 | /** | ||
40 | * Configuration file we use. One (big) configuration is used | ||
41 | * for the various components for this test. | ||
42 | */ | ||
43 | #define CONFIG_FILE "bank_twisted.conf" | ||
44 | |||
45 | /** | ||
46 | * True when the test runs against Fakebank. | ||
47 | */ | ||
48 | static int WITH_FAKEBANK; | ||
49 | |||
50 | /** | ||
51 | * (real) Twister URL. Used at startup time to check if it runs. | ||
52 | */ | ||
53 | static char *twister_url; | ||
54 | |||
55 | /** | ||
56 | * URL of the twister where all the connections to the | ||
57 | * bank that have to be proxied should be addressed to. | ||
58 | */ | ||
59 | #define TWISTED_BANK_URL twister_url | ||
60 | |||
61 | /** | ||
62 | * URL of the bank. | ||
63 | */ | ||
64 | static char *bank_url; | ||
65 | |||
66 | /** | ||
67 | * Twister process. | ||
68 | */ | ||
69 | static struct GNUNET_OS_Process *twisterd; | ||
70 | |||
71 | /** | ||
72 | * Python bank process handle. | ||
73 | */ | ||
74 | static struct GNUNET_OS_Process *bankd; | ||
75 | |||
76 | /** | ||
77 | * Main function that will tell | ||
78 | * the interpreter what commands to run. | ||
79 | * | ||
80 | * @param cls closure | ||
81 | */ | ||
82 | static void | ||
83 | run (void *cls, | ||
84 | struct TALER_TESTING_Interpreter *is) | ||
85 | { | ||
86 | |||
87 | struct TALER_TESTING_Command commands[] = { | ||
88 | |||
89 | /** | ||
90 | * Can't use the "wait service" CMD here because the | ||
91 | * fakebank runs inside the same process of the test. | ||
92 | */ | ||
93 | TALER_TESTING_cmd_wait_service ("wait-service", | ||
94 | TWISTED_BANK_URL), | ||
95 | |||
96 | TALER_TESTING_cmd_bank_history ("history-0", | ||
97 | TWISTED_BANK_URL, | ||
98 | EXCHANGE_ACCOUNT_NUMBER, | ||
99 | TALER_BANK_DIRECTION_BOTH, | ||
100 | GNUNET_NO, | ||
101 | NULL, | ||
102 | 5), | ||
103 | TALER_TESTING_cmd_end () | ||
104 | }; | ||
105 | |||
106 | if (GNUNET_YES == WITH_FAKEBANK) | ||
107 | TALER_TESTING_run_with_fakebank (is, | ||
108 | commands, | ||
109 | bank_url); | ||
110 | else | ||
111 | TALER_TESTING_run (is, | ||
112 | commands); | ||
113 | } | ||
114 | |||
115 | |||
116 | /** | ||
117 | * Kill, wait, and destroy convenience function. | ||
118 | * | ||
119 | * @param process process to purge. | ||
120 | */ | ||
121 | static void | ||
122 | purge_process (struct GNUNET_OS_Process *process) | ||
123 | { | ||
124 | GNUNET_OS_process_kill (process, SIGINT); | ||
125 | GNUNET_OS_process_wait (process); | ||
126 | GNUNET_OS_process_destroy (process); | ||
127 | } | ||
128 | |||
129 | |||
130 | int | ||
131 | main (int argc, | ||
132 | char *const *argv) | ||
133 | { | ||
134 | unsigned int ret; | ||
135 | |||
136 | /* These environment variables get in the way... */ | ||
137 | unsetenv ("XDG_DATA_HOME"); | ||
138 | unsetenv ("XDG_CONFIG_HOME"); | ||
139 | |||
140 | GNUNET_log_setup ("test-bank-api-with-(fake)bank-twisted", | ||
141 | "DEBUG", | ||
142 | NULL); | ||
143 | |||
144 | if (NULL == (twister_url = TALER_TESTING_prepare_twister | ||
145 | (CONFIG_FILE))) | ||
146 | { | ||
147 | GNUNET_break (0); | ||
148 | return 77; | ||
149 | } | ||
150 | if (NULL == (twisterd = TALER_TESTING_run_twister (CONFIG_FILE))) | ||
151 | { | ||
152 | GNUNET_break (0); | ||
153 | GNUNET_free (twister_url); | ||
154 | return 77; | ||
155 | } | ||
156 | |||
157 | WITH_FAKEBANK = TALER_TESTING_has_in_name (argv[0], | ||
158 | "_with_fakebank"); | ||
159 | |||
160 | if (GNUNET_YES == WITH_FAKEBANK) | ||
161 | { | ||
162 | TALER_LOG_DEBUG ("Running against the Fakebank.\n"); | ||
163 | if (NULL == (bank_url = TALER_TESTING_prepare_fakebank | ||
164 | (CONFIG_FILE, | ||
165 | "account-1"))) | ||
166 | { | ||
167 | GNUNET_break (0); | ||
168 | GNUNET_free (twister_url); | ||
169 | return 77; | ||
170 | } | ||
171 | } | ||
172 | else | ||
173 | { | ||
174 | TALER_LOG_DEBUG ("Running against the Pybank.\n"); | ||
175 | if (NULL == (bank_url = TALER_TESTING_prepare_bank | ||
176 | (CONFIG_FILE))) | ||
177 | { | ||
178 | GNUNET_break (0); | ||
179 | GNUNET_free (twister_url); | ||
180 | return 77; | ||
181 | } | ||
182 | |||
183 | if (NULL == (bankd = TALER_TESTING_run_bank | ||
184 | (CONFIG_FILE, | ||
185 | bank_url))) | ||
186 | { | ||
187 | GNUNET_break (0); | ||
188 | GNUNET_free (twister_url); | ||
189 | GNUNET_free (bank_url); | ||
190 | return 77; | ||
191 | } | ||
192 | } | ||
193 | |||
194 | ret = TALER_TESTING_setup (&run, | ||
195 | NULL, | ||
196 | CONFIG_FILE, | ||
197 | NULL, | ||
198 | GNUNET_NO); | ||
199 | purge_process (twisterd); | ||
200 | |||
201 | if (GNUNET_NO == WITH_FAKEBANK) | ||
202 | { | ||
203 | GNUNET_OS_process_kill (bankd, | ||
204 | SIGKILL); | ||
205 | GNUNET_OS_process_wait (bankd); | ||
206 | GNUNET_OS_process_destroy (bankd); | ||
207 | GNUNET_free (bank_url); | ||
208 | } | ||
209 | |||
210 | GNUNET_free (twister_url); | ||
211 | GNUNET_free (bank_url); | ||
212 | |||
213 | if (GNUNET_OK == ret) | ||
214 | return 0; | ||
215 | |||
216 | return 1; | ||
217 | } | ||
218 | |||
219 | /* end of test_bank_api_twisted.c */ | ||