summaryrefslogtreecommitdiff
path: root/src/backenddb
diff options
context:
space:
mode:
authorJonathan Buchanan <jonathan.russ.buchanan@gmail.com>2020-06-13 02:04:35 -0400
committerJonathan Buchanan <jonathan.russ.buchanan@gmail.com>2020-06-13 02:04:35 -0400
commitf0411396fada5862ce16b56dc57513b9aa79b706 (patch)
treecf5bffc007682d6722ca759040e4d616973f8658 /src/backenddb
parentae2bfdbeaaa2ef289e79c0b57c428672a8157ff0 (diff)
downloadmerchant-f0411396fada5862ce16b56dc57513b9aa79b706.tar.gz
merchant-f0411396fada5862ce16b56dc57513b9aa79b706.tar.bz2
merchant-f0411396fada5862ce16b56dc57513b9aa79b706.zip
more backenddb tests
Diffstat (limited to 'src/backenddb')
-rw-r--r--src/backenddb/plugin_merchantdb_postgres.c42
-rw-r--r--src/backenddb/test_merchantdb.c96
2 files changed, 127 insertions, 11 deletions
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c
index 0f338ff1..a6c10413 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -2024,11 +2024,6 @@ postgres_lookup_payment_status (void *cls,
uint8_t paid8;
uint8_t wired8;
enum GNUNET_DB_QueryStatus qs;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&order_serial),
- GNUNET_PQ_query_param_string (session_id),
- GNUNET_PQ_query_param_end
- };
struct GNUNET_PQ_ResultSpec rs[] = {
GNUNET_PQ_result_spec_auto_from_type ("paid",
&paid8),
@@ -2036,12 +2031,32 @@ postgres_lookup_payment_status (void *cls,
&wired8),
GNUNET_PQ_result_spec_end
};
-
check_connection (pg);
- qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "lookup_payment_status",
- params,
- rs);
+ if (NULL == session_id)
+ {
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&order_serial),
+ GNUNET_PQ_query_param_end
+ };
+
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "lookup_payment_status",
+ params,
+ rs);
+ }
+ else
+ {
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&order_serial),
+ GNUNET_PQ_query_param_string (session_id),
+ GNUNET_PQ_query_param_end
+ };
+
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "lookup_payment_status_session_id",
+ params,
+ rs);
+ }
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
{
*paid = (0 != paid8);
@@ -6918,6 +6933,13 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
" wired"
",paid"
" FROM merchant_contract_terms"
+ " WHERE order_serial=$1",
+ 1),
+ GNUNET_PQ_make_prepare ("lookup_payment_status_session_id",
+ "SELECT"
+ " wired"
+ ",paid"
+ " FROM merchant_contract_terms"
" WHERE order_serial=$1"
" AND session_id=$2",
2),
diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c
index 43208e89..c9c32404 100644
--- a/src/backenddb/test_merchantdb.c
+++ b/src/backenddb/test_merchantdb.c
@@ -1132,7 +1132,8 @@ test_lookup_orders (const struct InstanceData *instance,
if (false == cls.results_match[i])
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Lookup orders failed: mismatched data\n");
+ "Lookup orders failed: mismatched data (index %d)\n",
+ i);
return 1;
}
}
@@ -1269,6 +1270,67 @@ test_lookup_order_status (const struct InstanceData *instance,
}
+static int
+test_lookup_order_by_fulfillment (const struct InstanceData *instance,
+ const struct OrderData *order,
+ const char *session_id)
+{
+ char *order_id;
+ const char *fulfillment_url =
+ json_string_value (json_object_get (order->contract,
+ "fulfillment_url"));
+ GNUNET_assert (NULL != fulfillment_url);
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ plugin->lookup_order_by_fulfillment (plugin->cls,
+ instance->instance.id,
+ fulfillment_url,
+ session_id,
+ &order_id))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Lookup order by fulfillment failed\n");
+ GNUNET_free (order_id);
+ return 1;
+ }
+ if (0 != strcmp (order->id,
+ order_id))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Lookup order by fulfillment failed\n");
+ GNUNET_free (order_id);
+ return 1;
+ }
+ GNUNET_free (order_id);
+ return 0;
+}
+
+
+static int
+test_lookup_payment_status (uint64_t order_id,
+ const char *session_id,
+ bool expected_paid,
+ bool expected_wired)
+{
+ bool paid;
+ bool wired;
+ TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
+ plugin->lookup_payment_status (plugin->cls,
+ order_id,
+ session_id,
+ &paid,
+ &wired),
+ "Lookup payment status failed\n");
+ if ((expected_paid != paid) ||
+ (expected_wired != wired))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Lookup payment status failed\n");
+ return 1;
+ }
+ return 0;
+}
+
+
/**
* Closure for order tests.
*/
@@ -1407,6 +1469,11 @@ run_test_orders (struct TestOrders_Closure *cls)
TEST_RET_ON_FAIL (test_lookup_order_status (&cls->instance,
&cls->orders[0],
false));
+ /* Test lookup payment status */
+ TEST_RET_ON_FAIL (test_lookup_payment_status (1,
+ NULL,
+ false,
+ false));
/* Test lookup order status fails for nonexistent order */
{
struct GNUNET_HashCode h_contract_terms;
@@ -1427,6 +1494,18 @@ run_test_orders (struct TestOrders_Closure *cls)
TEST_RET_ON_FAIL (test_mark_contract_paid (&cls->instance,
&cls->orders[0],
GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
+ TEST_RET_ON_FAIL (test_lookup_payment_status (1,
+ NULL,
+ true,
+ false));
+ TEST_RET_ON_FAIL (test_lookup_payment_status (1,
+ "test_orders_session",
+ true,
+ false));
+ /* Test lookup order by fulfillment */
+ TEST_RET_ON_FAIL (test_lookup_order_by_fulfillment (&cls->instance,
+ &cls->orders[0],
+ "test_orders_session"));
/* Test mark as paid fails for nonexistent order */
TEST_RET_ON_FAIL (test_mark_contract_paid (&cls->instance,
&cls->orders[1],
@@ -4220,6 +4299,21 @@ run_test_lookup_orders_all_filters (struct
&filter_dec,
8,
expected_orders));
+ /* */
+ filter_inc.paid = TALER_EXCHANGE_YNA_NO;
+ for (unsigned int i = 0; i < 8; ++i)
+ expected_orders[i] = cls->orders[(2 * i) + 1];
+ TEST_RET_ON_FAIL (test_lookup_orders (&cls->instance,
+ &filter_inc,
+ 8,
+ expected_orders));
+ filter_dec.paid = TALER_EXCHANGE_YNA_NO;
+ reverse_order_data_array (8,
+ expected_orders);
+ TEST_RET_ON_FAIL (test_lookup_orders (&cls->instance,
+ &filter_dec,
+ 8,
+ expected_orders));
/* lookup_orders_inc_refunded */
filter_inc.paid = TALER_EXCHANGE_YNA_ALL;
filter_inc.refunded = TALER_EXCHANGE_YNA_YES;