2016-05-02 08:46:17 +02:00
|
|
|
/*
|
|
|
|
This file is part of TALER
|
2017-03-02 06:26:12 +01:00
|
|
|
Copyright (C) 2016, 2017 GNUnet e.V.
|
2016-05-02 08:46:17 +02:00
|
|
|
|
|
|
|
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
|
2016-07-07 17:55:25 +02:00
|
|
|
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
2016-05-02 08:46:17 +02:00
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @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.
|
|
|
|
*/
|
2016-05-03 06:15:09 +02:00
|
|
|
TBI_OC_ADMIN_ADD_INCOMING,
|
|
|
|
|
2017-05-04 23:52:54 +02:00
|
|
|
/**
|
|
|
|
* Request wire transfer history.
|
|
|
|
*/
|
|
|
|
TBI_OC_HISTORY,
|
|
|
|
|
2016-05-03 06:15:09 +02:00
|
|
|
/**
|
2016-05-04 05:38:29 +02:00
|
|
|
* Expect that we have received the specified transfer at fakebank.
|
2016-05-03 06:15:09 +02:00
|
|
|
*/
|
2016-05-04 05:38:29 +02:00
|
|
|
TBI_OC_EXPECT_TRANSFER,
|
2016-05-03 06:15:09 +02:00
|
|
|
|
|
|
|
/**
|
2016-05-04 05:38:29 +02:00
|
|
|
* Expect that we have exhaustively gone over all transfers at fakebank.
|
2016-05-03 06:15:09 +02:00
|
|
|
*/
|
2017-12-06 19:24:00 +01:00
|
|
|
TBI_OC_EXPECT_TRANSFERS_EMPTY,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reject incoming transfer.
|
|
|
|
*/
|
|
|
|
TBI_OC_REJECT
|
2016-05-02 08:46:17 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
2017-03-02 06:26:12 +01:00
|
|
|
/**
|
|
|
|
* Exchange base URL to use.
|
|
|
|
*/
|
|
|
|
const char *exchange_base_url;
|
|
|
|
|
2016-05-02 08:46:17 +02:00
|
|
|
/**
|
2017-12-06 19:24:00 +01:00
|
|
|
* Wire transfer subject to use.
|
2016-05-02 08:46:17 +02:00
|
|
|
*/
|
2017-12-06 19:24:00 +01:00
|
|
|
const char *subject;
|
2016-05-02 08:46:17 +02:00
|
|
|
|
2016-05-03 06:15:09 +02:00
|
|
|
/**
|
|
|
|
* Which response code do we expect for this command?
|
|
|
|
*/
|
|
|
|
unsigned int expected_response_code;
|
|
|
|
|
2016-05-02 08:46:17 +02:00
|
|
|
/**
|
|
|
|
* Set to the API's handle during the operation.
|
|
|
|
*/
|
|
|
|
struct TALER_BANK_AdminAddIncomingHandle *aih;
|
|
|
|
|
2017-05-07 21:11:56 +02:00
|
|
|
/**
|
|
|
|
* The serial ID for this record, as returned by the bank.
|
|
|
|
*/
|
|
|
|
uint64_t serial_id;
|
|
|
|
|
2016-05-02 08:46:17 +02:00
|
|
|
} admin_add_incoming;
|
|
|
|
|
2017-05-04 23:52:54 +02:00
|
|
|
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;
|
|
|
|
|
|
|
|
/**
|
2017-05-07 21:11:56 +02:00
|
|
|
* At which serial ID do we start? References the respective @e
|
|
|
|
* admin_add_incoming command. Use NULL for the extremes.
|
2017-05-04 23:52:54 +02:00
|
|
|
*/
|
2017-05-07 21:11:56 +02:00
|
|
|
const char *start_row_ref;
|
2017-05-04 23:52:54 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
2017-05-07 21:11:56 +02:00
|
|
|
/**
|
|
|
|
* How many results did we actually get?
|
|
|
|
*/
|
|
|
|
uint64_t results_obtained;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set to #GNUNET_YES if we encountered a problem.
|
|
|
|
*/
|
|
|
|
int failed;
|
|
|
|
|
2017-05-04 23:52:54 +02:00
|
|
|
} history;
|
|
|
|
|
2016-05-03 06:15:09 +02:00
|
|
|
/**
|
2016-05-04 05:38:29 +02:00
|
|
|
* If @e opcode is #TBI_OC_EXPECT_TRANSFER, this
|
|
|
|
* specifies which transfer we expected.
|
2016-05-03 06:15:09 +02:00
|
|
|
*/
|
|
|
|
struct {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Label of the command of an /admin/add/incoming
|
|
|
|
* request that we should check was executed.
|
|
|
|
*/
|
|
|
|
const char *cmd_ref;
|
|
|
|
|
2016-05-04 05:38:29 +02:00
|
|
|
} expect_transfer;
|
2016-05-03 06:15:09 +02:00
|
|
|
|
2017-12-06 19:24:00 +01:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
2016-05-02 08:46:17 +02:00
|
|
|
} details;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Entry point to the interpeter.
|
|
|
|
*
|
|
|
|
* @param resultp where to store the final result
|
2016-05-02 09:06:16 +02:00
|
|
|
* @param run_bank #GNUNET_YES to run the fakebank
|
2016-05-02 08:46:17 +02:00
|
|
|
* @param commands list of commands to run
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
TBI_run_interpreter (int *resultp,
|
2016-05-02 09:06:16 +02:00
|
|
|
int run_bank,
|
2016-05-02 08:46:17 +02:00
|
|
|
struct TBI_Command *commands);
|
|
|
|
|
|
|
|
#endif
|