diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-05-16 18:56:10 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-05-16 18:56:10 +0200 |
commit | fc48947e32670864a5fac44a73df51433f4fdee8 (patch) | |
tree | b46ee4d0d9f50de26c3ac92bf0dc5670d1302b08 /src/wire | |
parent | 5447ad86ccb134760fa826c114ce2a8e765af988 (diff) |
skeleton for the test for #4959
Diffstat (limited to 'src/wire')
-rw-r--r-- | src/wire/Makefile.am | 18 | ||||
-rw-r--r-- | src/wire/test_wire_plugin_transactions_test.c | 286 | ||||
-rw-r--r-- | src/wire/test_wire_plugin_transactions_test.conf | 15 |
3 files changed, 316 insertions, 3 deletions
diff --git a/src/wire/Makefile.am b/src/wire/Makefile.am index 7bea7c8c6..da1b8b598 100644 --- a/src/wire/Makefile.am +++ b/src/wire/Makefile.am @@ -16,7 +16,8 @@ pkgcfg_DATA = \ EXTRA_DIST = \ wire-sepa.conf \ wire-test.conf \ - test_wire_plugin.conf + test_wire_plugin.conf \ + test_wire_plugin_transactions_test.conf plugindir = $(libdir)/taler @@ -83,8 +84,8 @@ TESTS = \ check_PROGRAMS= \ test_sepa_wireformat \ - test_wire_plugin - + test_wire_plugin \ + test_wire_plugin_transactions_test test_sepa_wireformat_SOURCES = \ @@ -104,3 +105,14 @@ test_wire_plugin_LDADD = \ -ljansson \ libtalerwire.la \ $(top_builddir)/src/util/libtalerutil.la + + +test_wire_plugin_transactions_test_SOURCES = \ + test_wire_plugin_transactions_test.c +test_wire_plugin_transactions_test_LDADD = \ + -lgnunetjson \ + -lgnunetutil \ + -ljansson \ + libtalerwire.la \ + $(top_builddir)/src/bank-lib/libtalerfakebank.la \ + $(top_builddir)/src/util/libtalerutil.la diff --git a/src/wire/test_wire_plugin_transactions_test.c b/src/wire/test_wire_plugin_transactions_test.c new file mode 100644 index 000000000..3a9dc1a02 --- /dev/null +++ b/src/wire/test_wire_plugin_transactions_test.c @@ -0,0 +1,286 @@ +/* + This file is part of TALER + (C) 2015, 2016, 2017 GNUnet e.V. and Inria + + 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 wire/test_wire_plugin_transactions_test.c + * @brief Tests performing actual transactions with the TEST wire plugin against FAKEBANK + * @author Christian Grothoff + */ +#include "platform.h" +#include "taler_util.h" +#include "taler_wire_lib.h" +#include "taler_wire_plugin.h" +#include "taler_fakebank_lib.h" +#include <gnunet/gnunet_json_lib.h> +#include <jansson.h> + + +/** + * When does the test timeout? Right now, we expect this to be very + * fast. + */ +#define TIMEOUT GNUNET_TIME_UNIT_SECONDS + + +const char *json_proto += "{ \"type\":\"test\", \"bank_uri\":\"http://localhost:8088/\", \"account_number\":42 }"; + + +/** + * Private key used to sign wire details. + */ +static struct TALER_MasterPrivateKeyP priv_key; + +/** + * Public key matching #priv_key. + */ +static struct TALER_MasterPublicKeyP pub_key; + +/** + * Our configuration. + */ +static struct GNUNET_CONFIGURATION_Handle *cfg; + +/** + * Set to #GNUNET_SYSERR if the test failed. + */ +static int global_ret; + +/** + * The 'test' plugin that we are using for the test. + */ +static struct TALER_WIRE_Plugin *plugin; + +/** + * Active preparation handle, or NULL if not active. + */ +static struct TALER_WIRE_PrepareHandle *ph; + +/** + * Active execution handle, or NULL if not active. + */ +static struct TALER_WIRE_ExecuteHandle *eh; + +/** + * Handle to the bank. + */ +static struct TALER_FAKEBANK_Handle *fb; + +/** + * Handle to the history request. + */ +static struct TALER_WIRE_HistoryHandle *hh; + +/** + * Handle for the timeout task. + */ +static struct GNUNET_SCHEDULER_Task *tt; + + +/** + * Function called on shutdown (regular, error or CTRL-C). + * + * @param cls NULL + */ +static void +do_shutdown (void *cls) +{ + TALER_FAKEBANK_stop (fb); + fb = NULL; + if (NULL != eh) + { + plugin->execute_wire_transfer_cancel (plugin->cls, + eh); + eh = NULL; + } + if (NULL != ph) + { + plugin->prepare_wire_transfer_cancel (plugin->cls, + ph); + ph = NULL; + } + if (NULL != hh) + { + plugin->get_history_cancel (plugin->cls, + hh); + hh = NULL; + } + if (NULL != tt) + { + GNUNET_SCHEDULER_cancel (tt); + tt = NULL; + } +} + + +/** + * Function called on timeout. + * + * @param cls NULL + */ +static void +timeout_cb (void *cls) +{ + tt = NULL; + GNUNET_break (0); + global_ret = GNUNET_SYSERR; + GNUNET_SCHEDULER_shutdown (); +} + + +/** + * Callbacks of this type are used to serve the result of asking + * the bank for the transaction history. + * + * @param cls closure + * @param dir direction of the transfer + * @param row_off identification of the position at which we are querying + * @param row_off_size number of bytes in @a row_off + * @param details details about the wire transfer + * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration + */ +static int +history_result_cb (void *cls, + enum TALER_BANK_Direction dir, + const void *row_off, + size_t row_off_size, + const struct TALER_WIRE_TransferDetails *details) +{ + // FIXME: check result! + global_ret = GNUNET_OK; + GNUNET_SCHEDULER_shutdown (); + return GNUNET_OK; +} + + +/** + * Function called with the result from the execute step. + * + * @param cls closure + * @param success #GNUNET_OK on success, #GNUNET_SYSERR on failure + * @param serial_id unique ID of the wire transfer in the bank's records; UINT64_MAX on error + * @param emsg NULL on success, otherwise an error message + */ +static void +confirmation_cb (void *cls, + int success, + uint64_t serial_id, + const char *emsg) +{ + eh = NULL; + if (GNUNET_OK != success) + { + GNUNET_break (0); + global_ret = GNUNET_SYSERR; + GNUNET_SCHEDULER_shutdown (); + return; + } + hh = plugin->get_history (plugin->cls, + TALER_BANK_DIRECTION_BOTH, + NULL, 0, + 5, + &history_result_cb, + NULL); +} + + +/** + * Callback with prepared transaction. + * + * @param cls closure + * @param buf transaction data to persist, NULL on error + * @param buf_size number of bytes in @a buf, 0 on error + */ +static void +prepare_cb (void *cls, + const char *buf, + size_t buf_size) +{ + ph = NULL; + if (NULL == buf) + { + GNUNET_break (0); + global_ret = GNUNET_SYSERR; + GNUNET_SCHEDULER_shutdown (); + return; + } + plugin->execute_wire_transfer (plugin->cls, + buf, + buf_size, + &confirmation_cb, + NULL); +} + + +/** + * Run the test. + * + * @param cls NULL + */ +static void +run (void *cls) +{ + json_t *wire; + struct TALER_WireTransferIdentifierRawP wtid; + struct TALER_Amount amount; + + GNUNET_SCHEDULER_add_shutdown (&do_shutdown, + NULL); + tt = GNUNET_SCHEDULER_add_delayed (TIMEOUT, + &timeout_cb, + NULL); + fb = TALER_FAKEBANK_start (8088); + ph = plugin->prepare_wire_transfer (plugin->cls, + wire, + &amount, + "https://exchange.net/", + &wtid, + &prepare_cb, + NULL); +} + + +int +main (int argc, + const char *const argv[]) +{ + struct GNUNET_CRYPTO_EddsaPrivateKey *pk; + + GNUNET_log_setup ("test-wire-plugin-transactions-test", + "WARNING", + NULL); + cfg = GNUNET_CONFIGURATION_create (); + GNUNET_assert (GNUNET_OK == + GNUNET_CONFIGURATION_load (cfg, + "test_wire_plugin_transactions_test.conf")); + pk = GNUNET_CRYPTO_eddsa_key_create_from_file ("test_wire_plugin_key.priv"); + priv_key.eddsa_priv = *pk; + GNUNET_free (pk); + GNUNET_CRYPTO_eddsa_key_get_public (&priv_key.eddsa_priv, + &pub_key.eddsa_pub); + global_ret = GNUNET_OK; + plugin = TALER_WIRE_plugin_load (cfg, + "test"); + GNUNET_assert (NULL != plugin); + GNUNET_SCHEDULER_run (&run, + NULL); + TALER_WIRE_plugin_unload (plugin); + GNUNET_CONFIGURATION_destroy (cfg); + if (GNUNET_OK != global_ret) + return 1; + return 0; +} + +/* end of test_wire_plugin_transactions_test.c */ diff --git a/src/wire/test_wire_plugin_transactions_test.conf b/src/wire/test_wire_plugin_transactions_test.conf new file mode 100644 index 000000000..601b28f9a --- /dev/null +++ b/src/wire/test_wire_plugin_transactions_test.conf @@ -0,0 +1,15 @@ +# This file is in the public domain. +# +[test] +# This is the response we give out for the /wire request. It provides +# wallets with the bank information for transfers to the exchange. +TEST_RESPONSE_FILE = test_wire_plugin_test.json + +[exchange-wire-test] +# For transfers made by the exchange, we need to know +# the URI of the bank (where the /admin/add/incoming API +# is avaialble). +BANK_URI = http://localhost:8088/ + +[taler] +CURRENCY = "KUDOS" |