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: Fix track API tests


From: gnunet
Subject: [GNUnet-SVN] [taler-merchant] branch master updated: Fix track API tests.
Date: Fri, 10 Feb 2017 17:34:19 +0100

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

marcello pushed a commit to branch master
in repository merchant.

The following commit(s) were added to refs/heads/master by this push:
     new 3e4ae93  Fix track API tests.
3e4ae93 is described below

commit 3e4ae933093b6161aa4f7c6ec21f3210f4f23945
Author: Marcello Stanisci <address@hidden>
AuthorDate: Fri Feb 10 17:33:04 2017 +0100

    Fix track API tests.
---
 src/backend/taler-merchant-httpd_proposal.c        | 17 ++++++++++++++++-
 .../taler-merchant-httpd_track-transaction.c       | 13 ++++++++++---
 src/backenddb/plugin_merchantdb_postgres.c         | 21 ++++++++++++++-------
 src/backenddb/test_merchantdb.c                    |  4 +++-
 src/include/taler_merchant_service.h               |  1 +
 src/include/taler_merchantdb_plugin.h              |  6 ++++--
 src/lib/merchant_api_proposal.c                    |  6 ++++--
 src/lib/test_merchant_api.c                        | 22 ++++++++++++++--------
 8 files changed, 66 insertions(+), 24 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_proposal.c 
