gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] 03/04: worked on testing anastasis.c (truth upload)


From: gnunet
Subject: [taler-anastasis] 03/04: worked on testing anastasis.c (truth upload)
Date: Tue, 28 Apr 2020 19:14:50 +0200

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

dennis-neufeld pushed a commit to branch master
in repository anastasis.

commit 10f273c858aab501e7033ca72421c43d95df085b
Author: Dennis Neufeld <address@hidden>
AuthorDate: Tue Apr 28 16:16:33 2020 +0000

    worked on testing anastasis.c (truth upload)
---
 src/include/anastasis.h               |   1 +
 src/include/anastasis_testing_lib.h   |  52 +++++++++++++++
 src/lib/Makefile.am                   |   3 +-
 src/lib/test_anastasis.c              |   9 +--
 src/lib/testing_api_cmd_truth_store.c |   8 ---
 src/lib/testing_cmd_truth_upload.c    | 103 +++++++++++++++++++++++-------
 src/lib/testing_trait_truth.c         | 115 ++++++++++++++++++++++++++++++++++
 7 files changed, 255 insertions(+), 36 deletions(-)

diff --git a/src/include/anastasis.h b/src/include/anastasis.h
index c8270f6..8898b35 100644
--- a/src/include/anastasis.h
+++ b/src/include/anastasis.h
@@ -263,6 +263,7 @@ typedef void
 typedef void
 (*ANASTASIS_TruthCallback)(void *cls,
                            struct ANASTASIS_Truth *t);
+
 /**
 * Uploads a truth object onto a escrow provider
 *
diff --git a/src/include/anastasis_testing_lib.h 
b/src/include/anastasis_testing_lib.h
index ffa3574..f523058 100644
--- a/src/include/anastasis_testing_lib.h
+++ b/src/include/anastasis_testing_lib.h
@@ -433,6 +433,58 @@ ANASTASIS_TESTING_cmd_salt (const char *label,
 
 /* ********************* test truth upload ********************* */
 
