Line data Source code
1 : /*
2 : This file is part of TALER
3 : Copyright (C) 2018-2022 Taler Systems SA
4 :
5 : TALER is free software; you can redistribute it and/or modify it
6 : under the terms of the GNU General Public License as published by
7 : the Free Software Foundation; either version 3, or (at your
8 : 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 GNU
13 : 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/testing_api_cmd_common.c
21 : * @brief common functions for commands
22 : * @author Christian Grothoff
23 : */
24 : #include "platform.h"
25 : #include "taler_testing_lib.h"
26 :
27 :
28 : int
29 0 : TALER_TESTING_history_entry_cmp (
30 : const struct TALER_EXCHANGE_ReserveHistoryEntry *h1,
31 : const struct TALER_EXCHANGE_ReserveHistoryEntry *h2)
32 : {
33 0 : if (h1->type != h2->type)
34 0 : return 1;
35 0 : switch (h1->type)
36 : {
37 0 : case TALER_EXCHANGE_RTT_CREDIT:
38 0 : if ( (0 ==
39 0 : TALER_amount_cmp (&h1->amount,
40 0 : &h2->amount)) &&
41 0 : (0 == strcasecmp (h1->details.in_details.sender_url,
42 0 : h2->details.in_details.sender_url)) &&
43 0 : (h1->details.in_details.wire_reference ==
44 0 : h2->details.in_details.wire_reference) &&
45 0 : (GNUNET_TIME_timestamp_cmp (h1->details.in_details.timestamp,
46 : ==,
47 : h2->details.in_details.timestamp)) )
48 0 : return 0;
49 0 : return 1;
50 0 : case TALER_EXCHANGE_RTT_WITHDRAWAL:
51 0 : if ( (0 ==
52 0 : TALER_amount_cmp (&h1->amount,
53 0 : &h2->amount)) &&
54 : (0 ==
55 0 : TALER_amount_cmp (&h1->details.withdraw.fee,
56 : &h2->details.withdraw.fee)) )
57 : /* testing_api_cmd_withdraw doesn't set the out_authorization_sig,
58 : so we cannot test for it here. but if the amount matches,
59 : that should be good enough. */
60 0 : return 0;
61 0 : return 1;
62 0 : case TALER_EXCHANGE_RTT_RECOUP:
63 : /* exchange_sig, exchange_pub and timestamp are NOT available
64 : from the original recoup response, hence here NOT check(able/ed) */
65 0 : if ( (0 ==
66 0 : TALER_amount_cmp (&h1->amount,
67 0 : &h2->amount)) &&
68 : (0 ==
69 0 : GNUNET_memcmp (&h1->details.recoup_details.coin_pub,
70 : &h2->details.recoup_details.coin_pub)) )
71 0 : return 0;
72 0 : return 1;
73 0 : case TALER_EXCHANGE_RTT_CLOSE:
74 : /* testing_api_cmd_exec_closer doesn't set the
75 : receiver_account_details, exchange_sig, exchange_pub or wtid or timestamp
76 : so we cannot test for it here. but if the amount matches,
77 : that should be good enough. */
78 0 : if ( (0 ==
79 0 : TALER_amount_cmp (&h1->amount,
80 0 : &h2->amount)) &&
81 : (0 ==
82 0 : TALER_amount_cmp (&h1->details.close_details.fee,
83 : &h2->details.close_details.fee)) )
84 0 : return 0;
85 0 : return 1;
86 0 : case TALER_EXCHANGE_RTT_HISTORY:
87 0 : if ( (0 ==
88 0 : TALER_amount_cmp (&h1->amount,
89 0 : &h2->amount)) &&
90 0 : (GNUNET_TIME_timestamp_cmp (
91 : h1->details.history_details.request_timestamp,
92 : ==,
93 : h2->details.history_details.
94 0 : request_timestamp)) &&
95 : (0 ==
96 0 : GNUNET_memcmp (&h1->details.history_details.reserve_sig,
97 : &h2->details.history_details.reserve_sig)) )
98 0 : return 0;
99 0 : return 1;
100 0 : case TALER_EXCHANGE_RTT_MERGE:
101 0 : if ( (0 ==
102 0 : TALER_amount_cmp (&h1->amount,
103 0 : &h2->amount)) &&
104 : (0 ==
105 0 : TALER_amount_cmp (&h1->details.merge_details.purse_fee,
106 0 : &h2->details.merge_details.purse_fee)) &&
107 0 : (GNUNET_TIME_timestamp_cmp (h1->details.merge_details.merge_timestamp,
108 : ==,
109 : h2->details.merge_details.merge_timestamp))
110 0 : &&
111 0 : (GNUNET_TIME_timestamp_cmp (h1->details.merge_details.purse_expiration,
112 : ==,
113 : h2->details.merge_details.purse_expiration))
114 0 : &&
115 : (0 ==
116 0 : GNUNET_memcmp (&h1->details.merge_details.merge_pub,
117 0 : &h2->details.merge_details.merge_pub)) &&
118 : (0 ==
119 0 : GNUNET_memcmp (&h1->details.merge_details.h_contract_terms,
120 0 : &h2->details.merge_details.h_contract_terms)) &&
121 : (0 ==
122 0 : GNUNET_memcmp (&h1->details.merge_details.purse_pub,
123 0 : &h2->details.merge_details.purse_pub)) &&
124 : (0 ==
125 0 : GNUNET_memcmp (&h1->details.merge_details.reserve_sig,
126 0 : &h2->details.merge_details.reserve_sig)) &&
127 0 : (h1->details.merge_details.min_age ==
128 0 : h2->details.merge_details.min_age) &&
129 0 : (h1->details.merge_details.flags ==
130 0 : h2->details.merge_details.flags) )
131 0 : return 0;
132 0 : return 1;
133 : }
134 0 : GNUNET_assert (0);
135 : return 1;
136 : }
137 :
138 :
139 : enum GNUNET_GenericReturnValue
140 0 : TALER_TESTING_parse_coin_reference (
141 : const char *coin_reference,
142 : char **cref,
143 : unsigned int *idx)
144 : {
145 : const char *index;
146 : char dummy;
147 :
148 : /* We allow command references of the form "$LABEL#$INDEX" or
149 : just "$LABEL", which implies the index is 0. Figure out
150 : which one it is. */
151 0 : index = strchr (coin_reference, '#');
152 0 : if (NULL == index)
153 : {
154 0 : *idx = 0;
155 0 : *cref = GNUNET_strdup (coin_reference);
156 0 : return GNUNET_OK;
157 : }
158 0 : *cref = GNUNET_strndup (coin_reference,
159 : index - coin_reference);
160 0 : if (1 != sscanf (index + 1,
161 : "%u%c",
162 : idx,
163 : &dummy))
164 : {
165 0 : GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
166 : "Numeric index (not `%s') required after `#' in command reference of command in %s:%u\n",
167 : index,
168 : __FILE__,
169 : __LINE__);
170 0 : GNUNET_free (*cref);
171 0 : *cref = NULL;
172 0 : return GNUNET_SYSERR;
173 : }
174 0 : return GNUNET_OK;
175 : }
|