gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] 153/277: fixed test for increase_refund


From: gnunet
Subject: [taler-merchant] 153/277: fixed test for increase_refund
Date: Sun, 05 Jul 2020 20:51:06 +0200

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

grothoff pushed a commit to branch master
in repository merchant.

commit fffdd0cb9bdc5b306599fe64857abbfd713e37cf
Author: Jonathan Buchanan <jonathan.russ.buchanan@gmail.com>
AuthorDate: Sat May 30 01:09:25 2020 -0400

    fixed test for increase_refund
---
 src/backenddb/test_merchantdb.c | 115 ++++++++++++++++++++++++++++++----------
 1 file changed, 86 insertions(+), 29 deletions(-)

diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c
index f03fce3..a834eff 100644
--- a/src/backenddb/test_merchantdb.c
+++ b/src/backenddb/test_merchantdb.c
@@ -3664,7 +3664,7 @@ struct TestRefunds_Closure
   /**
    * The deposit data
    */
-  struct DepositData deposit;
+  struct DepositData deposits[2];
 
   /**
    * The refund data
@@ -3768,49 +3768,86 @@ pre_test_refunds (struct TestRefunds_Closure *cls)
                    GNUNET_JSON_from_time_abs (refund_deadline));
 
   /* Deposit */
-  cls->deposit.timestamp = GNUNET_TIME_absolute_get ();
+  cls->deposits[0].timestamp = GNUNET_TIME_absolute_get ();
   GNUNET_assert (GNUNET_OK ==
                  TALER_JSON_hash (cls->order.contract,
-                                  &cls->deposit.h_contract_terms));
+                                  &cls->deposits[0].h_contract_terms));
   GNUNET_CRYPTO_eddsa_key_create (&coin_priv.eddsa_priv);
   GNUNET_CRYPTO_eddsa_key_get_public (&coin_priv.eddsa_priv,
-                                      &cls->deposit.coin_pub.eddsa_pub);
-  cls->deposit.exchange_url = "test-exchange";
+                                      &cls->deposits[0].coin_pub.eddsa_pub);
+  cls->deposits[0].exchange_url = "test-exchange";
   GNUNET_assert (GNUNET_OK ==
                  TALER_string_to_amount ("EUR:50.00",
-                                         &cls->deposit.amount_with_fee));
+                                         &cls->deposits[0].amount_with_fee));
   GNUNET_assert (GNUNET_OK ==
                  TALER_string_to_amount ("EUR:1.00",
-                                         &cls->deposit.deposit_fee));
+                                         &cls->deposits[0].deposit_fee));
   GNUNET_assert (GNUNET_OK ==
                  TALER_string_to_amount ("EUR:1.50",
-                                         &cls->deposit.refund_fee));
+                                         &cls->deposits[0].refund_fee));
   GNUNET_assert (GNUNET_OK ==
                  TALER_string_to_amount ("EUR:2.00",
-                                         &cls->deposit.wire_fee));
-  cls->deposit.h_wire = cls->account.h_wire;
-  deposit_sign.h_contract_terms = cls->deposit.h_contract_terms;
-  deposit_sign.h_wire = cls->deposit.h_wire;
+                                         &cls->deposits[0].wire_fee));
+  cls->deposits[0].h_wire = cls->account.h_wire;
+  deposit_sign.h_contract_terms = cls->deposits[0].h_contract_terms;
+  deposit_sign.h_wire = cls->deposits[0].h_wire;
   deposit_sign.wallet_timestamp = GNUNET_TIME_absolute_hton (
     GNUNET_TIME_absolute_get ());
   deposit_sign.refund_deadline = GNUNET_TIME_absolute_hton (
     GNUNET_TIME_absolute_get ());
   TALER_amount_hton (&deposit_sign.amount_with_fee,
-                     &cls->deposit.amount_with_fee);
+                     &cls->deposits[0].amount_with_fee);
   TALER_amount_hton (&deposit_sign.deposit_fee,
-                     &cls->deposit.deposit_fee);
+                     &cls->deposits[0].deposit_fee);
   deposit_sign.merchant = cls->merchant_pub;
