gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-merchant] branch master updated: simplify structure


From: gnunet
Subject: [taler-merchant] branch master updated: simplify structure
Date: Sat, 02 Nov 2019 23:41:00 +0100

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository merchant.

The following commit(s) were added to refs/heads/master by this push:
     new 497bbc8  simplify structure
     new e3db526  wq Merge branch 'master' of git+ssh://git.taler.net/merchant
497bbc8 is described below

commit 497bbc8a9ce02640fe0bc7e232cacd497faf2e27
Author: Christian Grothoff <address@hidden>
AuthorDate: Sat Nov 2 23:24:21 2019 +0100

    simplify structure
---
 src/include/taler_merchant_testing_lib.h   |  15 +-
 src/lib/Makefile.am                        |   2 +
 src/lib/testing_api_cmd_pay.c              | 282 ++-----------------
 src/lib/testing_api_cmd_pay_abort_refund.c | 255 +++++++++++++++++
 src/lib/testing_api_cmd_proposal.c         | 215 +-------------
 src/lib/testing_api_cmd_proposal_lookup.c  | 221 +++++++++++++++
 src/lib/testing_api_cmd_refund_lookup.c    | 435 +++++++++++++++++++++++++++++
 7 files changed, 961 insertions(+), 464 deletions(-)

diff --git a/src/include/taler_merchant_testing_lib.h 
b/src/include/taler_merchant_testing_lib.h
index 5583062..ba0c927 100644
--- a/src/include/taler_merchant_testing_lib.h
+++ b/src/include/taler_merchant_testing_lib.h
@@ -149,11 +149,10 @@ TALER_TESTING_cmd_poll_payment_start (const char *label,
  * @return the command
  */
 struct TALER_TESTING_Command
-TALER_TESTING_cmd_check_payment (const char *label,
-                                 const char *merchant_url,
-                                 unsigned int http_status,
-                                 const char *proposal_reference,
-                                 unsigned int expect_paid);
+TALER_TESTING_cmd_poll_payment_conclude (const char *label,
+                                         unsigned int http_status,
+                                         const char *poll_start_reference,
+                                         unsigned int expect_paid);
 
 
 /**
@@ -412,6 +411,7 @@ TALER_TESTING_make_trait_merchant_sig (unsigned int index,
                                        const struct
                                        TALER_MerchantSignatureP *merchant_sig);
 
+
 /**
  * Obtain a merchant signature over a contract from a @a cmd.
  *
@@ -555,6 +555,7 @@ TALER_TESTING_get_trait_tip_id (const struct 
TALER_TESTING_Command *cmd,
                                 unsigned int index,
                                 const struct GNUNET_HashCode **tip_id);
 
+
 /**
  * Offer contract terms hash code.
  *
@@ -562,7 +563,6 @@ TALER_TESTING_get_trait_tip_id (const struct 
TALER_TESTING_Command *cmd,
  *        offer if there are multiple on offer
  * @param h_contract_terms set to the offered hashed
  *        contract terms.
- *
  * @return the trait
  */
 struct TALER_TESTING_Trait
@@ -570,13 +570,13 @@ TALER_TESTING_make_trait_h_contract_terms (unsigned int 
index,
                                            const struct
                                            GNUNET_HashCode *h_contract_terms);
 
+
 /**
  * Obtain contract terms hash from a @a cmd.
  *
  * @param cmd command to extract the trait from.
  * @param index index number of the trait to fetch.
  * @param h_contract_terms[out] set to the wanted data.
- *
  * @return #GNUNET_OK on success
  */
 int
@@ -591,7 +591,6 @@ TALER_TESTING_get_trait_h_contract_terms (const struct
  *
  * @param index index number of the trait to offer.
  * @param refund_entry set to the offered refund entry.
- *
  * @return the trait
  */
 struct TALER_TESTING_Trait
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index 3b1be0e..64af068 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -45,7 +45,9 @@ libtalermerchanttesting_la_SOURCES = \
   testing_api_cmd_check_payment.c \
   testing_api_cmd_history.c \
   testing_api_cmd_pay.c \
+  testing_api_cmd_pay_abort_refund.c \
   testing_api_cmd_proposal.c \
+  testing_api_cmd_proposal_lookup.c \
   testing_api_cmd_refund_increase.c \
   testing_api_cmd_refund_lookup.c \
   testing_api_cmd_rewind.c \
diff --git a/src/lib/testing_api_cmd_pay.c b/src/lib/testing_api_cmd_pay.c
index 32c7b51..44f332c 100644
--- a/src/lib/testing_api_cmd_pay.c
+++ b/src/lib/testing_api_cmd_pay.c
@@ -192,53 +192,6 @@ struct PayAbortState
 };
 
 
-/**
- * State for a "pay abort refund" CMD.  This command
- * takes the refund permissions from a "pay abort" CMD,
- * and redeems those at the exchange.
- */
-struct PayAbortRefundState
-{
-
-  /**
-   * "abort" CMD that will provide with refund permissions.
-   */
-  const char *abort_reference;
-
-  /**
-   * Expected number of coins that were refunded.
-   * Only used to counter-check, not to perform any
-   * operation.
-   */
-  unsigned int num_coins;
-
-  /**
-   * The amount to be "withdrawn" from the refund session.
-   */
-  const char *refund_amount;
-
-  /**
-   * The refund fee (charged to the merchant).
-   */
-  const char *refund_fee;
-
-  /**
-   * The interpreter state.
-   */
-  struct TALER_TESTING_Interpreter *is;
-
-  /**
-   * Handle to the refund operation.
-   */
-  struct TALER_EXCHANGE_RefundHandle *rh;
-
-  /**
-   * Expected HTTP response code.
-   */
-  unsigned int http_status;
-};
-
-
 /**
  * Parse the @a coins specification and grow the @a pc
  * array with the coins found, updating @a npc.
@@ -252,7 +205,6 @@ struct PayAbortRefundState
  * @param amount_without_fee to be removed, there is no
  *        per-contract fee, only per-coin exists.
  * @param refund_fee per-contract? per-coin?
- *
  * @return #GNUNET_OK on success
  */
 static int
@@ -335,22 +287,21 @@ build_coins (struct TALER_MERCHANT_PayCoin **pc,
       icoin->denom_value = *denom_value;
       icoin->amount_with_fee = *denom_value;
     }
-    GNUNET_assert (NULL != (dpk = TALER_TESTING_find_pk
-                                    (is->keys, &icoin->denom_value)));
-
-    GNUNET_assert (GNUNET_SYSERR != TALER_amount_subtract
-                     (&icoin->amount_without_fee,
-                     &icoin->denom_value,
-                     &dpk->fee_deposit));
-
-    GNUNET_assert
-      (GNUNET_OK == TALER_TESTING_get_trait_url
-        (coin_cmd, 0, &icoin->exchange_url));
-
-    GNUNET_assert
-      (GNUNET_OK == TALER_string_to_amount
-        (refund_fee, &icoin->refund_fee));
-
+    GNUNET_assert (NULL != (dpk =
+                              TALER_TESTING_find_pk (is->keys,
+                                                     &icoin->denom_value)));
+
+    GNUNET_assert (GNUNET_SYSERR !=
+                   TALER_amount_subtract (&icoin->amount_without_fee,
+                                          &icoin->denom_value,
+                                          &dpk->fee_deposit));
+    GNUNET_assert (GNUNET_OK ==
+                   TALER_TESTING_get_trait_url (coin_cmd,
+                                                0,
+                                                &icoin->exchange_url));
+    GNUNET_assert (GNUNET_OK ==
+                   TALER_string_to_amount (refund_fee,
+                                           &icoin->refund_fee));
   }
 
   return GNUNET_OK;
