gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] branch master updated (f6633b5 -> 8a98260)


From: gnunet
Subject: [taler-merchant] branch master updated (f6633b5 -> 8a98260)
Date: Sat, 02 Nov 2019 23:24:31 +0100

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

grothoff pushed a change to branch master
in repository merchant.

    from f6633b5  simplify structure
     new 241ce94  simplify structure
     new 8a98260  simplify structure

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/lib/Makefile.am                        |   2 +
 src/lib/testing_api_cmd_check_payment.c    | 228 ++++++++++++
 src/lib/testing_api_cmd_pay.c              | 579 ++++-------------------------
 src/lib/testing_api_cmd_pay_abort_refund.c | 255 +++++++++++++
 4 files changed, 562 insertions(+), 502 deletions(-)
 create mode 100644 src/lib/testing_api_cmd_check_payment.c
 create mode 100644 src/lib/testing_api_cmd_pay_abort_refund.c

diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index 439a48a..5ceadfe 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -42,8 +42,10 @@ libtalermerchant_la_LIBADD = \
   $(XLIB)
 
 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_refund_increase.c \
   testing_api_cmd_refund_lookup.c \
diff --git a/src/lib/testing_api_cmd_check_payment.c 
b/src/lib/testing_api_cmd_check_payment.c
new file mode 100644
index 0000000..e74dbd1
--- /dev/null
+++ b/src/lib/testing_api_cmd_check_payment.c
@@ -0,0 +1,228 @@
+/*
+  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_check_payment.c
+ * @brief command to test the /check-payment 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 /check-payment CMD.
+ */
+struct CheckPaymentState
+{
+
+  /**
+   * Operation handle.
+   */
+  struct TALER_MERCHANT_CheckPaymentOperation *cpo;
+
+  /**
+   * The interpreter state.
+   */
+  struct TALER_TESTING_Interpreter *is;
+
+  /**
+   * Expected HTTP response status code.
+   */
+  unsigned int http_status;
+
+  /**
+   * Reference to a command that can provide a order id,
+   * typically a /proposal test command.
+   */
+  const char *proposal_reference;
+
+  /**
+   * GNUNET_YES if we expect the proposal was paid.
+   */
+  unsigned int expect_paid;
+
+  /**
+   * The merchant base URL.
+   */
+  const char *merchant_url;
+};
+
+
+/**
+ * Free a /check-payment CMD, and possibly cancel a pending
+ * operation thereof.
+ *
+ * @param cls closure
+ * @param cmd the command currently getting freed.
+ */
+static void
+check_payment_cleanup (void *cls,
+                       const struct TALER_TESTING_Command *cmd)
+{
+  struct CheckPaymentState *cps = cls;
+
+  if (NULL != cps->cpo)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "Command `%s' was not terminated\n",
+                TALER_TESTING_interpreter_get_current_label (
+                  cps->is));
+    TALER_MERCHANT_check_payment_cancel (cps->cpo);
+  }
+  GNUNET_free (cps);
+}
+
+
+/**
+ * Callback for a /check-payment request.
+ *
+ * @param cls closure.
+ * @param http_status HTTP status code we got.
+ * @param json full response we got.
+ * @param paid #GNUNET_YES (GNUNET_NO) if the contract was paid
+ *        (not paid).
+ * @param refunded #GNUNET_YES (GNUNET_NO) if the contract was
+ *        refunded (not refunded).
+ * @param refund_amount the amount that was refunded to this
+ *        contract.
+ * @param taler_pay_uri the URI that instructs the wallets to process
+ *                      the payment
+ */
+static void
+check_payment_cb (void *cls,
+                  unsigned int http_status,
+                  const json_t *obj,
+                  int paid,
+                  int refunded,
+                  struct TALER_Amount *refund_amount,
+                  const char *taler_pay_uri)
+{
+  struct CheckPaymentState *cps = cls;
+
+  cps->cpo = NULL;
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "check payment: expected paid: %s: %d\n",
+              TALER_TESTING_interpreter_get_current_label (
+                cps->is),
+              cps->expect_paid);
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "check payment: paid: %d\n",
+              paid);
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "check payment: url: %s\n",
+              taler_pay_uri);
+
+  if (paid != cps->expect_paid)
+    TALER_TESTING_FAIL (cps->is);
+
+  if (cps->http_status != http_status)
+    TALER_TESTING_FAIL (cps->is);
+
+  TALER_TESTING_interpreter_next (cps->is);
+}
+
+
+/**
+ * Run a /check-payment CMD.
+ *
+ * @param cmd the command currenly being run.
+ * @param cls closure.
+ * @param is interpreter state.
+ */
+static void
+check_payment_run (void *cls,
+                   const struct TALER_TESTING_Command *cmd,
+                   struct TALER_TESTING_Interpreter *is)
+{
+  struct CheckPaymentState *cps = cls;
+  const struct TALER_TESTING_Command *proposal_cmd;
+  const char *order_id;
+
+  cps->is = is;
+  proposal_cmd = TALER_TESTING_interpreter_lookup_command (
+    is, cps->proposal_reference);
+
+  if (NULL == proposal_cmd)
+    TALER_TESTING_FAIL (is);
+
+  if (GNUNET_OK != TALER_TESTING_get_trait_order_id (
+        proposal_cmd, 0, &order_id))
+    TALER_TESTING_FAIL (is);
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Checking for order id `%s'\n",
+              order_id);
+
+  cps->cpo = TALER_MERCHANT_check_payment
+               (is->ctx,
+               cps->merchant_url,
+               order_id,
+               NULL,
+               check_payment_cb,
+               cps);
+
+  GNUNET_assert (NULL != cps->cpo);
+}
+
+
+/**
+ * Make a "check payment" test command.
+ *
+ * @param label command label.
+ * @param merchant_url merchant base url
+ * @param http_status expected HTTP response code.
+ * @param proposal_reference the proposal whose payment status
+ *        is going to be checked.
+ * @param expect_paid #GNUNET_YES if we expect the proposal to be
+ *        paid, #GNUNET_NO otherwise.
+ * @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)
+{
+  struct CheckPaymentState *cps;
+
+  cps = GNUNET_new (struct CheckPaymentState);
+  cps->http_status = http_status;
+  cps->proposal_reference = proposal_reference;
+  cps->expect_paid = expect_paid;
+  cps->merchant_url = merchant_url;
+  {
+    struct TALER_TESTING_Command cmd = {
+      .cls = cps,
+      .label = label,
+      .run = &check_payment_run,
+      .cleanup = &check_payment_cleanup
+    };
+
+    return cmd;
+  }
+}
+
+
+/* end of testing_api_cmd_check_payment.c */
diff --git a/src/lib/testing_api_cmd_pay.c b/src/lib/testing_api_cmd_pay.c
index 3e9fa37..44f332c 100644
--- a/src/lib/testing_api_cmd_pay.c
+++ b/src/lib/testing_api_cmd_pay.c
@@ -94,45 +94,6 @@ struct PayState
 };
 
 
-/**
- * State for a /check-payment CMD.
- */
-struct CheckPaymentState
-{
-
-  /**
-   * Operation handle.
-   */
-  struct TALER_MERCHANT_CheckPaymentOperation *cpo;
-
-  /**
-   * The interpreter state.
-   */
-  struct TALER_TESTING_Interpreter *is;
-
-  /**
-   * Expected HTTP response status code.
-   */
-  unsigned int http_status;
-
-  /**
-   * Reference to a command that can provide a order id,
-   * typically a /proposal test command.
-   */
-  const char *proposal_reference;
-
-  /**
-   * GNUNET_YES if we expect the proposal was paid.
-   */
-  unsigned int expect_paid;
-
-  /**
-   * The merchant base URL.
-   */
-  const char *merchant_url;
-};
-
-
 /**
  * State for a "pay again" CMD.
  */
@@ -207,7 +168,6 @@ struct PayAbortState
    */
   struct TALER_TESTING_Interpreter *is;
 
-
   /**
    * How many refund permissions this CMD got
    * the right for.  Roughly, there is one refund
@@ -232,210 +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;
-};
-
-
-/**
- * Free a /check-payment CMD, and possibly cancel a pending
- * operation thereof.
- *
- * @param cls closure
- * @param cmd the command currently getting freed.
- */
-static void
-check_payment_cleanup (void *cls,
-                       const struct TALER_TESTING_Command *cmd)
-{
-  struct CheckPaymentState *cps = cls;
-
-  if (NULL != cps->cpo)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "Command `%s' was not terminated\n",
-                TALER_TESTING_interpreter_get_current_label (
-                  cps->is));
-    TALER_MERCHANT_check_payment_cancel (cps->cpo);
-  }
-  GNUNET_free (cps);
-}
-
-
-/**
- * Callback for a /check-payment request.
- *
- * @param cls closure.
- * @param http_status HTTP status code we got.
- * @param json full response we got.
- * @param paid GNUNET_YES (GNUNET_NO) if the contract was paid
- *        (not paid).
- * @param refunded GNUNET_YES (GNUNET_NO) if the contract was
- *        refunded (not refunded).
- * @param refund_amount the amount that was refunded to this
- *        contract.
- * @param taler_pay_uri the URI that instructs the wallets to process
- *                      the payment
- */
-static void
-check_payment_cb (void *cls,
-                  unsigned int http_status,
-                  const json_t *obj,
-                  int paid,
-                  int refunded,
-                  struct TALER_Amount *refund_amount,
-                  const char *taler_pay_uri)
-{
-  struct CheckPaymentState *cps = cls;
-
-  cps->cpo = NULL;
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-              "check payment: expected paid: %s: %d\n",
-              TALER_TESTING_interpreter_get_current_label (
-                cps->is),
-              cps->expect_paid);
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-              "check payment: paid: %d\n",
-              paid);
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-              "check payment: url: %s\n",
-              taler_pay_uri);
-
-  if (paid != cps->expect_paid)
-    TALER_TESTING_FAIL (cps->is);
-
-  if (cps->http_status != http_status)
-    TALER_TESTING_FAIL (cps->is);
-
-  TALER_TESTING_interpreter_next (cps->is);
-}
-
-
-/**
- * Run a /check-payment CMD.
- *
- * @param cmd the command currenly being run.
- * @param cls closure.
- * @param is interpreter state.
- */
-static void
-check_payment_run (void *cls,
-                   const struct TALER_TESTING_Command *cmd,
-                   struct TALER_TESTING_Interpreter *is)
-{
-  struct CheckPaymentState *cps = cls;
-  const struct TALER_TESTING_Command *proposal_cmd;
-  const char *order_id;
-
-  cps->is = is;
-  proposal_cmd = TALER_TESTING_interpreter_lookup_command (
-    is, cps->proposal_reference);
-
-  if (NULL == proposal_cmd)
-    TALER_TESTING_FAIL (is);
-
-  if (GNUNET_OK != TALER_TESTING_get_trait_order_id (
-        proposal_cmd, 0, &order_id))
-    TALER_TESTING_FAIL (is);
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Checking for order id `%s'\n",
-              order_id);
-
-  cps->cpo = TALER_MERCHANT_check_payment
-               (is->ctx,
-               cps->merchant_url,
-               order_id,
-               NULL,
-               check_payment_cb,
-               cps);
-
-  GNUNET_assert (NULL != cps->cpo);
-}
-
-
-/**
- * Make a "check payment" test command.
- *
- * @param label command label.
- * @param merchant_url merchant base url
- * @param http_status expected HTTP response code.
- * @param proposal_reference the proposal whose payment status
- *        is going to be checked.
- * @param expect_paid GNUNET_YES if we expect the proposal to be
- *        paid, GNUNET_NO otherwise.
- *
- * @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)
-{
-  struct CheckPaymentState *cps;
-
-  cps = GNUNET_new (struct CheckPaymentState);
-  cps->http_status = http_status;
-  cps->proposal_reference = proposal_reference;
-  cps->expect_paid = expect_paid;
-  cps->merchant_url = merchant_url;
-
-  struct TALER_TESTING_Command cmd = {
-    .cls = cps,
-    .label = label,
-    .run = &check_payment_run,
-    .cleanup = &check_payment_cleanup
-  };
-
-  return cmd;
-
-}
-
-
 /**
  * Parse the @a coins specification and grow the @a pc
  * array with the coins found, updating @a npc.
@@ -449,7 +205,6 @@ TALER_TESTING_cmd_check_payment (const char *label,
  * @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
@@ -532,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;
@@ -574,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;
@@ -617,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"
@@ -686,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));
@@ -979,29 +734,28 @@ pay_traits (void *cls,
     GNUNET_break (0);
     return GNUNET_SYSERR;
   }
+  {
+    struct TALER_TESTING_Trait traits[] = {
+      TALER_TESTING_make_trait_amount
+        (AMOUNT_WITH_FEE, ps->amount_with_fee),
+      TALER_TESTING_make_trait_amount
+        (AMOUNT_WITHOUT_FEE, ps->amount_without_fee),
+      TALER_TESTING_make_trait_amount
+        (REFUND_FEE, ps->refund_fee),
+      TALER_TESTING_make_trait_proposal_reference
+        (0, ps->proposal_reference),
+      TALER_TESTING_make_trait_coin_reference
+        (0, ps->coin_reference),
+      TALER_TESTING_make_trait_order_id (0, order_id),
+      TALER_TESTING_make_trait_peer_key_pub (0, merchant_pub),
+      TALER_TESTING_trait_end ()
+    };
 
-  struct TALER_TESTING_Trait traits[] = {
-    TALER_TESTING_make_trait_amount
-      (AMOUNT_WITH_FEE, ps->amount_with_fee),
-    TALER_TESTING_make_trait_amount
-      (AMOUNT_WITHOUT_FEE, ps->amount_without_fee),
-    TALER_TESTING_make_trait_amount
-      (REFUND_FEE, ps->refund_fee),
-    TALER_TESTING_make_trait_proposal_reference
-      (0, ps->proposal_reference),
-    TALER_TESTING_make_trait_coin_reference
-      (0, ps->coin_reference),
-    TALER_TESTING_make_trait_order_id (0, order_id),
-    TALER_TESTING_make_trait_peer_key_pub (0, merchant_pub),
-    TALER_TESTING_trait_end ()
-  };
-
-  return TALER_TESTING_get_trait (traits,
-                                  ret,
-                                  trait,
-                                  index);
-
-  return GNUNET_SYSERR;
+    return TALER_TESTING_get_trait (traits,
+                                    ret,
+                                    trait,
+                                    index);
+  }
 }
 
 
@@ -1042,17 +796,17 @@ TALER_TESTING_cmd_pay (const char *label,
   ps->amount_with_fee = amount_with_fee;
   ps->amount_without_fee = amount_without_fee;
   ps->refund_fee = refund_fee;
+  {
+    struct TALER_TESTING_Command cmd = {
+      .cls = ps,
+      .label = label,
+      .run = &pay_run,
+      .cleanup = &pay_cleanup,
+      .traits = &pay_traits
+    };
 
-  struct TALER_TESTING_Command cmd = {
-    .cls = ps,
-    .label = label,
-    .run = &pay_run,
-    .cleanup = &pay_cleanup,
-    .traits = &pay_traits
-  };
-
-  return cmd;
-
+    return cmd;
+  }
 }
 
 
@@ -1159,7 +913,6 @@ pay_abort_traits (void *cls,
                   unsigned int index)
 {
   struct PayAbortState *pas = cls;
-
   struct TALER_TESTING_Trait traits[] = {
     TALER_TESTING_make_trait_peer_key_pub
       (0, &pas->merchant_pub.eddsa_pub),
@@ -1175,8 +928,6 @@ pay_abort_traits (void *cls,
                                   ret,
                                   trait,
                                   index);
-
-  return GNUNET_SYSERR;
 }
 
 
@@ -1202,16 +953,17 @@ TALER_TESTING_cmd_pay_abort (const char *label,
   pas->http_status = http_status;
   pas->pay_reference = pay_reference;
   pas->merchant_url = merchant_url;
+  {
+    struct TALER_TESTING_Command cmd = {
+      .cls = pas,
+      .label = label,
+      .run = &pay_abort_run,
+      .cleanup = &pay_abort_cleanup,
+      .traits = &pay_abort_traits
+    };
 
-  struct TALER_TESTING_Command cmd = {
-    .cls = pas,
-    .label = label,
-    .run = &pay_abort_run,
-    .cleanup = &pay_abort_cleanup,
-    .traits = &pay_abort_traits
-  };
-
-  return cmd;
+    return cmd;
+  }
 }
 
 
@@ -1313,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;
@@ -1370,7 +1121,6 @@ pay_again_cleanup (void *cls,
                   pas->is));
     TALER_MERCHANT_pay_cancel (pas->pao);
   }
-
   GNUNET_free (pas);
 }
 
@@ -1397,7 +1147,6 @@ TALER_TESTING_cmd_pay_again (const char *label,
                              const char *refund_fee,
                              unsigned int http_status)
 {
-
   struct PayAgainState *pas;
 
   pas = GNUNET_new (struct PayAgainState);
@@ -1406,190 +1155,16 @@ TALER_TESTING_cmd_pay_again (const char *label,
   pas->coin_reference = coin_reference;
   pas->merchant_url = merchant_url;
   pas->refund_fee = refund_fee;
-
-  struct TALER_TESTING_Command cmd = {
-    .cls = pas,
-    .label = label,
-    .run = &pay_again_run,
-    .cleanup = &pay_again_cleanup
-  };
-
-  return cmd;
-}
-
-
-/**
- * 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;
+    struct TALER_TESTING_Command cmd = {
+      .cls = pas,
+      .label = label,
+      .run = &pay_again_run,
+      .cleanup = &pay_again_cleanup
+    };
 
-  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);
+    return cmd;
   }
-  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_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;
+  }
+}

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



reply via email to

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