commit 6b5be95c5aceac17f94dfbaabc38381c880947bf
parent 678b9b47f3994e4c6af6ae31a115385accc3b892
Author: Matyja Lukas Adam <lukas.matyja@students.bfh.ch>
Date: Sun, 28 Apr 2024 18:32:43 +0200
[testing] add submit test (not yet finished)
Diffstat:
8 files changed, 303 insertions(+), 41 deletions(-)
diff --git a/src/donaudb/test_donaudb.c b/src/donaudb/test_donaudb.c
@@ -34,25 +34,25 @@ static int result;
* Report line of error if @a cond is true, and jump to label "drop".
*/
#define FAILIF(cond) \
- do { \
- if (! (cond)) { break;} \
- GNUNET_break (0); \
- goto drop; \
- } while (0)
+ do { \
+ if (! (cond)) { break;} \
+ GNUNET_break (0); \
+ goto drop; \
+ } while (0)
/**
* Initializes @a ptr with random data.
*/
#define RND_BLK(ptr) \
- GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, ptr, sizeof (* \
- ptr))
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, ptr, sizeof (* \
+ ptr))
/**
* Initializes @a ptr with zeros.
*/
#define ZR_BLK(ptr) \
- memset (ptr, 0, sizeof (*ptr))
+ memset (ptr, 0, sizeof (*ptr))
/**
diff --git a/src/include/donau_service.h b/src/include/donau_service.h
@@ -563,6 +563,10 @@ struct TALER_DonationUnitSignature
};
+
+/* ********************* POST / submit receipts *********************** */
+
+
/**
* @brief A Batch Submit receipts Handle
*/
diff --git a/src/include/donau_testing_lib.h b/src/include/donau_testing_lib.h
@@ -129,6 +129,25 @@ TALER_TESTING_cmd_issue_receipts (const char *label,
const size_t num_bkp,
unsigned int expected_response_code);
+
+/**
+ * Create a POST "batch-issue" command.
+ *
+ * @param label the command label.
+ * @param year current or past year (mostly)
+ * @param donor_tax_id current year (mostly)
+ * @param salt current year (mostly)
+ * @param expected_response_code expected HTTP response code.
+ * @return the command.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_submit_receipts (const char *label,
+ const uint64_t year,
+ const char *donor_tax_id,
+ const char *salt,
+ unsigned int expected_response_code);
+
+
/**
* Convenience function to run a test.
*
diff --git a/src/include/donaudb_plugin.h b/src/include/donaudb_plugin.h
@@ -216,7 +216,7 @@ struct DONAUDB_Plugin
* @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
*/
enum GNUNET_GenericReturnValue
- (*drop_tables)(void *cls);
+ (*drop_tables)(void *cls);
/**
* Create the necessary tables if they are not present
@@ -229,7 +229,7 @@ struct DONAUDB_Plugin
* @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
*/
enum GNUNET_GenericReturnValue
- (*create_tables)(void *cls);
+ (*create_tables)(void *cls);
/**
@@ -241,8 +241,8 @@ struct DONAUDB_Plugin
* @return #GNUNET_OK on success
*/
enum GNUNET_GenericReturnValue
- (*start)(void *cls,
- const char *name);
+ (*start)(void *cls,
+ const char *name);
/**
@@ -254,8 +254,8 @@ struct DONAUDB_Plugin
* @return #GNUNET_OK on success
*/
enum GNUNET_GenericReturnValue
- (*start_read_committed)(void *cls,
- const char *name);
+ (*start_read_committed)(void *cls,
+ const char *name);
/**
* Start a READ ONLY serializable transaction.
@@ -266,8 +266,8 @@ struct DONAUDB_Plugin
* @return #GNUNET_OK on success
*/
enum GNUNET_GenericReturnValue
- (*start_read_only)(void *cls,
- const char *name);
+ (*start_read_only)(void *cls,
+ const char *name);
/**
@@ -277,7 +277,7 @@ struct DONAUDB_Plugin
* @return transaction status
*/
enum GNUNET_DB_QueryStatus
- (*commit)(void *cls);
+ (*commit)(void *cls);
/**
@@ -291,7 +291,7 @@ struct DONAUDB_Plugin
* #GNUNET_SYSERR on hard errors
*/
enum GNUNET_GenericReturnValue
- (*preflight)(void *cls);
+ (*preflight)(void *cls);
/**
@@ -312,7 +312,7 @@ struct DONAUDB_Plugin
* #GNUNET_SYSERR on DB errors
*/
enum GNUNET_GenericReturnValue
- (*gc)(void *cls);
+ (*gc)(void *cls);
/**
@@ -367,7 +367,7 @@ struct DONAUDB_Plugin
* @return database transaction status
*/
enum GNUNET_DB_QueryStatus
- (*lookup_charity)(
+ (*lookup_charity)(
void *cls,
uint64_t charity_id,
struct DONAUDB_CharityMetaData *meta);
@@ -382,7 +382,7 @@ struct DONAUDB_Plugin
* @return database transaction status
*/
enum GNUNET_DB_QueryStatus
- (*do_charity_delete)(
+ (*do_charity_delete)(
void *cls,
uint64_t charity_id);
@@ -395,7 +395,7 @@ struct DONAUDB_Plugin
* @return database transaction status
*/
enum GNUNET_DB_QueryStatus
- (*get_charities)(
+ (*get_charities)(
void *cls,
DONAUDB_GetCharitiesCallback cb,
void *cb_cls);
@@ -409,7 +409,7 @@ struct DONAUDB_Plugin
* @return database transaction status
*/
enum GNUNET_DB_QueryStatus
- (*insert_charity)(
+ (*insert_charity)(
void *cls,
const struct DONAU_CharityPublicKeyP *charity_pub,
const char *charity_name,
@@ -428,7 +428,7 @@ struct DONAUDB_Plugin
* @return database transaction status
*/
enum GNUNET_DB_QueryStatus
- (*iterate_donation_units)(
+ (*iterate_donation_units)(
void *cls,
DONAUDB_IterateDonationUnitsCallback cb,
void *cb_cls);
@@ -442,7 +442,7 @@ struct DONAUDB_Plugin
* @return database transaction status
*/
enum GNUNET_DB_QueryStatus
- (*get_history)(
+ (*get_history)(
void *cls,
DONAUDB_GetHistoryCallback cb,
void *cb_cls);
@@ -456,7 +456,7 @@ struct DONAUDB_Plugin
* @return database transaction status
*/
enum GNUNET_DB_QueryStatus
- (*lookup_history_entry)(
+ (*lookup_history_entry)(
void *cls,
const unsigned long long charity_id,
const struct TALER_Amount *final_amount,
@@ -470,7 +470,7 @@ struct DONAUDB_Plugin
* @return database transaction status
*/
enum GNUNET_DB_QueryStatus
- (*insert_donation_unit)(
+ (*insert_donation_unit)(
void *cls,
const struct DONAU_DonationUnitHashP *h_donation_unit_pub,
const struct DONAU_DonationUnitPublicKey *donation_unit_pub,
@@ -487,7 +487,7 @@ struct DONAUDB_Plugin
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*insert_history_entry)(
+ (*insert_history_entry)(
void *cls,
const uint64_t charity_id,
const struct TALER_Amount *final_amount,
@@ -506,7 +506,7 @@ struct DONAUDB_Plugin
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*insert_issued_receipt)(
+ (*insert_issued_receipt)(
void *cls,
const size_t num_blinded_sig,
const struct DONAU_BlindedDonationUnitSignature signatures[num_blinded_sig],
@@ -527,7 +527,7 @@ struct DONAUDB_Plugin
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*insert_submitted_receipts)(
+ (*insert_submitted_receipts)(
void *cls,
struct DONAU_HashDonorTaxId *h_donor_tax_id,
size_t num_dr,
@@ -543,7 +543,7 @@ struct DONAUDB_Plugin
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*lookup_issued_receipts)(
+ (*lookup_issued_receipts)(
void *cls,
struct DONAU_DonationReceiptHashP *h_receitps,
struct DONAUDB_IssuedReceiptsMetaData *meta);
@@ -557,7 +557,7 @@ struct DONAUDB_Plugin
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*insert_signing_key)(
+ (*insert_signing_key)(
void *cls,
const struct DONAU_DonauPublicKeyP *donau_pub,
struct DONAUDB_SignkeyMetaData *meta);
@@ -571,7 +571,7 @@ struct DONAUDB_Plugin
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*lookup_signing_key)(
+ (*lookup_signing_key)(
void *cls,
const struct DONAU_DonauPublicKeyP *donau_pub,
struct DONAUDB_SignkeyMetaData *meta);
@@ -585,7 +585,7 @@ struct DONAUDB_Plugin
* @return database transaction status
*/
enum GNUNET_DB_QueryStatus
- (*iterate_active_signing_keys)(
+ (*iterate_active_signing_keys)(
void *cls,
DONAUDB_IterateActiveSigningKeysCallback cb,
void *cb_cls);
diff --git a/src/lib/donau_api_batch_submit_receipts.c b/src/lib/donau_api_batch_submit_receipts.c
@@ -93,8 +93,8 @@ submit_request_body_to_json (const size_t num_drs,
&drs[i].h_donation_unit_pub),
GNUNET_JSON_pack_data_auto ("nonce",
&drs[i].nonce),
- DONAU_JSON_pack_donation_unit_sig ("donation_unit_sig",
- &drs[i].donation_unit_sig));
+ DONAU_JSON_pack_donation_unit_sig ("donation_unit_sig",
+ &drs[i].donation_unit_sig));
GNUNET_assert (0 ==
json_array_append_new (donation_receipts,
receipt));
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
@@ -26,6 +26,7 @@ libdonautesting_la_SOURCES = \
testing_api_cmd_charity_post.c \
testing_api_cmd_charity_delete.c \
testing_api_cmd_issue_receipts.c \
+ testing_api_cmd_submit_receipts.c \
testing_api_traits.c \
testing_api_loop.c
diff --git a/src/testing/test_donau_api.c b/src/testing/test_donau_api.c
@@ -92,11 +92,16 @@ run (void *cls,
&bearer,
MHD_HTTP_OK),
// FIXME
- TALER_TESTING_cmd_issue_receipts ("issue-receipts",
- "post-charity",
- 2024,
- 3, // number of budi key pairs
- MHD_HTTP_CREATED),
+// TALER_TESTING_cmd_issue_receipts ("issue-receipts",
+// "post-charity",
+// 2024,
+// 3, // number of budi key pairs
+// MHD_HTTP_CREATED),
+ TALER_TESTING_cmd_submit_receipts ("submit-receipts",
+ 2024,
+ "7560001010000", // tax id
+ "1234", //salt
+ MHD_HTTP_OK),
TALER_TESTING_cmd_charity_delete ("delete-charity",
"post-charity", // cmd trait reference
&bearer,
diff --git a/src/testing/testing_api_cmd_submit_receipts.c b/src/testing/testing_api_cmd_submit_receipts.c
@@ -0,0 +1,233 @@
+/*
+ This file is part of TALER
+ 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 Foundation; either version 3, or
+ (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file testing/testing_api_cmd_submit_receipts.c
+ * @brief Implement the POST /charities test command.
+ * @author Lukas Matyja
+ */
+#include <taler/platform.h>
+#include <taler/taler_json_lib.h>
+#include <gnunet/gnunet_curl_lib.h>
+#include <taler/taler_testing_lib.h>
+#include "donau_testing_lib.h"
+
+
+/**
+ * State for a "status" CMD.
+ */
+struct StatusState
+{
+ /**
+ * Handle to the "charity status" operation.
+ */
+ struct DONAU_DonorReceiptsToStatementHandle *bsrh;
+
+ /**
+ * Expected HTTP response code.
+ */
+ unsigned int expected_response_code;
+
+ /**
+ * Interpreter state.
+ */
+ struct TALER_TESTING_Interpreter *is;
+
+ /**
+ * corresponding year
+ */
+ unsigned long long year;
+
+ /**
+ * number of donation receipts.
+ */
+ size_t num_receipts;
+
+ /**
+ * array of donation receipts
+ */
+ struct DONAU_DonationReceipt *receipts;
+
+ /**
+ * donau keys
+ */
+ struct DONAU_Keys *keys;
+
+ /**
+ * Hashed and salted tax id of the donor.
+ */
+ const struct DONAU_HashDonorTaxId *h_donor_tax_id;
+
+};
+
+
+/**
+ * Check that the reserve balance and HTTP response code are
+ * both acceptable.
+ *
+ * @param cls closure.
+ * @param rtsresp HTTP response details
+ */
+static void
+submit_receipts_status_cb (void *cls,
+ const struct DONAU_DonorReceiptsToStatementResult *rtsresp)
+{
+ struct StatusState *ss = cls;
+
+ // TODO: use the public donation unit keys from the DONAU to verify the signatures
+
+ ss->bsrh = NULL;
+ if (ss->expected_response_code != rtsresp->hr.http_status)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected HTTP response code: %d in %s:%u\n",
+ rtsresp->hr.http_status,
+ __FILE__,
+ __LINE__);
+ json_dumpf (rtsresp->hr.reply,
+ stderr,
+ 0);
+ TALER_TESTING_interpreter_fail (ss->is);
+ return;
+ }
+
+ TALER_TESTING_interpreter_next (ss->is);
+}
+
+
+/**
+ * Run the command.
+ *
+ * @param cls closure.
+ * @param cmd the command being executed.
+ * @param is the interpreter state.
+ */
+static void
+status_run (void *cls,
+ const struct TALER_TESTING_Command *cmd,
+ struct TALER_TESTING_Interpreter *is)
+{
+ struct StatusState *ss = cls;
+ ss->is = is;
+
+ /* Get donau keys from trait */
+ {
+ const struct TALER_TESTING_Command *keys_cmd;
+ struct DONAU_Keys *keys;
+
+ keys_cmd = TALER_TESTING_interpreter_lookup_command (is,
+ "get-donau");
+
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_donau_keys (keys_cmd, &keys))
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ ss->keys = keys;
+ }
+
+ // TODO: Get receipts from issue receipts test
+
+ ss->receipts
+ = GNUNET_new_array (ss->num_receipts,
+ struct DONAU_DonationReceipt);
+ for (size_t cnt = 0; cnt < ss->num_receipts; cnt++)
+ {
+ DONAU_donation_unit_pub_hash (&ss->keys->donation_unit_keys[0].key,
+ &ss->receipts[cnt].h_donation_unit_pub);
+
+ }
+ // const struct DONAU_DonationReceipt *receipts = ss->receipts;
+ ss->bsrh = DONAU_donor_receipts_to_statement (
+ TALER_TESTING_interpreter_get_context (is),
+ TALER_TESTING_get_donau_url (is),
+ ss->num_receipts,
+ ss->receipts,
+ ss->year,
+ ss->h_donor_tax_id,
+ &submit_receipts_status_cb,
+ ss);
+
+}
+
+
+/**
+ * Cleanup the state from a "issue receipt status" CMD, and possibly
+ * cancel a pending operation thereof.
+ *
+ * @param cls closure.
+ * @param cmd the command which is being cleaned up.
+ */
+static void
+cleanup (void *cls,
+ const struct TALER_TESTING_Command *cmd)
+{
+ struct StatusState *ss = cls;
+
+ if (NULL != ss->bsrh)
+ {
+ // log incomplete command
+ TALER_TESTING_command_incomplete (ss->is,
+ cmd->label);
+ DONAU_donor_receipts_to_statement_cancel (ss->bsrh);
+ ss->bsrh = NULL;
+ }
+ GNUNET_free (ss);
+}
+
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_submit_receipts (const char *label,
+ const uint64_t year,
+ const char *donor_tax_id,
+ const char *salt,
+ unsigned int expected_response_code)
+{
+ struct StatusState *ss;
+
+ ss = GNUNET_new (struct StatusState);
+
+ ss->year = year;
+ ss->expected_response_code = expected_response_code;
+ struct DONAU_HashDonorTaxId h_donor_tax_id;
+ struct GNUNET_HashContext *hash_context;
+ hash_context = GNUNET_CRYPTO_hash_context_start ();
+
+ GNUNET_CRYPTO_hash_context_read (hash_context,
+ donor_tax_id,
+ sizeof((*donor_tax_id))),
+ GNUNET_CRYPTO_hash_context_read (hash_context,
+ salt,
+ sizeof((*salt)));
+ GNUNET_CRYPTO_hash_context_finish (hash_context,
+ &h_donor_tax_id.hash);
+ ss->h_donor_tax_id = &h_donor_tax_id;
+ {
+ struct TALER_TESTING_Command cmd = {
+ .cls = ss,
+ .label = label,
+ .run = &status_run,
+ .cleanup = &cleanup
+ };
+
+ return cmd;
+
+ }
+}