From 17bf5e3ac2de2b9b36f7e36daa11578406435938 Mon Sep 17 00:00:00 2001 From: Marcello Stanisci Date: Thu, 28 Apr 2016 16:03:22 +0200 Subject: testing store_payment() and check_payment() --- src/backenddb/Makefile.am | 4 ++- src/backenddb/test_merchantdb.c | 60 ++++++++++++++++++++++++++++------------- 2 files changed, 45 insertions(+), 19 deletions(-) (limited to 'src/backenddb') diff --git a/src/backenddb/Makefile.am b/src/backenddb/Makefile.am index 692dd746..a1a9f54b 100644 --- a/src/backenddb/Makefile.am +++ b/src/backenddb/Makefile.am @@ -51,7 +51,9 @@ test_merchantdb_postgres_SOURCES = \ test_merchantdb.c test_merchantdb_postgres_LDFLAGS = \ - -lgnunetutil + -lgnunetutil \ + -ltalerutil \ + -ljansson test_merchantdb_postgres_LDADD = \ $(top_srcdir)/src/backenddb/libtalermerchantdb.la diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c index 2bc9b46e..02049e36 100644 --- a/src/backenddb/test_merchantdb.c +++ b/src/backenddb/test_merchantdb.c @@ -22,6 +22,7 @@ #include "platform.h" #include #include "taler_merchantdb_lib.h" +#include #define FAILIF(cond) \ do { \ @@ -30,6 +31,11 @@ goto drop; \ } while (0) +#define RND_BLK(ptr) \ + GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, ptr, sizeof (*ptr)) + +#define CURRENCY "EUR" + static int result; static struct TALER_MERCHANTDB_Plugin *plugin; @@ -42,28 +48,48 @@ static void run (void *cls) { struct GNUNET_CONFIGURATION_Handle *cfg = cls; + /* Data for 'store_payment()' */ + struct GNUNET_HashCode h_contract; + struct GNUNET_HashCode h_wire; + uint64_t transaction_id; + struct GNUNET_TIME_Absolute timestamp; + struct GNUNET_TIME_Absolute refund; + struct TALER_Amount amount_without_fee; + struct TALER_CoinSpendPublicKeyP coin_pub; + json_t *exchange_proof = NULL; - if (NULL == - (plugin = TALER_MERCHANTDB_plugin_load (cfg))) - { - result = 1; - return; - } - if (GNUNET_OK != - plugin->initialize (plugin->cls, - GNUNET_YES)) - { - result = 2; - goto drop; - } + FAILIF (NULL == (plugin = TALER_MERCHANTDB_plugin_load (cfg))); + FAILIF (GNUNET_OK != plugin->initialize (plugin->cls, GNUNET_YES)); /* Prepare data for 'store_payment()' */ - - /* Prepare data for 'check_payment()' */ + RND_BLK (&h_contract); + RND_BLK (&h_wire); + RND_BLK (&transaction_id); + timestamp = GNUNET_TIME_absolute_get(); + refund = GNUNET_TIME_absolute_get(); + GNUNET_assert (GNUNET_OK == + TALER_string_to_amount (CURRENCY ":1.000010", + &amount_without_fee)); + RND_BLK (&coin_pub); + exchange_proof = json_object (); + GNUNET_assert (0 == json_object_set (exchange_proof, "test", json_string ("backenddb test"))); + FAILIF (GNUNET_OK != plugin->store_payment (plugin->cls, + &h_contract, + &h_wire, + transaction_id, + timestamp, + refund, + &amount_without_fee, + &coin_pub, + exchange_proof)); + FAILIF (GNUNET_OK != plugin->check_payment (plugin->cls, transaction_id)); + result = 0; drop: TALER_MERCHANTDB_plugin_unload (plugin); plugin = NULL; + if (NULL != exchange_proof) + json_decref(exchange_proof); } int @@ -82,9 +108,7 @@ main (int argc, GNUNET_break (0); return -1; } - GNUNET_log_setup (argv[0], - "WARNING", - NULL); + GNUNET_log_setup (argv[0], "WARNING", NULL); plugin_name++; (void) GNUNET_asprintf (&testname, "test-merchantdb-%s", plugin_name); -- cgit v1.2.3