donau

Donation authority for GNU Taler (experimental)
Log | Files | Refs | Submodules | README | LICENSE

commit 4b3cfa2ad390104a577c5b1bb0feaba97fa4884f
parent 11aea1a7977dceda58a1b8906f812e202dcbb055
Author: Casaburi Johannes <johannes.casaburi@students.bfh.ch>
Date:   Fri, 12 Apr 2024 19:23:41 +0200

added some db tests

Diffstat:
Msrc/donau/donau-httpd_post-charity.c | 10+++++-----
Msrc/donaudb/Makefile.am | 2+-
Dsrc/donaudb/list.txt | 20--------------------
Msrc/donaudb/pg_insert_charity.c | 24++++++++++++------------
Msrc/donaudb/procedures.sql.in | 2+-
Msrc/donaudb/test_donaudb.c | 79+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
6 files changed, 96 insertions(+), 41 deletions(-)

diff --git a/src/donau/donau-httpd_post-charity.c b/src/donau/donau-httpd_post-charity.c @@ -78,7 +78,7 @@ insert_charity (void *cls, &icc->max_per_year, &icc->receipts_to_date, &icc->current_year, - &icc->charity_id); + &icc->charity_id); if (qs <= 0) { if (GNUNET_DB_STATUS_SOFT_ERROR != qs) @@ -153,14 +153,14 @@ DH_handler_charity_post (struct DH_RequestContext *rc, } GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "generated charity id: %lu\n", - icc.charity_id); + "generated charity id: %lu\n", + icc.charity_id); return TALER_MHD_REPLY_JSON_PACK ( rc->connection, MHD_HTTP_CREATED, - GNUNET_JSON_pack_uint64 ("charity-id", - icc.charity_id)); + GNUNET_JSON_pack_uint64 ("charity-id", + icc.charity_id)); } diff --git a/src/donaudb/Makefile.am b/src/donaudb/Makefile.am @@ -126,7 +126,6 @@ libdonaudb_la_LDFLAGS = \ check_PROGRAMS = \ test-donaudb-postgres -AM_TESTS_ENVIRONMENT=export TALER_PREFIX=$${TALER_PREFIX:-@libdir@};export PATH=$${TALER_PREFIX:-@prefix@}/bin:$$PATH; TESTS = \ $(check_SCRIPTS) \ $(check_PROGRAMS) @@ -139,6 +138,7 @@ test_donaudb_postgres_LDADD = \ -ljansson \ -lgnunetjson \ -lgnunetutil \ + -ltalerutil \ -ltalerjson \ -ltalerpq \ $(XLIB) diff --git a/src/donaudb/list.txt b/src/donaudb/list.txt @@ -1,20 +0,0 @@ -0002-recoup.sql -0002-reserves_out.sql -donau-0002.sql -donau_do_batch_withdraw_insert.sql -donau_do_batch_withdraw.sql -donau_do_gc.sql -donau_do_recoup_by_reserve.sql -donau_do_withdraw.sql -pg_get_coin_transactions.c -pg_get_reserve_by_h_blind.c -pg_get_reserve_history.c -pg_get_withdraw_info.c -pg_insert_records_by_table.c -pg_lookup_records_by_table.c -pg_lookup_serial_by_table.c -pg_select_recoup_above_serial_id.c -pg_select_withdrawals_above_serial_id.c -pg_select_withdraw_amounts_for_kyc_check.c -procedures.sql -shard-0001.sql diff --git a/src/donaudb/pg_insert_charity.c b/src/donaudb/pg_insert_charity.c @@ -29,14 +29,14 @@ enum GNUNET_DB_QueryStatus DH_PG_insert_charity ( - void *cls, - const struct DONAU_CharityPublicKeyP *charity_pub, - const char *charity_name, - const char *charity_url, - struct TALER_Amount *max_per_year, - struct TALER_Amount *receipts_to_date, - uint64_t *current_year, - uint64_t *charity_id) + void *cls, + const struct DONAU_CharityPublicKeyP *charity_pub, + const char *charity_name, + const char *charity_url, + struct TALER_Amount *max_per_year, + struct TALER_Amount *receipts_to_date, + uint64_t *current_year, + uint64_t *charity_id) { struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { @@ -53,7 +53,7 @@ DH_PG_insert_charity ( struct GNUNET_PQ_ResultSpec rs[] = { GNUNET_PQ_result_spec_uint64 ("charity_id", - charity_id), + charity_id), GNUNET_PQ_result_spec_end }; @@ -70,7 +70,7 @@ DH_PG_insert_charity ( "($1, $2, $3, $4, $5, $6) " "RETURNING charity_id;"); return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "insert_charity", - params, - rs); + "insert_charity", + params, + rs); } diff --git a/src/donaudb/procedures.sql.in b/src/donaudb/procedures.sql.in @@ -1,6 +1,6 @@ -- -- This file is part of TALER --- Copyright (C) 2014--2022 Taler Systems SA +-- Copyright (C) 2024 Taler Systems SA -- -- TALER is free software; you can redistribute it and/or modify it under the -- terms of the GNU General Public License as published by the Free Software diff --git a/src/donaudb/test_donaudb.c b/src/donaudb/test_donaudb.c @@ -21,8 +21,8 @@ * @author Marcello Stanisci */ #include <taler/platform.h> -#include "donaudb_lib.h" #include <taler/taler_json_lib.h> +#include "donaudb_lib.h" #include "donaudb_plugin.h" /** @@ -76,6 +76,22 @@ run (void *cls) { struct GNUNET_CONFIGURATION_Handle *cfg = cls; + // Charity information + json_t *charities; + struct DONAU_CharityPublicKeyP charity_pub; + const char *charity_name; + const char *charity_url; + struct TALER_Amount max_per_year; + struct TALER_Amount receipts_to_date; + uint64_t current_year; + uint64_t charity_id; + + // Donation unit information + struct DONAU_DonationUnitHashP h_donation_unit_pub; + struct DONAU_DonationUnitPublicKey donation_unit_pub; + uint64_t validity_year; + struct TALER_Amount du_value; + if (NULL == (plugin = DONAUDB_plugin_load (cfg))) { @@ -94,7 +110,66 @@ run (void *cls) plugin->start (plugin->cls, "test-1")); -// TODO Add tests + /* test DB is empty */ + charity_id = 1; + FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != + plugin->lookup_charity (plugin->cls, + charity_id, + NULL)); + + /* test insert charity */ + current_year = 2024; + charity_name = "charity_name"; + charity_url = "charity_url"; + charities = json_array (); + RND_BLK (&charity_pub); + GNUNET_assert (GNUNET_OK == + TALER_string_to_amount (CURRENCY ":1.000010", + &max_per_year)); + GNUNET_assert (GNUNET_OK == + TALER_string_to_amount (CURRENCY ":0.000010", + &receipts_to_date)); + FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != + plugin->insert_charity (plugin->cls, + &charity_pub, + charity_name, + charity_url, + &max_per_year, + &receipts_to_date, + &current_year, + NULL)); + /* test get charities */ + FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != + plugin->get_charities (plugin->cls, + NULL, + charities)); + /* test delete charity */ + FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != + plugin->do_charity_delete (plugin->cls, + charity_id)); + + /* test insert donation unit */ + RND_BLK (&h_donation_unit_pub); + RND_BLK (&donation_unit_pub); + validity_year = 2024; + GNUNET_assert (GNUNET_OK == + TALER_string_to_amount (CURRENCY ":1.000010", + &du_value)); + + FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != + plugin->insert_donation_unit (plugin->cls, + &h_donation_unit_pub, + &donation_unit_pub, + validity_year, + &du_value)); + + /* test iterate donation units */ + FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != + plugin->iterate_donation_units (plugin->cls, + NULL, + NULL)); + + // TODO Add more tests drop: if (0 != result)