Line data Source code
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 test_merchant_api.c
21 : * @brief testcase to test exchange's HTTP API interface
22 : * @author Sree Harsha Totakura <sreeharsha@totakura.in>
23 : * @author Christian Grothoff
24 : * @author Marcello Stanisci
25 : */
26 : #include "platform.h"
27 : #include <gnunet/gnunet_time_lib.h>
28 : #include <taler/taler_util.h>
29 : #include <taler/taler_signatures.h>
30 : #include <taler/taler_exchange_service.h>
31 : #include <taler/taler_json_lib.h>
32 : #include <gnunet/gnunet_util_lib.h>
33 : #include <gnunet/gnunet_testing_lib.h>
34 : #include <microhttpd.h>
35 : #include <taler/taler_bank_service.h>
36 : #include <taler/taler_fakebank_lib.h>
37 : #include <taler/taler_testing_lib.h>
38 : #include <taler/taler_error_codes.h>
39 : #include "taler_merchant_testing_lib.h"
40 :
41 :
42 : /**
43 : * The 'poll-orders-conclude-1' and other 'conclude'
44 : * commands should NOT wait for this timeout!
45 : */
46 : #define POLL_ORDER_TIMEOUT \
47 : GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
48 :
49 : /**
50 : * The 'poll-orders-conclude-1x' and other 'conclude'
51 : * commands that should (!) wait for this timeout! Hence,
52 : * here we use a short value!
53 : */
54 : #define POLL_ORDER_SHORT_TIMEOUT \
55 : GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2)
56 :
57 : /**
58 : * Configuration file we use. One (big) configuration is used
59 : * for the various components for this test.
60 : */
61 : static char *config_file;
62 :
63 : /**
64 : * Exchange base URL. Could also be taken from config.
65 : */
66 : #define EXCHANGE_URL "http://localhost:8081/"
67 :
68 : /**
69 : * Payto URI of the customer (payer).
70 : */
71 : static struct TALER_FullPayto payer_payto;
72 :
73 : /**
74 : * Payto URI of the exchange (escrow account).
75 : */
76 : static struct TALER_FullPayto exchange_payto;
77 :
78 : /**
79 : * Payto URI of the merchant (receiver).
80 : */
81 : static struct TALER_FullPayto merchant_payto;
82 :
83 : /**
84 : * Credentials for the test.
85 : */
86 : static struct TALER_TESTING_Credentials cred;
87 :
88 : /**
89 : * Merchant base URL.
90 : */
91 : static const char *merchant_url;
92 :
93 : /**
94 : * Merchant instance "i1a" base URL.
95 : */
96 : static char *merchant_url_i1a;
97 :
98 : /**
99 : * Account number of the exchange at the bank.
100 : */
101 : #define EXCHANGE_ACCOUNT_NAME "2"
102 :
103 : /**
104 : * Account number of some user.
105 : */
106 : #define USER_ACCOUNT_NAME "62"
107 :
108 : /**
109 : * Account number of some other user.
110 : */
111 : #define USER_ACCOUNT_NAME2 "63"
112 :
113 : /**
114 : * Account number used by the merchant
115 : */
116 : #define MERCHANT_ACCOUNT_NAME "3"
117 :
118 : static const char *order_1_transfers[] = {
119 : "post-transfer-1",
120 : NULL
121 : };
122 :
123 :
124 : /**
125 : * Run wire transfer of funds from some user's account to the
126 : * exchange.
127 : *
128 : * @param label label to use for the command.
129 : * @param amount amount to transfer, i.e. "EUR:1"
130 : * @param url exchange_url
131 : */
132 : static struct TALER_TESTING_Command
133 1 : cmd_transfer_to_exchange (const char *label,
134 : const char *amount)
135 : {
136 1 : return TALER_TESTING_cmd_admin_add_incoming (label,
137 : amount,
138 : &cred.ba,
139 : payer_payto);
140 : }
141 :
142 :
143 : /**
144 : * Main function that will tell the interpreter what commands to
145 : * run.
146 : *
147 : * @param cls closure
148 : */
149 : static void
150 1 : run (void *cls,
151 : struct TALER_TESTING_Interpreter *is)
152 : {
153 : struct TALER_TESTING_Command pay[] = {
154 : /**
155 : * Move money to the exchange's bank account.
156 : */
157 1 : cmd_transfer_to_exchange ("create-reserve-1",
158 : "EUR:5.01"),
159 : /**
160 : * Make a reserve exist, according to the previous transfer.
161 : */
162 1 : TALER_TESTING_cmd_exec_wirewatch ("wirewatch-1",
163 : config_file),
164 1 : TALER_TESTING_cmd_check_bank_admin_transfer ("check_bank_transfer-2",
165 : "EUR:5.01",
166 : payer_payto,
167 : exchange_payto,
168 : "create-reserve-1"),
169 1 : TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-1",
170 : "create-reserve-1",
171 : "EUR:5",
172 : 0,
173 : MHD_HTTP_OK),
174 : /**
175 : * Check the reserve is depleted.
176 : */
177 1 : TALER_TESTING_cmd_status ("withdraw-status-1",
178 : "create-reserve-1",
179 : "EUR:0",
180 : MHD_HTTP_OK),
181 1 : TALER_TESTING_cmd_merchant_post_orders2 ("create-proposal-1",
182 1 : cred.cfg,
183 : merchant_url,
184 : MHD_HTTP_OK,
185 : "1",
186 1 : GNUNET_TIME_UNIT_ZERO_TS, /* refund deadline */
187 1 : GNUNET_TIME_UNIT_FOREVER_TS, /* pay deadline */
188 : true, /* use claim token */
189 : "EUR:5.0",
190 : "x-taler-bank",
191 : "",
192 : "",
193 : NULL),
194 1 : TALER_TESTING_cmd_merchant_claim_order ("reclaim-1",
195 : merchant_url,
196 : MHD_HTTP_OK,
197 : "create-proposal-1",
198 : NULL),
199 1 : TALER_TESTING_cmd_wallet_get_order ("get-order-wallet-1",
200 : merchant_url,
201 : "create-proposal-1",
202 : false,
203 : false,
204 : false,
205 : MHD_HTTP_PAYMENT_REQUIRED),
206 1 : TALER_TESTING_cmd_merchant_get_order ("get-order-merchant-1",
207 : merchant_url,
208 : "create-proposal-1",
209 : TALER_MERCHANT_OSC_CLAIMED,
210 : false,
211 : MHD_HTTP_OK,
212 : NULL),
213 1 : TALER_TESTING_cmd_merchant_pay_order ("deposit-simple",
214 : merchant_url,
215 : MHD_HTTP_OK,
216 : "create-proposal-1",
217 : "withdraw-coin-1",
218 : "EUR:5",
219 : "EUR:4.99",
220 : "session-0"),
221 1 : TALER_TESTING_cmd_merchant_get_order ("get-order-merchant-1-2a",
222 : merchant_url,
223 : "create-proposal-1",
224 : TALER_MERCHANT_OSC_PAID,
225 : false,
226 : MHD_HTTP_OK,
227 : NULL),
228 1 : TALER_TESTING_cmd_sleep (
229 : "Wait for wire transfer deadline",
230 : 3),
231 1 : TALER_TESTING_cmd_exec_aggregator ("run-aggregator",
232 : config_file),
233 1 : TALER_TESTING_cmd_exec_transfer ("run-transfer",
234 : config_file),
235 1 : TALER_TESTING_cmd_check_bank_transfer ("check_bank_transfer-498c",
236 : EXCHANGE_URL,
237 : "EUR:4.98",
238 : exchange_payto,
239 : merchant_payto),
240 : // FIXME: replace by taler-merchant-wirewatch!
241 1 : TALER_TESTING_cmd_merchant_post_transfer ("post-transfer-1",
242 : &cred.ba,
243 : merchant_payto,
244 : merchant_url,
245 : "EUR:4.98",
246 : MHD_HTTP_NO_CONTENT,
247 : "deposit-simple",
248 : NULL),
249 1 : TALER_TESTING_cmd_depositcheck ("run-depositcheck",
250 : config_file),
251 1 : TALER_TESTING_cmd_run_tme ("run taler-merchant-reconciliation-1",
252 : config_file),
253 1 : TALER_TESTING_cmd_merchant_get_order2 ("get-order-merchant-1-2b",
254 : merchant_url,
255 : "create-proposal-1",
256 : // FIXME: we won't want paid, we want settled!
257 : TALER_MERCHANT_OSC_PAID,
258 : true, /* wired */
259 : order_1_transfers, /* "post-transfer-1" */
260 : false, /* refunded */
261 : NULL,
262 : NULL,
263 : MHD_HTTP_OK),
264 1 : TALER_TESTING_cmd_check_bank_empty ("check_bank_empty-2"),
265 1 : TALER_TESTING_cmd_end ()
266 : };
267 :
268 : struct TALER_TESTING_Command commands[] = {
269 : /* general setup */
270 1 : TALER_TESTING_cmd_run_fakebank (
271 : "run-fakebank",
272 1 : cred.cfg,
273 : "exchange-account-exchange"),
274 1 : TALER_TESTING_cmd_system_start (
275 : "start-taler",
276 : config_file,
277 : "-em",
278 : "-u", "exchange-account-exchange",
279 : "-r", "merchant-exchange-test",
280 : NULL),
281 1 : TALER_TESTING_cmd_get_exchange (
282 : "get-exchange",
283 1 : cred.cfg,
284 : NULL,
285 : true,
286 : true),
287 1 : TALER_TESTING_cmd_config (
288 : "config",
289 : merchant_url,
290 : MHD_HTTP_OK),
291 1 : TALER_TESTING_cmd_merchant_get_instances (
292 : "instances-empty",
293 : merchant_url,
294 : MHD_HTTP_OK,
295 : NULL),
296 1 : TALER_TESTING_cmd_merchant_post_instances (
297 : "instance-create-default-setup",
298 : merchant_url,
299 : "admin",
300 : MHD_HTTP_NO_CONTENT),
301 : // FIXME: setup full account for taler-merchant-wirewatch
302 1 : TALER_TESTING_cmd_merchant_post_account (
303 : "instance-create-default-account",
304 : merchant_url,
305 : merchant_payto,
306 : NULL, NULL,
307 : MHD_HTTP_OK),
308 1 : TALER_TESTING_cmd_merchant_post_instances (
309 : "instance-create-i1",
310 : merchant_url,
311 : "i1",
312 : MHD_HTTP_NO_CONTENT),
313 1 : TALER_TESTING_cmd_batch ("pay",
314 : pay),
315 : /**
316 : * End the suite.
317 : */
318 1 : TALER_TESTING_cmd_end ()
319 : };
320 :
321 1 : TALER_TESTING_run (is,
322 : commands);
323 1 : }
324 :
325 :
326 : int
327 1 : main (int argc,
328 : char *const *argv)
329 : {
330 : {
331 : char *cipher;
332 :
333 1 : cipher = GNUNET_STRINGS_get_suffix_from_binary_name (argv[0]);
334 1 : GNUNET_assert (NULL != cipher);
335 1 : GNUNET_asprintf (&config_file,
336 : "test_merchant_api-%s.conf",
337 : cipher);
338 1 : GNUNET_free (cipher);
339 : }
340 1 : payer_payto.full_payto =
341 : (char *) "payto://x-taler-bank/localhost/" USER_ACCOUNT_NAME
342 : "?receiver-name=" USER_ACCOUNT_NAME;
343 1 : exchange_payto.full_payto =
344 : (char *) "payto://x-taler-bank/localhost/" EXCHANGE_ACCOUNT_NAME
345 : "?receiver-name="
346 : EXCHANGE_ACCOUNT_NAME;
347 1 : merchant_payto.full_payto =
348 : (char *) "payto://x-taler-bank/localhost/" MERCHANT_ACCOUNT_NAME
349 : "?receiver-name=" MERCHANT_ACCOUNT_NAME;
350 1 : merchant_url = "http://localhost:8080/";
351 1 : GNUNET_asprintf (&merchant_url_i1a,
352 : "%sinstances/i1a/",
353 : merchant_url);
354 1 : return TALER_TESTING_main (argv,
355 : "INFO",
356 : config_file,
357 : "exchange-account-exchange",
358 : TALER_TESTING_BS_FAKEBANK,
359 : &cred,
360 : &run,
361 : NULL);
362 : }
363 :
364 :
365 : /* end of test_merchant_api.c */
|