@@ -377,7 +328,6 @@ pay_cb (void *cls,
         const json_t *obj)
 {
   struct PayState *ps = cls;
-
   struct GNUNET_CRYPTO_EddsaSignature sig;
   const char *error_name;
   unsigned int error_line;
@@ -420,17 +370,21 @@ pay_cb (void *cls,
     /* proposal reference was used at least once, at this point */
     GNUNET_assert
       (NULL !=
-      (proposal_cmd = TALER_TESTING_interpreter_lookup_command
-                        (ps->is, ps->proposal_reference)));
+      (proposal_cmd =
+         TALER_TESTING_interpreter_lookup_command (ps->is,
+                                                   ps->proposal_reference)));
 
-    if (GNUNET_OK != TALER_TESTING_get_trait_peer_key_pub
-          (proposal_cmd, 0, &merchant_pub))
+    if (GNUNET_OK !=
+        TALER_TESTING_get_trait_peer_key_pub (proposal_cmd,
+                                              0,
+                                              &merchant_pub))
       TALER_TESTING_FAIL (ps->is);
 
-    if (GNUNET_OK != GNUNET_CRYPTO_eddsa_verify (
-          TALER_SIGNATURE_MERCHANT_PAYMENT_OK,
-          &mr.purpose, &sig,
-          merchant_pub))
+    if (GNUNET_OK !=
+        GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_MERCHANT_PAYMENT_OK,
+                                    &mr.purpose,
+                                    &sig,
+                                    merchant_pub))
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                   "Merchant signature given in response to /pay"
@@ -489,10 +443,8 @@ pay_abort_cb (void *cls,
                 "Received %u refunds\n",
                 num_refunds);
     pas->num_refunds = num_refunds;
-
-    pas->res = GNUNET_new_array
-                 (num_refunds, struct TALER_MERCHANT_RefundEntry);
-
+    pas->res = GNUNET_new_array (num_refunds,
+                                 struct TALER_MERCHANT_RefundEntry);
     memcpy (pas->res,
             res,
             num_refunds * sizeof (struct TALER_MERCHANT_RefundEntry));
