[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-merchant] 152/277: wrote db tests for tips/lookups
From: |
gnunet |
Subject: |
[taler-merchant] 152/277: wrote db tests for tips/lookups |
Date: |
Sun, 05 Jul 2020 20:51:05 +0200 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository merchant.
commit 6ad48a9a799f64f296de2c49999aefb37a69d5d0
Author: Jonathan Buchanan <jonathan.russ.buchanan@gmail.com>
AuthorDate: Sat May 30 00:45:39 2020 -0400
wrote db tests for tips/lookups
---
src/backenddb/test_merchantdb.c | 272 +++++++++++++++++++++++++++++++++++++++-
1 file changed, 268 insertions(+), 4 deletions(-)
diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c
index 70e20a6..f03fce3 100644
--- a/src/backenddb/test_merchantdb.c
+++ b/src/backenddb/test_merchantdb.c
@@ -2956,6 +2956,259 @@ test_lookup_reserves (const char *instance_id,
}
+static int
+test_lookup_tip (const char *instance_id,
+ const struct GNUNET_HashCode *tip_id,
+ const struct TALER_Amount *expected_total_authorized,
+ const struct TALER_Amount *expected_total_picked_up,
+ const struct GNUNET_TIME_Absolute *expected_expiration,
+ const char *expected_exchange_url,
+ const struct TALER_ReservePrivateKeyP *expected_reserve_priv)
+{
+ struct TALER_Amount total_authorized;
+ struct TALER_Amount total_picked_up;
+ struct GNUNET_TIME_Absolute expiration;
+ char *exchange_url;
+ struct TALER_ReservePrivateKeyP reserve_priv;
+ if (1 != plugin->lookup_tip (plugin->cls,
+ instance_id,
+ tip_id,
+ &total_authorized,
+ &total_picked_up,
+ &expiration,
+ &exchange_url,
+ &reserve_priv))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Lookup tip failed\n");
+ if (NULL != exchange_url)
+ GNUNET_free (exchange_url);
+ return 1;
+ }
+ if ((GNUNET_OK != TALER_amount_cmp_currency (expected_total_authorized,
+ &total_authorized)) ||
+ (0 != TALER_amount_cmp (expected_total_authorized,
+ &total_authorized)) ||
+ (GNUNET_OK != TALER_amount_cmp_currency (expected_total_picked_up,
+ &total_picked_up)) ||
+ (0 != TALER_amount_cmp (expected_total_picked_up,
+ &total_picked_up)) ||
+ (expected_expiration->abs_value_us != expiration.abs_value_us) ||
+ (0 != strcmp (expected_exchange_url,
+ exchange_url)) ||
+ (0 != GNUNET_memcmp (expected_reserve_priv,
+ &reserve_priv)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Lookup tip failed: mismatched data\n");
+ if (NULL != exchange_url)
+ GNUNET_free (exchange_url);
+ return 1;
+ }
+ if (NULL != exchange_url)
+ GNUNET_free (exchange_url);
+ return 0;
+}
+
+
+static int
+test_lookup_tip_details (const char *instance_id,
+ const struct GNUNET_HashCode tip_id,
+ const struct TALER_Amount *expected_total_authorized,
+ const struct TALER_Amount *expected_total_picked_up,
+ const char *expected_justification,
+ const struct GNUNET_TIME_Absolute
*expected_expiration,
+ const struct
+ TALER_ReservePublicKeyP *expected_reserve_pub,
+ unsigned int expected_pickups_length,
+ const struct
+ TALER_MERCHANTDB_PickupDetails *expected_pickups)
+{
+ struct TALER_Amount total_authorized;
+ struct TALER_Amount total_picked_up;
+ char *justification = NULL;
+ struct GNUNET_TIME_Absolute expiration;
+ struct TALER_ReservePublicKeyP reserve_pub;
+ unsigned int pickups_length;
+ struct TALER_MERCHANTDB_PickupDetails *pickups = NULL;
+ unsigned int results_matching[expected_pickups_length];
+ if (TALER_EC_NONE != plugin->lookup_tip_details (plugin->cls,
+ instance_id,
+ tip_id,
+ true,
+ &total_authorized,
+ &total_picked_up,
+ &justification,
+ &expiration,
+ &reserve_pub,
+ &pickups_length,
+ &pickups))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Lookup tip details failed\n");
+ if (NULL != justification)
+ GNUNET_free (justification);
+ if (NULL != pickups)
+ GNUNET_free (pickups);
+ return 1;
+ }
+ if ((GNUNET_OK != TALER_amount_cmp_currency (expected_total_authorized,
+ &total_authorized)) ||
+ (0 != TALER_amount_cmp (expected_total_authorized,
+ &total_authorized)) ||
+ (GNUNET_OK != TALER_amount_cmp_currency (expected_total_picked_up,
+ &total_picked_up)) ||
+ (0 != TALER_amount_cmp (expected_total_picked_up,
+ &total_picked_up)) ||
+ (0 != strcmp (expected_justification,
+ justification)) ||
+ (expected_expiration->abs_value_us != expiration.abs_value_us) ||
+ (0 != GNUNET_memcmp (expected_reserve_pub,
+ &reserve_pub)) ||
+ (expected_pickups_length != pickups_length))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Lookup tip details failed: mismatched data\n");
+ if (NULL != justification)
+ GNUNET_free (justification);
+ if (NULL != pickups)
+ GNUNET_free (pickups);
+ return 1;
+ }
+ memset (results_matching, 0, sizeof (unsigned int) *
expected_pickups_length);
+ for (unsigned int i = 0; expected_pickups_length > i; ++i)
+ {
+ for (unsigned int j = 0; pickups_length > j; ++j)
+ {
+ /* Compare expected_pickups[i] with pickups[j] */
+ if ((0 == GNUNET_memcmp (&expected_pickups[i].pickup_id,
+ &pickups[j].pickup_id)) &&
+ (GNUNET_OK == TALER_amount_cmp_currency (
+ &expected_pickups[i].requested_amount,
+ &pickups[j].requested_amount))
+ &&
+ (0 == TALER_amount_cmp (&expected_pickups[i].requested_amount,
+ &pickups[j].requested_amount)) &&
+ (GNUNET_OK == TALER_amount_cmp_currency (
+ &expected_pickups[i].exchange_amount,
+ &pickups[j].requested_amount))
+ &&
+ (0 == TALER_amount_cmp (&expected_pickups[i].exchange_amount,
+ &pickups[j].exchange_amount)) &&
+ (expected_pickups[i].num_planchets == pickups[j].num_planchets))
+ {
+ results_matching[i] += 1;
+ }
+ }
+ }
+ for (unsigned int i = 0; expected_pickups_length > i; ++i)
+ {
+ if (1 != results_matching[i])
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Lookup tip details failed: mismatched data\n");
+ if (NULL != justification)
+ GNUNET_free (justification);
+ if (NULL != pickups)
+ GNUNET_free (pickups);
+ return 1;
+ }
+ }
+ return 0;
+}
+
+
+static void
+free_rsa_signature_array (unsigned int sigs_length,
+ struct GNUNET_CRYPTO_RsaSignature **sigs)
+{
+ for (unsigned int i = 0; sigs_length > i; ++i)
+ {
+ if (NULL != sigs[i])
+ GNUNET_free (sigs[i]);
+ }
+}
+
+
+static int
+test_lookup_pickup (const char *instance_id,
+ const struct GNUNET_HashCode *tip_id,
+ const struct GNUNET_HashCode *pickup_id,
+ const char *expected_exchange_url,
+ const struct
+ TALER_ReservePrivateKeyP *expected_reserve_priv,
+ unsigned int expected_sigs_length,
+ const struct GNUNET_CRYPTO_RsaSignature **expected_sigs)
+{
+ char *exchange_url = NULL;
+ struct TALER_ReservePrivateKeyP reserve_priv;
+ struct GNUNET_CRYPTO_RsaSignature *sigs[expected_sigs_length];
+ unsigned int results_matching[expected_sigs_length];
+ memset (sigs,
+ 0,
+ sizeof (struct GNUNET_CRYPTO_RsaSignature *) * expected_sigs_length);
+ if (1 != plugin->lookup_pickup (plugin->cls,
+ instance_id,
+ tip_id,
+ pickup_id,
+ &exchange_url,
+ &reserve_priv,
+ expected_sigs_length,
+ sigs))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Lookup pickup failed\n");
+ if (NULL != exchange_url)
+ GNUNET_free (exchange_url);
+ free_rsa_signature_array (expected_sigs_length,
+ sigs);
+ return 1;
+ }
+ if ((0 != strcmp (expected_exchange_url,
+ exchange_url)) ||
+ (0 != GNUNET_memcmp (expected_reserve_priv,
+ &reserve_priv)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Lookup pickup failed: mismatched data\n");
+ if (NULL != exchange_url)
+ GNUNET_free (exchange_url);
+ free_rsa_signature_array (expected_sigs_length,
+ sigs);
+ return 1;
+ }
+ memset (results_matching,
+ 0,
+ sizeof (unsigned int) * expected_sigs_length);
+ for (unsigned int i = 0; expected_sigs_length > i; ++i)
+ {
+ for (unsigned int j = 0; expected_sigs_length > j; ++j)
+ {
+ /* compare expected_sigs[i] to sigs[j] */
+ if (0 == GNUNET_CRYPTO_rsa_signature_cmp (expected_sigs[i],
+ sigs[j]))
+ {
+ results_matching[i] += 1;
+ }
+ }
+ }
+ for (unsigned int i = 0; expected_sigs_length > i; ++i)
+ {
+ if (1 != results_matching[i])
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Lookup pickup failed: mismatched data\n");
+ if (NULL != exchange_url)
+ GNUNET_free (exchange_url);
+ free_rsa_signature_array (expected_sigs_length,
+ sigs);
+ return 1;
+ }
+ }
+ return 0;
+}
+
+
struct TestTips_Closure
{
/**
@@ -3655,10 +3908,21 @@ run_test_refunds (struct TestRefunds_Closure *cls)
return 1;
}
- /* Test lookup refund proof */
- TEST_RET_ON_FAIL (test_lookup_refund_proof (1,
- &cls->refund_proof.exchange_sig,
- &cls->exchange_pub));
+ /* Test increase refund */
+ struct TALER_Amount inc;
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount ("EUR:50.00",
+ &inc));
+ if (1 != plugin->increase_refund (plugin->cls,
+ cls->is.id,
+ cls->order.id,
+ &inc,
+ "more"))
+
+ /* 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.
- [taler-merchant] 158/277: work on tip APIs, (continued)
- [taler-merchant] 158/277: work on tip APIs, gnunet, 2020/07/05
- [taler-merchant] 156/277: implement lookup tip details, gnunet, 2020/07/05
- [taler-merchant] 159/277: add POST /tips logic, gnunet, 2020/07/05
- [taler-merchant] 164/277: fixed db test building and added test for wire fee storage, gnunet, 2020/07/05
- [taler-merchant] 163/277: implement filter, gnunet, 2020/07/05
- [taler-merchant] 165/277: add logic for activation of reserves to merchant backend DB, gnunet, 2020/07/05
- [taler-merchant] 147/277: added more tests for contract terms, deposits, and transfers, gnunet, 2020/07/05
- [taler-merchant] 160/277: address DB fixes for missing EC values, gnunet, 2020/07/05
- [taler-merchant] 157/277: fix DB use, gnunet, 2020/07/05
- [taler-merchant] 166/277: SQL fixing, gnunet, 2020/07/05
- [taler-merchant] 152/277: wrote db tests for tips/lookups,
gnunet <=
- [taler-merchant] 145/277: refactored the existing product and order tests, gnunet, 2020/07/05
- [taler-merchant] 171/277: tests/fixes for tips and pickups in backenddb, gnunet, 2020/07/05
- [taler-merchant] 169/277: implement POST /private/reserves, gnunet, 2020/07/05
- [taler-merchant] 161/277: fix misc issues in client APIs, gnunet, 2020/07/05
- [taler-merchant] 162/277: implement GET /reserves/RPUB, gnunet, 2020/07/05
- [taler-merchant] 170/277: implement POST /private/reserves, gnunet, 2020/07/05
- [taler-merchant] 175/277: avoid amount_zero, use DEFAULT instead, gnunet, 2020/07/05
- [taler-merchant] 174/277: new backenddb APIs for GET /private/orders/ID, gnunet, 2020/07/05
- [taler-merchant] 168/277: implement GET /reserves/RESERVE_ID, gnunet, 2020/07/05
- [taler-merchant] 167/277: implement TALER_MERCHANT_reserves_get(), gnunet, 2020/07/05