diff options
Diffstat (limited to 'src/backenddb/test_merchantdb.c')
-rw-r--r-- | src/backenddb/test_merchantdb.c | 96 |
1 files changed, 95 insertions, 1 deletions
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; |