summaryrefslogtreecommitdiff
path: root/src/backenddb
diff options
context:
space:
mode:
authorJonathan Buchanan <jonathan.russ.buchanan@gmail.com>2020-05-30 00:45:39 -0400
committerJonathan Buchanan <jonathan.russ.buchanan@gmail.com>2020-05-30 00:45:39 -0400
commit6ad48a9a799f64f296de2c49999aefb37a69d5d0 (patch)
tree0f770fd567ad3fb090dc671de27bdf8fac0380b1 /src/backenddb
parentf1e1ff81885ed8605006a351cbde888456bddc09 (diff)
downloadmerchant-6ad48a9a799f64f296de2c49999aefb37a69d5d0.tar.gz
merchant-6ad48a9a799f64f296de2c49999aefb37a69d5d0.tar.bz2
merchant-6ad48a9a799f64f296de2c49999aefb37a69d5d0.zip
wrote db tests for tips/lookups
Diffstat (limited to 'src/backenddb')
-rw-r--r--src/backenddb/test_merchantdb.c272
1 files changed, 268 insertions, 4 deletions
diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c
index 70e20a63..f03fce3b 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;
}