gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] branch master updated: -towards fixing the template tes


From: gnunet
Subject: [taler-merchant] branch master updated: -towards fixing the template tests
Date: Thu, 29 Dec 2022 14:47:19 +0100

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

grothoff pushed a commit to branch master
in repository merchant.

The following commit(s) were added to refs/heads/master by this push:
     new 2c19f6a6 -towards fixing the template tests
2c19f6a6 is described below

commit 2c19f6a6fb180f059fcaeb193dd387c4d6af21b1
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Thu Dec 29 14:47:17 2022 +0100

    -towards fixing the template tests
---
 src/backend/taler-merchant-httpd_helper.c          |  21 +--
 .../taler-merchant-httpd_post-using-templates.c    | 191 +++++++++-----------
 ...taler-merchant-httpd_private-get-templates-ID.c |  15 +-
 .../taler-merchant-httpd_private-post-templates.c  |  43 ++---
 src/backenddb/plugin_merchantdb_postgres.c         |  48 ++---
 src/include/taler_merchant_service.h               |   1 +
 src/include/taler_merchant_testing_lib.h           |  59 ++----
 src/lib/merchant_api_get_template.c                |  12 +-
 src/lib/merchant_api_post_orders.c                 |   4 +
 src/lib/merchant_api_post_templates.c              |  54 +++++-
 src/lib/merchant_api_post_using_templates.c        |  12 +-
 src/testing/test_merchant_api.c                    | 201 ++++++++++++---------
 src/testing/testing_api_cmd_get_template.c         |  41 +++--
 src/testing/testing_api_cmd_post_templates.c       |  42 ++---
 src/testing/testing_api_cmd_post_using_templates.c | 116 ++++--------
 15 files changed, 438 insertions(+), 422 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_helper.c 
b/src/backend/taler-merchant-httpd_helper.c
index a5de1781..86ff37c3 100644
--- a/src/backend/taler-merchant-httpd_helper.c
+++ b/src/backend/taler-merchant-httpd_helper.c
@@ -88,6 +88,7 @@ TMH_payto_uri_array_valid (const json_t *payto_uris)
   return payto_ok;
 }
 
+
 bool
 TMH_location_object_valid (const json_t *location)
 {
@@ -270,8 +271,8 @@ TMH_products_array_valid (const json_t *products)
     if ( (NULL != taxes) &&
          (! TMH_taxes_array_valid (taxes)) )
     {
-        GNUNET_break_op (0);
-        valid = false;
+      GNUNET_break_op (0);
+      valid = false;
     }
     if ( (NULL != description_i18n) &&
          (! TALER_JSON_check_i18n (description_i18n)) )
@@ -315,13 +316,14 @@ TMH_image_data_url_valid (const char *image_data_url)
   return true;
 }
 
+
 bool
 TMH_template_contract_valid (const json_t *template_contract)
 {
   const char *summary;
   struct TALER_Amount amount = { .value = 0};
   uint32_t minimum_age = 0;
-  struct GNUNET_TIME_Relative pay_duration= { 0 };
+  struct GNUNET_TIME_Relative pay_duration = { 0 };
   struct GNUNET_JSON_Specification spec[] = {
     GNUNET_JSON_spec_mark_optional (
       GNUNET_JSON_spec_string ("summary",
@@ -332,14 +334,10 @@ TMH_template_contract_valid (const json_t 
*template_contract)
                               TMH_currency,
                               &amount),
       NULL),
-    GNUNET_JSON_spec_mark_optional (
-      GNUNET_JSON_spec_uint32 ("minimum_age",
-                               &minimum_age),
-      NULL),
-    GNUNET_JSON_spec_mark_optional (
-      GNUNET_JSON_spec_relative_time ("pay_duration",
-                                     &pay_duration),
-      NULL),
+    GNUNET_JSON_spec_uint32 ("minimum_age",
+                             &minimum_age),
+    GNUNET_JSON_spec_relative_time ("pay_duration",
+                                    &pay_duration),
     GNUNET_JSON_spec_end ()
   };
   const char *ename;
@@ -359,6 +357,7 @@ TMH_template_contract_valid (const json_t 
*template_contract)
   return true;
 }
 
