gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-merchant] branch master updated (bf9076a -> f0de247)


From: gnunet
Subject: [GNUnet-SVN] [taler-merchant] branch master updated (bf9076a -> f0de247)
Date: Wed, 09 May 2018 16:24:35 +0200

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

marcello pushed a change to branch master
in repository merchant.

    from bf9076a  terminate bank and merchant when done.
     new 93063ba  proposal CMD generates order_id if missing.
     new c68788d  paygen banks.
     new 323c183  User loging.
     new d30f4e1  Introducing "rewind" CMD.
     new f0de247  Importing CMDs.

The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/include/taler_merchant_testing_lib.h           |  18 +++
 src/lib/Makefile.am                                |   1 +
 src/lib/testing_api_cmd_proposal.c                 |  19 +++
 src/lib/testing_api_cmd_rewind.c                   |  92 ++++++++++++++
 src/merchant-tools/Makefile.am                     |   2 +-
 .../taler-merchant-generate-payments_new.c         | 136 ++++++++++++++++++---
 6 files changed, 252 insertions(+), 16 deletions(-)
 create mode 100644 src/lib/testing_api_cmd_rewind.c

diff --git a/src/include/taler_merchant_testing_lib.h 
b/src/include/taler_merchant_testing_lib.h
index 8394fc4..304a16b 100644
--- a/src/include/taler_merchant_testing_lib.h
+++ b/src/include/taler_merchant_testing_lib.h
@@ -581,5 +581,23 @@ TALER_TESTING_cmd_tip_pickup
    const char **amounts,
    struct TALER_EXCHANGE_Handle *exchange);
 
