summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Buchanan <jonathan.russ.buchanan@gmail.com>2020-06-24 00:08:31 -0400
committerJonathan Buchanan <jonathan.russ.buchanan@gmail.com>2020-06-24 00:08:31 -0400
commitebfa7888c0cbb461cf70a8d809b1d183011713ce (patch)
treea47145f16f53387657a3ed2f056ad580cf5f6621
parent4ce3a78d0071035a66cfb889c23fe9a9d731086f (diff)
downloadmerchant-ebfa7888c0cbb461cf70a8d809b1d183011713ce.tar.gz
merchant-ebfa7888c0cbb461cf70a8d809b1d183011713ce.tar.bz2
merchant-ebfa7888c0cbb461cf70a8d809b1d183011713ce.zip
made a testing trait for order claim nonce
-rw-r--r--src/include/taler_merchant_testing_lib.h31
-rw-r--r--src/testing/Makefile.am1
-rw-r--r--src/testing/testing_api_cmd_claim_order.c13
-rw-r--r--src/testing/testing_api_cmd_post_orders.c7
-rw-r--r--src/testing/testing_api_trait_claim_nonce.c76
5 files changed, 116 insertions, 12 deletions
diff --git a/src/include/taler_merchant_testing_lib.h b/src/include/taler_merchant_testing_lib.h
index af14955b..3ae227cd 100644
--- a/src/include/taler_merchant_testing_lib.h
+++ b/src/include/taler_merchant_testing_lib.h
@@ -1244,6 +1244,37 @@ TALER_TESTING_get_trait_merchant_sig (
/**
+ * Offer an order claim nonce.
+ *
+ * @param index which nonce to offer if there are
+ * multiple on offer.
+ * @param nonce set to the offered nonce.
+ * @return the trait
+ */
+struct TALER_TESTING_Trait
+TALER_TESTING_make_trait_claim_nonce (unsigned int index,
+ const struct
+ GNUNET_CRYPTO_EddsaPublicKey *nonce);
+
+
+/**
+ * Obtain an order claim nonce from a @a cmd.
+ *
+ * @param cmd command to extract the trait from.
+ * @param index which nonce to pick if @a
+ * cmd has multiple on offer
+ * @param nonce[out] set to the wanted data.
+ *
+ * @return #GNUNET_OK on success
+ */
+int
+TALER_TESTING_get_trait_claim_nonce (const struct TALER_TESTING_Command *cmd,
+ unsigned int index,
+ const struct
+ GNUNET_CRYPTO_EddsaPublicKey **nonce);
+
+
+/**
* Obtain a reference to a proposal command. Any command that
* works with proposals, might need to offer their reference to
* it. Notably, the "pay" command, offers its proposal reference
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
index 1c9fcb26..6e52b33f 100644
--- a/src/testing/Makefile.am
+++ b/src/testing/Makefile.am
@@ -49,6 +49,7 @@ libtalermerchanttesting_la_SOURCES = \
testing_api_cmd_wallet_get_order.c \
testing_api_cmd_wallet_get_tip.c \
testing_api_helpers.c \
+ testing_api_trait_claim_nonce.c \
testing_api_trait_merchant_sig.c \
testing_api_trait_string.c \
testing_api_trait_hash.c \
diff --git a/src/testing/testing_api_cmd_claim_order.c b/src/testing/testing_api_cmd_claim_order.c
index 0cdfff0e..f47ddcc5 100644
--- a/src/testing/testing_api_cmd_claim_order.c
+++ b/src/testing/testing_api_cmd_claim_order.c
@@ -186,11 +186,9 @@ order_claim_run (void *cls,
{
struct OrderClaimState *pls = cls;
const char *order_id;
- const struct TALER_MerchantPublicKeyP *nonce;
+ const struct GNUNET_CRYPTO_EddsaPublicKey *nonce;
/* Only used if we do NOT use the nonce from traits. */
- struct TALER_MerchantPublicKeyP dummy_nonce;
-#define GET_TRAIT_NONCE(cmd,ptr) \
- TALER_TESTING_get_trait_merchant_pub (cmd, 1, ptr)
+ struct GNUNET_CRYPTO_EddsaPublicKey dummy_nonce;
pls->is = is;
if (NULL != pls->order_id)
@@ -211,8 +209,9 @@ order_claim_run (void *cls,
if (NULL == order_cmd)
TALER_TESTING_FAIL (is);
if (GNUNET_OK !=
- GET_TRAIT_NONCE (order_cmd,
- &nonce))
+ TALER_TESTING_get_trait_claim_nonce (order_cmd,
+ 0,
+ &nonce))
{
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
&dummy_nonce,
@@ -229,7 +228,7 @@ order_claim_run (void *cls,
pls->och = TALER_MERCHANT_order_claim (is->ctx,
pls->merchant_url,
order_id,
- &nonce->eddsa_pub,
+ nonce,
&order_claim_cb,
pls);
GNUNET_assert (NULL != pls->och);
diff --git a/src/testing/testing_api_cmd_post_orders.c b/src/testing/testing_api_cmd_post_orders.c
index 8bdd7862..8e1cc3fc 100644
--- a/src/testing/testing_api_cmd_post_orders.c
+++ b/src/testing/testing_api_cmd_post_orders.c
@@ -115,17 +115,14 @@ orders_traits (void *cls,
unsigned int index)
{
struct OrdersState *ps = cls;
- // FIXME: wtf is this?
-#define MAKE_TRAIT_NONCE(ptr) \
- TALER_TESTING_make_trait_merchant_pub ( \
- 1, (struct TALER_MerchantPublicKeyP *) (ptr))
+
struct TALER_TESTING_Trait traits[] = {
TALER_TESTING_make_trait_order_id (0, ps->order_id),
TALER_TESTING_make_trait_contract_terms (0, ps->contract_terms),
TALER_TESTING_make_trait_h_contract_terms (0, &ps->h_contract_terms),
TALER_TESTING_make_trait_merchant_sig (0, &ps->merchant_sig),
TALER_TESTING_make_trait_merchant_pub (0, &ps->merchant_pub),
- MAKE_TRAIT_NONCE (&ps->nonce),
+ TALER_TESTING_make_trait_claim_nonce (0, &ps->nonce),
TALER_TESTING_trait_end ()
};
diff --git a/src/testing/testing_api_trait_claim_nonce.c b/src/testing/testing_api_trait_claim_nonce.c
new file mode 100644
index 00000000..96494795
--- /dev/null
+++ b/src/testing/testing_api_trait_claim_nonce.c
@@ -0,0 +1,76 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2020 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 lib/testing_api_trait_claim_nonce.c
+ * @brief offer a trait that is the nonce used to claim an order.
+ * @author Jonathan Buchanan
+ */
+#include "platform.h"
+#include <taler/taler_signatures.h>
+#include <taler/taler_exchange_service.h>
+#include <taler/taler_testing_lib.h>
+
+#define TALER_TESTING_TRAIT_CLAIM_NONCE "nonce"
+
+/**
+ * Obtain an order claim nonce from a @a cmd.
+ *
+ * @param cmd command to extract the trait from.
+ * @param index which nonce to pick if @a
+ * cmd has multiple on offer
+ * @param nonce[out] set to the wanted data.
+ *
+ * @return #GNUNET_OK on success
+ */
+int
+TALER_TESTING_get_trait_claim_nonce
+ (const struct TALER_TESTING_Command *cmd,
+ unsigned int index,
+ const struct GNUNET_CRYPTO_EddsaPublicKey **nonce)
+{
+ return cmd->traits (cmd->cls,
+ (const void **) nonce,
+ TALER_TESTING_TRAIT_CLAIM_NONCE,
+ index);
+}
+
+
+/**
+ * Offer an order claim nonce.
+ *
+ * @param index which nonce to offer if there are
+ * multiple on offer.
+ * @param nonce set to the offered nonce.
+ * @return the trait
+ */
+struct TALER_TESTING_Trait
+TALER_TESTING_make_trait_claim_nonce
+ (unsigned int index,
+ const struct GNUNET_CRYPTO_EddsaPublicKey *nonce)
+{
+ struct TALER_TESTING_Trait ret = {
+ .index = index,
+ .trait_name = TALER_TESTING_TRAIT_CLAIM_NONCE,
+ .ptr = (const void *) nonce
+ };
+ return ret;
+}
+
+
+/* end of testing_api_trait_claim_nonce.c */