summaryrefslogtreecommitdiff
path: root/src/bank-lib/test_bank_interpreter.h
blob: ae323055d22eac1440ff96f1b91d25f4e8be4865 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/*
  This file is part of TALER
  Copyright (C) 2016, 2017 GNUnet e.V.

  TALER is free software; you can redistribute it and/or modify it under the
  terms of the GNU General Public License as published by the Free Software
  Foundation; either version 3, or (at your option) any later version.

  TALER is distributed in the hope that it will be useful, but WITHOUT ANY
  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

  You should have received a copy of the GNU General Public License along with
  TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
*/
/**
 * @file bank/test_bank_interpreter.h
 * @brief interpreter for tests of the bank's HTTP API interface
 * @author Christian Grothoff
 */
#ifndef TEST_BANK_INTERPRETER_H
#define TEST_BANK_INTERPRETER_H

#include "taler_util.h"
#include "taler_signatures.h"
#include "taler_bank_service.h"
#include <gnunet/gnunet_util_lib.h>
#include <gnunet/gnunet_curl_lib.h>
#include <microhttpd.h>


/**
 * Opcodes for the interpreter.
 */
enum TBI_OpCode
{
  /**
   * Termination code, stops the interpreter loop (with success).
   */
  TBI_OC_END = 0,

  /**
   * Add funds to a reserve by (faking) incoming wire transfer.
   */
  TBI_OC_ADMIN_ADD_INCOMING,

  /**
   * Request wire transfer history.
   */
  TBI_OC_HISTORY,

  /**
   * Expect that we have received the specified transfer at fakebank.
   */
  TBI_OC_EXPECT_TRANSFER,

  /**
   * Expect that we have exhaustively gone over all transfers at fakebank.
   */
  TBI_OC_EXPECT_TRANSFERS_EMPTY,

  /**
   * Reject incoming transfer.
   */
  TBI_OC_REJECT

};


/**
 * Details for a bank operation to execute.
 */
struct TBI_Command
{
  /**
   * Opcode of the command.
   */
  enum TBI_OpCode oc;

  /**
   * Label for the command, can be NULL.
   */
  const char *label;

  /**
   * Details about the command.
   */
  union
  {

    /**
     * Information for a #TBI_OC_ADMIN_ADD_INCOMING command.
     */
    struct
    {

      /**
       * String describing the amount to add to the reserve.
       */
      const char *amount;

      /**
       * Credited account number.
       */
      uint64_t credit_account_no;

      /**
       * Debited account number.
       */
      uint64_t debit_account_no;

      /**
       * Exchange base URL to use.
       */
      const char *exchange_base_url;

      /**
       * Wire transfer subject to use.
       */
      const char *subject;

      /**
       * Which response code do we expect for this command?
       */
      unsigned int expected_response_code;

      /**
       * Set to the API's handle during the operation.
       */
      struct TALER_BANK_AdminAddIncomingHandle *aih;

      /**
       * The serial ID for this record, as returned by the bank.
       */
      uint64_t row_id;

    } admin_add_incoming;

    struct {

      /**
       * For which account do we query the history.
       */
      uint64_t account_number;

      /**
       * Which types of transactions should be listed?
       */
      enum TALER_BANK_Direction direction;

      /**
       * At which serial ID do we start? References the respective @e
       * admin_add_incoming command.  Use NULL for the extremes.
       */
      const char *start_row_ref;

      /**
       * How many results should be returned (if available)?
       */
      int64_t num_results;

      /**
       * Set to the API's handle during the operation.
       */
      struct TALER_BANK_HistoryHandle *hh;

      /**
       * How many results did we actually get?
       */
      uint64_t results_obtained;

      /**
       * Set to #GNUNET_YES if we encountered a problem.
       */
      int failed;

      /**
       * if true, the history elements will be asked in
       * chronological order.
       */
      unsigned int ascending;

    } history;

    /**
     * If @e opcode is #TBI_OC_EXPECT_TRANSFER, this
     * specifies which transfer we expected.
     */
    struct {

      /**
       * Label of the command of an /admin/add/incoming
       * request that we should check was executed.
       */
      const char *cmd_ref;

    } expect_transfer;

    /**
     * Execute /reject operation.
     */
    struct {

      /**
       * Reference to the matching transfer that is now to be rejected.
       */
      const char *cmd_ref;

      /**
       * Set to the API's handle during the operation.
       */
      struct TALER_BANK_RejectHandle *rh;

    } reject;

  } details;

};


/**
 * Entry point to the interpeter.
 *
 * @param resultp where to store the final result
 * @param run_bank #GNUNET_YES to run the fakebank
 * @param commands list of commands to run
 */
void
TBI_run_interpreter (int *resultp,
                     int run_bank,
                     struct TBI_Command *commands);

#endif