aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorMarcello Stanisci <stanisci.m@gmail.com>2018-02-22 14:51:12 +0100
committerMarcello Stanisci <stanisci.m@gmail.com>2018-02-26 14:12:46 +0100
commitb593d416d6e788b2053c2f5ebb634e0bb39fe560 (patch)
treecf08a83fb1922c32d4a0e4ce161ae3ff20023a69 /src/include
parent8d5cc9f550da58610ad220d72f21d930c47ad0a8 (diff)
Bank-lib tests, using the new (libraries-based) style.
Diffstat (limited to 'src/include')
-rw-r--r--src/include/Makefile.am3
-rw-r--r--src/include/taler_testing_bank_lib.h108
-rw-r--r--src/include/taler_testing_lib.h108
3 files changed, 213 insertions, 6 deletions
diff --git a/src/include/Makefile.am b/src/include/Makefile.am
index 6583ad524..2916a812c 100644
--- a/src/include/Makefile.am
+++ b/src/include/Makefile.am
@@ -28,7 +28,8 @@ talerinclude_HEADERS = \
taler_pq_lib.h \
taler_signatures.h \
taler_wire_lib.h \
- taler_wire_plugin.h
+ taler_wire_plugin.h \
+ taler_testing_bank_lib.h
endif
diff --git a/src/include/taler_testing_bank_lib.h b/src/include/taler_testing_bank_lib.h
new file mode 100644
index 000000000..87187a733
--- /dev/null
+++ b/src/include/taler_testing_bank_lib.h
@@ -0,0 +1,108 @@
+/*
+ This file is part of TALER
+ (C) 2018 Taler Systems SA
+
+ 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 include/taler_testing_bank_lib.h
+ * @brief API for writing an interpreter to test Taler components
+ * @author Marcello Stanisci
+ */
+#ifndef TALER_TESTING_BANK_LIB_H
+#define TALER_TESTING_BANK_LIB_H
+
+#include "taler_util.h"
+#include <gnunet/gnunet_json_lib.h>
+#include "taler_json_lib.h"
+#include <microhttpd.h>
+#include "taler_bank_service.h"
+#include "taler_testing_lib.h"
+
+
+/* ******** Credentials to log in at the bank ******* */
+
+#define BANK_ACCOUNT_NUMBER 1
+#define BANK_USERNAME "Bank"
+#define BANK_PASSWORD "x"
+#define EXCHANGE_ACCOUNT_NUMBER 2
+#define EXCHANGE_USERNAME "Exchange"
+#define EXCHANGE_PASSWORD "x"
+#define USER_ACCOUNT_NUMBER 3
+#define USER_USERNAME "user3"
+#define USER_PASSWORD "pass3"
+
+
+/* ********************* Helper functions ********************* */
+
+#define BANK_FAIL() \
+ do {GNUNET_break (0); return NULL; } while (0)
+
+/**
+ * Start the (Python) bank process. Assume the port
+ * is available and the database is clean. Use the "prepare
+ * bank" function to do such tasks.
+ *
+ * @param config_filename configuration filename.
+ *
+ * @return the process, or NULL if the process could not
+ * be started.
+ */
+struct GNUNET_OS_Process *
+TALER_TESTING_run_bank (const char *config_filename);
+
+/**
+ * Prepare the bank execution. Check if the port is available
+ * (and reset database?).
+ *
+ * @param config_filename configuration filename.
+ *
+ * @return the base url, or NULL upon errors. Must be freed
+ * by the caller.
+ */
+char *
+TALER_TESTING_prepare_bank (const char *config_filename);
+
+
+/* ******************* Generic interpreter logic ************ */
+
+/* ************** Specific interpreter commands ************ */
+
+/**
+ * Test /history API from the bank.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_bank_history
+ (const char *label,
+ const char *bank_url,
+ uint64_t account_no,
+ enum TALER_BANK_Direction direction,
+ const char *start_row_reference,
+ unsigned int num_results);
+
+/**
+ * FIXME.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_bank_reject (const char *label,
+ const char *bank_url,
+ const char *deposit_reference);
+
+/* *** Generic trait logic for implementing traits ********* */
+
+/* ****** Specific traits supported by this component ******* */
+
+#endif
diff --git a/src/include/taler_testing_lib.h b/src/include/taler_testing_lib.h
index b4350e0c3..d06105dd1 100644
--- a/src/include/taler_testing_lib.h
+++ b/src/include/taler_testing_lib.h
@@ -27,6 +27,7 @@
#define TALER_TESTING_LIB_H
#include "taler_util.h"
+#include "taler_exchange_service.h"
#include <gnunet/gnunet_json_lib.h>
#include "taler_json_lib.h"
#include <microhttpd.h>
@@ -35,6 +36,37 @@
/* ********************* Helper functions ********************* */
/**
+ * Print failing line number and trigger shutdown. Useful
+ * quite any time after the command "run" method has been called.
+ */
+#define TALER_TESTING_FAIL(is) \
+ do \
+ {\
+ GNUNET_break (0); \
+ TALER_TESTING_interpreter_fail (is); \
+ return; \
+ } while (0)
+
+
+#define TALER_TESTING_GET_TRAIT_CREDIT_ACCOUNT(cmd,out) \
+ TALER_TESTING_get_trait_uint64 (cmd, 0, out)
+
+#define TALER_TESTING_MAKE_TRAIT_CREDIT_ACCOUNT(data) \
+ TALER_TESTING_make_trait_uint64 (0, data)
+
+#define TALER_TESTING_GET_TRAIT_DEBIT_ACCOUNT(cmd,out) \
+ TALER_TESTING_get_trait_uint64 (cmd, 1, out)
+
+#define TALER_TESTING_MAKE_TRAIT_DEBIT_ACCOUNT(data) \
+ TALER_TESTING_make_trait_uint64 (1, data)
+
+#define TALER_TESTING_GET_TRAIT_ROW_ID(cmd,out) \
+ TALER_TESTING_get_trait_uint64 (cmd, 3, out)
+
+#define TALER_TESTING_MAKE_TRAIT_ROW_ID(data) \
+ TALER_TESTING_make_trait_uint64 (3, data)
+
+/**
* Allocate and return a piece of wire-details. Mostly, it adds
* the bank_url to the JSON.
*
@@ -747,8 +779,16 @@ TALER_TESTING_cmd_check_bank_transfer
(const char *label,
const char *exchange_base_url,
const char *amount,
- unsigned int debit_account,
- unsigned int credit_account);
+ uint64_t debit_account,
+ uint64_t credit_account);
+
+/**
+ * FIXME.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_check_bank_transfer_with_ref
+ (const char *label,
+ const char *deposit_reference);
/**
* Check bank's balance is zero.
@@ -1017,6 +1057,33 @@ TALER_TESTING_make_trait_denom_sig
(unsigned int index,
const struct TALER_DenominationSignature *sig);
+
+/**
+ * @param selector associate the object with this "tag"
+ * @param i which object should be returned
+ *
+ * @return the trait, to be put in the traits array of the command
+ */
+struct TALER_TESTING_Trait
+TALER_TESTING_make_trait_uint64
+ (unsigned int index,
+ const uint64_t *i);
+
+/**
+ * Obtain a "number" value from @a cmd.
+ *
+ * @param cmd command to extract trait from
+ * @param selector which coin to pick if @a cmd has multiple on
+ * offer
+ * @param n[out] set to the number coming from @a cmd.
+ * @return #GNUNET_OK on success
+ */
+int
+TALER_TESTING_get_trait_uint64
+ (const struct TALER_TESTING_Command *cmd,
+ unsigned int index,
+ const uint64_t **n);
+
/**
* @param selector associate the object with this "tag"
* @param i which object should be returned
@@ -1225,7 +1292,7 @@ int
TALER_TESTING_get_trait_transfer_subject
(const struct TALER_TESTING_Command *cmd,
unsigned int index,
- char **transfer_subject);
+ const char **transfer_subject);
/**
@@ -1239,7 +1306,7 @@ TALER_TESTING_get_trait_transfer_subject
struct TALER_TESTING_Trait
TALER_TESTING_make_trait_transfer_subject
(unsigned int index,
- char *transfer_subject);
+ const char *transfer_subject);
/**
@@ -1369,11 +1436,42 @@ int
TALER_TESTING_get_trait_amount_obj (
const struct TALER_TESTING_Command *cmd,
unsigned int index,
- struct TALER_Amount **amount);
+ const struct TALER_Amount **amount);
struct TALER_TESTING_Trait
TALER_TESTING_make_trait_amount_obj (
unsigned int index,
const struct TALER_Amount *amount);
+
+/**
+ * Offer reference to a bank transfer which has been
+ * rejected.
+ *
+ * @param index which reference is to be picked, in case
+ * multiple are offered.
+ * @param rejected_reference the url to offer
+ * @return the trait, to be put in the traits array of the command
+ */
+struct TALER_TESTING_Trait
+TALER_TESTING_make_trait_rejected
+ (unsigned int index,
+ const char *rejected);
+
+/**
+ * Obtain the reference from a bank transfer which has
+ * been rejected.
+ *
+ * @param cmd command to extract trait from
+ * @param index which reference is to be picked, in case
+ * multiple are offered.
+ * @param rejected_reference[out] where to write the order id.
+ * @return #GNUNET_OK on success
+ */
+int
+TALER_TESTING_get_trait_rejected
+ (const struct TALER_TESTING_Command *cmd,
+ unsigned int index,
+ const char **rejected_reference);
+
#endif