@@ -1113,7 +1065,6 @@ pay_again_run (void *cls,
 {
   struct PayAgainState *pas = cls;
   const struct TALER_TESTING_Command *pay_cmd;
-
   const char *proposal_reference;
   const char *amount_with_fee;
   const char *amount_without_fee;
@@ -1217,179 +1168,4 @@ TALER_TESTING_cmd_pay_again (const char *label,
 }
 
 
-/**
- * Callback used to work out the response from the exchange
- * to a refund operation.  Currently only checks if the response
- * code is as expected.
- *
- * @param cls closure
- * @param http_status HTTP response code, #MHD_HTTP_OK (200) for
- *        successful deposit; 0 if the exchange's reply is bogus
- *        (fails to follow the protocol)
- * @param ec taler-specific error code, #TALER_EC_NONE on success
- * @param sign_key exchange key used to sign @a obj, or NULL
- * @param obj the received JSON reply, should be kept as proof
- *        (and, in particular, be forwarded to the customer)
- */
-static void
-abort_refund_cb (void *cls,
-                 unsigned int http_status,
-                 enum TALER_ErrorCode ec,
-                 const struct TALER_ExchangePublicKeyP *sign_key,
-                 const json_t *obj)
-{
-  struct PayAbortRefundState *pars = cls;
-
-  pars->rh = NULL;
-  if (pars->http_status != http_status)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Unexpected response code %u (%d) to command %s\n",
-                http_status,
-                ec,
-                TALER_TESTING_interpreter_get_current_label
-                  (pars->is));
-    TALER_TESTING_interpreter_fail (pars->is);
-    return;
-  }
-  TALER_TESTING_interpreter_next (pars->is);
-}
-
-
-/**
- * Free the state of a "pay abort refund" CMD, and possibly
- * cancel a pending operation.
- *
- * @param cls closure.
- * @param cmd the command currently being freed.
- */
-static void
-pay_abort_refund_cleanup (void *cls,
-                          const struct TALER_TESTING_Command *cmd)
-{
-  struct PayAbortRefundState *pars = cls;
-
-  if (NULL != pars->rh)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "Command `%s' did not complete.\n",
-                TALER_TESTING_interpreter_get_current_label (
-                  pars->is));
-    TALER_EXCHANGE_refund_cancel (pars->rh);
-  }
-  GNUNET_free (pars);
-}
-
-
-/**
- * Run a "pay abort refund" CMD.
- *
- * @param cls closure.
- * @param cmd command currently being run.
- * @param is interpreter state.
- */
-static void
-pay_abort_refund_run (void *cls,
-                      const struct TALER_TESTING_Command *cmd,
-                      struct TALER_TESTING_Interpreter *is)
-{
-  struct PayAbortRefundState *pars = cls;
-  struct TALER_Amount refund_fee;
-  struct TALER_Amount refund_amount;
-  const struct TALER_MERCHANT_RefundEntry *refund_entry;
-  const unsigned int *num_refunds;
-  const struct TALER_TESTING_Command *abort_cmd;
-  const struct GNUNET_CRYPTO_EddsaPublicKey *merchant_pub;
-  const struct GNUNET_HashCode *h_contract_terms;
-
-  pars->is = is;
-  if (NULL ==
-      (abort_cmd = TALER_TESTING_interpreter_lookup_command
-                     (is, pars->abort_reference)) )
-    TALER_TESTING_FAIL (is);
-
-  if (GNUNET_OK != TALER_TESTING_get_trait_uint
-        (abort_cmd, 0, &num_refunds))
-    TALER_TESTING_FAIL (is);
-
-  if (pars->num_coins >= *num_refunds)
-    TALER_TESTING_FAIL (is);
-
-  if (GNUNET_OK != TALER_TESTING_get_trait_h_contract_terms
-        (abort_cmd, 0, &h_contract_terms))
-    TALER_TESTING_FAIL (is);
-
-  if (GNUNET_OK != TALER_TESTING_get_trait_peer_key_pub
-        (abort_cmd, 0, &merchant_pub))
-    TALER_TESTING_FAIL (is);
-
-  if (GNUNET_OK != TALER_TESTING_get_trait_refund_entry
-        (abort_cmd, 0, &refund_entry))
-    TALER_TESTING_FAIL (is);
-
-  GNUNET_assert (GNUNET_OK == TALER_string_to_amount
-                   (pars->refund_amount, &refund_amount));
-  GNUNET_assert (GNUNET_OK == TALER_string_to_amount
-                   (pars->refund_fee, &refund_fee));
-
-  pars->rh = TALER_EXCHANGE_refund2
-               (is->exchange,
-               &refund_amount,
-               &refund_fee,
-               h_contract_terms,
-               &refund_entry->coin_pub,
-               refund_entry->rtransaction_id,
-               (const struct TALER_MerchantPublicKeyP *) merchant_pub,
-               &refund_entry->merchant_sig,
-               &abort_refund_cb,
-               pars);
-
-  GNUNET_assert (NULL != pars->rh);
-}
-
-
-/**
- * Make a "pay abort refund" CMD.  This command uses the
- * refund permission from a "pay abort" CMD, and redeems it
- * at the exchange.
- *
- * @param label command label.
- * @param abort_reference reference to the "pay abort" CMD that
- *        will offer the refund permission.
- * @param num_coins how many coins are expected to be refunded.
- * @param refund_amount the amount we are going to redeem as
- *        refund.
- * @param refund_fee the refund fee (merchant pays it)
- * @param http_status expected HTTP response code.
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_pay_abort_refund
-  (const char *label,
-  const char *abort_reference,
-  unsigned int num_coins,
-  const char *refund_amount,
-  const char *refund_fee,
-  unsigned int http_status)
-{
-  struct PayAbortRefundState *pars;
-
-  pars = GNUNET_new (struct PayAbortRefundState);
-  pars->abort_reference = abort_reference;
-  pars->num_coins = num_coins;
-  pars->refund_amount = refund_amount;
-  pars->refund_fee = refund_fee;
-  pars->http_status = http_status;
-  {
-    struct TALER_TESTING_Command cmd = {
-      .cls = pars,
-      .label = label,
-      .run = &pay_abort_refund_run,
-      .cleanup = &pay_abort_refund_cleanup
-    };
-
-    return cmd;
-  }
-}
-
-
 /* end of testing_api_cmd_pay.c */
