gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-donau] 01/03: [testing] working on issue receipts


From: gnunet
Subject: [taler-donau] 01/03: [testing] working on issue receipts
Date: Wed, 13 Mar 2024 20:16:29 +0100

This is an automated email from the git hooks/post-receive script.

lukas-matyja pushed a commit to branch master
in repository donau.

commit a2359c873e88958c2fb7bf16f1b326b3d6c46f21
Author: Matyja Lukas Adam <lukas.matyja@students.bfh.ch>
AuthorDate: Wed Mar 13 20:14:58 2024 +0100

    [testing] working on issue receipts
---
 src/include/donau_testing_lib.h              |  38 ++++-
 src/testing/Makefile.am                      |   1 +
 src/testing/test_donau_api.c                 |   6 +
 src/testing/testing_api_cmd_issue_receipts.c | 228 +++++++++++++++++++++++++++
 4 files changed, 269 insertions(+), 4 deletions(-)

diff --git a/src/include/donau_testing_lib.h b/src/include/donau_testing_lib.h
index 41d386e..3d91504 100644
--- a/src/include/donau_testing_lib.h
+++ b/src/include/donau_testing_lib.h
@@ -38,9 +38,7 @@
  *
  * @param label command label
  * @param cfg configuration to use
- * @param last_keys_ref reference to command with prior /keys response, NULL 
for none
  * @param wait_for_keys block until we got /keys
- * @param load_private_key obtain private key from file indicated in @a cfg
  * @return the command.
  */
 struct TALER_TESTING_Command