+/**
+ * Obtain numbers of truth traits from @a cmd.
+ *
+ * @param cmd command to extract the number from.
+ * @param index the index of the number
+ * @param n[out] set to the number coming from @a cmd.
+ * @return #GNUNET_OK on success.
+ */
+int
+ANASTASIS_TESTING_get_trait_truth_number (const struct
+                                          TALER_TESTING_Command *cmd,
+                                          unsigned int index,
+                                          const unsigned int **n);
+
+
+/**
+ * Offer the number of truth traits.
+ *
+ * @param index the number's index number (usually zero).
+ * @param n the number to offer.
+ * @return #GNUNET_OK on success.
+ */
+struct TALER_TESTING_Trait
+ANASTASIS_TESTING_make_trait_truth_number (unsigned int index,
+                                           const unsigned int *n);
+
+
+/**
+ * Obtain a truth from @a cmd.
+ *
+ * @param cmd command to extract the truth from.
+ * @param index the index of the truth
+ * @param t[out] set to the truth coming from @a cmd.
+ * @return #GNUNET_OK on success.
+ */
+int
+ANASTASIS_TESTING_get_trait_truth (const struct TALER_TESTING_Command *cmd,
+                                   unsigned int index,
+                                   const struct ANASTASIS_Truth **t);
+
+
+/**
+ * Offer an truth.
+ *
+ * @param index the truth's index number.
+ * @param t the truth to offer.
+ * @return #GNUNET_OK on success.
+ */
+struct TALER_TESTING_Trait
+ANASTASIS_TESTING_make_trait_truth (unsigned int index,
+                                    const struct ANASTASIS_Truth *t);
+
 /**
  * Creates a sample of id_data.
  *
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index a5f8ecb..32bcd5c 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -69,7 +69,8 @@ libanastasistesting_la_SOURCES = \
   testing_api_trait_hash.c \
   testing_cmd_truth_upload.c \
   testing_cmd_secret_share.c \
-  testing_cmd_recover_secret.c
+  testing_cmd_recover_secret.c \
+  testing_trait_truth.c
 libanastasistesting_la_LIBADD = \
   $(top_builddir)/src/lib/libanastasisrest.la \
   -ltalerexchange \
diff --git a/src/lib/test_anastasis.c b/src/lib/test_anastasis.c
index a488161..0c4be60 100644
--- a/src/lib/test_anastasis.c
+++ b/src/lib/test_anastasis.c
@@ -197,7 +197,7 @@ run (void *cls,
                                         strlen ("HashOfSomeTruth"),
                                         MHD_HTTP_NO_CONTENT,
                                         ANASTASIS_TESTING_TSO_NONE,
-                                        NULL);
+                                        NULL),
 
     ANASTASIS_TESTING_cmd_truth_upload ("truth-create-2",
                                         anastasis_url,
@@ -211,7 +211,7 @@ run (void *cls,
                                         strlen ("HashOfSomeTruth"),
                                         MHD_HTTP_NO_CONTENT,
                                         ANASTASIS_TESTING_TSO_NONE,
-                                        "truth-create-1");
+                                        "truth-create-1"),
 
     ANASTASIS_TESTING_cmd_truth_upload ("truth-create-3",
                                         anastasis_url,
@@ -225,8 +225,8 @@ run (void *cls,
                                         strlen ("HashOfSomeTruth"),
                                         MHD_HTTP_NO_CONTENT,
                                         ANASTASIS_TESTING_TSO_NONE,
-                                        "truth-create-2");
-
+                                        "truth-create-2"),
+    /*
     ANASTASIS_TESTING_cmd_secret_share ("secret-share-1",
                                         anastasis_url,
                                         MHD_HTTP_PAYMENT_REQUIRED,
@@ -238,6 +238,7 @@ run (void *cls,
                                           MHD_HTTP_PAYMENT_REQUIRED,
                                           ANASTASIS_TESTING_RSO_NONE,
                                           NULL),
+    */
 
     TALER_TESTING_cmd_end ()
   };
diff --git a/src/lib/testing_api_cmd_truth_store.c 
b/src/lib/testing_api_cmd_truth_store.c
index ebfa10a..e994d20 100644
--- a/src/lib/testing_api_cmd_truth_store.c
+++ b/src/lib/testing_api_cmd_truth_store.c
@@ -5,19 +5,11 @@
   Anastasis is free software; you can redistribute it and/or modify it under 
the
   terms of the GNU Lesser General Public License as published by the Free 
Software
   Foundation; either version 3, or (at your option) any later version.
-<<<<<<< HEAD
 
   Anastasis 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.
 
-=======
-
-  Anastasis 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.
-
->>>>>>> f6a488c... modified salt request
   You should have received a copy of the GNU General Public License along with
   Anastasis; see the file COPYING.GPL.  If not, see 
<http://www.gnu.org/licenses/>
 */
diff --git a/src/lib/testing_cmd_truth_upload.c 
b/src/lib/testing_cmd_truth_upload.c
index 096c7a1..b749bf0 100644
--- a/src/lib/testing_cmd_truth_upload.c
+++ b/src/lib/testing_cmd_truth_upload.c
@@ -45,7 +45,7 @@ struct TruthUploadState
   /**
    * The ID data to generate user identifier
    */
-  const jsont_t *id_data;
+  const json_t *id_data;
 
   /**
    * The escrow method
@@ -83,6 +83,11 @@ struct TruthUploadState
    */
   struct ANASTASIS_TruthUpload *tuo;
 
+  /**
+   * closure for the payment callback
+   */
+  void *tpc_cls;
+
   /**
    * Reference to upload command of previous truth upload.
    */
@@ -92,36 +97,61 @@ struct TruthUploadState
    * Options for how we are supposed to do the upload.
    */
   enum ANASTASIS_TESTING_TruthStoreOption tsopt;