diff --git a/src/lib/testing_api_cmd_pay_abort_refund.c 
b/src/lib/testing_api_cmd_pay_abort_refund.c
new file mode 100644
index 0000000..7f44c01
--- /dev/null
+++ b/src/lib/testing_api_cmd_pay_abort_refund.c
@@ -0,0 +1,255 @@
+/*
+  This file is part of TALER
+  Copyright (C) 2014-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 lib/testing_api_cmd_pay_abort_refund.c
+ * @brief command to test the pay-abort-refund feature.
+ * @author Marcello Stanisci
+ */
+#include "platform.h"
+#include <taler/taler_exchange_service.h>
+#include <taler/taler_testing_lib.h>
+#include <taler/taler_signatures.h>
+#include "taler_merchant_service.h"
+#include "taler_merchant_testing_lib.h"
+
+
+/**
+ * State for a "pay abort refund" CMD.  This command
+ * takes the refund permissions from a "pay abort" CMD,
+ * and redeems those at the exchange.
+ */
+struct PayAbortRefundState
+{
+
+  /**
+   * "abort" CMD that will provide with refund permissions.
+   */
+  const char *abort_reference;
+
+  /**
+   * Expected number of coins that were refunded.
+   * Only used to counter-check, not to perform any
+   * operation.
+   */
+  unsigned int num_coins;
+
+  /**
+   * The amount to be "withdrawn" from the refund session.
+   */
+  const char *refund_amount;
+
+  /**
+   * The refund fee (charged to the merchant).
+   */
+  const char *refund_fee;
+
+  /**
+   * The interpreter state.
+   */
+  struct TALER_TESTING_Interpreter *is;
+
+  /**
+   * Handle to the refund operation.
+   */
+  struct TALER_EXCHANGE_RefundHandle *rh;
+
+  /**
+   * Expected HTTP response code.
+   */
+  unsigned int http_status;
+};
+
+
+/**
+ * Callback used to work out the response from the exchange
+ * to a refund operation.  Currently only checks if the response
+ * code is as expected.
+ *
+ * @param cls closure
+ * @param http_status HTTP response code, #MHD_HTTP_OK (200) for
+ *        successful deposit; 0 if the exchange's reply is bogus
+ *        (fails to follow the protocol)
+ * @param ec taler-specific error code, #TALER_EC_NONE on success
+ * @param sign_key exchange key used to sign @a obj, or NULL
+ * @param obj the received JSON reply, should be kept as proof
+ *        (and, in particular, be forwarded to the customer)
+ */
+static void
+abort_refund_cb (void *cls,
+                 unsigned int http_status,
+                 enum TALER_ErrorCode ec,
+                 const struct TALER_ExchangePublicKeyP *sign_key,
+                 const json_t *obj)
+{
+  struct PayAbortRefundState *pars = cls;
+
+  pars->rh = NULL;
+  if (pars->http_status != http_status)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Unexpected response code %u (%d) to command %s\n",
+                http_status,
+                ec,
+                TALER_TESTING_interpreter_get_current_label
+                  (pars->is));
+    TALER_TESTING_interpreter_fail (pars->is);
+    return;
+  }
+  TALER_TESTING_interpreter_next (pars->is);
+}
+
+
+/**
+ * Free the state of a "pay abort refund" CMD, and possibly
+ * cancel a pending operation.
+ *
+ * @param cls closure.
+ * @param cmd the command currently being freed.
+ */
+static void
+pay_abort_refund_cleanup (void *cls,
+                          const struct TALER_TESTING_Command *cmd)
+{
+  struct PayAbortRefundState *pars = cls;
+
+  if (NULL != pars->rh)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "Command `%s' did not complete.\n",
+                TALER_TESTING_interpreter_get_current_label (
+                  pars->is));
+    TALER_EXCHANGE_refund_cancel (pars->rh);
+  }
+  GNUNET_free (pars);
+}
+
+
+/**
+ * Run a "pay abort refund" CMD.
+ *
+ * @param cls closure.
+ * @param cmd command currently being run.
+ * @param is interpreter state.
+ */
+static void
+pay_abort_refund_run (void *cls,
+                      const struct TALER_TESTING_Command *cmd,
+                      struct TALER_TESTING_Interpreter *is)
+{
+  struct PayAbortRefundState *pars = cls;
+  struct TALER_Amount refund_fee;
+  struct TALER_Amount refund_amount;
+  const struct TALER_MERCHANT_RefundEntry *refund_entry;
+  const unsigned int *num_refunds;
+  const struct TALER_TESTING_Command *abort_cmd;
+  const struct GNUNET_CRYPTO_EddsaPublicKey *merchant_pub;
+  const struct GNUNET_HashCode *h_contract_terms;
+
+  pars->is = is;
+  if (NULL ==
+      (abort_cmd =
+         TALER_TESTING_interpreter_lookup_command (is,
+                                                   pars->abort_reference)) )
+    TALER_TESTING_FAIL (is);
+  if (GNUNET_OK !=
+      TALER_TESTING_get_trait_uint (abort_cmd,
+                                    0,
+                                    &num_refunds))
+    TALER_TESTING_FAIL (is);
+  if (pars->num_coins >= *num_refunds)
+    TALER_TESTING_FAIL (is);
+  if (GNUNET_OK !=
+      TALER_TESTING_get_trait_h_contract_terms (abort_cmd,
+                                                0,
+                                                &h_contract_terms))
+    TALER_TESTING_FAIL (is);
+  if (GNUNET_OK !=
+      TALER_TESTING_get_trait_peer_key_pub (abort_cmd,
+                                            0,
+                                            &merchant_pub))
+    TALER_TESTING_FAIL (is);
+  if (GNUNET_OK !=
+      TALER_TESTING_get_trait_refund_entry (abort_cmd,
+                                            0,
+                                            &refund_entry))
+    TALER_TESTING_FAIL (is);
+  GNUNET_assert (GNUNET_OK ==
+                 TALER_string_to_amount (pars->refund_amount,
+                                         &refund_amount));
+  GNUNET_assert (GNUNET_OK ==
+                 TALER_string_to_amount (pars->refund_fee,
+                                         &refund_fee));
+  pars->rh = TALER_EXCHANGE_refund2
+               (is->exchange,
+               &refund_amount,
+               &refund_fee,
+               h_contract_terms,
+               &refund_entry->coin_pub,
+               refund_entry->rtransaction_id,
+               (const struct TALER_MerchantPublicKeyP *) merchant_pub,
+               &refund_entry->merchant_sig,
+               &abort_refund_cb,
+               pars);
+  GNUNET_assert (NULL != pars->rh);
+}
+
+
+/**
+ * Make a "pay abort refund" CMD.  This command uses the
+ * refund permission from a "pay abort" CMD, and redeems it
+ * at the exchange.
+ *
+ * @param label command label.
+ * @param abort_reference reference to the "pay abort" CMD that
+ *        will offer the refund permission.
+ * @param num_coins how many coins are expected to be refunded.
+ * @param refund_amount the amount we are going to redeem as
+ *        refund.
+ * @param refund_fee the refund fee (merchant pays it)
+ * @param http_status expected HTTP response code.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_pay_abort_refund
+  (const char *label,
+  const char *abort_reference,
+  unsigned int num_coins,
+  const char *refund_amount,
+  const char *refund_fee,
+  unsigned int http_status)
+{
+  struct PayAbortRefundState *pars;
+
+  pars = GNUNET_new (struct PayAbortRefundState);
+  pars->abort_reference = abort_reference;
+  pars->num_coins = num_coins;
+  pars->refund_amount = refund_amount;
+  pars->refund_fee = refund_fee;
+  pars->http_status = http_status;
+  {
+    struct TALER_TESTING_Command cmd = {
+      .cls = pars,
+      .label = label,
+      .run = &pay_abort_refund_run,
+      .cleanup = &pay_abort_refund_cleanup
+    };
+
+    return cmd;
+  }
+}
diff --git a/src/lib/testing_api_cmd_proposal.c 
b/src/lib/testing_api_cmd_proposal.c
index 5e1f4eb..7d51d97 100644
--- a/src/lib/testing_api_cmd_proposal.c
+++ b/src/lib/testing_api_cmd_proposal.c
@@ -18,8 +18,8 @@
 */
 
 /**
- * @file exchange/testing_api_cmd_exec_merchant.c
- * @brief command to execute the merchant backend service.
+ * @file exchange/testing_api_cmd_proposal.c
+ * @brief command to run /proposal
  * @author Marcello Stanisci
  */
 
@@ -100,45 +100,6 @@ struct ProposalState
 };
 
 