-  deposit_sign.coin_pub = cls->deposit.coin_pub;
+  deposit_sign.coin_pub = cls->deposits[0].coin_pub;
   GNUNET_CRYPTO_eddsa_sign (&cls->exchange_priv.eddsa_priv,
                             &deposit_sign,
-                            &cls->deposit.exchange_sig.eddsa_signature);
+                            &cls->deposits[0].exchange_sig.eddsa_signature);
+
+  cls->deposits[1].timestamp = GNUNET_TIME_absolute_get ();
+  GNUNET_assert (GNUNET_OK ==
+                 TALER_JSON_hash (cls->order.contract,
+                                  &cls->deposits[1].h_contract_terms));
+  GNUNET_CRYPTO_eddsa_key_create (&coin_priv.eddsa_priv);
+  GNUNET_CRYPTO_eddsa_key_get_public (&coin_priv.eddsa_priv,
+                                      &cls->deposits[1].coin_pub.eddsa_pub);
+  cls->deposits[1].exchange_url = "test-exchange";
+  GNUNET_assert (GNUNET_OK ==
+                 TALER_string_to_amount ("EUR:21.00",
+                                         &cls->deposits[1].amount_with_fee));
+  GNUNET_assert (GNUNET_OK ==
+                 TALER_string_to_amount ("EUR:1.00",
+                                         &cls->deposits[1].deposit_fee));
+  GNUNET_assert (GNUNET_OK ==
+                 TALER_string_to_amount ("EUR:1.50",
+                                         &cls->deposits[1].refund_fee));
+  GNUNET_assert (GNUNET_OK ==
+                 TALER_string_to_amount ("EUR:2.00",
+                                         &cls->deposits[1].wire_fee));
+  cls->deposits[1].h_wire = cls->account.h_wire;
+  deposit_sign.h_contract_terms = cls->deposits[1].h_contract_terms;
+  deposit_sign.h_wire = cls->deposits[1].h_wire;
+  deposit_sign.wallet_timestamp = GNUNET_TIME_absolute_hton (
+    GNUNET_TIME_absolute_get ());
+  deposit_sign.refund_deadline = GNUNET_TIME_absolute_hton (
+    GNUNET_TIME_absolute_get ());
+  TALER_amount_hton (&deposit_sign.amount_with_fee,
+                     &cls->deposits[1].amount_with_fee);
+  TALER_amount_hton (&deposit_sign.deposit_fee,
+                     &cls->deposits[1].deposit_fee);
+  deposit_sign.merchant = cls->merchant_pub;
+  deposit_sign.coin_pub = cls->deposits[1].coin_pub;
+  GNUNET_CRYPTO_eddsa_sign (&cls->exchange_priv.eddsa_priv,
+                            &deposit_sign,
+                            &cls->deposits[1].exchange_sig.eddsa_signature);
 
   /* Refund */
   cls->refund.timestamp = GNUNET_TIME_absolute_get ();
   cls->refund.reason = "some reason";
-  cls->refund.refund_amount = cls->deposit.amount_with_fee;
-  cls->refund.coin_pub = &cls->deposit.coin_pub;
-  cls->refund.exchange_url = cls->deposit.exchange_url;
+  cls->refund.refund_amount = cls->deposits[0].amount_with_fee;
+  cls->refund.coin_pub = &cls->deposits[0].coin_pub;
+  cls->refund.exchange_url = cls->deposits[0].exchange_url;
 
   /* Refund proof */
   GNUNET_assert (GNUNET_OK ==
@@ -3868,12 +3905,26 @@ run_test_refunds (struct TestRefunds_Closure *cls)
   /* Insert a deposit */
   TEST_RET_ON_FAIL (test_insert_deposit (cls->is.id,
                                          &cls->exchange_pub,
-                                         &cls->deposit));
+                                         &cls->deposits[0]));
+  TEST_RET_ON_FAIL (test_insert_deposit (cls->is.id,
+                                         &cls->exchange_pub,
+                                         &cls->deposits[1]));
+
+  /* Mark as paid */
+  if (1 != plugin->mark_contract_paid (plugin->cls,
+                                       cls->is.id,
+                                       &cls->deposits[0].h_contract_terms,
+                                       "test_orders_session"))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Mark contract as paid failed\n");
+    return 1;
+  }
 
   /* Test refund coin */
   if (1 != plugin->refund_coin (plugin->cls,
                                 cls->is.id,
-                                &cls->deposit.h_contract_terms,
+                                &cls->deposits[0].h_contract_terms,
                                 cls->refund.timestamp,
                                 cls->refund.coin_pub,
                                 cls->refund.reason))
@@ -3885,14 +3936,15 @@ run_test_refunds (struct TestRefunds_Closure *cls)
 
   /* Test lookup refunds */
   TEST_RET_ON_FAIL (test_lookup_refunds (cls->is.id,
-                                         &cls->deposit.h_contract_terms,
+                                         &cls->deposits[0].h_contract_terms,
                                          1,
                                          cls->refund.coin_pub,
-                                         &cls->deposit.amount_with_fee));
+                                         &cls->refund.refund_amount));
 
   /* Test lookup refunds detailed */
   TEST_RET_ON_FAIL (test_lookup_refunds_detailed (cls->is.id,
-                                                  
&cls->deposit.h_contract_terms,
+                                                  &cls->deposits[0].
+                                                  h_contract_terms,
                                                   1,
                                                   &cls->refund));
 
@@ -3911,18 +3963,23 @@ run_test_refunds (struct TestRefunds_Closure *cls)
   /* Test increase refund */
   struct TALER_Amount inc;
   GNUNET_assert (GNUNET_OK ==
-                 TALER_string_to_amount ("EUR:50.00",
+                 TALER_string_to_amount ("EUR:1.00",
                                          &inc));
   if (1 != plugin->increase_refund (plugin->cls,
                                     cls->is.id,
                                     cls->order.id,
                                     &inc,
                                     "more"))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Increase refund failed\n");
+    return 1;
+  }
 
-    /* Test lookup refund proof */
-    TEST_RET_ON_FAIL (test_lookup_refund_proof (1,
-                                                
&cls->refund_proof.exchange_sig,
-                                                &cls->exchange_pub));
+  /* Test lookup refund proof */
+  TEST_RET_ON_FAIL (test_lookup_refund_proof (1,
+                                              &cls->refund_proof.exchange_sig,
+                                              &cls->exchange_pub));
 
   return 0;
 }

-- 
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]