b/src/backend/taler-merchant-httpd_proposal.c
index 6e45b2d..0ee23c8 100644
--- a/src/backend/taler-merchant-httpd_proposal.c
+++ b/src/backend/taler-merchant-httpd_proposal.c
@@ -292,6 +292,7 @@ MH_handler_proposal_put (struct TMH_RequestHandler *rh,
   if (GNUNET_OK !=
       db->insert_proposal_data (db->cls,
                                 &h_oid,
+                                &mi->pubkey,
                                 order))
     return TMH_RESPONSE_reply_internal_error (connection,
                                               TALER_EC_PROPOSAL_STORE_DB_ERROR,
@@ -329,9 +330,22 @@ MH_handler_proposal_lookup (struct TMH_RequestHandler *rh,
                             size_t *upload_data_size)
 {
   const char *order_id;
+  const char *instance;
   struct GNUNET_HashCode h_oid;
   int res;
   json_t *proposal_data;
+  struct MerchantInstance *mi;
+
+  instance = MHD_lookup_connection_value (connection,
+                                          MHD_GET_ARGUMENT_KIND,
+                                          "instance");
+  if (NULL == instance)
+    return TMH_RESPONSE_reply_arg_missing (connection,
+                                          TALER_EC_PARAMETER_MISSING,
+                                           "instance");
+
+  mi = TMH_lookup_instance (instance);
+  GNUNET_assert (NULL != mi);
 
   order_id = MHD_lookup_connection_value (connection,
                                           MHD_GET_ARGUMENT_KIND,
@@ -346,7 +360,8 @@ MH_handler_proposal_lookup (struct TMH_RequestHandler *rh,
 
   res = db->find_proposal_data (db->cls,
                                 &proposal_data,
-                                &h_oid);
+                                &h_oid,
+                                &mi->pubkey);
   if (GNUNET_NO == res)
     return TMH_RESPONSE_reply_not_found (connection, 
                                          TALER_EC_PROPOSAL_LOOKUP_NOT_FOUND,
diff --git a/src/backend/taler-merchant-httpd_track-transaction.c 
b/src/backend/taler-merchant-httpd_track-transaction.c
index 0e48b3c..608c3eb 100644
--- a/src/backend/taler-merchant-httpd_track-transaction.c
+++ b/src/backend/taler-merchant-httpd_track-transaction.c
@@ -907,17 +907,21 @@ MH_handler_track_transaction (struct TMH_RequestHandler 
*rh,
                                           "instance");
   if (NULL == instance)
     instance = "default";
+
   GNUNET_CRYPTO_hash (instance,
                       strlen (instance),
                       &h_instance);
+
   GNUNET_CRYPTO_hash (order_id,
                       strlen (order_id),
                       &h_order_id);
 
-
-
   tctx->mi = GNUNET_CONTAINER_multihashmap_get (by_id_map,
                                                 &h_instance);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Tracking on behalf of instance '%s'\n",
+              instance);
+
   if (NULL == tctx->mi)
     return TMH_RESPONSE_reply_not_found (connection,
                                         
TALER_EC_TRACK_TRANSACTION_INSTANCE_UNKNOWN,
@@ -925,7 +929,8 @@ MH_handler_track_transaction (struct TMH_RequestHandler *rh,
 
   if (GNUNET_YES != db->find_proposal_data (db->cls,
                                             &proposal_data,
-                                            &h_order_id))
+                                            &h_order_id,
+                                            &tctx->mi->pubkey))
 
     return TMH_RESPONSE_reply_not_found (connection,
                                         TALER_EC_PROPOSAL_LOOKUP_NOT_FOUND,
@@ -944,6 +949,8 @@ MH_handler_track_transaction (struct TMH_RequestHandler *rh,
                               tctx);
   if (GNUNET_NO == ret)
   {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "h_proposal_data not found\n");
     return TMH_RESPONSE_reply_not_found (connection,
                                         
TALER_EC_TRACK_TRANSACTION_TRANSACTION_UNKNOWN,
                                          "h_proposal_data is unknown");
diff --git a/src/backenddb/plugin_merchantdb_postgres.c 
b/src/backenddb/plugin_merchantdb_postgres.c
index 6a8bb46..1c47902 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -165,8 +165,9 @@ postgres_initialize (void *cls)
   PG_EXEC (pg,
            "CREATE TABLE IF NOT EXISTS merchant_proposal_data ("
            "h_order_id BYTEA NOT NULL"
+           ",merchant_pub BYTEA NOT NULL"
            ",proposal_data BYTEA NOT NULL"
-          ",PRIMARY KEY (h_order_id)"
+          ",PRIMARY KEY (h_order_id, merchant_pub)"
            ");");
 
   PG_EXEC (pg,
@@ -279,17 +280,19 @@ postgres_initialize (void *cls)
               "insert_proposal_data",
               "INSERT INTO merchant_proposal_data"
               "(h_order_id"
+              ",merchant_pub"
               ",proposal_data)"
               " VALUES "
-              "($1, $2)",
-              2);
+              "($1, $2, $3)",
+              3);
 
   PG_PREPARE (pg,
               "find_proposal_data",
               "SELECT proposal_data FROM merchant_proposal_data"
               " WHERE"
-              " h_order_id=$1",
-              1);
+              " h_order_id=$1"
+              " AND merchant_pub=$2",
+              2);
 
   PG_PREPARE (pg,
               "find_transactions_by_date",
@@ -406,7 +409,8 @@ postgres_initialize (void *cls)
 static int
 postgres_find_proposal_data (void *cls,
                              json_t **proposal_data,
-                             struct GNUNET_HashCode *h_transaction_id)
+                             const struct GNUNET_HashCode *h_transaction_id,
+                             const struct TALER_MerchantPublicKeyP 
*merchant_pub)
 {
   struct PostgresClosure *pg = cls;
   PGresult *result;
@@ -414,6 +418,7 @@ postgres_find_proposal_data (void *cls,
 
   struct GNUNET_PQ_QueryParam params[] = {
     GNUNET_PQ_query_param_auto_from_type (h_transaction_id),
+    GNUNET_PQ_query_param_auto_from_type (merchant_pub),
     GNUNET_PQ_query_param_end
   };
 
@@ -461,7 +466,8 @@ postgres_find_proposal_data (void *cls,
  */
 static int
 postgres_insert_proposal_data (void *cls,
-                               struct GNUNET_HashCode *h_transaction_id,
+                               const struct GNUNET_HashCode *h_transaction_id,
+                               const struct TALER_MerchantPublicKeyP 
*merchant_pub,
                                const json_t *proposal_data)
 {
   struct PostgresClosure *pg = cls;
@@ -470,6 +476,7 @@ postgres_insert_proposal_data (void *cls,
 
   struct GNUNET_PQ_QueryParam params[] = {
     GNUNET_PQ_query_param_auto_from_type (h_transaction_id),
+    GNUNET_PQ_query_param_auto_from_type (merchant_pub),
     TALER_PQ_query_param_json (proposal_data),
     GNUNET_PQ_query_param_end
   };
diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c
index b74549d..c8366f3 100644
--- a/src/backenddb/test_merchantdb.c
+++ b/src/backenddb/test_merchantdb.c
@@ -372,6 +372,7 @@ run (void *cls)
   FAILIF (GNUNET_OK !=
           plugin->insert_proposal_data (plugin->cls,
                                         &h_transaction_id,
+                                        &merchant_pub,
                                         proposal_data));
 
   json_t *out;
@@ -379,7 +380,8 @@ run (void *cls)
   FAILIF (GNUNET_OK !=
           plugin->find_proposal_data (plugin->cls,
                                       &out, // plain data
-                                      &h_transaction_id));
+                                      &h_transaction_id,
+                                      &merchant_pub));
 
   FAILIF (GNUNET_OK !=
           plugin->store_transaction (plugin->cls,
diff --git a/src/include/taler_merchant_service.h 
b/src/include/taler_merchant_service.h
index 61919d0..6c549c8 100644
--- a/src/include/taler_merchant_service.h
+++ b/src/include/taler_merchant_service.h
@@ -123,6 +123,7 @@ struct TALER_MERCHANT_ProposalLookupOperation *
 TALER_MERCHANT_proposal_lookup (struct GNUNET_CURL_Context *ctx,
                                 const char *backend_uri,
                                 const char *transaction_id,
+                                const char *instance,
                                 TALER_MERCHANT_ProposalLookupOperationCallback 
plo_cb,
                                 void *plo_cb_cls);
 
diff --git a/src/include/taler_merchantdb_plugin.h 
b/src/include/taler_merchantdb_plugin.h
index 06f1c56..33102a0 100644
--- a/src/include/taler_merchantdb_plugin.h
+++ b/src/include/taler_merchantdb_plugin.h
@@ -158,7 +158,8 @@ struct TALER_MERCHANTDB_Plugin
    */
   int
   (*insert_proposal_data) (void *cls,
-                           struct GNUNET_HashCode *h_transaction_id,
+                           const struct GNUNET_HashCode *h_transaction_id,
+                           const struct TALER_MerchantPublicKeyP *merchant_pub,
                            const json_t *proposal_data);
 
 
@@ -176,7 +177,8 @@ struct TALER_MERCHANTDB_Plugin
   int
   (*find_proposal_data) (void *cls,
                          json_t **proposal_data,
-                         struct GNUNET_HashCode *h_transaction_id);
+                         const struct GNUNET_HashCode *h_transaction_id,
+                         const struct TALER_MerchantPublicKeyP *merchant_pub);
 
 
   /**
diff --git a/src/lib/merchant_api_proposal.c b/src/lib/merchant_api_proposal.c
index 60b38d9..c3e5873 100644
--- a/src/lib/merchant_api_proposal.c
+++ b/src/lib/merchant_api_proposal.c
@@ -288,6 +288,7 @@ struct TALER_MERCHANT_ProposalLookupOperation *
 TALER_MERCHANT_proposal_lookup (struct GNUNET_CURL_Context *ctx,
                                 const char *backend_uri,
                                 const char *order_id,
+                                const char *instance,
                                 TALER_MERCHANT_ProposalLookupOperationCallback 
plo_cb,
                                 void *plo_cb_cls)
 {
@@ -300,9 +301,10 @@ TALER_MERCHANT_proposal_lookup (struct GNUNET_CURL_Context 
*ctx,
   plo->cb_cls = plo_cb_cls;
 
   GNUNET_asprintf (&plo->url,
-                   "%s/proposal?order_id=%s",
+                   "%s/proposal?order_id=%s&instance=%s",
                    backend_uri,
-                   order_id);
+                   order_id,
+                   instance);
   eh = curl_easy_init ();
   if (CURLE_OK != curl_easy_setopt (eh,
                                     CURLOPT_URL,
diff --git a/src/lib/test_merchant_api.c b/src/lib/test_merchant_api.c
index a69e4c9..0a7856c 100644
--- a/src/lib/test_merchant_api.c
+++ b/src/lib/test_merchant_api.c
@@ -1046,6 +1046,9 @@ proposal_cb (void *cls,
     cmd->details.proposal.proposal_data = json_incref ((json_t *) 
proposal_data);
     cmd->details.proposal.merchant_sig = *sig;
     cmd->details.proposal.hash = *hash;
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Hashed proposal, '%s'\n",
+                GNUNET_h2s (hash));
     break;
   default:
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -1357,6 +1360,8 @@ track_transaction_cb (void *cls,
       struct TALER_Amount ea;
       struct TALER_Amount coin_contribution;
 
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "Successful /track/tracking\n");
       if (1 != num_transfers)
       {
         GNUNET_break (0);
@@ -1511,7 +1516,7 @@ interpreter_run (void *cls)
       is->ip = 0;
       instance_idx++;
       instance = instances[instance_idx];
-      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
                   "Switching instance: '%s'\n",
                   instance);
   
@@ -1535,6 +1540,7 @@ interpreter_run (void *cls)
                        = TALER_MERCHANT_proposal_lookup (ctx,
                                                          MERCHANT_URI,
                                                          order_id,
+                                                         instance,
                                                          proposal_lookup_cb,
                                                          is)));
     }
@@ -1762,9 +1768,6 @@ interpreter_run (void *cls)
                           cmd->details.pay.contract_ref);
       GNUNET_assert (NULL != ref);
       merchant_sig = ref->details.proposal.merchant_sig;
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                  "Depositing I on '%s'\n",
-                  GNUNET_h2s (&ref->details.proposal.hash));
       GNUNET_assert (NULL != ref->details.proposal.proposal_data);
       {
         /* Get information that need to be replied in the deposit permission */
@@ -1840,10 +1843,6 @@ interpreter_run (void *cls)
        }
       }
 
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                  "Depositing II on '%s'\n",
-                  GNUNET_h2s (&ref->details.proposal.hash));
-
       cmd->details.pay.ph
        = TALER_MERCHANT_pay_wallet (ctx,
                                     MERCHANT_URI,
@@ -2380,6 +2379,13 @@ run (void *cls)
     { .oc = OC_CHECK_BANK_TRANSFERS_EMPTY,
       .label = "check_bank_empty" },
 
+    { .oc = OC_TRACK_TRANSACTION,
+      .label = "track-transaction-1",
+      .expected_response_code = MHD_HTTP_OK,
+      .details.track_transaction.expected_transfer_ref = 
"check_bank_transfer-499c",
+      .details.track_transaction.pay_ref = "deposit-simple"  
+    },
+
     /* Trace the WTID back to the original transaction */
     { .oc = OC_TRACK_TRANSFER,
       .label = "track-transfer-1",

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



reply via email to

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