+/**
+ * Make the instruction pointer point to @a new_ip
+ * only if @a counter is greater than zero.
+ *
+ * @param label command label
+ * @param new_ip new instruction pointer's value.  Note that,
+ * when the next instruction will be called, the interpreter
+ * will increment the ip under the hood so this value must be
+ * set to the index of the instruction we want to execute next
+ * MINUS one.
+ * @param counter counts how many times the rewinding has
+ * to happen.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_rewind_ip
+  (const char *label,
+   int new_ip,
+   unsigned int *counter);
 
 #endif
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index 39acd3a..6e88568 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -47,6 +47,7 @@ libtalermerchanttesting_la_SOURCES = \
   testing_api_cmd_tip.c \
   testing_api_cmd_track.c \
   testing_api_cmd_history.c \
+  testing_api_cmd_rewind.c \
   testing_api_helpers.c \
   testing_api_trait_merchant_sig.c \
   testing_api_trait_string.c \
diff --git a/src/lib/testing_api_cmd_proposal.c 
b/src/lib/testing_api_cmd_proposal.c
index 4529e40..13d32ab 100644
--- a/src/lib/testing_api_cmd_proposal.c
+++ b/src/lib/testing_api_cmd_proposal.c
@@ -346,6 +346,25 @@ proposal_run (void *cls,
     return;
   }
 
+  if (NULL == json_object_get (order,
+                               "order_id"))
+  {
+    struct GNUNET_TIME_Absolute now;
+    char *order_id;
+
+    now = GNUNET_TIME_absolute_get (); 
+
+    order_id = GNUNET_STRINGS_data_to_string_alloc
+      (&now.abs_value_us,
+       sizeof (now.abs_value_us));
+
+    json_object_set (order,
+                     "order_id",
+                     json_string (order_id));
+
+    GNUNET_free (order_id);
+  }
+
   GNUNET_CRYPTO_random_block
     (GNUNET_CRYPTO_QUALITY_WEAK,
      &ps->nonce,
diff --git a/src/lib/testing_api_cmd_rewind.c b/src/lib/testing_api_cmd_rewind.c
new file mode 100644
index 0000000..3e51f00
--- /dev/null
+++ b/src/lib/testing_api_cmd_rewind.c
@@ -0,0 +1,92 @@
+/*
+  This file is part of TALER
+  Copyright (C) 2014-2018 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_cmd_rewind.c
+ * @brief command to rewind the instruction pointer.
+ * @author Marcello Stanisci
+ */
+
+#include "platform.h"
+#include <taler/taler_exchange_service.h>
+#include <taler/taler_testing_lib.h>
+#include "taler_merchant_service.h"
+#include "taler_merchant_testing_lib.h"
+
+struct RewindIpState
+{
+  unsigned int new_ip;
+  unsigned int *counter;
+};
+
+static void
+rewind_ip_cleanup (void *cls,
+                   const struct TALER_TESTING_Command *cmd)
+{}
+
+static void
+rewind_ip_run (void *cls,
+               const struct TALER_TESTING_Command *cmd,
+               struct TALER_TESTING_Interpreter *is)
+{
+  struct RewindIpState *ris = cls;
+
+  if (1 < *ris->counter)
+  {
+    is->ip = ris->new_ip;
+    *ris->counter -= 1; 
+  }
+
+  TALER_TESTING_interpreter_next (is);
+}
+
+/**
+ * Make the instruction pointer point to @a new_ip
+ * only if @a counter is greater than zero.
+ *
+ * @param label command label
+ * @param new_ip new instruction pointer's value.  Note that,
+ * when the next instruction will be called, the interpreter
+ * will increment the ip under the hood so this value must be
+ * set to the index of the instruction we want to execute next
+ * MINUS one.
+ * @param counter counts how many times the rewinding has
+ * to happen.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_rewind_ip
+  (const char *label,
+   int new_ip,
+   unsigned int *counter)
+{
+  struct RewindIpState *ris;
+  struct TALER_TESTING_Command cmd;
+
+  ris = GNUNET_new (struct RewindIpState);
+  ris->new_ip = new_ip;
+  ris->counter = counter;
+
+  cmd.cls = ris;
+  cmd.label = label;
+  cmd.run = &rewind_ip_run;
+  cmd.cleanup = &rewind_ip_cleanup;
+
+  return cmd;
+}
+
diff --git a/src/merchant-tools/Makefile.am b/src/merchant-tools/Makefile.am
index be51a7c..69354cd 100644
--- a/src/merchant-tools/Makefile.am
+++ b/src/merchant-tools/Makefile.am
@@ -21,9 +21,9 @@ taler_merchant_generate_payments_new_SOURCES = \
 taler_merchant_generate_payments_new_LDADD = \
   $(top_srcdir)/src/backenddb/libtalermerchantdb.la \
   $(top_srcdir)/src/lib/libtalermerchant.la \
+  $(top_srcdir)/src/lib/libtalermerchanttesting.la \
   $(LIBGCRYPT_LIBS) \
   -ltalertesting \
-  -ltalermerchanttesting \
   -ltalerfakebank \
   -ltalerbank \
   -ltalerbanktesting \
diff --git a/src/merchant-tools/taler-merchant-generate-payments_new.c 
b/src/merchant-tools/taler-merchant-generate-payments_new.c
index 67a1a48..a2df433 100644
--- a/src/merchant-tools/taler-merchant-generate-payments_new.c
+++ b/src/merchant-tools/taler-merchant-generate-payments_new.c
@@ -43,30 +43,50 @@
 #define MISSING_BANK_URL 4
 #define FAILED_TO_LAUNCH_BANK 5
 
+#define USER_ACCOUNT_NO 3
+#define EXCHANGE_ACCOUNT_NO 2
+#define USER_LOGIN_NAME "Tor"
+#define USER_LOGIN_PASS "x"
+#define EXCHANGE_URL "http://example.com/";
+
+#define CMD_TRANSFER_TO_EXCHANGE(label,amount) \
+   TALER_TESTING_cmd_fakebank_transfer (label, amount, \
+     bank_url, USER_ACCOUNT_NO, EXCHANGE_ACCOUNT_NO, \
+     USER_LOGIN_NAME, USER_LOGIN_PASS, EXCHANGE_URL)
+
 /**
  * Exit code.
  */
-unsigned int result;
+static unsigned int result;
 
 /**
- * Merchant process.
+ * Bank process.
  */
-static struct GNUNET_OS_Process *merchantd;
+static struct GNUNET_OS_Process *bankd;
 
 /**
- * Bank process.
+ * Indicates whether we'll use the Python bank (GNUNET_YES),
+ * or the fakebank.
  */
-static struct GNUNET_OS_Process *bankd;
+static int with_pybank;
+
+/**
+ * Merchant process.
+ */
+static struct GNUNET_OS_Process *merchantd;
 
 /**
  * How many payments we want to generate.
  */
-unsigned int payments_number;
+static unsigned int payments_number = 1;
 
 /**
  * How many /tracks operation we want to perform.
  */
