merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

commit 47f22f8001969bac389005d5e53e607e426e0ca2
parent 567702d2e63001a0a2bfde6558b9061f27f93978
Author: priscilla <priscilla.huang@efrei.net>
Date:   Mon,  6 Feb 2023 11:00:45 -0500

git pull

Diffstat:
Msrc/backenddb/plugin_merchantdb_postgres.c | 82-------------------------------------------------------------------------------
Msrc/backenddb/test_merchantdb.c | 90+++++++++----------------------------------------------------------------------
2 files changed, 10 insertions(+), 162 deletions(-)

diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c @@ -7535,73 +7535,6 @@ postgres_insert_pending_webhook (void *cls, /** - * Lookup details about a particular pending webhook. - * - * @param cls closure - * @param instance_id instance to lookup webhook for - * @param webhook_serial webhook to lookup - * @param[out] pwb set to the pending webhook details on success, can be NULL - * (in that case we only want to check if the webhook exists) - * @return database result code - */ -static enum GNUNET_DB_QueryStatus -postgres_lookup_pending_webhook (void *cls, - const char *instance_id, - uint64_t *webhook_serial, - struct TALER_MERCHANTDB_PendingWebhookDetails * - pwb) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (instance_id), - GNUNET_PQ_query_param_uint64 (webhook_serial), - GNUNET_PQ_query_param_end - }; - - if (NULL == pwb) - { - struct GNUNET_PQ_ResultSpec rs_null[] = { - GNUNET_PQ_result_spec_end - }; - - check_connection (pg); - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "lookup_pending_webhook", - params, - rs_null); - } - else - { - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_absolute_time ("next_attempt", - &pwb->next_attempt), - GNUNET_PQ_result_spec_uint32 ("retries", - &pwb->retries), - GNUNET_PQ_result_spec_string ("url", - &pwb->url), - GNUNET_PQ_result_spec_string ("http_method", - &pwb->http_method), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_string ("header", - &pwb->header), - NULL), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_string ("body", - &pwb->body), - NULL), - GNUNET_PQ_result_spec_end - }; - - check_connection (pg); - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "lookup_pending_webhook", - params, - rs); - } -} - - -/** * Context used for postgres_lookup_future_webhook(). */ struct LookupPendingWebhookContext @@ -10469,20 +10402,6 @@ postgres_connect (void *cls) " retries=retries+1" ",next_attempt=$2" " WHERE webhook_pending_serial=$1"), - /* for postgres_lookup_pending_webhook(): DELETE? Seems useless... */ - GNUNET_PQ_make_prepare ("lookup_pending_webhook", - "SELECT" - " next_attempt" - ",retries" - ",url" - ",http_method" - ",header" - ",body" - " FROM merchant_pending_webhooks" - " JOIN merchant_instances" - " USING (merchant_serial)" - " WHERE merchant_instances.merchant_id=$1" - " AND merchant_pending_webhooks.webhook_serial=$2"), /* for postgres_lookup_pending_webhooks() */ GNUNET_PQ_make_prepare ("lookup_pending_webhooks", "SELECT" @@ -10686,7 +10605,6 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) plugin->delete_webhook = &postgres_delete_webhook; plugin->insert_webhook = &postgres_insert_webhook; plugin->update_webhook = &postgres_update_webhook; - plugin->lookup_pending_webhook = &postgres_lookup_pending_webhook; plugin->lookup_webhook_by_event = &postgres_lookup_webhook_by_event; plugin->lookup_all_webhooks = &postgres_lookup_all_webhooks; plugin->lookup_future_webhook = &postgres_lookup_future_webhook; diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c @@ -7806,6 +7806,11 @@ test_webhooks (void) */ struct PendingWebhookData { + /* + * webhook_pending_serial from SQL TABLE. + */ + uint64_t webhook_pending_serial; + /** * Reference to the configured webhook template. */ @@ -7839,39 +7844,6 @@ make_pending_webhook (uint64_t webhook_serial, /** - * Compare two pending webhooks for equality. - * - * @param a the first pending webhook. - * @param b the second pending webhook. - * @return 0 on equality, 1 otherwise. - */ -static int -check_pending_webhooks_equal (const struct - TALER_MERCHANTDB_PendingWebhookDetails *a, - const struct - TALER_MERCHANTDB_PendingWebhookDetails *b) -{ - if (GNUNET_TIME_absolute_cmp (a->next_attempt, - !=, - b->next_attempt) || - (a->retries != b->retries) || - (0 != strcmp (a->url, - b->url)) || - (0 != strcmp (a->http_method, - b->http_method)) || - (0 != strcmp (a->header, - b->header)) || - (0 != strcmp (a->body, - b->body))) - { - fprintf (stdout, " retries %d vs %d", a->retries, b->retries); - return 1; - } - return 0; -} - - -/** * Tests inserting pending webhook data into the database. * * @param instance the instance to insert the pending webhook for. @@ -7888,8 +7860,7 @@ test_insert_pending_webhook (const struct InstanceData *instance, TEST_COND_RET_ON_FAIL (expected_result == plugin->insert_pending_webhook (plugin->cls, instance->instance.id, - pwebhook-> - webhook_serial, + pwebhook->webhook_serial, pwebhook->pwebhook.url, pwebhook->pwebhook. http_method, @@ -7916,8 +7887,7 @@ test_update_pending_webhook (const struct InstanceData *instance, { TEST_COND_RET_ON_FAIL (expected_result == plugin->update_pending_webhook (plugin->cls, - pwebhook-> - webhook_serial, + pwebhook->webhook_serial, pwebhook->pwebhook. next_attempt), "Update pending webhook failed\n"); @@ -7925,43 +7895,6 @@ test_update_pending_webhook (const struct InstanceData *instance, } -/** - * Tests looking up a pending webhook from the db. - * - * @param instance the instance to query from. - * @param pwebhook the pending webhook to query and compare to. - * @return 0 when successful, 1 otherwise. - */ -static int -test_lookup_pending_webhook (const struct InstanceData *instance, - struct PendingWebhookData *pwebhook) -{ - struct TALER_MERCHANTDB_PendingWebhookDetails lookup_result; - if (0 > plugin->lookup_pending_webhook (plugin->cls, - instance->instance.id, - &pwebhook->webhook_serial, - &lookup_result)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Lookup pending webhook failed\n"); - TALER_MERCHANTDB_pending_webhook_details_free (&lookup_result); - return 1; - } - const struct TALER_MERCHANTDB_PendingWebhookDetails *to_cmp = - &pwebhook->pwebhook; - if (0 != check_pending_webhooks_equal (&lookup_result, - to_cmp)) - { - GNUNET_break (0); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Lookup pending webhook failed: incorrect pending webhook returned\n"); - TALER_MERCHANTDB_pending_webhook_details_free (&lookup_result); - return 1; - } - TALER_MERCHANTDB_pending_webhook_details_free (&lookup_result); - return 0; -} - /** * Closure for testing pending webhook lookup @@ -8180,12 +8113,12 @@ test_lookup_all_webhooks (const struct InstanceData *instance, * @return 0 when successful, 1 otherwise. */ static int -test_delete_pending_webhook (const struct PendingWebhookData *webhook, +test_delete_pending_webhook (uint64_t webhook_pending_serial, enum GNUNET_DB_QueryStatus expected_result) { TEST_COND_RET_ON_FAIL (expected_result == plugin->delete_pending_webhook (plugin->cls, - webhook->webhook_serial), + webhook_pending_serial), "Delete webhook failed\n"); return 0; } @@ -8267,9 +8200,6 @@ run_test_pending_webhooks (struct TestPendingWebhooks_Closure *cls) TEST_RET_ON_FAIL (test_insert_pending_webhook (&cls->instance, &cls->pwebhooks[0], GNUNET_DB_STATUS_SUCCESS_ONE_RESULT)); - /* Test lookup of individual pending webhook */ - TEST_RET_ON_FAIL (test_lookup_pending_webhook (&cls->instance, - &cls->pwebhooks[0])); /* Test pending webhook update */ cls->pwebhooks[0].pwebhook.next_attempt = GNUNET_TIME_absolute_get (); @@ -8344,7 +8274,7 @@ run_tests (void) TEST_RET_ON_FAIL (test_kyc ()); TEST_RET_ON_FAIL (test_templates ()); TEST_RET_ON_FAIL (test_webhooks ()); - // TEST_RET_ON_FAIL (test_pending_webhooks ()); + TEST_RET_ON_FAIL (test_pending_webhooks ()); return 0; }