-/**
- * State for a "proposal lookup" CMD.  Not used by
- * the initial lookup operation.
- */
-struct ProposalLookupState
-{
-  /**
-   * The interpreter state.
-   */
-  struct TALER_TESTING_Interpreter *is;
-
-  /**
-   * URL of the merchant backend.
-   */
-  const char *merchant_url;
-
-  /**
-   * Expected status code.
-   */
-  unsigned int http_status;
-
-  /**
-   * /proposal/lookup operation handle.
-   */
-  struct TALER_MERCHANT_ProposalLookupOperation *plo;
-
-  /**
-   * Reference to a proposal operation.  Will offer the
-   * nonce for the operation.
-   */
-  const char *proposal_reference;
-
-  /**
-   * Order id to lookup upon.  If null, the @a proposal_reference
-   * will offer this value.
-   */
-  const char *order_id;
-};
-
 /**
  * Offer internal data to other commands.
  *
@@ -154,9 +115,8 @@ proposal_traits (void *cls,
                  const char *trait,
                  unsigned int index)
 {
-
   struct ProposalState *ps = cls;
-  #define MAKE_TRAIT_NONCE(ptr) \
+#define MAKE_TRAIT_NONCE(ptr)                       \
   TALER_TESTING_make_trait_peer_key_pub (1, ptr)
 
   struct TALER_TESTING_Trait traits[] = {
@@ -419,30 +379,6 @@ proposal_cleanup (void *cls,
 }
 
 
-/**
- * Free the state of a "proposal lookup" CMD, and possibly
- * cancel it if it did not complete.
- *
- * @param cls closure.
- * @param cmd command being freed.
- */
-static void
-proposal_lookup_cleanup (void *cls,
-                         const struct TALER_TESTING_Command *cmd)
-{
-  struct ProposalLookupState *pls = cls;
-
-  if (NULL != pls->plo)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "Command '%s' did not complete\n",
-                cmd->label);
-    TALER_MERCHANT_proposal_lookup_cancel (pls->plo);
-  }
-  GNUNET_free (pls);
-}
-
-
 /**
  * Make the "proposal" command.
  *
@@ -466,142 +402,15 @@ TALER_TESTING_cmd_proposal (const char *label,
   ps->order = order;
   ps->http_status = http_status;
   ps->merchant_url = merchant_url;
-
-  struct TALER_TESTING_Command cmd = {
-    .cls = ps,
-    .label = label,
-    .run = &proposal_run,
-    .cleanup = &proposal_cleanup,
-    .traits = &proposal_traits
-  };
-
-  return cmd;
-}
-
-
-/**
- * Callback for "proposal lookup" operation, to check the
- * response code is as expected.
- *
- * @param cls closure
- * @param http_status HTTP status code we got
- * @param json full response we got
- * @param contract_terms the contract terms; they are the
- *        backend-filled up proposal minus cryptographic
- *        information.
- * @param sig merchant signature over the contract terms.
- * @param hash hash code of the contract terms.
- */
-static void
-proposal_lookup_cb (void *cls,
-                    unsigned int http_status,
-                    const json_t *json,
-                    const json_t *contract_terms,
-                    const struct TALER_MerchantSignatureP *sig,
-                    const struct GNUNET_HashCode *hash)
-{
-  struct ProposalLookupState *pls = cls;
-
-  pls->plo = NULL;
-  if (pls->http_status != http_status)
-    TALER_TESTING_FAIL (pls->is);
-
-  TALER_TESTING_interpreter_next (pls->is);
-}
-
-
-/**
- * Run the "proposal lookup" CMD.
- *
- * @param cls closure.
- * @param cmd command currently being run.
- * @param is interpreter state.
- */
-static void
-proposal_lookup_run (void *cls,
-                     const struct TALER_TESTING_Command *cmd,
-                     struct TALER_TESTING_Interpreter *is)
-{
-  struct ProposalLookupState *pls = cls;
-  const char *order_id;
-  const struct GNUNET_CRYPTO_EddsaPublicKey *nonce;
-  /* Only used if we do NOT use the nonce from traits.  */
-  struct GNUNET_CRYPTO_EddsaPublicKey dummy_nonce;
-  #define GET_TRAIT_NONCE(cmd,ptr) \
-  TALER_TESTING_get_trait_peer_key_pub (cmd, 1, ptr)
-
-  pls->is = is;
-
-  if (NULL != pls->order_id)
-  {
-    order_id = pls->order_id;
-    GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
-                                &dummy_nonce,
-                                sizeof (dummy_nonce));
-    nonce = &dummy_nonce;
-  }
-  else
   {
-    const struct TALER_TESTING_Command *proposal_cmd;
-
-    proposal_cmd = TALER_TESTING_interpreter_lookup_command
-                     (is, pls->proposal_reference);
-
-    if (NULL == proposal_cmd)
-      TALER_TESTING_FAIL (is);
-
-    if (GNUNET_OK != GET_TRAIT_NONCE (proposal_cmd,
-                                      &nonce))
-      TALER_TESTING_FAIL (is);
-
-    if (GNUNET_OK != TALER_TESTING_get_trait_order_id
-          (proposal_cmd, 0, &order_id))
-      TALER_TESTING_FAIL (is);
+    struct TALER_TESTING_Command cmd = {
+      .cls = ps,
+      .label = label,
+      .run = &proposal_run,
+      .cleanup = &proposal_cleanup,
+      .traits = &proposal_traits
+    };
+
+    return cmd;
   }
