aboutsummaryrefslogtreecommitdiff
path: root/src/wire-plugins/test_wire_plugin_legacy_taler-bank.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/wire-plugins/test_wire_plugin_legacy_taler-bank.c')
-rw-r--r--src/wire-plugins/test_wire_plugin_legacy_taler-bank.c373
1 files changed, 0 insertions, 373 deletions
diff --git a/src/wire-plugins/test_wire_plugin_legacy_taler-bank.c b/src/wire-plugins/test_wire_plugin_legacy_taler-bank.c
deleted file mode 100644
index 690666f87..000000000
--- a/src/wire-plugins/test_wire_plugin_legacy_taler-bank.c
+++ /dev/null
@@ -1,373 +0,0 @@
1/*
2 This file is part of TALER
3 (C) 2015-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,
17 see <http://www.gnu.org/licenses/>
18*/
19
20/**
21 * @file wire/test_wire_plugin_legacy_taler-bank.c
22 * @brief Tests legacy history-range API against the Fakebank.
23 * Version for the real Python bank forthcoming.
24 *
25 * @author Christian Grothoff
26 * @author Marcello Stanisci
27 */
28#include "platform.h"
29#include "taler_util.h"
30#include "taler_wire_lib.h"
31#include "taler_wire_plugin.h"
32#include "taler_fakebank_lib.h"
33#include <gnunet/gnunet_json_lib.h>
34
35/**
36 * How many wire transfers this test should accomplish, before
37 * delving into actual checks.
38 */
39#define NTRANSACTIONS 5
40
41/**
42 * Destination account to use.
43 */
44static const char *dest_account = "payto://x-taler-bank/localhost:8088/42";
45
46/**
47 * Origin account, section in the configuration file.
48 */
49static const char *my_account = "account-test";
50
51/**
52 * Our configuration.
53 */
54static struct GNUNET_CONFIGURATION_Handle *cfg;
55
56/**
57 * Set to #GNUNET_SYSERR if the test failed.
58 */
59static int global_ret;
60
61/**
62 * The 'test' plugin that we are using for the test.
63 */
64static struct TALER_WIRE_Plugin *plugin;
65
66/**
67 * Active preparation handle, or NULL if not active.
68 */
69static struct TALER_WIRE_PrepareHandle *ph;
70
71/**
72 * Active execution handle, or NULL if not active.
73 */
74static struct TALER_WIRE_ExecuteHandle *eh;
75
76/**
77 * Handle to the bank.
78 */
79static struct TALER_FAKEBANK_Handle *fb;
80
81/**
82 * Handle to the history-range request (the "legacy" bank API).
83 */
84static struct TALER_WIRE_HistoryHandle *hhr;
85
86/**
87 * Wire transfer identifier we are using.
88 */
89static struct TALER_WireTransferIdentifierRawP wtid;
90
91/**
92 * Number of total transaction to make it happen in the test.
93 */
94static int Ntransactions = NTRANSACTIONS;
95static int ntransactions = NTRANSACTIONS;
96static int ztransactions = 0;
97
98/**
99 * Timestamp used as the oldest extreme in the query range.
100 */
101static struct GNUNET_TIME_Absolute first_timestamp;
102
103/**
104 * Function called on shutdown (regular, error or CTRL-C).
105 *
106 * @param cls NULL
107 */
108static void
109do_shutdown (void *cls)
110{
111 TALER_FAKEBANK_stop (fb);
112 fb = NULL;
113 if (NULL != eh)
114 {
115 plugin->execute_wire_transfer_cancel (plugin->cls,
116 eh);
117 eh = NULL;
118 }
119 if (NULL != ph)
120 {
121 plugin->prepare_wire_transfer_cancel (plugin->cls,
122 ph);
123 ph = NULL;
124 }
125
126 if (NULL != hhr)
127 {
128 plugin->get_history_cancel (plugin->cls,
129 hhr);
130 hhr = NULL;
131 }
132
133 TALER_WIRE_plugin_unload (plugin);
134}
135
136
137/**
138 * Callbacks of this type are used to serve the result of asking
139 * the bank for the transaction history.
140 *
141 * @param cls closure
142 * @param ec taler status code
143 * @param dir direction of the transfer
144 * @param row_off identification of the position at
145 * which we are querying
146 * @param row_off_size number of bytes in @a row_off
147 * @param details details about the wire transfer
148 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to
149 * abort iteration
150 */
151static int
152history_result_cb
153 (void *cls,
154 enum TALER_ErrorCode ec,
155 enum TALER_BANK_Direction dir,
156 const void *row_off,
157 size_t row_off_size,
158 const struct TALER_WIRE_TransferDetails *details)
159{
160 int *expected_number = cls;
161 static int accumulator = 0;
162
163 if ( (TALER_BANK_DIRECTION_NONE == dir) &&
164 (GNUNET_OK == global_ret) )
165 {
166 /* End-of-list, check all the transactions got accounted
167 * into the history. */
168
169 if (*expected_number != accumulator)
170 {
171 GNUNET_break (0);
172 TALER_LOG_ERROR
173 ("Unexpected # of transactions: %d, %d were expected.\n",
174 accumulator,
175 *expected_number);
176 global_ret = GNUNET_NO;
177 }
178
179 if (ztransactions != *expected_number)
180 {
181 /* Call the second test, under the assumption that after
182 * running the test with ztransactions expected entries,
183 * we shut the test down. */
184
185 accumulator = 0;
186 GNUNET_assert
187 (NULL != (hhr = plugin->get_history_range
188 (plugin->cls,
189 my_account,
190 TALER_BANK_DIRECTION_BOTH,
191 GNUNET_TIME_UNIT_ZERO_ABS,
192 GNUNET_TIME_absolute_subtract
193 (first_timestamp,
194 GNUNET_TIME_UNIT_HOURS),
195 &history_result_cb,
196
197 /**
198 * Zero results are expected from 1970 up to 1 hour ago.
199 */
200 &ztransactions)));
201
202 return GNUNET_OK;
203 }
204
205 GNUNET_SCHEDULER_shutdown ();
206 return GNUNET_OK;
207 }
208
209 accumulator++;
210 return GNUNET_OK;
211}
212
213
214/**
215 * Function called with the result from the execute step.
216 *
217 * @param cls closure
218 * @param success #GNUNET_OK on success,
219 * #GNUNET_SYSERR on failure
220 * @param row_id ID of the fresh transaction,
221 * in _network_ byte order.
222 * @param emsg NULL on success, otherwise an error message
223 */
224static void
225confirmation_cb (void *cls,
226 int success,
227 const void *row_id,
228 size_t row_id_size,
229 const char *emsg);
230
231/**
232 * Callback with prepared transaction.
233 *
234 * @param cls closure
235 * @param buf transaction data to persist, NULL on error
236 * @param buf_size number of bytes in @a buf, 0 on error
237 */
238static void
239prepare_cb (void *cls,
240 const char *buf,
241 size_t buf_size)
242{
243 ph = NULL;
244 if (NULL == buf)
245 {
246 GNUNET_break (0);
247 global_ret = GNUNET_SYSERR;
248 GNUNET_SCHEDULER_shutdown ();
249 return;
250 }
251 plugin->execute_wire_transfer (plugin->cls,
252 buf,
253 buf_size,
254 &confirmation_cb,
255 NULL);
256}
257
258/**
259 * Function called with the result from the execute step.
260 *
261 * @param cls closure
262 * @param success #GNUNET_OK on success,
263 * #GNUNET_SYSERR on failure
264 * @param row_id ID of the fresh transaction,
265 * in _network_ byte order.
266 * @param emsg NULL on success, otherwise an error message
267 */
268static void
269confirmation_cb (void *cls,
270 int success,
271 const void *row_id,
272 size_t row_id_size,
273 const char *emsg)
274{
275 struct TALER_Amount amount;
276
277 eh = NULL;
278 if (GNUNET_OK != success)
279 {
280 GNUNET_break (0);
281 global_ret = GNUNET_SYSERR;
282 GNUNET_SCHEDULER_shutdown ();
283 return;
284 }
285
286 if (0 >= --Ntransactions)
287 {
288 GNUNET_assert
289 (NULL != (hhr = plugin->get_history_range
290 (plugin->cls,
291 my_account,
292 TALER_BANK_DIRECTION_BOTH,
293 GNUNET_TIME_UNIT_ZERO_ABS,
294 GNUNET_TIME_UNIT_FOREVER_ABS,
295 &history_result_cb,
296 &ntransactions)));
297 return;
298 }
299
300 /* Issue a new wire transfer! */
301 GNUNET_assert
302 (GNUNET_OK == TALER_string_to_amount ("KUDOS:5.01",
303 &amount));
304
305 ph = plugin->prepare_wire_transfer (plugin->cls,
306 my_account,
307 dest_account,
308 &amount,
309 "https://exchange.net/",
310 &wtid,
311 &prepare_cb,
312 NULL);
313}
314
315
316/**
317 * Run the test.
318 *
319 * @param cls NULL
320 */
321static void
322run (void *cls)
323{
324 struct TALER_Amount amount;
325 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
326 NULL);
327
328 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
329 &wtid,
330 sizeof (wtid));
331 GNUNET_assert
332 (GNUNET_OK == TALER_string_to_amount ("KUDOS:5.01",
333 &amount));
334 fb = TALER_FAKEBANK_start (8088);
335
336
337 first_timestamp = GNUNET_TIME_absolute_get ();
338 ph = plugin->prepare_wire_transfer (plugin->cls,
339 my_account,
340 dest_account,
341 &amount,
342 "https://exchange.net/",
343 &wtid,
344 &prepare_cb,
345 NULL);
346}
347
348
349int
350main (int argc,
351 const char *const argv[])
352{
353 GNUNET_log_setup ("test-wire-plugin-legacy-test",
354 "WARNING",
355 NULL);
356 cfg = GNUNET_CONFIGURATION_create ();
357 GNUNET_assert
358 (GNUNET_OK == GNUNET_CONFIGURATION_load
359 (cfg,
360 "test_wire_plugin_legacy_taler-bank.conf"));
361 global_ret = GNUNET_OK;
362 plugin = TALER_WIRE_plugin_load (cfg,
363 "taler_bank");
364 GNUNET_assert (NULL != plugin);
365 GNUNET_SCHEDULER_run (&run,
366 NULL);
367 GNUNET_CONFIGURATION_destroy (cfg);
368 if (GNUNET_OK != global_ret)
369 return 1;
370 return 0;
371}
372
373/* end of test_wire_plugin_legacy_taler-bank.c */