+
 bool
 TMH_taxes_array_valid (const json_t *taxes)
 {
diff --git a/src/backend/taler-merchant-httpd_post-using-templates.c 
b/src/backend/taler-merchant-httpd_post-using-templates.c
index 75f489dd..9252afc8 100644
--- a/src/backend/taler-merchant-httpd_post-using-templates.c
+++ b/src/backend/taler-merchant-httpd_post-using-templates.c
@@ -1,6 +1,6 @@
 /*
   This file is part of TALER
-  (C) 2020 Taler Systems SA
+  (C) 2022 Taler Systems SA
 
   TALER is free software; you can redistribute it and/or modify
   it under the terms of the GNU Affero General Public License as
@@ -28,11 +28,6 @@
 #include "taler-merchant-httpd_helper.h"
 #include <taler/taler_json_lib.h>
 
-/**
- * How often do we retry the simple INSERT database transaction?
- */
-#define MAX_RETRIES 3
-
 
 MHD_RESULT
 TMH_post_using_templates_ID (const struct TMH_RequestHandler *rh,
@@ -48,7 +43,7 @@ TMH_post_using_templates_ID (const struct TMH_RequestHandler 
*rh,
   struct TALER_Amount amount;
   bool no_amount;
   json_t *fake_body;
-   bool no_summary;
+  bool no_summary;
   struct TALER_MERCHANTDB_TemplateDetails etp;
 
   struct GNUNET_JSON_Specification spec[] = {
@@ -64,7 +59,7 @@ TMH_post_using_templates_ID (const struct TMH_RequestHandler 
*rh,
     GNUNET_JSON_spec_end ()
   };
 
- {
+  {
     enum GNUNET_GenericReturnValue res;
 
     res = TALER_MHD_parse_json_data (connection,
@@ -79,13 +74,13 @@ TMH_post_using_templates_ID (const struct 
TMH_RequestHandler *rh,
     }
   }
 
- {
-   enum GNUNET_DB_QueryStatus qs;
+  {
+    enum GNUNET_DB_QueryStatus qs;
 
-   qs = TMH_db->lookup_template (TMH_db->cls,
-                                   mi->settings.id,
-                                   template_id,
-                                   &etp);
+    qs = TMH_db->lookup_template (TMH_db->cls,
+                                  mi->settings.id,
+                                  template_id,
+                                  &etp);
     switch (qs)
     {
     case GNUNET_DB_STATUS_HARD_ERROR:
@@ -115,15 +110,15 @@ TMH_post_using_templates_ID (const struct 
TMH_RequestHandler *rh,
       /* all good */
       break;
     } /* End of the switch */
- }
+  }
 
- const char *tsummary;
- uint32_t min_age;
- struct GNUNET_TIME_Relative pay_duration;
- struct TALER_Amount tamount;
- bool no_tamount;
+  const char *tsummary;
+  uint32_t min_age;
+  struct GNUNET_TIME_Relative pay_duration;
+  struct TALER_Amount tamount;
+  bool no_tamount;
 
- struct GNUNET_JSON_Specification tspec[] = {
+  struct GNUNET_JSON_Specification tspec[] = {
     GNUNET_JSON_spec_mark_optional (
       GNUNET_JSON_spec_string ("summary",
                                &tsummary),
@@ -135,14 +130,12 @@ TMH_post_using_templates_ID (const struct 
TMH_RequestHandler *rh,
       &no_tamount),
     GNUNET_JSON_spec_uint32 ("minimum_age",
                              &min_age),
-    GNUNET_JSON_spec_mark_optional (
-      GNUNET_JSON_spec_relative_time ("pay_duration",
-                                      &pay_duration),
-      NULL),
+    GNUNET_JSON_spec_relative_time ("pay_duration",
+                                    &pay_duration),
     GNUNET_JSON_spec_end ()
   };
 
- {
+  {
     enum GNUNET_GenericReturnValue res;
     const char *err_name;
     unsigned int err_line;
@@ -154,6 +147,9 @@ TMH_post_using_templates_ID (const struct 
TMH_RequestHandler *rh,
     if (GNUNET_OK != res)
     {
       GNUNET_break (0);
+      json_dumpf (etp.template_contract,
+                  stderr,
+                  JSON_INDENT (2));
       GNUNET_JSON_parse_free (spec);
       return TALER_MHD_reply_with_error (connection,
                                          MHD_HTTP_INTERNAL_SERVER_ERROR,
@@ -162,85 +158,78 @@ TMH_post_using_templates_ID (const struct 
TMH_RequestHandler *rh,
     }
   }
 
- // if amount given in template AND request
- if ((!no_amount) && (!no_tamount))
-       {
-         GNUNET_JSON_parse_free (spec);
-         return TALER_MHD_reply_with_error (connection,
-                                            MHD_HTTP_CONFLICT,
-                                            
TALER_EC_MERCHANT_POST_USING_TEMPLATES_AMOUNT_CONFLICT_TEMPLATES_CONTRACT_AMOUNT,
-                                            NULL);
-       }
-
- // if there is no amount in template and request
- if (no_amount && no_tamount)
-   {
-     GNUNET_JSON_parse_free (spec);
-     return TALER_MHD_reply_with_error (connection,
-                                        MHD_HTTP_CONFLICT,
-                                        
TALER_EC_MERCHANT_POST_USING_TEMPLATES_NO_AMOUNT,
-                                        NULL);
-   }
-
- // if subject given in both
- if ( (NULL!=summary) && (NULL != tsummary))
-   {
-
-     GNUNET_JSON_parse_free (spec);
-     return TALER_MHD_reply_with_error (connection,
-                                        MHD_HTTP_CONFLICT,
-                                        
TALER_EC_MERCHANT_POST_USING_TEMPLATES_SUMMARY_CONFLICT_TEMPLATES_CONTRACT_SUBJECT,
-                                        NULL);
-   }
-
- //if there is no summary in template and request
- if ( (NULL == summary) && (NULL == tsummary) )
-   {
-     GNUNET_JSON_parse_free (spec);
-     return TALER_MHD_reply_with_error (connection,
-                                        MHD_HTTP_CONFLICT,
-                                        
TALER_EC_MERCHANT_POST_USING_TEMPLATES_NO_SUMMARY,
-                                        NULL);
-   }
-
- else
-   {
-     if ( (NULL == summary) )
-       {
-         no_summary = true;
-       }
-     else
-       {
-         no_summary = false;
-       }
-   }
-
-    fake_body = GNUNET_JSON_PACK (
+  // if amount given in template AND request
+  if ((! no_amount) && (! no_tamount))
+  {
+    GNUNET_JSON_parse_free (spec);
+    return TALER_MHD_reply_with_error (connection,
+                                       MHD_HTTP_CONFLICT,
+                                       
TALER_EC_MERCHANT_POST_USING_TEMPLATES_AMOUNT_CONFLICT_TEMPLATES_CONTRACT_AMOUNT,
+                                       NULL);
+  }
+
+  // if there is no amount in template and request
+  if (no_amount && no_tamount)
+  {
+    GNUNET_JSON_parse_free (spec);
+    return TALER_MHD_reply_with_error (connection,
+                                       MHD_HTTP_CONFLICT,
+                                       
TALER_EC_MERCHANT_POST_USING_TEMPLATES_NO_AMOUNT,
+                                       NULL);
+  }
+
+  if ( (NULL!=summary) && (NULL != tsummary))
+  {
+
+    GNUNET_JSON_parse_free (spec);
+    return TALER_MHD_reply_with_error (connection,
+                                       MHD_HTTP_CONFLICT,
+                                       
TALER_EC_MERCHANT_POST_USING_TEMPLATES_SUMMARY_CONFLICT_TEMPLATES_CONTRACT_SUBJECT,
+                                       NULL);
+  }
+
+  // if there is no summary in template and request
+  if ( (NULL == summary) && (NULL == tsummary) )
+  {
+    GNUNET_JSON_parse_free (spec);
+    return TALER_MHD_reply_with_error (connection,
+                                       MHD_HTTP_CONFLICT,
+                                       
TALER_EC_MERCHANT_POST_USING_TEMPLATES_NO_SUMMARY,
+                                       NULL);
+  }
+  no_summary = (NULL == summary);
+  fake_body = GNUNET_JSON_PACK (
     GNUNET_JSON_pack_object_steal ("order",
                                    GNUNET_JSON_PACK (
-    TALER_JSON_pack_amount ("amount",
-                            no_amount ? &tamount : &amount),
-    GNUNET_JSON_pack_string ("summary",
-                            no_summary ? tsummary : summary),
-    GNUNET_JSON_pack_allow_null (
-    GNUNET_JSON_pack_string ("fulfillment_url",
-                             fulfillment_url)),
-    GNUNET_JSON_pack_allow_null (
-    GNUNET_JSON_pack_string ("fulfillment_message",
-                             fulfillment_message))
-                                                     ))
+                                     TALER_JSON_pack_amount ("amount",
+                                                             no_amount ?
+                                                             &tamount :
+                                                             &amount),
+                                     GNUNET_JSON_pack_string ("summary",
+                                                              no_summary ?
+                                                              tsummary :
+                                                              summary),
+                                     GNUNET_JSON_pack_allow_null (
+                                       GNUNET_JSON_pack_string (
+                                         "fulfillment_url",
+                                         fulfillment_url)),
+                                     GNUNET_JSON_pack_allow_null (
+                                       GNUNET_JSON_pack_string (
+                                         "fulfillment_message",
+                                         fulfillment_message))
+                                     ))
     );
-
-
   TALER_MERCHANTDB_template_details_free (&etp);
-
-  struct TMH_HandlerContext fake_hc = {
-    .request_body = fake_body,
-    .instance = hc->instance
-  };
-  mret = TMH_private_post_orders (NULL, /* not even used */
-                                 connection,
-                                 &fake_hc);
+  {
+    struct TMH_HandlerContext fake_hc = {
+      .request_body = fake_body,
+      .instance = hc->instance
+    };
+
+    mret = TMH_private_post_orders (NULL, /* not even used */
+                                    connection,
+                                    &fake_hc);
+  }
   json_decref (fake_body);
   return mret;
 }
diff --git a/src/backend/taler-merchant-httpd_private-get-templates-ID.c 
b/src/backend/taler-merchant-httpd_private-get-templates-ID.c
index 76e28fac..be5359f8 100644
--- a/src/backend/taler-merchant-httpd_private-get-templates-ID.c
+++ b/src/backend/taler-merchant-httpd_private-get-templates-ID.c
@@ -33,8 +33,8 @@
  */
 MHD_RESULT
 TMH_private_get_templates_ID (const struct TMH_RequestHandler *rh,
-                             struct MHD_Connection *connection,
-                             struct TMH_HandlerContext *hc)
+                              struct MHD_Connection *connection,
+                              struct TMH_HandlerContext *hc)
 {
   struct TMH_MerchantInstance *mi = hc->instance;
   struct TALER_MERCHANTDB_TemplateDetails tp = { 0 };
@@ -42,9 +42,9 @@ TMH_private_get_templates_ID (const struct TMH_RequestHandler 
*rh,
 
   GNUNET_assert (NULL != mi);
   qs = TMH_db->lookup_template (TMH_db->cls,
-                               mi->settings.id,
-                               hc->infix,
-                               &tp);
+                                mi->settings.id,
+                                hc->infix,
+                                &tp);
   if (0 > qs)
   {
     GNUNET_break (0);
@@ -68,8 +68,9 @@ TMH_private_get_templates_ID (const struct TMH_RequestHandler 
*rh,
       MHD_HTTP_OK,
       GNUNET_JSON_pack_string ("template_description",
                                tp.template_description),
-      GNUNET_JSON_pack_string ("image",
-                               tp.image),
+      GNUNET_JSON_pack_allow_null (
+        GNUNET_JSON_pack_string ("image",
+                                 tp.image)),
       GNUNET_JSON_pack_object_steal ("template_contract",
                                      tp.template_contract));
     GNUNET_free (tp.template_description);
diff --git a/src/backend/taler-merchant-httpd_private-post-templates.c 
b/src/backend/taler-merchant-httpd_private-post-templates.c
index 38daf664..136f0891 100644
--- a/src/backend/taler-merchant-httpd_private-post-templates.c
+++ b/src/backend/taler-merchant-httpd_private-post-templates.c
@@ -43,21 +43,23 @@
  */
 static bool
 templates_equal (const struct TALER_MERCHANTDB_TemplateDetails *t1,
-                const struct TALER_MERCHANTDB_TemplateDetails *t2)
+                 const struct TALER_MERCHANTDB_TemplateDetails *t2)
 {
   return ( (0 == strcmp (t1->template_description,
                          t2->template_description)) &&
-           (0 == strcmp (t1->image,
-                         t2->image)) &&
+           ( ( (NULL == t1->image) && (NULL == t2->image) ) ||
+             ( (NULL != t1->image) && (NULL != t2->image) &&
+               (0 == strcmp (t1->image,
+                             t2->image)) ) ) &&
            (1 == json_equal (t1->template_contract,
-                             t2->template_contract)));
+                             t2->template_contract)) );
 }
 
 
 MHD_RESULT
 TMH_private_post_templates (const struct TMH_RequestHandler *rh,
-                           struct MHD_Connection *connection,
-                           struct TMH_HandlerContext *hc)
+                            struct MHD_Connection *connection,
+                            struct TMH_HandlerContext *hc)
 {
   struct TMH_MerchantInstance *mi = hc->instance;
   struct TALER_MERCHANTDB_TemplateDetails tp = { 0 };
@@ -92,15 +94,12 @@ TMH_private_post_templates (const struct TMH_RequestHandler 
*rh,
              : MHD_NO;
     }
   }
-
-
-  if (NULL == tp.template_contract)
-    tp.template_contract = json_object ();;
-
-
   if (! TMH_template_contract_valid (tp.template_contract))
   {
     GNUNET_break_op (0);
+    json_dumpf (tp.template_contract,
+                stderr,
+                JSON_INDENT (2));
     GNUNET_JSON_parse_free (spec);
     return TALER_MHD_reply_with_error (connection,
                                        MHD_HTTP_BAD_REQUEST,
@@ -108,10 +107,8 @@ TMH_private_post_templates (const struct 
TMH_RequestHandler *rh,
                                        "template_contract");
   }
 
-
-  if (NULL == tp.image)
-    tp.image = "";
-  if (! TMH_image_data_url_valid (tp.image))
+  if ( (NULL != tp.image) &&
+       (! TMH_image_data_url_valid (tp.image)) )
   {
     GNUNET_break_op (0);
     GNUNET_JSON_parse_free (spec);
@@ -139,9 +136,9 @@ TMH_private_post_templates (const struct TMH_RequestHandler 
*rh,
                                          NULL);
     }
     qs = TMH_db->lookup_template (TMH_db->cls,
-                                 mi->settings.id,
-                                 template_id,
-                                 &etp);
+                                  mi->settings.id,
+                                  template_id,
+                                  &etp);
     switch (qs)
     {
     case GNUNET_DB_STATUS_HARD_ERROR:
@@ -165,7 +162,7 @@ TMH_private_post_templates (const struct TMH_RequestHandler 
*rh,
         bool eq;
 
         eq = templates_equal (&tp,
-                             &etp);
+                              &etp);
         TALER_MERCHANTDB_template_details_free (&etp);
         TMH_db->rollback (TMH_db->cls);
         GNUNET_JSON_parse_free (spec);
@@ -183,9 +180,9 @@ TMH_private_post_templates (const struct TMH_RequestHandler 
*rh,
     } /* end switch (qs) */
 
     qs = TMH_db->insert_template (TMH_db->cls,
-                                 mi->settings.id,
-                                 template_id,
-                                 &tp);
+                                  mi->settings.id,
+                                  template_id,
+                                  &tp);
     if (GNUNET_DB_STATUS_HARD_ERROR == qs)
     {
       TMH_db->rollback (TMH_db->cls);
diff --git a/src/backenddb/plugin_merchantdb_postgres.c 
b/src/backenddb/plugin_merchantdb_postgres.c
index 32f0b1be..e3f5762d 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -6864,10 +6864,11 @@ postgres_insert_template (void *cls,
     GNUNET_PQ_query_param_string (instance_id),
     GNUNET_PQ_query_param_string (template_id),
     GNUNET_PQ_query_param_string (td->template_description),
-    GNUNET_PQ_query_param_string (td->image),
+    NULL == td->image
+    ? GNUNET_PQ_query_param_null ()
+    : GNUNET_PQ_query_param_string (td->image),
     TALER_PQ_query_param_json (td->template_contract),
     GNUNET_PQ_query_param_end
-
   };
 
   check_connection (pg);
@@ -7059,14 +7060,17 @@ postgres_lookup_template (void *cls,
     struct GNUNET_PQ_ResultSpec rs[] = {
       GNUNET_PQ_result_spec_string ("template_description",
                                     &td->template_description),
-      GNUNET_PQ_result_spec_string ("image",
-                                    &td->image),
+      GNUNET_PQ_result_spec_allow_null (
+        GNUNET_PQ_result_spec_string ("image",
+                                      &td->image),
+        NULL),
       TALER_PQ_result_spec_json ("template_contract",
                                  &td->template_contract),
       GNUNET_PQ_result_spec_end
     };
 
     check_connection (pg);
+    td->image = NULL;
     return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
                                                      "lookup_template",
                                                      params,
@@ -7074,7 +7078,8 @@ postgres_lookup_template (void *cls,
   }
 }
 
-  /**
+
+/**
  * Delete information about a webhook.
  *
  * @param cls closure
@@ -7085,8 +7090,8 @@ postgres_lookup_template (void *cls,
  */
 static enum GNUNET_DB_QueryStatus
 postgres_delete_webhook (void *cls,
-                          const char *instance_id,
-                          const char *webhook_id)
+                         const char *instance_id,
+                         const char *webhook_id)
 {
   struct PostgresClosure *pg = cls;
   struct GNUNET_PQ_QueryParam params[] = {
@@ -7113,9 +7118,9 @@ postgres_delete_webhook (void *cls,
  */
 static enum GNUNET_DB_QueryStatus
 postgres_insert_webhook (void *cls,
-                          const char *instance_id,
-                          const char *webhook_id,
-                          const struct TALER_MERCHANTDB_WebhookDetails *wb)
+                         const char *instance_id,
+                         const char *webhook_id,
+                         const struct TALER_MERCHANTDB_WebhookDetails *wb)
 {
   struct PostgresClosure *pg = cls;
   struct GNUNET_PQ_QueryParam params[] = {
@@ -7150,9 +7155,9 @@ postgres_insert_webhook (void *cls,
  */
 static enum GNUNET_DB_QueryStatus
 postgres_update_webhook (void *cls,
-                          const char *instance_id,
-                          const char *webhook_id,
-                          const struct TALER_MERCHANTDB_WebhookDetails *wb)
+                         const char *instance_id,
+                         const char *webhook_id,
+                         const struct TALER_MERCHANTDB_WebhookDetails *wb)
 {
   struct PostgresClosure *pg = cls;
   struct GNUNET_PQ_QueryParam params[] = {
@@ -7206,8 +7211,8 @@ struct LookupWebhookContext
  */
 static void
 lookup_webhooks_cb (void *cls,
-                     PGresult *result,
-                     unsigned int num_results)
+                    PGresult *result,
+                    unsigned int num_results)
 {
   struct LookupWebhookContext *wlc = cls;
 
@@ -7239,6 +7244,7 @@ lookup_webhooks_cb (void *cls,
   }
 }
 
+
 /**
  * Lookup all of the webhooks the given instance has configured.
  *
@@ -7250,9 +7256,9 @@ lookup_webhooks_cb (void *cls,
  */
 static enum GNUNET_DB_QueryStatus
 postgres_lookup_webhooks (void *cls,
-                           const char *instance_id,
-                           TALER_MERCHANTDB_WebhooksCallback cb,
-                           void *cb_cls)
+                          const char *instance_id,
+                          TALER_MERCHANTDB_WebhooksCallback cb,
+                          void *cb_cls)
 {
   struct PostgresClosure *pg = cls;
   struct LookupWebhookContext wlc = {
@@ -7292,9 +7298,9 @@ postgres_lookup_webhooks (void *cls,
  */
 static enum GNUNET_DB_QueryStatus
 postgres_lookup_webhook (void *cls,
-                          const char *instance_id,
-                          const char *webhook_id,
-                          struct TALER_MERCHANTDB_WebhookDetails *wb)
+                         const char *instance_id,
+                         const char *webhook_id,
+                         struct TALER_MERCHANTDB_WebhookDetails *wb)
 {
   struct PostgresClosure *pg = cls;
   struct GNUNET_PQ_QueryParam params[] = {
diff --git a/src/include/taler_merchant_service.h 
b/src/include/taler_merchant_service.h
index a544380c..44793d4c 100644
--- a/src/include/taler_merchant_service.h
+++ b/src/include/taler_merchant_service.h
@@ -4380,6 +4380,7 @@ typedef void
 (*TALER_MERCHANT_UsingTemplatesPostCallback)(
   void *cls,
   const struct TALER_MERCHANT_HttpResponse *hr);
+// FIXME: should be: const struct TALER_MERCHANT_PostOrdersReply *por);
 
 /**
  * Make a POST /using-templates request to add an using template
diff --git a/src/include/taler_merchant_testing_lib.h 
b/src/include/taler_merchant_testing_lib.h
index d820d1af..baaa4c1a 100644
--- a/src/include/taler_merchant_testing_lib.h
+++ b/src/include/taler_merchant_testing_lib.h
@@ -1527,13 +1527,12 @@ TALER_TESTING_cmd_merchant_post_templates2 (
  */
 struct TALER_TESTING_Command
 TALER_TESTING_cmd_merchant_post_templates (const char *label,
-                                          const char *merchant_url,
-                                          const char *template_id,
-                                          const char *template_description,
+                                           const char *merchant_url,
+                                           const char *template_id,
+                                           const char *template_description,
                                            unsigned int http_status);
 
 
-
 /**
  * Define a "PATCH /templates/$ID" CMD.
  *
@@ -1572,8 +1571,8 @@ TALER_TESTING_cmd_merchant_patch_template (
  */
 struct TALER_TESTING_Command
 TALER_TESTING_cmd_merchant_get_templates (const char *label,
-                                         const char *merchant_url,
-                                         unsigned int http_status,
+                                          const char *merchant_url,
+                                          unsigned int http_status,
                                           ...);
 
 
@@ -1591,13 +1590,12 @@ TALER_TESTING_cmd_merchant_get_templates (const char 
*label,
  */
 struct TALER_TESTING_Command
 TALER_TESTING_cmd_merchant_get_template (const char *label,
-                                        const char *merchant_url,
-                                        const char *template_id,
-                                        unsigned int http_status,
+                                         const char *merchant_url,
+                                         const char *template_id,
+                                         unsigned int http_status,
                                          const char *template_reference);
 
 
-
 /**
  * Define a "DELETE template" CMD.
  *
@@ -1610,34 +1608,16 @@ TALER_TESTING_cmd_merchant_get_template (const char 
*label,
  */
 struct TALER_TESTING_Command
 TALER_TESTING_cmd_merchant_delete_template (const char *label,
-                                           const char *merchant_url,
-                                           const char *template_id,
+                                            const char *merchant_url,
+                                            const char *template_id,
                                             unsigned int http_status);
 
-/**
- * Define a "POST /using-templates" CMD.
- *
- * @param label command label.
- * @param merchant_url base URL of the merchant serving the
- *        POST /using-templates request.
- * @param summary given by the customer to know what they did pay
- * @param amount given by the customer to pay
- * @param http_status expected HTTP response code.
- * @return the command.
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_merchant_post_using_templates2 (
-  const char *label,
-  const char *merchant_url,
-  const char *summary,
-  const char *amount,
-  unsigned int http_status);
-
 
 /**
  * Define a "POST /using-templates" CMD, simple version
  *
  * @param label command label.
+ * @param template_ref label of command that created the template to use
  * @param merchant_url base URL of the merchant serving the
  *        POST /using-templates request.
  * @param summary given by the customer to know what they did pay
@@ -1647,6 +1627,7 @@ TALER_TESTING_cmd_merchant_post_using_templates2 (
  */
 struct TALER_TESTING_Command
 TALER_TESTING_cmd_merchant_post_using_templates (const char *label,
+                                                 const char *template_ref,
                                                  const char *merchant_url,
                                                  const char *summary,
                                                  const char *amount,
@@ -1700,7 +1681,7 @@ TALER_TESTING_cmd_merchant_post_webhooks (const char 
*label,
                                           const char *merchant_url,
                                           const char *webhook_id,
                                           const char *event_type,
-                                           unsigned int http_status);
+                                          unsigned int http_status);
 
 
 /**
@@ -1747,7 +1728,7 @@ struct TALER_TESTING_Command
 TALER_TESTING_cmd_merchant_get_webhooks (const char *label,
                                          const char *merchant_url,
                                          unsigned int http_status,
-                                          ...);
+                                         ...);
 
 
 /**
@@ -1767,8 +1748,7 @@ TALER_TESTING_cmd_merchant_get_webhook (const char *label,
                                         const char *merchant_url,
                                         const char *webhook_id,
                                         unsigned int http_status,
-                                         const char *webhook_reference);
-
+                                        const char *webhook_reference);
 
 
 /**
@@ -1785,10 +1765,7 @@ struct TALER_TESTING_Command
 TALER_TESTING_cmd_merchant_delete_webhook (const char *label,
                                            const char *merchant_url,
                                            const char *webhook_id,
-                                            unsigned int http_status);
-
-
-
+                                           unsigned int http_status);
 
 
 /* ****** Specific traits supported by this component ******* */
@@ -1835,14 +1812,14 @@ TALER_TESTING_cmd_merchant_delete_webhook (const char 
*label,
   op (template_description, const char *) \
   op (template_image, const char *) \
   op (template_id, const char *) \
-  op (template_contract, const json_t)\
+  op (template_contract, const json_t) \
   op (event_type, const char *)   \
   op (url, const char *) \
   op (webhook_id, const char *) \
   op (http_method, const char *)   \
   op (header_template, const char *)   \
   op (body_template, const char *)   \
-  op (summary, const char *) 
+  op (summary, const char *)
 
 
 /**
diff --git a/src/lib/merchant_api_get_template.c 
b/src/lib/merchant_api_get_template.c
index 23c35d8b..bced4097 100644
--- a/src/lib/merchant_api_get_template.c
+++ b/src/lib/merchant_api_get_template.c
@@ -74,8 +74,8 @@ struct TALER_MERCHANT_TemplateGetHandle
  */
 static void
 handle_get_template_finished (void *cls,
-                             long response_code,
-                             const void *response)
+                              long response_code,
+                              const void *response)
 {
   struct TALER_MERCHANT_TemplateGetHandle *tgh = cls;
   const json_t *json = response;
@@ -93,14 +93,16 @@ handle_get_template_finished (void *cls,
   case MHD_HTTP_OK:
     {
       const char *template_description;
-      const char *image;
+      const char *image = NULL;
       json_t *template_contract;
       bool rst_ok = true;
       struct GNUNET_JSON_Specification spec[] = {
         GNUNET_JSON_spec_string ("template_description",
                                  &template_description),
-        GNUNET_JSON_spec_string ("image",
-                                 &image),
+        GNUNET_JSON_spec_mark_optional (
+          GNUNET_JSON_spec_string ("image",
+                                   &image),
+          NULL),
         GNUNET_JSON_spec_json ("template_contract",
                                &template_contract),
         GNUNET_JSON_spec_end ()
diff --git a/src/lib/merchant_api_post_orders.c 
b/src/lib/merchant_api_post_orders.c
index c4ccea36..bb11f31c 100644
--- a/src/lib/merchant_api_post_orders.c
+++ b/src/lib/merchant_api_post_orders.c
@@ -95,6 +95,8 @@ handle_post_order_finished (void *cls,
   struct TALER_ClaimTokenP token;
 
   po->job = NULL;
+  // to_be_written_new_function (po->cb, po->cb_cls, response_code, json);
+  // roughly from here
   switch (response_code)
   {
   case 0:
@@ -214,6 +216,8 @@ handle_post_order_finished (void *cls,
   }
   po->cb (po->cb_cls,
           &por);
+  // end of new function
+
   TALER_MERCHANT_orders_post_cancel (po);
 }
 
diff --git a/src/lib/merchant_api_post_templates.c 
b/src/lib/merchant_api_post_templates.c
index 300039a4..eb6c0d20 100644
--- a/src/lib/merchant_api_post_templates.c
+++ b/src/lib/merchant_api_post_templates.c
@@ -81,8 +81,8 @@ struct TALER_MERCHANT_TemplatesPostHandle
  */
 static void
 handle_post_templates_finished (void *cls,
-                               long response_code,
-                               const void *response)
+                                long response_code,
+                                const void *response)
 {
   struct TALER_MERCHANT_TemplatesPostHandle *tph = cls;
   const json_t *json = response;
@@ -152,6 +152,46 @@ handle_post_templates_finished (void *cls,
 }
 
 
+static bool
+test_template_contract_valid (const json_t *template_contract)
+{
+  const char *summary;
+  struct TALER_Amount amount = { .value = 0};
+  uint32_t minimum_age = 0;
+  struct GNUNET_TIME_Relative pay_duration = { 0 };
+  struct GNUNET_JSON_Specification spec[] = {
+    GNUNET_JSON_spec_mark_optional (
+      GNUNET_JSON_spec_string ("summary",
+                               &summary),
+      NULL),
+    GNUNET_JSON_spec_mark_optional (
+      TALER_JSON_spec_amount_any ("amount",
+                                  &amount),
+      NULL),
+    GNUNET_JSON_spec_uint32 ("minimum_age",
+                             &minimum_age),
+    GNUNET_JSON_spec_relative_time ("pay_duration",
+                                    &pay_duration),
+    GNUNET_JSON_spec_end ()
+  };
+  const char *ename;
+  unsigned int eline;
+
+  if (GNUNET_OK !=
+      GNUNET_JSON_parse (template_contract,
+                         spec,
+                         &ename,
+                         &eline))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "Invalid template_contract for field %s\n",
+                ename);
+    return false;
+  }
+  return true;
+}
+
+
 struct TALER_MERCHANT_TemplatesPostHandle *
 TALER_MERCHANT_templates_post (
   struct GNUNET_CURL_Context *ctx,
@@ -166,13 +206,19 @@ TALER_MERCHANT_templates_post (
   struct TALER_MERCHANT_TemplatesPostHandle *tph;
   json_t *req_obj;
 
+  if (! test_template_contract_valid (template_contract))
+  {
+    GNUNET_break (0);
+    return NULL;
+  }
   req_obj = GNUNET_JSON_PACK (
     GNUNET_JSON_pack_string ("template_id",
                              template_id),
     GNUNET_JSON_pack_string ("template_description",
                              template_description),
-    GNUNET_JSON_pack_string ("image",
-                             image),
+    GNUNET_JSON_pack_allow_null (
+      GNUNET_JSON_pack_string ("image",
+                               image)),
     GNUNET_JSON_pack_object_incref ("template_contract",
                                     (json_t *) template_contract));
   tph = GNUNET_new (struct TALER_MERCHANT_TemplatesPostHandle);
diff --git a/src/lib/merchant_api_post_using_templates.c 
b/src/lib/merchant_api_post_using_templates.c
index 1985fba1..ded88e75 100644
--- a/src/lib/merchant_api_post_using_templates.c
+++ b/src/lib/merchant_api_post_using_templates.c
@@ -91,6 +91,8 @@ handle_post_using_templates_finished (void *cls,
   };
 
   utph->job = NULL;
+  // to_be_written_new_function (utph->cb, utph->cb_cls, response_code, json);
+  // start of code to be removed
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               "POST /using-templates completed with response code %u\n",
               (unsigned int) response_code);
@@ -150,6 +152,8 @@ handle_post_using_templates_finished (void *cls,
   } /* end of the switch */
   utph->cb (utph->cb_cls,
             &hr);
+  // end of code to be removed
+
   TALER_MERCHANT_using_templates_post_cancel (utph);
 }
 
@@ -207,10 +211,10 @@ TALER_MERCHANT_using_templates_post (
                                          req_obj));
     json_decref (req_obj);
     utph->job = GNUNET_CURL_job_add2 (ctx,
-                                     eh,
-                                     utph->post_ctx.headers,
-                                     &handle_post_using_templates_finished,
-                                     utph);
+                                      eh,
+                                      utph->post_ctx.headers,
+                                      &handle_post_using_templates_finished,
+                                      utph);
     GNUNET_assert (NULL != utph->job);
   }
   return utph;
diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c
index a4a6dfd9..a53ec442 100644
--- a/src/testing/test_merchant_api.c
+++ b/src/testing/test_merchant_api.c
@@ -1299,79 +1299,133 @@ run (void *cls,
                                               MHD_HTTP_OK,
                                               NULL),
     TALER_TESTING_cmd_merchant_post_templates ("post-templates-t1",
-                                              merchant_url,
-                                              "template-1",
-                                              "a template",
-                                              MHD_HTTP_NO_CONTENT),
+                                               merchant_url,
+                                               "template-1",
+                                               "a template",
+                                               MHD_HTTP_NO_CONTENT),
     TALER_TESTING_cmd_merchant_post_templates ("post-templates-t1-idem",
-                                              merchant_url,
-                                              "template-1",
-                                              "a template",
-                                              MHD_HTTP_NO_CONTENT),
+                                               merchant_url,
+                                               "template-1",
+                                               "a template",
+                                               MHD_HTTP_NO_CONTENT),
     TALER_TESTING_cmd_merchant_post_templates ("post-templates-t1-non-idem",
-                                              merchant_url,
-                                              "template-1",
-                                              "a different template",
-                                              MHD_HTTP_CONFLICT),
+                                               merchant_url,
+                                               "template-1",
+                                               "a different template",
+                                               MHD_HTTP_CONFLICT),
     TALER_TESTING_cmd_merchant_get_templates ("get-templates-t1",
+                                              merchant_url,
+                                              MHD_HTTP_OK,
+                                              "post-templates-t1",
+                                              NULL),
+    TALER_TESTING_cmd_merchant_get_template ("get-template-t1",
                                              merchant_url,
+                                             "template-1",
                                              MHD_HTTP_OK,
-                                             "post-templates-t1",
-                                             NULL),
-    TALER_TESTING_cmd_merchant_get_template ("get-template-t1",
-                                            merchant_url,
-                                            "template-1",
-                                            MHD_HTTP_OK,
-                                            "post-templates-t1"),
+                                             "post-templates-t1"),
     TALER_TESTING_cmd_merchant_post_templates ("post-templates-t2",
-                                              merchant_url,
-                                              "template-2",
-                                              "a template",
-                                              MHD_HTTP_NO_CONTENT),
-    TALER_TESTING_cmd_merchant_patch_template ("patch-templates-t2",
-                                              merchant_url,
-                                              "template-2",
-                                              "another template",
-                                              "data:image/jpeg;base64,RAWDATA",
-                                               json_pack ("{s:s}",
-                                                          "summary",
-                                                         "EUR"),
-                                              MHD_HTTP_NO_CONTENT),
+                                               merchant_url,
+                                               "template-2",
+                                               "a template",
+                                               MHD_HTTP_NO_CONTENT),
+    TALER_TESTING_cmd_merchant_patch_template (
+      "patch-templates-t2",
+      merchant_url,
+      "template-2",
+      "another template",
+      "data:image/jpeg;base64,RAWDATA",
+      json_pack ("{s:s}",
+                 "summary",
+                 "my new summary"),
+      MHD_HTTP_NO_CONTENT),
     TALER_TESTING_cmd_merchant_get_template ("get-template-t2",
-                                            merchant_url,
-                                            "template-2",
-                                            MHD_HTTP_OK,
-                                            "patch-templates-t2"),
+                                             merchant_url,
+                                             "template-2",
+                                             MHD_HTTP_OK,
+                                             "patch-templates-t2"),
     TALER_TESTING_cmd_merchant_get_template ("get-template-nx",
-                                            merchant_url,
-                                            "template-nx",
-                                            MHD_HTTP_NOT_FOUND,
-                                            NULL),
-    TALER_TESTING_cmd_merchant_patch_template ("patch-templates-t3-nx",
-                                              merchant_url,
-                                              "template-3",
-                                              "updated template",
-                                              "data:image/jpeg;base64,RAWDATA",
-                                               json_pack ("{s:s}",
-                                                          "summary",
-                                                         "EUR"),
-                                              MHD_HTTP_NOT_FOUND),
+                                             merchant_url,
+                                             "template-nx",
+                                             MHD_HTTP_NOT_FOUND,
+                                             NULL),
+    TALER_TESTING_cmd_merchant_patch_template (
+      "patch-templates-t3-nx",
+      merchant_url,
+      "template-3",
+      "updated template",
+      "data:image/jpeg;base64,RAWDATA",
+      json_pack ("{s:s}",
+                 "summary",
+                 "my new summary"),
+      MHD_HTTP_NOT_FOUND),
+    TALER_TESTING_cmd_merchant_post_templates2 (
+      "post-templates-t3-amount",
+      merchant_url,
+      "template-amount",
+      "a different template with an amount",
+      NULL,
+      json_pack ("{s:s}",
+                 "amount",
+                 "EUR:4"),
+      MHD_HTTP_NO_CONTENT),
+    TALER_TESTING_cmd_merchant_post_using_templates (
+      "using-templates-t1",
+      "post-templates-t1",
+      merchant_url,
+      "summary-1",
+      "EUR:10",
+      MHD_HTTP_OK),
+    TALER_TESTING_cmd_merchant_post_using_templates (
+      "using-templates-t1-amount-missing",
+      "post-templates-t1",
+      merchant_url,
+      "summary-1",
+      NULL,
+      MHD_HTTP_CONFLICT),
+    TALER_TESTING_cmd_merchant_post_using_templates (
+      "using-templates-t1-summary-missing",
+      "post-templates-t1",
+      merchant_url,
+      NULL,
+      "EUR:10",
+      MHD_HTTP_CONFLICT),
+    TALER_TESTING_cmd_merchant_post_using_templates (
+      "using-templates-t1-amount-conflict",
+      "post-templates-t3-amount",
+      merchant_url,
+      "summary-1",
+      "EUR:10",
+      MHD_HTTP_CONFLICT),
+    TALER_TESTING_cmd_merchant_post_using_templates (
+      "using-templates-t1-amount-duplicate",
+      "post-templates-t3-amount",
+      merchant_url,
+      "summary-1",
+      "EUR:4",
+      MHD_HTTP_CONFLICT),
     TALER_TESTING_cmd_merchant_delete_template ("get-templates-empty",
-                                               merchant_url,
-                                               "t1",
-                                               MHD_HTTP_NOT_FOUND),
+                                                merchant_url,
+                                                "t1",
+                                                MHD_HTTP_NOT_FOUND),
     TALER_TESTING_cmd_merchant_delete_template ("get-templates-empty",
-                                               merchant_url,
-                                               "template-1",
-                                               MHD_HTTP_NO_CONTENT),
+                                                merchant_url,
+                                                "template-1",
+                                                MHD_HTTP_NO_CONTENT),
+    TALER_TESTING_cmd_merchant_post_using_templates (
+      "post-templates-t1-deleted",
+      "post-templates-t1",
+      merchant_url,
+      "summary-1",
+      "EUR:5",
+      MHD_HTTP_NOT_FOUND),
     TALER_TESTING_cmd_end ()
-   };
+  };
 
-   struct TALER_TESTING_Command webhooks[] = {
+  struct TALER_TESTING_Command webhooks[] = {
     TALER_TESTING_cmd_merchant_get_webhooks ("get-webhooks-empty",
-                                              merchant_url,
-                                              MHD_HTTP_OK,
-                                              NULL),
+                                             merchant_url,
+                                             MHD_HTTP_OK,
+                                             NULL),
     TALER_TESTING_cmd_merchant_post_webhooks ("post-webhooks-w1",
                                               merchant_url,
                                               "webhook-1",
@@ -1439,31 +1493,8 @@ run (void *cls,
                                                "webhook-1",
                                                MHD_HTTP_NO_CONTENT),
     TALER_TESTING_cmd_end ()
-   };
+  };
 
-     struct TALER_TESTING_Command using_templates[] = {
-    TALER_TESTING_cmd_merchant_post_using_templates ("post-templates-t1",
-                                                     merchant_url,
-                                                     "template-1",
-                                                     "EUR:10",
-                                                     MHD_HTTP_NO_CONTENT),
-    TALER_TESTING_cmd_merchant_post_using_templates ("post-templates-t1-idem",
-                                                     merchant_url,
-                                                     "template-1",
-                                                     "EUR:10",
-                                                     MHD_HTTP_NO_CONTENT),
-    TALER_TESTING_cmd_merchant_post_using_templates 
("post-templates-t1-non-idem",
-                                                     merchant_url,
-                                                     "template-1",
-                                                     "EUR:5",
-                                                     MHD_HTTP_CONFLICT),
-    TALER_TESTING_cmd_merchant_post_using_templates ("post-templates-t2",
-                                                     merchant_url,
-                                                     "template-2",
-                                                     "EUR:10",
-                                                     MHD_HTTP_NO_CONTENT),
-    TALER_TESTING_cmd_end ()
-   };
 
   struct TALER_TESTING_Command commands[] = {
     /* general setup */
@@ -1819,8 +1850,6 @@ run (void *cls,
                              templates),
     TALER_TESTING_cmd_batch ("webhooks",
                              webhooks),
-    TALER_TESTING_cmd_batch ("using_templates",
-                             using_templates),
     /**
      * End the suite.
      */
diff --git a/src/testing/testing_api_cmd_get_template.c 
b/src/testing/testing_api_cmd_get_template.c
index 4e5580da..2f0f882a 100644
--- a/src/testing/testing_api_cmd_get_template.c
+++ b/src/testing/testing_api_cmd_get_template.c
@@ -78,10 +78,10 @@ struct GetTemplateState
  */
 static void
 get_template_cb (void *cls,
-                const struct TALER_MERCHANT_HttpResponse *hr,
-                const char *template_description,
-                const char *image,
-                const json_t *template_contract)
+                 const struct TALER_MERCHANT_HttpResponse *hr,
+                 const char *template_description,
+                 const char *image,
+                 const json_t *template_contract)
 {
   struct GetTemplateState *gis = cls;
   const struct TALER_TESTING_Command *template_cmd;
@@ -108,7 +108,7 @@ get_template_cb (void *cls,
         gis->template_reference);
       if (GNUNET_OK !=
           TALER_TESTING_get_trait_template_description (template_cmd,
-                                                       &expected_description))
+                                                        &expected_description))
         TALER_TESTING_interpreter_fail (gis->is);
       if (0 != strcmp (template_description,
                        *expected_description))
@@ -124,10 +124,13 @@ get_template_cb (void *cls,
 
       if (GNUNET_OK !=
           TALER_TESTING_get_trait_template_image (template_cmd,
-                                                 &expected_image))
+                                                  &expected_image))
         TALER_TESTING_interpreter_fail (gis->is);
-      if (0 != strcmp (image,
-                       *expected_image))
+      if ( ( (NULL == image) && (NULL != *expected_image)) ||
+           ( (NULL != image) && (NULL == *expected_image)) ||
+           ( (NULL != image) &&
+             (0 != strcmp (image,
+                           *expected_image)) ) )
       {
         GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                     "Template image does not match\n");
@@ -174,17 +177,17 @@ get_template_cb (void *cls,
  */
 static void
 get_template_run (void *cls,
-                 const struct TALER_TESTING_Command *cmd,
-                 struct TALER_TESTING_Interpreter *is)
+                  const struct TALER_TESTING_Command *cmd,
+                  struct TALER_TESTING_Interpreter *is)
 {
   struct GetTemplateState *gis = cls;
 
   gis->is = is;
   gis->igh = TALER_MERCHANT_template_get (is->ctx,
-                                         gis->merchant_url,
-                                         gis->template_id,
-                                         &get_template_cb,
-                                         gis);
+                                          gis->merchant_url,
+                                          gis->template_id,
+                                          &get_template_cb,
+                                          gis);
   GNUNET_assert (NULL != gis->igh);
 }
 
@@ -198,7 +201,7 @@ get_template_run (void *cls,
  */
 static void
 get_template_cleanup (void *cls,
-                     const struct TALER_TESTING_Command *cmd)
+                      const struct TALER_TESTING_Command *cmd)
 {
   struct GetTemplateState *gis = cls;
 
@@ -214,10 +217,10 @@ get_template_cleanup (void *cls,
 
 struct TALER_TESTING_Command
 TALER_TESTING_cmd_merchant_get_template (const char *label,
-                                        const char *merchant_url,
-                                        const char *template_id,
-                                        unsigned int http_status,
-                                        const char *template_reference)
+                                         const char *merchant_url,
+                                         const char *template_id,
+                                         unsigned int http_status,
+                                         const char *template_reference)
 {
   struct GetTemplateState *gis;
 
diff --git a/src/testing/testing_api_cmd_post_templates.c 
b/src/testing/testing_api_cmd_post_templates.c
index 3708a467..c80e00cf 100644
--- a/src/testing/testing_api_cmd_post_templates.c
+++ b/src/testing/testing_api_cmd_post_templates.c
@@ -85,7 +85,7 @@ struct PostTemplatesState
  */
 static void
 post_templates_cb (void *cls,
-                  const struct TALER_MERCHANT_HttpResponse *hr)
+                   const struct TALER_MERCHANT_HttpResponse *hr)
 {
   struct PostTemplatesState *tis = cls;
 
@@ -130,20 +130,20 @@ post_templates_cb (void *cls,
  */
 static void
 post_templates_run (void *cls,
-                   const struct TALER_TESTING_Command *cmd,
-                   struct TALER_TESTING_Interpreter *is)
+                    const struct TALER_TESTING_Command *cmd,
+                    struct TALER_TESTING_Interpreter *is)
 {
   struct PostTemplatesState *tis = cls;
 
   tis->is = is;
   tis->iph = TALER_MERCHANT_templates_post (is->ctx,
-                                           tis->merchant_url,
-                                           tis->template_id,
-                                           tis->template_description,
-                                           tis->image,
-                                           tis->template_contract,
-                                           &post_templates_cb,
-                                           tis);
+                                            tis->merchant_url,
+                                            tis->template_id,
+                                            tis->template_description,
+                                            tis->image,
+                                            tis->template_contract,
+                                            &post_templates_cb,
+                                            tis);
   GNUNET_assert (NULL != tis->iph);
 }
 
@@ -158,11 +158,11 @@ post_templates_run (void *cls,
  * @param index index number of the object to extract.
  * @return #GNUNET_OK on success
  */
-static int
+static enum GNUNET_GenericReturnValue
 post_templates_traits (void *cls,
-                      const void **ret,
-                      const char *trait,
-                      unsigned int index)
+                       const void **ret,
+                       const char *trait,
+                       unsigned int index)
 {
   struct PostTemplatesState *pts = cls;
   struct TALER_TESTING_Trait traits[] = {
@@ -190,7 +190,7 @@ post_templates_traits (void *cls,
  */
 static void
 post_templates_cleanup (void *cls,
-                       const struct TALER_TESTING_Command *cmd)
+                        const struct TALER_TESTING_Command *cmd)
 {
   struct PostTemplatesState *tis = cls;
 
@@ -226,7 +226,7 @@ TALER_TESTING_cmd_merchant_post_templates2 (
   tis->template_id = template_id;
   tis->http_status = http_status;
   tis->template_description = template_description;
-  tis->image = GNUNET_strdup (image);
+  tis->image = (NULL == image) ? NULL : GNUNET_strdup (image);
   tis->template_contract = template_contract;
   {
     struct TALER_TESTING_Command cmd = {
@@ -244,17 +244,17 @@ TALER_TESTING_cmd_merchant_post_templates2 (
 
 struct TALER_TESTING_Command
 TALER_TESTING_cmd_merchant_post_templates (const char *label,
-                                          const char *merchant_url,
-                                          const char *template_id,
-                                          const char *template_description,
-                                          unsigned int http_status)
+                                           const char *merchant_url,
+                                           const char *template_id,
+                                           const char *template_description,
+                                           unsigned int http_status)
 {
   return TALER_TESTING_cmd_merchant_post_templates2 (
     label,
     merchant_url,
     template_id,
     template_description,
-    "",
+    NULL,
     json_pack ("{s:s}", "merchant", "Pay"),
     http_status);
 }
diff --git a/src/testing/testing_api_cmd_post_using_templates.c 
b/src/testing/testing_api_cmd_post_using_templates.c
index 6b97aa36..026d460a 100644
--- a/src/testing/testing_api_cmd_post_using_templates.c
+++ b/src/testing/testing_api_cmd_post_using_templates.c
@@ -1,6 +1,6 @@
 /*
   This file is part of TALER
-  Copyright (C) 2020 Taler Systems SA
+  Copyright (C) 2022 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
@@ -58,6 +58,11 @@ struct PostUsingTemplatesState
    */
   struct TALER_Amount amount;
 
+  /**
+   * Label of a command that created the template we should use.
+   */
+  const char *template_ref;
+
   /**
    * Expected HTTP response code.
    */
@@ -91,14 +96,11 @@ post_using_templates_cb (void *cls,
   }
   switch (hr->http_status)
   {
-  case MHD_HTTP_NO_CONTENT:
-    break;
-  case MHD_HTTP_NOT_ACCEPTABLE:
+  case MHD_HTTP_OK:
+    // FIXME: check reply!
     break;
   case MHD_HTTP_CONFLICT:
     break;
-  case MHD_HTTP_FORBIDDEN:
-    break;
   case MHD_HTTP_NOT_FOUND:
     break;
   default:
@@ -106,10 +108,12 @@ post_using_templates_cb (void *cls,
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                 "Unhandled HTTP status %u for POST /templates/$ID.\n",
                 hr->http_status);
+    break;
   }
   TALER_TESTING_interpreter_next (tis->is);
 }
 
+
 /**
  * Run the "POST /using-templates" CMD.
  *
@@ -124,62 +128,30 @@ post_using_templates_run (void *cls,
                           struct TALER_TESTING_Interpreter *is)
 {
   struct PostUsingTemplatesState *tis = cls;
-  const char *template_id;
+  const struct TALER_TESTING_Command *ref;
+  const char **template_id;
 
   tis->is = is;
-
-  const json_t *contract_terms;
-  const char *error_name;
-  unsigned int error_line;
-  const char **proposal_reference;
-
-  if (NULL== cmd)
+  ref = TALER_TESTING_interpreter_lookup_command (is,
+                                                  tis->template_ref);
+  if (GNUNET_OK !=
+      TALER_TESTING_get_trait_template_id (ref,
+                                           &template_id))
     TALER_TESTING_FAIL (is);
-  {
-
-    if (GNUNET_OK !=
-        TALER_TESTING_get_trait_contract_terms (cmd,
-                                                &contract_terms))
-      TALER_TESTING_FAIL (is);
-    {
-      /* Get information that needs to be put verbatim in the
-       * deposit permission */
-      struct GNUNET_JSON_Specification spec[] = {
-        GNUNET_JSON_spec_string ("template_id",
-                                 &template_id),
-        GNUNET_JSON_spec_end ()
-      };
-      
-      if (GNUNET_OK !=
-          GNUNET_JSON_parse (contract_terms,
-                             spec,
-                             &error_name,
-                             &error_line))
-        {
-          char *js;
-          js = json_dumps (contract_terms,
-                           JSON_INDENT (1));
-          GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                      "Parser failed on %s:%u for input `%s'\n",
-                      error_name,
-                      error_line,
-                      js);
-          free (js);
-          TALER_TESTING_FAIL (is);
-        }
-    }
-  }
-
-  tis->iph = TALER_MERCHANT_using_templates_post (is->ctx,
-                                                  tis->merchant_url,
-                                                  template_id,
-                                                  tis->summary,
-                                                  &tis->amount,
-                                                  &post_using_templates_cb,
-                                                  tis);
+  tis->iph = TALER_MERCHANT_using_templates_post (
+    is->ctx,
+    tis->merchant_url,
+    *template_id,
+    tis->summary,
+    TALER_amount_is_valid (&tis->amount)
+    ? &tis->amount
+    : NULL,
+    &post_using_templates_cb,
+    tis);
   GNUNET_assert (NULL != tis->iph);
 }
 
+
 /**
  * Offers information from the POST /using-templates CMD state to other
  * commands.
@@ -190,7 +162,7 @@ post_using_templates_run (void *cls,
  * @param index index number of the object to extract.
  * @return #GNUNET_OK on success
  */
-static int
+static enum GNUNET_GenericReturnValue
 post_using_templates_traits (void *cls,
                              const void **ret,
                              const char *trait,
@@ -198,11 +170,10 @@ post_using_templates_traits (void *cls,
 {
   struct PostUsingTemplatesState *pts = cls;
   struct TALER_TESTING_Trait traits[] = {
-    TALER_TESTING_make_trait_summary (&pts->summary),
-    TALER_TESTING_make_trait_amount (&pts->amount),
     TALER_TESTING_trait_end (),
   };
 
+  (void) pts;
   return TALER_TESTING_get_trait (traits,
                                   ret,
                                   trait,
@@ -234,8 +205,9 @@ post_using_templates_cleanup (void *cls,
 
 
 struct TALER_TESTING_Command
-TALER_TESTING_cmd_merchant_post_using_templates2 (
+TALER_TESTING_cmd_merchant_post_using_templates (
   const char *label,
+  const char *template_ref,
   const char *merchant_url,
   const char *summary,
   const char *amount,
@@ -244,13 +216,14 @@ TALER_TESTING_cmd_merchant_post_using_templates2 (
   struct PostUsingTemplatesState *tis;
 
   tis = GNUNET_new (struct PostUsingTemplatesState);
+  tis->template_ref = template_ref;
   tis->merchant_url = merchant_url;
   tis->http_status = http_status;
   tis->summary = summary;
-  GNUNET_assert (GNUNET_OK ==
-                 TALER_string_to_amount (amount,
-                                         &tis->amount));
-
+  if (NULL != amount)
+    GNUNET_assert (GNUNET_OK ==
+                   TALER_string_to_amount (amount,
+                                           &tis->amount));
   {
     struct TALER_TESTING_Command cmd = {
       .cls = tis,
@@ -264,20 +237,5 @@ TALER_TESTING_cmd_merchant_post_using_templates2 (
   }
 }
 
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_merchant_post_using_templates (const char *label,
-                                                 const char *merchant_url,
-                                                 const char *summary,
-                                                 const char *amount,
-                                                 unsigned int http_status)
-{
-  return TALER_TESTING_cmd_merchant_post_using_templates2 (
-    label,
-    merchant_url,
-    summary,
-    amount,
-    http_status);
-}
-
 
 /* end of testing_api_cmd_post_using_templates.c */

-- 
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]