-  pls->plo = TALER_MERCHANT_proposal_lookup (is->ctx,
-                                             pls->merchant_url,
-                                             order_id,
-                                             nonce,
-                                             &proposal_lookup_cb,
-                                             pls);
-  GNUNET_assert (NULL != pls->plo);
-}
-
-
-/**
- * Make a "proposal lookup" command.
- *
- * @param label command label.
- * @param merchant_url base URL of the merchant backend
- *        serving the proposal lookup request.
- * @param http_status expected HTTP response code.
- * @param proposal_reference reference to a "proposal" CMD.
- * @param order_id order id to lookup, can be NULL.
- *
- * @return the command.
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_proposal_lookup
-  (const char *label,
-  const char *merchant_url,
-  unsigned int http_status,
-  const char *proposal_reference,
-  const char *order_id)
-{
-  struct ProposalLookupState *pls;
-
-  pls = GNUNET_new (struct ProposalLookupState);
-  pls->http_status = http_status;
-  pls->proposal_reference = proposal_reference;
-  pls->merchant_url = merchant_url;
-  pls->order_id = order_id;
-
-  struct TALER_TESTING_Command cmd = {
-    .cls = pls,
-    .label = label,
-    .run = &proposal_lookup_run,
-    .cleanup = &proposal_lookup_cleanup
-  };
-
-  return cmd;
 }
diff --git a/src/lib/testing_api_cmd_proposal_lookup.c 
b/src/lib/testing_api_cmd_proposal_lookup.c
new file mode 100644
index 0000000..2ab5d9e
--- /dev/null
+++ b/src/lib/testing_api_cmd_proposal_lookup.c
@@ -0,0 +1,221 @@
+/*
+  This file is part of TALER
+  Copyright (C) 2014-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 exchange/testing_api_cmd_proposal_lookup.c
+ * @brief command to execute a proposal lookup
+ * @author Marcello Stanisci
+ */
+#include "platform.h"
+#include <taler/taler_exchange_service.h>
+#include <taler/taler_testing_lib.h>
+#include "taler_merchant_service.h"
+#include "taler_merchant_testing_lib.h"
+
+/**
+ * State for a "proposal lookup" CMD.  Not used by
+ * the initial lookup operation.
+ */
+struct ProposalLookupState
+{
+  /**
+   * The interpreter state.
+   */
+  struct TALER_TESTING_Interpreter *is;
+
+  /**
+   * URL of the merchant backend.
+   */
+  const char *merchant_url;
+
+  /**
+   * Expected status code.
+   */
+  unsigned int http_status;
+
+  /**
+   * /proposal/lookup operation handle.
+   */
+  struct TALER_MERCHANT_ProposalLookupOperation *plo;
+
+  /**
+   * Reference to a proposal operation.  Will offer the
+   * nonce for the operation.
+   */
+  const char *proposal_reference;
+
+  /**
+   * Order id to lookup upon.  If null, the @a proposal_reference
+   * will offer this value.
+   */
+  const char *order_id;
+};
+
+
+/**
+ * Free the state of a "proposal lookup" CMD, and possibly
+ * cancel it if it did not complete.
+ *
+ * @param cls closure.
+ * @param cmd command being freed.
+ */
+static void
+proposal_lookup_cleanup (void *cls,
+                         const struct TALER_TESTING_Command *cmd)
+{
+  struct ProposalLookupState *pls = cls;
+
+  if (NULL != pls->plo)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "Command '%s' did not complete\n",
+                cmd->label);
+    TALER_MERCHANT_proposal_lookup_cancel (pls->plo);
+  }
+  GNUNET_free (pls);
+}
+
+
+/**
+ * Callback for "proposal lookup" operation, to check the
+ * response code is as expected.
+ *
+ * @param cls closure
+ * @param http_status HTTP status code we got
+ * @param json full response we got
+ * @param contract_terms the contract terms; they are the
+ *        backend-filled up proposal minus cryptographic
+ *        information.
+ * @param sig merchant signature over the contract terms.
+ * @param hash hash code of the contract terms.
+ */
+static void
+proposal_lookup_cb (void *cls,
+                    unsigned int http_status,
+                    const json_t *json,
+                    const json_t *contract_terms,
+                    const struct TALER_MerchantSignatureP *sig,
+                    const struct GNUNET_HashCode *hash)
+{
+  struct ProposalLookupState *pls = cls;
+
+  pls->plo = NULL;
+  if (pls->http_status != http_status)
+    TALER_TESTING_FAIL (pls->is);
+
+  TALER_TESTING_interpreter_next (pls->is);
+}
+
+
+/**
+ * Run the "proposal lookup" CMD.
+ *
+ * @param cls closure.
+ * @param cmd command currently being run.
+ * @param is interpreter state.
+ */
+static void
+proposal_lookup_run (void *cls,
+                     const struct TALER_TESTING_Command *cmd,
+                     struct TALER_TESTING_Interpreter *is)
+{
+  struct ProposalLookupState *pls = cls;
+  const char *order_id;
+  const struct GNUNET_CRYPTO_EddsaPublicKey *nonce;
+  /* Only used if we do NOT use the nonce from traits.  */
+  struct GNUNET_CRYPTO_EddsaPublicKey dummy_nonce;
+  #define GET_TRAIT_NONCE(cmd,ptr) \
+  TALER_TESTING_get_trait_peer_key_pub (cmd, 1, ptr)
+
+  pls->is = is;
+
+  if (NULL != pls->order_id)
+  {
+    order_id = pls->order_id;
+    GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
+                                &dummy_nonce,
+                                sizeof (dummy_nonce));
+    nonce = &dummy_nonce;
+  }
+  else
+  {
+    const struct TALER_TESTING_Command *proposal_cmd;
+
+    proposal_cmd = TALER_TESTING_interpreter_lookup_command
+                     (is, pls->proposal_reference);
+
+    if (NULL == proposal_cmd)
+      TALER_TESTING_FAIL (is);
+
+    if (GNUNET_OK != GET_TRAIT_NONCE (proposal_cmd,
+                                      &nonce))
+      TALER_TESTING_FAIL (is);
+
+    if (GNUNET_OK != TALER_TESTING_get_trait_order_id
+          (proposal_cmd, 0, &order_id))
+      TALER_TESTING_FAIL (is);
+  }
+  pls->plo = TALER_MERCHANT_proposal_lookup (is->ctx,
+                                             pls->merchant_url,
+                                             order_id,
+                                             nonce,
+                                             &proposal_lookup_cb,
+                                             pls);
+  GNUNET_assert (NULL != pls->plo);
+}
+
+
+/**
+ * Make a "proposal lookup" command.
+ *
+ * @param label command label.
+ * @param merchant_url base URL of the merchant backend
+ *        serving the proposal lookup request.
+ * @param http_status expected HTTP response code.
+ * @param proposal_reference reference to a "proposal" CMD.
+ * @param order_id order id to lookup, can be NULL.
+ *
+ * @return the command.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_proposal_lookup
+  (const char *label,
+  const char *merchant_url,
+  unsigned int http_status,
+  const char *proposal_reference,
+  const char *order_id)
+{
+  struct ProposalLookupState *pls;
+
+  pls = GNUNET_new (struct ProposalLookupState);
+  pls->http_status = http_status;
+  pls->proposal_reference = proposal_reference;
+  pls->merchant_url = merchant_url;
+  pls->order_id = order_id;
+  {
+    struct TALER_TESTING_Command cmd = {
+      .cls = pls,
+      .label = label,
+      .run = &proposal_lookup_run,
+      .cleanup = &proposal_lookup_cleanup
+    };
+
+    return cmd;
+  }
+}
diff --git a/src/lib/testing_api_cmd_refund_lookup.c 
b/src/lib/testing_api_cmd_refund_lookup.c
new file mode 100644
index 0000000..fa02d6a
--- /dev/null
+++ b/src/lib/testing_api_cmd_refund_lookup.c
@@ -0,0 +1,435 @@
+/*
+  This file is part of TALER
+  Copyright (C) 2014-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 lib/testing_api_cmd_refund_lookup.c
+ * @brief command to test refunds.
+ * @author Marcello Stanisci
+ */
+
+#include "platform.h"
+#include <taler/taler_exchange_service.h>
+#include <taler/taler_testing_lib.h>
+#include "taler_merchant_service.h"
+#include "taler_merchant_testing_lib.h"
+
+
+/**
+ * State for a "refund lookup" CMD.
+ */
+struct RefundLookupState
+{
+  /**
+   * Operation handle for a GET /public/refund request.
+   */
+  struct TALER_MERCHANT_RefundLookupOperation *rlo;
+
+  /**
+   * Base URL of the merchant serving the request.
+   */
+  const char *merchant_url;
+
+  /**
+   * Order id to look up.
+   */
+  const char *order_id;
+
+  /**
+   * Reference to a "pay" CMD, used to double-check if
+   * refunded coins were actually spent:
+   */
+  const char *pay_reference;
+
+  /**
+   * Reference to a "refund increase" CMD that offer
+   * the expected amount to be refunded; can be NULL.
+   */
+  const char *increase_reference;
+
+  /**
+   * Expected HTTP response code.
+   */
+  unsigned int http_code;
+
+  /**
+   * Interpreter state.
+   */
+  struct TALER_TESTING_Interpreter *is;
+
+  /**
+   * Explicit amount to be refunded, must be defined if @a
+   * increase_reference is NULL.
+   */
+  const char *refund_amount;
+};
+
+
+/**
+ * Free the state of a "refund lookup" CMD, and
+ * possibly cancel a pending "refund lookup" operation.
+ *
+ * @param cls closure
+ * @param cmd command currently being freed.
+ */
+static void
+refund_lookup_cleanup (void *cls,
+                       const struct TALER_TESTING_Command *cmd)
+{
+  struct RefundLookupState *rls = cls;
+
+  if (NULL != rls->rlo)
+  {
+    TALER_LOG_WARNING ("Refund-lookup operation"
+                       " did not complete\n");
+    TALER_MERCHANT_refund_lookup_cancel (rls->rlo);
+  }
+  GNUNET_free (rls);
+}
+
+
+/**
+ * Callback that frees all the elements in the hashmap
+ *
+ * @param cls closure, NULL
+ * @param key current key
+ * @param value a `struct TALER_Amount`
+ *
+ * @return always #GNUNET_YES (continue to iterate)
+ */
+static int
+hashmap_free (void *cls,
+              const struct GNUNET_HashCode *key,
+              void *value)
+{
+  struct TALER_Amount *refund_amount = value;
+
+  GNUNET_free (refund_amount);
+  return GNUNET_YES;
+}
+
+
+/**
+ * Process "GET /public/refund" (lookup) response;
+ * mainly checking if the refunded amount matches the
+ * expectation.
+ *
+ * @param cls closure
+ * @param http_status HTTP status code
+ * @param ec taler-specific error object
+ * @param obj response body; is NULL on error.
+ */
+static void
+refund_lookup_cb (void *cls,
+                  unsigned int http_status,
+                  enum TALER_ErrorCode ec,
+                  const json_t *obj)
+{
+  struct RefundLookupState *rls = cls;
+  struct GNUNET_CONTAINER_MultiHashMap *map;
+  size_t index;
+  json_t *elem;
+  const char *error_name;
+  unsigned int error_line;
+  struct GNUNET_HashCode h_coin_pub;
+  const char *coin_reference;
+  char *coin_reference_dup;
+  const char *icoin_reference;
+  const struct TALER_TESTING_Command *pay_cmd;
+  const struct TALER_TESTING_Command *increase_cmd;
+  const char *refund_amount;
+  struct TALER_Amount acc;
+  struct TALER_Amount ra;
+  const json_t *arr;
+
+  rls->rlo = NULL;
+  if (rls->http_code != http_status)
+    TALER_TESTING_FAIL (rls->is);
+
+  arr = json_object_get (obj, "refund_permissions");
+  if (NULL == arr)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                "Tolerating a refund permission not found\n");
+    TALER_TESTING_interpreter_next (rls->is);
+    return;
+  }
+  map = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO);
+
+  /* Put in array every refunded coin.  */
+  json_array_foreach (arr, index, elem)
+  {
+    struct TALER_CoinSpendPublicKeyP coin_pub;
+    struct TALER_Amount *irefund_amount = GNUNET_new
+                                            (struct TALER_Amount);
+    struct GNUNET_JSON_Specification spec[] = {
+      GNUNET_JSON_spec_fixed_auto ("coin_pub", &coin_pub),
+      TALER_JSON_spec_amount ("refund_amount", irefund_amount),
+      GNUNET_JSON_spec_end ()
+    };
+
+    GNUNET_assert (GNUNET_OK == GNUNET_JSON_parse (elem,
+                                                   spec,
+                                                   &error_name,
+                                                   &error_line));
+    GNUNET_CRYPTO_hash (&coin_pub,
+                        sizeof (struct TALER_CoinSpendPublicKeyP),
+                        &h_coin_pub);
+    GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put
+                     (map,
+                     &h_coin_pub, // which
+                     irefund_amount, // how much
+                     GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+  };
+
+  /* Compare spent coins with refunded, and if they match,
+   * increase an accumulator.  */
+  if (NULL ==
+      (pay_cmd = TALER_TESTING_interpreter_lookup_command
+                   (rls->is, rls->pay_reference)))
+    TALER_TESTING_FAIL (rls->is);
+
+  if (GNUNET_OK != TALER_TESTING_get_trait_coin_reference
+        (pay_cmd, 0, &coin_reference))
+    TALER_TESTING_FAIL (rls->is);
+
+  GNUNET_assert (GNUNET_OK == TALER_amount_get_zero ("EUR",
+                                                     &acc));
+  coin_reference_dup = GNUNET_strdup (coin_reference);
+  for (icoin_reference = strtok (coin_reference_dup, ";");
+       NULL != icoin_reference;
+       icoin_reference = strtok (NULL, ";"))
+  {
+    const struct TALER_CoinSpendPrivateKeyP *icoin_priv;
+    struct TALER_CoinSpendPublicKeyP icoin_pub;
+    struct GNUNET_HashCode h_icoin_pub;
+    struct TALER_Amount *iamount;
+    const struct TALER_TESTING_Command *icoin_cmd;
+
+    if (NULL ==
+        (icoin_cmd = TALER_TESTING_interpreter_lookup_command
+                       (rls->is, icoin_reference)) )
+    {
+      GNUNET_break (0);
+      TALER_LOG_ERROR ("Bad reference `%s'\n",
+                       icoin_reference);
+      TALER_TESTING_interpreter_fail (rls->is);
+      GNUNET_CONTAINER_multihashmap_destroy (map);
+      return;
+    }
+
+    if (GNUNET_OK != TALER_TESTING_get_trait_coin_priv
+          (icoin_cmd, 0, &icoin_priv))
+    {
+      GNUNET_break (0);
+      TALER_LOG_ERROR ("Command `%s' failed to give coin"
+                       " priv trait\n",
+                       icoin_reference);
+      TALER_TESTING_interpreter_fail (rls->is);
+      GNUNET_CONTAINER_multihashmap_destroy (map);
+      return;
+    }
+
+    GNUNET_CRYPTO_eddsa_key_get_public (&icoin_priv->eddsa_priv,
+                                        &icoin_pub.eddsa_pub);
+    GNUNET_CRYPTO_hash (&icoin_pub,
+                        sizeof (struct TALER_CoinSpendPublicKeyP),
+                        &h_icoin_pub);
+
+    iamount = GNUNET_CONTAINER_multihashmap_get
+                (map, &h_icoin_pub);
+
+    /* Can be NULL: not all coins are involved in refund */
+    if (NULL == iamount)
+      continue;
+
+    GNUNET_assert (GNUNET_OK == TALER_amount_add (&acc,
+                                                  &acc,
+                                                  iamount));
+  }
+
+  GNUNET_free (coin_reference_dup);
+
+  if (NULL !=
+      (increase_cmd = TALER_TESTING_interpreter_lookup_command
+                        (rls->is, rls->increase_reference)))
+  {
+    if (GNUNET_OK != TALER_TESTING_get_trait_amount
+          (increase_cmd, 0, &refund_amount))
+      TALER_TESTING_FAIL (rls->is);
+
+    if (GNUNET_OK != TALER_string_to_amount
+          (refund_amount, &ra))
+      TALER_TESTING_FAIL (rls->is);
+  }
+  else
+  {
+    GNUNET_assert (NULL != rls->refund_amount);
+
+    if (GNUNET_OK != TALER_string_to_amount
+          (rls->refund_amount, &ra))
+      TALER_TESTING_FAIL (rls->is);
+  }
+
+  GNUNET_CONTAINER_multihashmap_iterate (map,
+                                         &hashmap_free,
+                                         NULL);
+  GNUNET_CONTAINER_multihashmap_destroy (map);
+
+  /* Check that what the backend claims to have been refunded
+   * actually matches _our_ refund expectation.  */
+  if (0 != TALER_amount_cmp (&acc,
+                             &ra))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Incomplete refund: expected '%s', got '%s'\n",
+                TALER_amount_to_string (&ra),
+                TALER_amount_to_string (&acc));
+    TALER_TESTING_interpreter_fail (rls->is);
+    return;
+  }
+
+  TALER_TESTING_interpreter_next (rls->is);
+}
+
+
+/**
+ * Run the "refund lookup" CMD.
+ *
+ * @param cls closure.
+ * @param cmd command being currently run.
+ * @param is interpreter state.
+ */
+static void
+refund_lookup_run (void *cls,
+                   const struct TALER_TESTING_Command *cmd,
+                   struct TALER_TESTING_Interpreter *is)
+{
+  struct RefundLookupState *rls = cls;
+
+  rls->is = is;
+  rls->rlo = TALER_MERCHANT_refund_lookup (is->ctx,
+                                           rls->merchant_url,
+                                           rls->order_id,
+                                           &refund_lookup_cb,
+                                           rls);
+  GNUNET_assert (NULL != rls->rlo);
+}
+
+
+/**
+ * Define a "refund lookup" CMD.
+ *
+ * @param label command label.
+ * @param merchant_url base URL of the merchant serving the
+ *        "refund lookup" request.
+ * @param increase_reference reference to a "refund increase" CMD
+ *        that will offer the amount to check the looked up refund
+ *        against.  Must NOT be NULL.
+ * @param pay_reference reference to the "pay" CMD whose coins got
+ *        refunded.  It is used to double-check if the refunded
+ *        coins were actually spent in the first place.
+ * @param order_id order id whose refund status is to be looked up.
+ * @param http_code expected HTTP response code.
+ *
+ * @return the command.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_refund_lookup
+  (const char *label,
+  const char *merchant_url,
+  const char *increase_reference,
+  const char *pay_reference,
+  const char *order_id,
+  unsigned int http_code)
+{
+  struct RefundLookupState *rls;
+
+  rls = GNUNET_new (struct RefundLookupState);
+  rls->merchant_url = merchant_url;
+  rls->order_id = order_id;
+  rls->pay_reference = pay_reference;
+  rls->increase_reference = increase_reference;
+  rls->http_code = http_code;
+  {
+    struct TALER_TESTING_Command cmd = {
+      .cls = rls,
+      .label = label,
+      .run = &refund_lookup_run,
+      .cleanup = &refund_lookup_cleanup
+    };
+
+    return cmd;
+  }
+}
+
+
+/**
+ * Define a "refund lookup" CMD, equipped with a expected refund
+ * amount.
+ *
+ * @param label command label.
+ * @param merchant_url base URL of the merchant serving the
+ *        "refund lookup" request.
+ * @param increase_reference reference to a "refund increase" CMD
+ *        that will offer the amount to check the looked up refund
+ *        against.  Can be NULL, takes precedence over @a
+ *        refund_amount.
+ * @param pay_reference reference to the "pay" CMD whose coins got
+ *        refunded.  It is used to double-check if the refunded
+ *        coins were actually spent in the first place.
+ * @param order_id order id whose refund status is to be looked up.
+ * @param http_code expected HTTP response code.
+ * @param refund_amount expected refund amount.  Must be defined
+ *        if @a increase_reference is NULL.
+ *
+ * @return the command.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_refund_lookup_with_amount
+  (const char *label,
+  const char *merchant_url,
+  const char *increase_reference,
+  const char *pay_reference,
+  const char *order_id,
+  unsigned int http_code,
+  const char *refund_amount)
+{
+  struct RefundLookupState *rls;
+
+  rls = GNUNET_new (struct RefundLookupState);
+  rls->merchant_url = merchant_url;
+  rls->order_id = order_id;
+  rls->pay_reference = pay_reference;
+  rls->increase_reference = increase_reference;
+  rls->http_code = http_code;
+  rls->refund_amount = refund_amount;
+  {
+    struct TALER_TESTING_Command cmd = {
+      .cls = rls,
+      .label = label,
+      .run = &refund_lookup_run,
+      .cleanup = &refund_lookup_cleanup
+    };
+
+    return cmd;
+  }
+}
+
+
+/* end of testing_api_cmd_refund_lookup.c */

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]