+
+  /**
+   * Truth object
+   */
+  const struct ANASTASIS_Truth *truth;
+
+  /**
+   * index of truth (for trait)
+   */
+  unsigned int truth_number;
 };
 
 
 /**
- * Function called with the results of a #truth_upload().
- *
- * @param cls closure
- * @param ec ANASTASIS error code
- * @param http_status HTTP status of the request
- * @param ud details about the upload operation
- */
+* Upload information
+* caller MUST free 't' using ANASTASIS_truth_free()
+*
+* @param cls closure for callback
+* @param t Truth object (contains provider url and uuid)
+*/
 static void
 truth_upload_cb (void *cls,
-                 enum ANASTASIS_ErrorCode ec,
-                 unsigned int http_status,
-                 const struct ANASTASIS_UploadDetails *ud)
+                 struct ANASTASIS_Truth *t)
 {
   struct TruthUploadState *tus = cls;
   tus->tuo = NULL;
-  if (http_status != tss->http_status)
+
+  if (NULL == t)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Unexpected response code %u to command %s in %s:%u\n",
-                http_status,
-                tss->is->commands[tss->is->ip].label,
-                __FILE__,
-                __LINE__);
-    TALER_TESTING_interpreter_fail (tss->is);
+    GNUNET_break (0);
+    TALER_TESTING_interpreter_fail (tus->is);
     return;
   }
+  tus->truth = t;
+
+  TALER_TESTING_interpreter_next (tus->is);
+}
+
+
+/**
+ * Initiates a callback for the payment of the truth upload
+ *
+ * @param cls closure
+ * @param taler_pay_url payment link for the transaction (taler://pay/Foo)
+ * @param ec status code of the request
+ */
+static void
+truth_payment_cb (void *cls,
+                  const char *taler_pay_url,
+                  enum TALER_ErrorCode ec)
+{
+  struct TruthUploadState *tus = cls;
+  tus->tuo = NULL;
+  // FIXME: Payment handling
+  return;
 }
 
 
@@ -140,7 +170,6 @@ truth_upload_run (void *cls,
   struct TruthUploadState *tus = cls;
 
   tus->is = is;
-  // FIXME: Whole secret share procedure here
   if (NULL != tus->upload_reference)
   {
     const struct TALER_TESTING_Command *ref;
@@ -154,7 +183,22 @@ truth_upload_run (void *cls,
       TALER_TESTING_interpreter_fail (tus->is);
       return;
     }
-    // FIXME: get trait truth array
+    const unsigned int *number;
+
+    if (GNUNET_OK !=
+        ANASTASIS_TESTING_get_trait_truth_number (ref,
+                                                  0,
+                                                  &number))
+    {
+      GNUNET_break (0);
+      TALER_TESTING_interpreter_fail (tus->is);
+      return;
+    }
+    tus->truth_number = *number + 1;
+  }
+  else
+  {
+    tus->truth_number = 0;
   }
 
   tus->tuo = ANASTASIS_truth_upload (tus->id_data,
@@ -164,7 +208,7 @@ truth_upload_run (void *cls,
                                      tus->mime_type,
                                      tus->truth_data,
                                      tus->truth_data_size,
-                                     tus->tpc,
+                                     &truth_payment_cb,
                                      tus->tpc_cls,
                                      &truth_upload_cb,
                                      tus);
@@ -192,6 +236,16 @@ truth_upload_cleanup (void *cls,
   // FIXME: Cleanup logic
   struct TruthUploadState *tus = cls;
 
+  if (NULL != tus->tuo)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "Command '%s' did not complete\n",
+                cmd->label);
+    ANASTASIS_truth_upload_cancel (tus->tuo);
+    tus->tuo = NULL;
+  }
+  GNUNET_free_non_null ((void *) tus->truth);
+  GNUNET_free_non_null ((void *) tus->truth_data);
   GNUNET_free (tus);
 }
 
