gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] branch master updated: tests for forget results


From: gnunet
Subject: [taler-merchant] branch master updated: tests for forget results
Date: Wed, 22 Jul 2020 11:03:15 +0200

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

jonathan-buchanan pushed a commit to branch master
in repository merchant.

The following commit(s) were added to refs/heads/master by this push:
     new badec7a  tests for forget results
badec7a is described below

commit badec7af6eab1f0972f7d49527f5f0772589bb3f
Author: Jonathan Buchanan <jonathan.russ.buchanan@gmail.com>
AuthorDate: Wed Jul 22 05:03:04 2020 -0400

    tests for forget results
---
 src/include/taler_merchant_testing_lib.h         |   4 +
 src/testing/test_merchant_api.c                  | 159 +++++++++++++++--------
 src/testing/testing_api_cmd_forget_order.c       |  50 ++-----
 src/testing/testing_api_cmd_merchant_get_order.c | 102 ++++++++++++++-
 4 files changed, 218 insertions(+), 97 deletions(-)

diff --git a/src/include/taler_merchant_testing_lib.h 
b/src/include/taler_merchant_testing_lib.h
index 68978c9..0314d6d 100644
--- a/src/include/taler_merchant_testing_lib.h
+++ b/src/include/taler_merchant_testing_lib.h
@@ -654,6 +654,9 @@ TALER_TESTING_cmd_merchant_get_order (const char *label,
  *        refunds (commands) we expect to be aggregated in the order
  *        (assuming @a http_code is #MHD_HTTP_OK). If @e refunded is false,
  *        this parameter is ignored.
+ * @param forgets a NULL-terminated list of references to forget commands
+ *        that apply to the order we are querying. If NULL, this is
+ *        interpreted as no forgets are expected.
  * @param http_status expected HTTP response code for the request.
  */
 struct TALER_TESTING_Command
@@ -665,6 +668,7 @@ TALER_TESTING_cmd_merchant_get_order2 (const char *label,
                                        const char **transfers,
                                        bool refunded,
                                        const char **refunds,
+                                       const char **forgets,
                                        unsigned int http_status);
 
 
diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c
index 7837774..41fa321 100644
--- a/src/testing/test_merchant_api.c
+++ b/src/testing/test_merchant_api.c
@@ -117,6 +117,29 @@ const char *payto_uris[] = {
                                           inactivation. */
 };
 
+const char *order_1_transfers[] = {
+  "post-transfer-1",
+  NULL
+};
+
+const char *order_1_forgets_1[] = {
+  "forget-1",
+  NULL
+};
+
+const char *order_1_forgets_2[] = {
+  "forget-1",
+  "forget-order-array-elem",
+  NULL
+};
+
+const char *order_1_forgets_3[] = {
+  "forget-1",
+  "forget-order-array-elem",
+  "forget-order-array-wc",
+  NULL
+};
+
 
 /**
  * Execute the taler-exchange-wirewatch command with
@@ -171,11 +194,6 @@ static void
 run (void *cls,
      struct TALER_TESTING_Interpreter *is)
 {
-  const char *order_1_transfers[] = {
-    "post-transfer-1",
-    NULL
-  };
-
   struct TALER_TESTING_Command get_private_order_id[] = {
 
     TALER_TESTING_cmd_merchant_post_instances ("instance-create-default",
@@ -311,71 +329,28 @@ run (void *cls,
                                           "withdraw-coin-1",
                                           "EUR:5",
                                           "EUR:4.99"),
-    TALER_TESTING_cmd_merchant_forget_order ("forget-1",
-                                             merchant_url,
-                                             MHD_HTTP_OK,
-                                             "create-proposal-1",
-                                             NULL,
-                                             "$.dummy_obj",
-                                             NULL),
-    TALER_TESTING_cmd_merchant_forget_order ("forget-unforgettable",
-                                             merchant_url,
-                                             MHD_HTTP_CONFLICT,
-                                             "create-proposal-1",
-                                             NULL,
-                                             "$.amount",
-                                             NULL),
-    TALER_TESTING_cmd_merchant_forget_order ("forget-order-nx",
-                                             merchant_url,
-                                             MHD_HTTP_NOT_FOUND,
-                                             NULL,
-                                             "nx-order",
-                                             "$.dummy_obj",
-                                             NULL),
-    TALER_TESTING_cmd_merchant_forget_order ("forget-order-array-elem",
-                                             merchant_url,
-                                             MHD_HTTP_OK,
-                                             "create-proposal-1",
-                                             NULL,
-                                             "$.dummy_array[0].item",
-                                             NULL),
-    TALER_TESTING_cmd_merchant_forget_order ("forget-order-array-wc",
-                                             merchant_url,
-                                             MHD_HTTP_OK,
-                                             "create-proposal-1",
-                                             NULL,
-                                             "$.dummy_array[*].item",
-                                             NULL),
-    TALER_TESTING_cmd_merchant_forget_order ("forget-order-malformed",
-                                             merchant_url,
-                                             MHD_HTTP_BAD_REQUEST,
-                                             "create-proposal-1",
-                                             NULL,
-                                             "$.dummy_array[abc].item",
-                                             NULL),
     TALER_TESTING_cmd_poll_order_conclude ("poll-order-merchant-1-conclude",
                                            MHD_HTTP_OK,
                                            "poll-order-merchant-1-start"),
-    /*
     TALER_TESTING_cmd_wallet_get_order ("get-order-wallet-1-2",
                                         merchant_url,
                                         "create-proposal-1",
                                         true,
                                         false,
-                                        MHD_HTTP_OK),*/
-    /*TALER_TESTING_cmd_merchant_get_order ("get-order-merchant-1-2",
+                                        MHD_HTTP_OK),
+    TALER_TESTING_cmd_merchant_get_order ("get-order-merchant-1-2",
                                           merchant_url,
                                           "create-proposal-1",
                                           true,
                                           false,
-                                          MHD_HTTP_OK),*/
-    /*TALER_TESTING_cmd_merchant_pay_order ("replay-simple",
+                                          MHD_HTTP_OK),
+    TALER_TESTING_cmd_merchant_pay_order ("replay-simple",
                                           merchant_url,
                                           MHD_HTTP_OK,
                                           "create-proposal-1",
                                           "withdraw-coin-1",
                                           "EUR:5",
-                                          "EUR:4.99"),*/
+                                          "EUR:4.99"),
     TALER_TESTING_cmd_check_bank_empty ("check_bank_empty-1"),
     CMD_EXEC_AGGREGATOR ("run-aggregator"),
     TALER_TESTING_cmd_check_bank_transfer ("check_bank_transfer-498c",
@@ -397,7 +372,24 @@ run (void *cls,
                                               MHD_HTTP_OK,
                                               "post-transfer-1",
                                               NULL),
-    /*TALER_TESTING_cmd_merchant_get_order2 ("get-order-merchant-1-2",
+    TALER_TESTING_cmd_merchant_get_order2 ("get-order-merchant-1-2",
+                                           merchant_url,
+                                           "create-proposal-1",
+                                           true,
+                                           true,
+                                           order_1_transfers,
+                                           false,
+                                           NULL,
+                                           NULL,
+                                           MHD_HTTP_OK),
+    TALER_TESTING_cmd_merchant_forget_order ("forget-1",
+                                             merchant_url,
+                                             MHD_HTTP_OK,
+                                             "create-proposal-1",
+                                             NULL,
+                                             "$.dummy_obj",
+                                             NULL),
+    TALER_TESTING_cmd_merchant_get_order2 ("get-order-merchant-1-forget-1",
                                            merchant_url,
                                            "create-proposal-1",
                                            true,
@@ -405,7 +397,63 @@ run (void *cls,
                                            order_1_transfers,
                                            false,
                                            NULL,
-                                           MHD_HTTP_OK),*/
+                                           order_1_forgets_1,
+                                           MHD_HTTP_OK),
+    TALER_TESTING_cmd_merchant_forget_order ("forget-unforgettable",
+                                             merchant_url,
+                                             MHD_HTTP_CONFLICT,
+                                             "create-proposal-1",
+                                             NULL,
+                                             "$.amount",
+                                             NULL),
+    TALER_TESTING_cmd_merchant_forget_order ("forget-order-nx",
+                                             merchant_url,
+                                             MHD_HTTP_NOT_FOUND,
+                                             NULL,
+                                             "nx-order",
+                                             "$.dummy_obj",
+                                             NULL),
+    TALER_TESTING_cmd_merchant_forget_order ("forget-order-array-elem",
+                                             merchant_url,
+                                             MHD_HTTP_OK,
+                                             "create-proposal-1",
+                                             NULL,
+                                             "$.dummy_array[0].item",
+                                             NULL),
+    TALER_TESTING_cmd_merchant_get_order2 ("get-order-merchant-1-forget-2",
+                                           merchant_url,
+                                           "create-proposal-1",
+                                           true,
+                                           true,
+                                           order_1_transfers,
+                                           false,
+                                           NULL,
+                                           order_1_forgets_2,
+                                           MHD_HTTP_OK),
+    TALER_TESTING_cmd_merchant_forget_order ("forget-order-array-wc",
+                                             merchant_url,
+                                             MHD_HTTP_OK,
+                                             "create-proposal-1",
+                                             NULL,
+                                             "$.dummy_array[*].item",
+                                             NULL),
+    TALER_TESTING_cmd_merchant_get_order2 ("get-order-merchant-1-forget-3",
+                                           merchant_url,
+                                           "create-proposal-1",
+                                           true,
+                                           true,
+                                           order_1_transfers,
+                                           false,
+                                           NULL,
+                                           order_1_forgets_3,
+                                           MHD_HTTP_OK),
+    TALER_TESTING_cmd_merchant_forget_order ("forget-order-malformed",
+                                             merchant_url,
+                                             MHD_HTTP_BAD_REQUEST,
+                                             "create-proposal-1",
+                                             NULL,
+                                             "$.dummy_array[abc].item",
+                                             NULL),
     TALER_TESTING_cmd_merchant_post_products ("post-products-p3",
                                               merchant_url,
                                               "product-3",
@@ -611,6 +659,7 @@ run (void *cls,
                                            NULL,
                                            true,
                                            order_1r_refunds,
+                                           NULL,
                                            MHD_HTTP_OK),
 #if 0
     TALER_TESTING_cmd_poll_payment_conclude ("poll-payment-refund-conclude-1",
diff --git a/src/testing/testing_api_cmd_forget_order.c 
b/src/testing/testing_api_cmd_forget_order.c
index 7b86c18..c256052 100644
--- a/src/testing/testing_api_cmd_forget_order.c
+++ b/src/testing/testing_api_cmd_forget_order.c
@@ -118,38 +118,9 @@ order_forget_cb (void *cls,
 {
   struct OrderForgetState *ofs = cls;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Expected: %u\n", ofs->http_status);
-  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Given: %u\n", hr->http_status);
-
   ofs->ofh = NULL;
   if (ofs->http_status != hr->http_status)
     TALER_TESTING_FAIL (ofs->is);
-  /*if (MHD_HTTP_OK == hr->http_status)
-  {
-    pls->contract_terms = json_object_get (hr->reply,
-                                           "contract_terms");
-    if (NULL == pls->contract_terms)
-      TALER_TESTING_FAIL (pls->is);
-    json_incref (pls->contract_terms);
-    pls->contract_terms_hash = *hash;
-    pls->merchant_sig = *sig;
-    {
-      const char *error_name;
-      unsigned int error_line;
-      struct GNUNET_JSON_Specification spec[] = {
-        GNUNET_JSON_spec_fixed_auto ("merchant_pub",
-                                     &pls->merchant_pub),
-        GNUNET_JSON_spec_end ()
-      };
-
-      if (GNUNET_OK !=
-          GNUNET_JSON_parse (contract_terms,
-                             spec,
-                             &error_name,
-                             &error_line))
-        TALER_TESTING_FAIL (pls->is);
-    }
-  }*/
   TALER_TESTING_interpreter_next (ofs->is);
 }
 
@@ -215,18 +186,15 @@ order_forget_traits (void *cls,
                      const char *trait,
                      unsigned int index)
 {
-  // struct OrderForgetState *ofs = cls;
-  struct TALER_TESTING_Trait traits[] = {
-    /*TALER_TESTING_make_trait_contract_terms (0,
-                                             pls->contract_terms),
-    TALER_TESTING_make_trait_h_contract_terms (0,
-                                               &pls->contract_terms_hash),
-    TALER_TESTING_make_trait_merchant_sig (0,
-                                           &pls->merchant_sig),
-    TALER_TESTING_make_trait_merchant_pub (0,
-                                           &pls->merchant_pub),*/
-    TALER_TESTING_trait_end ()
-  };
+  struct OrderForgetState *ofs = cls;
+  struct TALER_TESTING_Trait traits[ofs->paths_length + 2];
+
+  traits[0] = TALER_TESTING_make_trait_uint32 (0,
+                                               &ofs->paths_length);
+  for (unsigned int i = 0; i < ofs->paths_length; ++i)
+    traits[i + 1] = TALER_TESTING_make_trait_string (i,
+                                                     ofs->paths[i]);
+  traits[ofs->paths_length + 1] = TALER_TESTING_trait_end ();
 
   return TALER_TESTING_get_trait (traits,
                                   ret,
diff --git a/src/testing/testing_api_cmd_merchant_get_order.c 
b/src/testing/testing_api_cmd_merchant_get_order.c
index 7364291..4ae459a 100644
--- a/src/testing/testing_api_cmd_merchant_get_order.c
+++ b/src/testing/testing_api_cmd_merchant_get_order.c
@@ -92,9 +92,39 @@ struct MerchantGetOrderState
    * The length of @e transfers.
    */
   unsigned int transfers_length;
+
+  /**
+   * A list of forget commands that apply to this order's contract terms.
+   */
+  const char **forgets;
+
+  /**
+   * The length of @e forgets.
+   */
+  unsigned int forgets_length;
 };
 
 
+/**
+ * Forget part of the contract terms.
+ *
+ * @param cls pointer to the result of the forget operation.
+ * @param object_id name of the object to forget.
+ * @param parent parent of the object at @e object_id.
+ */
+static void
+apply_forget (void *cls,
+              const char *object_id,
+              json_t *parent)
+{
+  int *res = cls;
+  if (GNUNET_OK !=
+      TALER_JSON_contract_part_forget (parent,
+                                       object_id))
+    *res = GNUNET_SYSERR;
+}
+
+
 /**
  * Callback to process a GET /orders/$ID request
  *
@@ -149,6 +179,7 @@ merchant_get_order_cb (
 
       {
         const json_t *expected_contract_terms;
+        json_t *ct;
 
         if (GNUNET_OK !=
             TALER_TESTING_get_trait_contract_terms (order_cmd,
@@ -160,7 +191,56 @@ merchant_get_order_cb (
           TALER_TESTING_interpreter_fail (gos->is);
           return;
         }
-        if (1 != json_equal (expected_contract_terms,
+
+        ct = json_deep_copy (expected_contract_terms);
+
+        /* Apply all forgets, then compare */
+        for (unsigned int i = 0; i < gos->forgets_length; ++i)
+        {
+          const struct TALER_TESTING_Command *forget_cmd;
+          const unsigned int *paths_length;
+
+          forget_cmd = TALER_TESTING_interpreter_lookup_command (
+            gos->is,
+            gos->forgets[i]);
+
+          if (GNUNET_OK !=
+              TALER_TESTING_get_trait_uint32 (forget_cmd,
+                                              0,
+                                              &paths_length))
+          {
+            GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                        "Couldn't fetch forget paths length\n");
+            TALER_TESTING_interpreter_fail (gos->is);
+            return;
+          }
+
+          for (unsigned int j = 0; j < *paths_length; ++j)
+          {
+            const char *path;
+            int res = GNUNET_OK;
+
+            if (GNUNET_OK !=
+                TALER_TESTING_get_trait_string (forget_cmd,
+                                                j,
+                                                &path))
+            {
+              GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                          "Couldn't fetch forget path\n");
+              TALER_TESTING_interpreter_fail (gos->is);
+              return;
+            }
+
+            GNUNET_assert (GNUNET_OK ==
+                           TALER_JSON_expand_path (ct,
+                                                   path,
+                                                   &apply_forget,
+                                                   &res));
+            GNUNET_assert (GNUNET_OK == res);
+          }
+        }
+
+        if (1 != json_equal (ct,
                              osr->details.paid.contract_terms))
         {
           GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -168,6 +248,8 @@ merchant_get_order_cb (
           TALER_TESTING_interpreter_fail (gos->is);
           return;
         }
+
+        json_decref (ct);
       }
       if (gos->wired != osr->details.paid.wired)
       {
@@ -437,6 +519,9 @@ merchant_get_order_cleanup (void *cls,
   GNUNET_array_grow (gos->refunds,
                      gos->refunds_length,
                      0);
+  GNUNET_array_grow (gos->forgets,
+                     gos->forgets_length,
+                     0);
   GNUNET_free (gos);
 }
 
@@ -518,6 +603,9 @@ TALER_TESTING_cmd_merchant_get_order (const char *label,
  *        refunds (commands) we expect to be aggregated in the order
  *        (assuming @a http_code is #MHD_HTTP_OK). If @e refunded is false,
  *        this parameter is ignored.
+ * @param forgets a NULL-terminated list of references to forget commands
+ *        that apply to the order we are querying. If NULL, this is
+ *        interpreted as no forgets are expected.
  * @param http_status expected HTTP response code for the request.
  */
 struct TALER_TESTING_Command
@@ -529,6 +617,7 @@ TALER_TESTING_cmd_merchant_get_order2 (const char *label,
                                        const char **transfers,
                                        bool refunded,
                                        const char **refunds,
+                                       const char **forgets,
                                        unsigned int http_status)
 {
   struct MerchantGetOrderState *gos;
@@ -544,6 +633,8 @@ TALER_TESTING_cmd_merchant_get_order2 (const char *label,
   gos->transfers_length = 0;
   gos->refunds = NULL;
   gos->refunds_length = 0;
+  gos->forgets = NULL;
+  gos->forgets_length = 0;
   if (wired)
   {
     for (const char **clabel = transfers; *clabel != NULL; ++clabel)
@@ -562,6 +653,15 @@ TALER_TESTING_cmd_merchant_get_order2 (const char *label,
                            *clabel);
     }
   }
+  if (NULL != forgets)
+  {
+    for (const char **clabel = forgets; *clabel != NULL; ++clabel)
+    {
+      GNUNET_array_append (gos->forgets,
+                           gos->forgets_length,
+                           *clabel);
+    }
+  }
   {
     struct TALER_TESTING_Command cmd = {
       .cls = gos,

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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