gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-merchant] branch master updated: Refund corner case.


From: gnunet
Subject: [GNUnet-SVN] [taler-merchant] branch master updated: Refund corner case.
Date: Tue, 22 May 2018 10:02:58 +0200

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

marcello pushed a commit to branch master
in repository merchant.

The following commit(s) were added to refs/heads/master by this push:
     new 16d26b2  Refund corner case.
16d26b2 is described below

commit 16d26b2b4c34ff3a8227f37845b3433af9b78e33
Author: Marcello Stanisci <address@hidden>
AuthorDate: Tue May 22 10:02:00 2018 +0200

    Refund corner case.
    
    Trying to pick up a refund from a regularly paid
    contract that was never refund-increased in the
    first place.
---
 src/include/taler_merchant_testing_lib.h |  11 ++++
 src/lib/test_merchant_api_new.c          | 102 ++++++++++++++++++++++++++++---
 src/lib/testing_api_cmd_refund.c         |  59 +++++++++++++++---
 3 files changed, 155 insertions(+), 17 deletions(-)

diff --git a/src/include/taler_merchant_testing_lib.h 
b/src/include/taler_merchant_testing_lib.h
index 97e03d9..357a223 100644
--- a/src/include/taler_merchant_testing_lib.h
+++ b/src/include/taler_merchant_testing_lib.h
@@ -222,6 +222,17 @@ TALER_TESTING_cmd_refund_lookup
    const char *order_id,
    unsigned int http_code);
 
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_refund_lookup_with_amount
+  (const char *label,
+   const char *merchant_url,
+   struct GNUNET_CURL_Context *ctx,
+   const char *increase_reference,
+   const char *pay_reference,
+   const char *order_id,
+   unsigned int http_code,
+   const char *refund_amount);
+
 
 /**
  * FIXME
diff --git a/src/lib/test_merchant_api_new.c b/src/lib/test_merchant_api_new.c
index 83e565b..6d5ed02 100644
--- a/src/lib/test_merchant_api_new.c
+++ b/src/lib/test_merchant_api_new.c
@@ -305,13 +305,14 @@ run (void *cls,
                                10, // start
                                10), // nrows
 
-    TALER_TESTING_cmd_fakebank_transfer ("create-reserve-2",
-                                         "EUR:1",
-                                         fakebank_url,
-                                         USER_ACCOUNT_NO, EXCHANGE_ACCOUNT_NO,
-                                         "user62",
-                                         "pass62",
-                                         EXCHANGE_URL),
+    TALER_TESTING_cmd_fakebank_transfer
+      ("create-reserve-2",
+       "EUR:1",
+       fakebank_url,
+       USER_ACCOUNT_NO, EXCHANGE_ACCOUNT_NO,
+       "user62",
+       "pass62",
+       EXCHANGE_URL),
 
     TALER_TESTING_cmd_fakebank_transfer_with_ref
       ("create-reserve-2b",
@@ -465,6 +466,7 @@ run (void *cls,
        "EUR:0.01",
        MHD_HTTP_OK),
 
+    /* Ordinary refund.  */
     TALER_TESTING_cmd_refund_lookup ("refund-lookup-1",
                                      merchant_url,
                                      is->ctx,
@@ -473,7 +475,7 @@ run (void *cls,
                                      "1",
                                      MHD_HTTP_OK),
 
-    /* Trying to pick up a non existent refund.  */
+    /* Trying to pick up refund from non existent proposal.  */
     TALER_TESTING_cmd_refund_lookup ("refund-lookup-non-existent",
                                      merchant_url,
                                      is->ctx,
@@ -506,6 +508,7 @@ run (void *cls,
                          \"value\":\"{EUR:5}\"} ] }",
         NULL),
 
+    /* Try to increase a non paid proposal.  */
     TALER_TESTING_cmd_refund_increase
       ("refund-increase-unpaid-proposal",
        merchant_url,
@@ -516,6 +519,7 @@ run (void *cls,
        "EUR:0.01",
        MHD_HTTP_BAD_REQUEST),
 
+    /* Try to increase a non existent proposal.  */
     TALER_TESTING_cmd_refund_increase
       ("refund-increase-unpaid-proposal",
        merchant_url,
@@ -526,6 +530,88 @@ run (void *cls,
        "EUR:0.01",
        MHD_HTTP_NOT_FOUND),
 
+    /**
+     * The following block will (1) create a new
+     * reserve, then (2) a proposal, then (3) pay for
+     * it, and finally (4) attempt to pick up a refund 
+     * from it without any increasing taking place
+     * in the first place.
+     **/
+    CMD_TRANSFER_TO_EXCHANGE ("create-reserve-unincreased-refund",
+                              "EUR:5.01"),
+
+    CMD_EXEC_WIREWATCH ("wirewatch-unincreased-refund"),
+
+    TALER_TESTING_cmd_check_bank_transfer
+      ("check_bank_transfer-unincreased-refund",
+       EXCHANGE_URL,
+       "EUR:5.01",
+       USER_ACCOUNT_NO,
+       EXCHANGE_ACCOUNT_NO),
+
+    TALER_TESTING_cmd_withdraw_amount
+      ("withdraw-coin-unincreased-refund",
+       is->exchange,
+       "create-reserve-unincreased-refund",
+       "EUR:5",
+       MHD_HTTP_OK),
+
+    TALER_TESTING_cmd_proposal
+      ("create-proposal-unincreased-refund",
+       merchant_url,
+       is->ctx,
+       MHD_HTTP_OK,
+       "{\"max_fee\":\
+          {\"currency\":\"EUR\",\
+           \"value\":0,\
+           \"fraction\":50000000},\
+        \"order_id\":\"unincreased-proposal\",\
+        \"refund_deadline\":\"\\/Date(0)\\/\",\
+        \"pay_deadline\":\"\\/Date(99999999999)\\/\",\
+        \"amount\":\
+          {\"currency\":\"EUR\",\
+           \"value\":5,\
+           \"fraction\":0},\
+        \"summary\": \"merchant-lib testcase\",\
+        \"fulfillment_url\": \"https://example.com/\",\
+        \"products\": [ {\"description\":\"ice cream\",\
+                         \"value\":\"{EUR:5}\"} ] }",
+        NULL),
+
+    TALER_TESTING_cmd_pay ("pay-unincreased-proposal",
+                           merchant_url,
+                           is->ctx,
+                           MHD_HTTP_OK,
+                           "create-proposal-unincreased-refund",
+                           "withdraw-coin-unincreased-refund",
+                           "EUR:5",
+                           "EUR:4.99",
+                           "EUR:0.01"),
+
+    CMD_EXEC_AGGREGATOR ("run-aggregator-unincreased-refund"),
+
+    TALER_TESTING_cmd_check_bank_transfer
+      ("check_bank_transfer-unincreased-refund",
+       EXCHANGE_URL,
+       "EUR:4.98",
+       EXCHANGE_ACCOUNT_NO,
+       MERCHANT_ACCOUNT_NO),
+
+    /* Actually try to pick up the refund from the
+     * "unincreased proposal".  */
+    TALER_TESTING_cmd_refund_lookup_with_amount
+      ("refund-lookup-unincreased",
+       merchant_url,
+       is->ctx,
+       NULL,
+       "pay-unincreased-proposal",
+       "unincreased-proposal",
+       MHD_HTTP_OK,
+       /* If a lookup is attempted on an unincreased proposal,
+        * the backend will simply respond with a empty refunded
+        * coin "set", but the HTTP response code is 200 OK.  */
+       "EUR:0"),
+
     /* Test tipping.  */
     TALER_TESTING_cmd_fakebank_transfer_with_instance
       ("create-reserve-tip-1",
diff --git a/src/lib/testing_api_cmd_refund.c b/src/lib/testing_api_cmd_refund.c
index 7dc5683..d008f65 100644
--- a/src/lib/testing_api_cmd_refund.c
+++ b/src/lib/testing_api_cmd_refund.c
@@ -68,6 +68,8 @@ struct RefundLookupState
   unsigned int http_code;
 
   struct TALER_TESTING_Interpreter *is;
+
+  const char *refund_amount;
 };
 
 
@@ -314,30 +316,40 @@ refund_lookup_cb (void *cls,
 
   GNUNET_free (coin_reference_dup);
   
-  if (NULL ==
+  if (NULL !=
     (increase_cmd = TALER_TESTING_interpreter_lookup_command
       (rls->is, rls->increase_reference)))
-    TALER_TESTING_FAIL (rls->is);
+  {
+    if (GNUNET_OK != TALER_TESTING_get_trait_amount
+        (increase_cmd, 0, &refund_amount))
+      TALER_TESTING_FAIL (rls->is);
 
-  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 (refund_amount,
-                                           &ra))
-    TALER_TESTING_FAIL (rls->is);
+    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",
-                refund_amount,
+                TALER_amount_to_string (&ra),
                 TALER_amount_to_string (&acc));
     TALER_TESTING_interpreter_fail (rls->is);
     return;
@@ -465,6 +477,35 @@ TALER_TESTING_cmd_refund_lookup
   return cmd;
 }
 
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_refund_lookup_with_amount
+  (const char *label,
+   const char *merchant_url,
+   struct GNUNET_CURL_Context *ctx,
+   const char *increase_reference,
+   const char *pay_reference,
+   const char *order_id,
+   unsigned int http_code,
+   const char *refund_amount)
+{
+  struct RefundLookupState *rls;
+  struct TALER_TESTING_Command cmd;
+
+  rls = GNUNET_new (struct RefundLookupState);
+  rls->merchant_url = merchant_url;
+  rls->ctx = ctx;
+  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;
+
+  cmd.cls = rls;
+  cmd.label = label;
+  cmd.run = &refund_lookup_run;
+  cmd.cleanup = &refund_lookup_cleanup;
 
+  return cmd;
+}
 
 /* end of testing_api_cmd_refund.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]