-unsigned int tracks_number;
+static unsigned int tracks_number;
+
+
+static const char *default_config_file;
 
 /**
  * Bank base URL.
@@ -90,11 +110,92 @@ static void
 run (void *cls,
      struct TALER_TESTING_Interpreter *is)
 {
+
   struct TALER_TESTING_Command commands[] = {
+
+    CMD_TRANSFER_TO_EXCHANGE
+      ("create-reserve-1",
+       "USD:10.02"),
+
+    TALER_TESTING_cmd_exec_wirewatch
+      ("wirewatch-1",
+       default_config_file),
+
+    TALER_TESTING_cmd_withdraw_amount
+      ("withdraw-coin-1",
+       is->exchange,
+       "create-reserve-1",
+       "USD:5",
+       MHD_HTTP_OK),
+
+    TALER_TESTING_cmd_withdraw_amount
+      ("withdraw-coin-2",
+       is->exchange,
+       "create-reserve-1",
+       "USD:5",
+       MHD_HTTP_OK),
+
+    TALER_TESTING_cmd_status
+      ("withdraw-status-1",
+       is->exchange,
+       "create-reserve-1",
+       "USD:0",
+       MHD_HTTP_OK),
+
+    TALER_TESTING_cmd_proposal
+      ("create-proposal-1",
+       merchant_url,
+       is->ctx,
+       MHD_HTTP_OK,
+       "{\"max_fee\":\
+          {\"currency\":\"USD\",\
+           \"value\":0,\
+           \"fraction\":50000000},\
+        \"refund_deadline\":\"\\/Date(0)\\/\",\
+        \"pay_deadline\":\"\\/Date(99999999999)\\/\",\
+        \"amount\":\
+          {\"currency\":\"USD\",\
+           \"value\":5,\
+           \"fraction\":0},\
+        \"summary\": \"merchant-lib testcase\",\
+        \"fulfillment_url\": \"https://example.com/\",\
+        \"products\": [ {\"description\":\"ice cream\",\
+                         \"value\":\"{USD:5}\"} ] }",
+        NULL),
+
+    TALER_TESTING_cmd_check_payment
+      ("check-payment-1",
+       merchant_url,
+       is->ctx,
+       MHD_HTTP_OK,
+       "create-proposal-1",
+       GNUNET_NO),
+
+    TALER_TESTING_cmd_pay
+      ("deposit-simple",
+       merchant_url,
+       is->ctx,
+       MHD_HTTP_OK,
+       "create-proposal-1",
+       "withdraw-coin-1",
+       "USD:5",
+       "USD:4.99",
+       "USD:0.01"),
+
     TALER_TESTING_cmd_end ()
   };
 
-  TALER_TESTING_run (is, commands);
+  if (GNUNET_YES == with_pybank)
+  {
+    TALER_TESTING_run (is,
+                       commands);
+    return; 
+  }
+
+  TALER_TESTING_run_with_fakebank
+    (is,
+     commands,
+     bank_url);
 }
 
 /**
@@ -122,8 +223,6 @@ main (int argc,
       char *const *argv)
 {
 
-  const char *default_config_file;
-
   default_config_file = GNUNET_OS_project_data_get
     ()->user_config_file;
 
@@ -171,6 +270,12 @@ main (int argc,
        "will log to file LF",
        &logfile),
 
+    GNUNET_GETOPT_option_flag
+      ('p',
+       "with-pybank",
+       "Use the Python bank, if given",
+       &with_pybank),
+
     GNUNET_GETOPT_OPTION_END
   };
 
@@ -181,7 +286,7 @@ main (int argc,
      argv));
 
   GNUNET_log_setup ("taler-merchant-generate-payments-new",
-                    "INFO",
+                    "DEBUG",
                     logfile);
 
   if (NULL == merchant_url)
@@ -204,9 +309,10 @@ main (int argc,
     return MISSING_BANK_URL;
   }
 
-  if (NULL == (bankd = TALER_TESTING_run_bank
-    (default_config_file,
-     bank_url)))
+  if ((GNUNET_YES == with_pybank)
+      && NULL == (bankd = TALER_TESTING_run_bank
+        (default_config_file,
+         bank_url)))
   {
     TALER_LOG_ERROR ("Failed to run the bank\n");
     terminate_process (bankd);
@@ -219,8 +325,8 @@ main (int argc,
      NULL,
      default_config_file);
 
-  terminate_process (bankd);
   terminate_process (merchantd);
+  terminate_process (bankd);
 
   return (GNUNET_OK == result) ? 0 : result;
 }

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



reply via email to

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