@@ -213,7 +267,10 @@ truth_upload_traits (void *cls,
 {
   struct TruthUploadState *tus = cls;
   struct TALER_TESTING_Trait traits[] = {
-    // FIXME: What traits are usefull?
+    ANASTASIS_TESTING_make_trait_truth (tus->truth_number,
+                                        tus->truth),
+    ANASTASIS_TESTING_make_trait_truth_number (0,
+                                               &tus->truth_number),
     TALER_TESTING_trait_end ()
   };
 
diff --git a/src/lib/testing_trait_truth.c b/src/lib/testing_trait_truth.c
new file mode 100644
index 0000000..2ed45a2
--- /dev/null
+++ b/src/lib/testing_trait_truth.c
@@ -0,0 +1,115 @@
+/*
+  This file is part of TALER
+  Copyright (C) 2020 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 lib/testing_api_trait_uuid.c
+ * @brief traits to offer a hash
+ * @author Christian Grothoff
+ * @author Dominik Meister
+ * @author Dennis Neufeld
+ */
+#include "platform.h"
+#include "anastasis_testing_lib.h"
+
+#define ANASTASIS_TESTING_TRAIT_TRUTH "anastasis-truth"
+#define ANASTASIS_TESTING_TRAIT_TRUTH_NUMBER "anastasis-truth-number"
+
+/**
+ * Obtain numbers of truth traits from @a cmd.
+ *
+ * @param cmd command to extract the number from.
+ * @param index the index of the number
+ * @param n[out] set to the number coming from @a cmd.
+ * @return #GNUNET_OK on success.
+ */
+int
+ANASTASIS_TESTING_get_trait_truth_number (const struct
+                                          TALER_TESTING_Command *cmd,
+                                          unsigned int index,
+                                          const unsigned int **n)
+{
+  return cmd->traits (cmd->cls,
+                      (const void **) n,
+                      ANASTASIS_TESTING_TRAIT_TRUTH_NUMBER,
+                      index);
+}
+
+
+/**
+ * Offer the number of truth traits.
+ *
+ * @param index the number's index number (usually zero).
+ * @param n the number to offer.
+ * @return #GNUNET_OK on success.
+ */
+struct TALER_TESTING_Trait
+ANASTASIS_TESTING_make_trait_truth_number
+  (unsigned int index,
+  const unsigned int *n)
+{
+  struct TALER_TESTING_Trait ret = {
+    .index = index,
+    .trait_name = ANASTASIS_TESTING_TRAIT_TRUTH_NUMBER,
+    .ptr = (const void *) n
+  };
+  return ret;
+}
+
+
+/**
+ * Obtain a truth from @a cmd.
+ *
+ * @param cmd command to extract the truth from.
+ * @param index the index of the truth
+ * @param t[out] set to the truth coming from @a cmd.
+ * @return #GNUNET_OK on success.
+ */
+int
+ANASTASIS_TESTING_get_trait_truth (const struct TALER_TESTING_Command *cmd,
+                                   unsigned int index,
+                                   const struct ANASTASIS_Truth **t)
+{
+  return cmd->traits (cmd->cls,
+                      (const void **) t,
+                      ANASTASIS_TESTING_TRAIT_TRUTH,
+                      index);
+}
+
+
+/**
+ * Offer an truth.
+ *
+ * @param index the truth's index number.
+ * @param t the truth to offer.
+ * @return #GNUNET_OK on success.
+ */
+struct TALER_TESTING_Trait
+ANASTASIS_TESTING_make_trait_truth
+  (unsigned int index,
+  const struct ANASTASIS_Truth *t)
+{
+  struct TALER_TESTING_Trait ret = {
+    .index = index,
+    .trait_name = ANASTASIS_TESTING_TRAIT_TRUTH,
+    .ptr = (const void *) t
+  };
+  return ret;
+}
+
+
+/* end of testing_trait_truth.c */

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

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