@@ -53,7 +51,7 @@ TALER_TESTING_cmd_get_donau (
  * Create a GET "charity" command.
  *
  * @param label the command label.
- * @param charity_id
+ * @param charity_reference reference for traits
  * @param bearer authorization token
  * @param expected_response_code expected HTTP response code.
  * @return the command.
@@ -68,7 +66,10 @@ TALER_TESTING_cmd_charity_get (const char *label,
  * Create a POST "charity" command.
  *
  * @param label the command label.
- * @param charity_id
+ * @param name of the charity
+ * @param url of the charity
+ * @param max_per_year max donation receipt amount per year
+ * @param receipts_to_date
  * @param bearer authorization token
  * @param expected_response_code expected HTTP response code.
  * @return the command.
@@ -83,6 +84,15 @@ TALER_TESTING_cmd_charity_post (const char *label,
                                 const struct DONAU_BearerToken *bearer,
                                 unsigned int expected_response_code);
 
+/**
+ * Create a DELETE "charity" command.
+ *
+ * @param label the command label.
+ * @param charity_reference reference for traits
+ * @param bearer authorization token
+ * @param expected_response_code expected HTTP response code.
+ * @return the command.
+ */
 struct TALER_TESTING_Command
 TALER_TESTING_cmd_charity_delete (const char *label,
                                   const char *charity_reference,
@@ -93,6 +103,7 @@ TALER_TESTING_cmd_charity_delete (const char *label,
  * Create a GET "charities" command.
  *
  * @param label the command label.
+ * @param bearer authorization token
  * @param expected_response_code expected HTTP response code.
  * @return the command.
  */
@@ -101,6 +112,25 @@ TALER_TESTING_cmd_charities_get (const char *label,
                                  const struct DONAU_BearerToken *bearer,
                                  unsigned int expected_response_code);
 
+/**
+ * Create a POST "batch-issue" command.
+ *
+ * @param label the command label.
+ * @param charity_reference reference for traits
+ * @param year current year (mostly)
+ * @param num_bkp number of @bkp
+ * @param bkp budi key pair array
+ * @param expected_response_code expected HTTP response code.
+ * @return the command.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_issue_receipts (const char *label,
+                                                               const char 
*charity_reference,
+                const uint64_t year,
+                                                               const unsigned 
int num_bkp,
+                                                               const struct 
DONAU_BlindedUniqueDonationIdentifierKeyPair *bkp[static num_bkp],
+                unsigned int expected_response_code);
+
 /**
  * Convenience function to run a test.
  *
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
index 5623c1c..dbeb39b 100644
--- a/src/testing/Makefile.am
+++ b/src/testing/Makefile.am
@@ -25,6 +25,7 @@ libdonautesting_la_SOURCES = \
   testing_api_cmd_charity_get.c \
   testing_api_cmd_charity_post.c \
   testing_api_cmd_charity_delete.c \
+  testing_api_cmd_issue_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
index 76aace5..40df674 100644
--- a/src/testing/test_donau_api.c
+++ b/src/testing/test_donau_api.c
@@ -91,6 +91,12 @@ run (void *cls,
          TALER_TESTING_cmd_charities_get ("get-charities",
                                                                          
&bearer,
                                                                          
MHD_HTTP_OK),
+         TALER_TESTING_cmd_issue_receipts ("issue-receipts",
+                                                                         
"post-charity",
+                                                                         2024,
+                                                                         24,
+                                                                         bkp,
+                                                                         
MHD_HTTP_CREATED),
          TALER_TESTING_cmd_charity_delete("delete-charity",
                                                                          
"post-charity", // cmd trait reference
                                                                          
&bearer,
diff --git a/src/testing/testing_api_cmd_issue_receipts.c 
b/src/testing/testing_api_cmd_issue_receipts.c
new file mode 100644
index 0000000..a9eac50
--- /dev/null
+++ b/src/testing/testing_api_cmd_issue_receipts.c
@@ -0,0 +1,228 @@
+/*
+  This file is part of TALER
+  Copyright (C) 2014-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_issue_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_BatchIssueReceiptHandle *birh;
+
+  /**
+   * The charity POST request.
+   */
+  struct DONAU_CharityRequest charity_req;
+
+  /**
+   * Private key of the charity, for signature.
+   */
+  struct DONAU_CharityPrivateKeyP charity_priv;
+
+  /**
+   * Expected HTTP response code.
+   */
+  unsigned int expected_response_code;
+
+  /**
+   * Interpreter state.
+   */
+  struct TALER_TESTING_Interpreter *is;
+
+  /**
+   * charity id
+   */
+  unsigned long long charity_id;
+
+  /**
+   * charity id
+   */
+  unsigned long long year;
+
+  /**
+   * number of budi key pair.
+   */
+  uint64_t num_bkp;
+
+  /**
+   * budi key pair array
+   */
+  const struct DONAU_BlindedUniqueDonationIdentifierKeyPair *bkp;
+
+};
+
+
+/**
+ * Check that the reserve balance and HTTP response code are
+ * both acceptable.
+ *
+ * @param cls closure.
+ * @param biresp HTTP response details
+ */
+static void
+issue_receipts_status_cb (void *cls,
+                   const struct DONAU_BatchIssueResponse *biresp)
+{
+  struct StatusState *ss = cls;
+
+  ss->birh = NULL;
+  if (ss->expected_response_code != biresp->hr.http_status)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Unexpected HTTP response code: %d in %s:%u\n",
+                biresp->hr.http_status,
+                __FILE__,
+                __LINE__);
+    json_dumpf (biresp->hr.reply,
+                stderr,
+                0);
+    TALER_TESTING_interpreter_fail (ss->is);
+    return;
+  }
+  //if (ss->expected_response_code == biresp->hr.http_status)
+    //ss->charity_id = (unsigned long long) biresp->details.ok.charity_id;
+  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;
+
+  ss->birh = DONAU_charity_issue_receipt (
+    TALER_TESTING_interpreter_get_context (is),
+    TALER_TESTING_get_donau_url (is),
+    &ss->charity_priv,
+    ss->charity_id,
+    ss->year,
+       ss->num_bkp,
+       &ss->bkp,
+    &issue_receipts_status_cb,
+    ss);
+
+}
+
+
+/**
+ * Cleanup the state from a "reserve 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->birh)
+  {
+    // log incomplete command
+    TALER_TESTING_command_incomplete (ss->is,
+                                      cmd->label);
+    DONAU_charity_issue_receipt_cancel (ss->birh);
+    ss->birh = NULL;
+  }
+  GNUNET_free (ss);
+}
+
+
+/**
+ * Offer internal data from a "deposit" CMD, to other commands.
+ *
+ * @param cls closure.
+ * @param[out] ret result.
+ * @param trait name of the trait.
+ * @param index index number of the object to offer.
+ * @return #GNUNET_OK on success.
+ */
+static enum GNUNET_GenericReturnValue
+charity_post_traits (void *cls,
+                     const void **ret,
+                     const char *trait,
+                     unsigned int index)
+{
+  struct StatusState *ss = cls;
+  struct TALER_TESTING_Trait traits[] = {
+    TALER_TESTING_make_trait_charity_priv (&ss->charity_priv),
+    TALER_TESTING_make_trait_charity_pub (&ss->charity_req.charity_pub),
+    TALER_TESTING_make_trait_charity_id (&ss->charity_id),
+    TALER_TESTING_trait_end ()
+  };
+
+  return TALER_TESTING_get_trait (traits,
+                                  ret,
+                                  trait,
+                                  index);
+}
+
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_issue_receipts (const char *label,
+                                                               const char 
*charity_reference,
+                                                               const uint64_t 
year,
+                                                               const unsigned 
int num_bkp,
+                                                               const struct 
DONAU_BlindedUniqueDonationIdentifierKeyPair *bkp[static num_bkp],
+                                                               unsigned int 
expected_response_code)
+{
+  struct StatusState *ss;
+
+  ss = GNUNET_new (struct StatusState);
+
+  ss->year = year;
+  ss->expected_response_code = expected_response_code;
+  {
+    struct TALER_TESTING_Command cmd = {
+      .cls = ss,
+      .label = label,
+      .run = &status_run,
+      .cleanup = &cleanup
+      //.traits = &charity_post_traits
+    };
+
+    return cmd;
+
+  }
+}

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]