summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/taler_merchant_testing_lib.h57
-rw-r--r--src/testing/Makefile.am1
-rw-r--r--src/testing/testing_api_cmd_get_instance.c143
-rw-r--r--src/testing/testing_api_cmd_patch_instance.c40
-rw-r--r--src/testing/testing_api_cmd_post_instances.c40
-rw-r--r--src/testing/testing_api_trait_merchant_json.c114
6 files changed, 390 insertions, 5 deletions
diff --git a/src/include/taler_merchant_testing_lib.h b/src/include/taler_merchant_testing_lib.h
index e2cec7be..ff9f785d 100644
--- a/src/include/taler_merchant_testing_lib.h
+++ b/src/include/taler_merchant_testing_lib.h
@@ -1258,6 +1258,63 @@ TALER_TESTING_get_trait_merchant_sig (
unsigned int index,
struct TALER_MerchantSignatureP **merchant_sig);
+
+/**
+ * Obtain merchant address from @a cmd.
+ *
+ * @param cmd command to extract the address from.
+ * @param index index number associate with the address on offer.
+ * @param[out] address where to write the address.
+ * @return #GNUNET_OK on success.
+ */
+int
+TALER_TESTING_get_trait_merchant_address (const struct
+ TALER_TESTING_Command *cmd,
+ unsigned int index,
+ const json_t **address);
+
+
+/**
+ * Offer merchant address in a trait.
+ *
+ * @param index index number associate with the address
+ * on offer.
+ * @param address address to offer.
+ * @return the trait.
+ */
+struct TALER_TESTING_Trait
+TALER_TESTING_make_trait_merchant_address (unsigned int index,
+ const json_t *address);
+
+
+/**
+ * Obtain merchant jurisdiction from @a cmd.
+ *
+ * @param cmd command to extract the jurisdiction from.
+ * @param index index number associate with the jurisdiction on offer.
+ * @param[out] jurisdiction where to write the jurisdiction.
+ * @return #GNUNET_OK on success.
+ */
+int
+TALER_TESTING_get_trait_merchant_jurisdiction (const struct
+ TALER_TESTING_Command *cmd,
+ unsigned int index,
+ const json_t **jurisdiction);
+
+
+/**
+ * Offer merchant jurisdiction in a trait.
+ *
+ * @param index index number associate with the jurisdiction
+ * on offer.
+ * @param jurisdiction jurisdiction to offer.
+ * @return the trait.
+ */
+struct TALER_TESTING_Trait
+TALER_TESTING_make_trait_merchant_jurisdiction (unsigned int index,
+ const json_t *jurisdiction);
+
+
/**
* Obtain a reference to a proposal command. Any command that
* works with proposals, might need to offer their reference to
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
index 228113df..8a41ae30 100644
--- a/src/testing/Makefile.am
+++ b/src/testing/Makefile.am
@@ -53,6 +53,7 @@ libtalermerchanttesting_la_SOURCES = \
testing_api_trait_merchant_sig.c \
testing_api_trait_string.c \
testing_api_trait_hash.c \
+ testing_api_trait_merchant_json.c \
testing_api_trait_planchet.c \
testing_api_trait_refund_entry.c
diff --git a/src/testing/testing_api_cmd_get_instance.c b/src/testing/testing_api_cmd_get_instance.c
index 5dc1d3d0..a5896659 100644
--- a/src/testing/testing_api_cmd_get_instance.c
+++ b/src/testing/testing_api_cmd_get_instance.c
@@ -79,8 +79,13 @@ get_instance_cb (void *cls,
const struct TALER_MERCHANT_Account accounts[],
const struct TALER_MERCHANT_InstanceDetails *details)
{
- /* FIXME, deeper checks should be implemented here. */
+ /* FIXME, deeper checks should be implemented here (for accounts). */
struct GetInstanceState *gis = cls;
+ const struct TALER_TESTING_Command *instance_cmd;
+
+ instance_cmd = TALER_TESTING_interpreter_lookup_command (
+ gis->is,
+ gis->instance_reference);
gis->igh = NULL;
if (gis->http_status != hr->http_status)
@@ -96,8 +101,140 @@ get_instance_cb (void *cls,
switch (hr->http_status)
{
case MHD_HTTP_OK:
- // FIXME: use gis->instance_reference here to
- // check if the data returned matches that from the POST / PATCH
+ {
+ const char *name;
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_string (instance_cmd,
+ 0,
+ &name))
+ TALER_TESTING_interpreter_fail (gis->is);
+ if (0 != strcmp (details->name,
+ name))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Instance name does not match\n");
+ TALER_TESTING_interpreter_fail (gis->is);
+ return;
+ }
+ }
+ {
+ const struct json_t *address;
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_merchant_address (instance_cmd,
+ 0,
+ &address))
+ TALER_TESTING_interpreter_fail (gis->is);
+ if (1 != json_equal (details->address,
+ address))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Instance address does not match\n");
+ TALER_TESTING_interpreter_fail (gis->is);
+ return;
+ }
+ }
+ {
+ const struct json_t *jurisdiction;
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_merchant_jurisdiction (instance_cmd,
+ 0,
+ &jurisdiction))
+ TALER_TESTING_interpreter_fail (gis->is);
+ if (1 != json_equal (details->jurisdiction,
+ jurisdiction))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Instance jurisdiction does not match\n");
+ TALER_TESTING_interpreter_fail (gis->is);
+ return;
+ }
+ }
+ {
+ const struct TALER_Amount *default_max_wire_fee;
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_amount_obj (instance_cmd,
+ 0,
+ &default_max_wire_fee))
+ TALER_TESTING_interpreter_fail (gis->is);
+ if ((GNUNET_OK != TALER_amount_cmp_currency (
+ details->default_max_wire_fee,
+ default_max_wire_fee)) ||
+ (0 != TALER_amount_cmp (details->default_max_wire_fee,
+ default_max_wire_fee)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Instance default max wire fee does not match\n");
+ TALER_TESTING_interpreter_fail (gis->is);
+ return;
+ }
+ }
+ {
+ const uint32_t *default_wire_fee_amortization;
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_uint32 (instance_cmd,
+ 0,
+ &default_wire_fee_amortization))
+ TALER_TESTING_interpreter_fail (gis->is);
+ if (details->default_wire_fee_amortization !=
+ *default_wire_fee_amortization)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Instance default wire fee amortization does not match\n");
+ TALER_TESTING_interpreter_fail (gis->is);
+ return;
+ }
+ }
+ {
+ const struct TALER_Amount *default_max_deposit_fee;
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_amount_obj (instance_cmd,
+ 0,
+ &default_max_deposit_fee))
+ TALER_TESTING_interpreter_fail (gis->is);
+ if ((GNUNET_OK != TALER_amount_cmp_currency (
+ details->default_max_deposit_fee,
+ default_max_deposit_fee)) ||
+ (0 != TALER_amount_cmp (details->default_max_deposit_fee,
+ default_max_deposit_fee)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Instance default max deposit fee does not match\n");
+ TALER_TESTING_interpreter_fail (gis->is);
+ return;
+ }
+ }
+ {
+ const struct GNUNET_TIME_Relative *default_wire_transfer_delay;
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_relative_time (instance_cmd,
+ 0,
+ &default_wire_transfer_delay))
+ TALER_TESTING_interpreter_fail (gis->is);
+ if (details->default_wire_transfer_delay.rel_value_us !=
+ default_wire_transfer_delay->rel_value_us)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Instance default wire transfer delay does not match\n");
+ TALER_TESTING_interpreter_fail (gis->is);
+ return;
+ }
+ }
+ {
+ const struct GNUNET_TIME_Relative *default_pay_delay;
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_relative_time (instance_cmd,
+ 1,
+ &default_pay_delay))
+ TALER_TESTING_interpreter_fail (gis->is);
+ if (details->default_pay_delay.rel_value_us !=
+ default_pay_delay->rel_value_us)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Instance default pay delay does not match\n");
+ TALER_TESTING_interpreter_fail (gis->is);
+ return;
+ }
+ }
break;
default:
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
diff --git a/src/testing/testing_api_cmd_patch_instance.c b/src/testing/testing_api_cmd_patch_instance.c
index 81190769..cb547ff4 100644
--- a/src/testing/testing_api_cmd_patch_instance.c
+++ b/src/testing/testing_api_cmd_patch_instance.c
@@ -183,6 +183,43 @@ patch_instance_run (void *cls,
/**
+ * Offers information from the PATCH /instances CMD state to other
+ * commands.
+ *
+ * @param cls closure
+ * @param ret[out] result (could be anything)
+ * @param trait name of the trait
+ * @param index index number of the object to extract.
+ * @return #GNUNET_OK on success
+ */
+static int
+patch_instance_traits (void *cls,
+ const void **ret,
+ const char *trait,
+ unsigned int index)
+{
+ struct PatchInstanceState *pis = cls;
+ struct TALER_TESTING_Trait traits[] = {
+ TALER_TESTING_make_trait_string (0, pis->name),
+ TALER_TESTING_make_trait_merchant_address (0, pis->address),
+ TALER_TESTING_make_trait_merchant_jurisdiction (0, pis->jurisdiction),
+ TALER_TESTING_make_trait_amount_obj (0, &pis->default_max_wire_fee),
+ TALER_TESTING_make_trait_uint32 (0, &pis->default_wire_fee_amortization),
+ TALER_TESTING_make_trait_amount_obj (1, &pis->default_max_deposit_fee),
+ TALER_TESTING_make_trait_relative_time (0,
+ &pis->default_wire_transfer_delay),
+ TALER_TESTING_make_trait_relative_time (1, &pis->default_pay_delay),
+ TALER_TESTING_trait_end (),
+ };
+
+ return TALER_TESTING_get_trait (traits,
+ ret,
+ trait,
+ index);
+}
+
+
+/**
* Free the state of a "PATCH /instances/$ID" CMD, and possibly
* cancel a pending operation thereof.
*
@@ -274,7 +311,8 @@ TALER_TESTING_cmd_merchant_patch_instance (
.cls = pis,
.label = label,
.run = &patch_instance_run,
- .cleanup = &patch_instance_cleanup
+ .cleanup = &patch_instance_cleanup,
+ .traits = &patch_instance_traits
};
return cmd;
diff --git a/src/testing/testing_api_cmd_post_instances.c b/src/testing/testing_api_cmd_post_instances.c
index 3c3ffc74..55a27841 100644
--- a/src/testing/testing_api_cmd_post_instances.c
+++ b/src/testing/testing_api_cmd_post_instances.c
@@ -186,6 +186,43 @@ post_instances_run (void *cls,
/**
+ * Offers information from the POST /instances CMD state to other
+ * commands.
+ *
+ * @param cls closure
+ * @param ret[out] result (could be anything)
+ * @param trait name of the trait
+ * @param index index number of the object to extract.
+ * @return #GNUNET_OK on success
+ */
+static int
+post_instances_traits (void *cls,
+ const void **ret,
+ const char *trait,
+ unsigned int index)
+{
+ struct PostInstancesState *pis = cls;
+ struct TALER_TESTING_Trait traits[] = {
+ TALER_TESTING_make_trait_string (0, pis->name),
+ TALER_TESTING_make_trait_merchant_address (0, pis->address),
+ TALER_TESTING_make_trait_merchant_jurisdiction (0, pis->jurisdiction),
+ TALER_TESTING_make_trait_amount_obj (0, &pis->default_max_wire_fee),
+ TALER_TESTING_make_trait_uint32 (0, &pis->default_wire_fee_amortization),
+ TALER_TESTING_make_trait_amount_obj (1, &pis->default_max_deposit_fee),
+ TALER_TESTING_make_trait_relative_time (0,
+ &pis->default_wire_transfer_delay),
+ TALER_TESTING_make_trait_relative_time (1, &pis->default_pay_delay),
+ TALER_TESTING_trait_end (),
+ };
+
+ return TALER_TESTING_get_trait (traits,
+ ret,
+ trait,
+ index);
+}
+
+
+/**
* Free the state of a "POST /instances" CMD, and possibly
* cancel a pending operation thereof.
*
@@ -277,7 +314,8 @@ TALER_TESTING_cmd_merchant_post_instances2 (
.cls = pis,
.label = label,
.run = &post_instances_run,
- .cleanup = &post_instances_cleanup
+ .cleanup = &post_instances_cleanup,
+ .traits = &post_instances_traits
};
return cmd;
diff --git a/src/testing/testing_api_trait_merchant_json.c b/src/testing/testing_api_trait_merchant_json.c
new file mode 100644
index 00000000..8caa5c11
--- /dev/null
+++ b/src/testing/testing_api_trait_merchant_json.c
@@ -0,0 +1,114 @@
+/*
+ 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_merchant_json.c
+ * @brief offer merchant address and jurisdiction
+ * @author Jonathan Buchanan
+ */
+#include "platform.h"
+#include <taler/taler_signatures.h>
+#include <taler/taler_exchange_service.h>
+#include <taler/taler_testing_lib.h>
+
+#define TALER_TESTING_TRAIT_MERCHANT_ADDRESS "merchant-address"
+#define TALER_TESTING_TRAIT_MERCHANT_JURISDICTION "merchant_jurisdiction"
+
+
+/**
+ * Obtain merchant address from @a cmd.
+ *
+ * @param cmd command to extract the address from.
+ * @param index index number associate with the address on offer.
+ * @param[out] address where to write the address.
+ * @return #GNUNET_OK on success.
+ */
+int
+TALER_TESTING_get_trait_merchant_address (const struct
+ TALER_TESTING_Command *cmd,
+ unsigned int index,
+ const json_t **address)
+{
+ return cmd->traits (cmd->cls,
+ (const void **) address,
+ TALER_TESTING_TRAIT_MERCHANT_ADDRESS,
+ index);
+}
+
+
+/**
+ * Offer merchant address in a trait.
+ *
+ * @param index index number associate with the address
+ * on offer.
+ * @param address address to offer.
+ * @return the trait.
+ */
+struct TALER_TESTING_Trait
+TALER_TESTING_make_trait_merchant_address (unsigned int index,
+ const json_t *address)
+{
+ struct TALER_TESTING_Trait ret = {
+ .index = index,
+ .trait_name = TALER_TESTING_TRAIT_MERCHANT_ADDRESS,
+ .ptr = (const void *) address
+ };
+ return ret;
+}
+
+
+/**
+ * Obtain merchant jurisdiction from @a cmd.
+ *
+ * @param cmd command to extract the jurisdiction from.
+ * @param index index number associate with the jurisdiction on offer.
+ * @param[out] jurisdiction where to write the jurisdiction.
+ * @return #GNUNET_OK on success.
+ */
+int
+TALER_TESTING_get_trait_merchant_jurisdiction (const struct
+ TALER_TESTING_Command *cmd,
+ unsigned int index,
+ const json_t **jurisdiction)
+{
+ return cmd->traits (cmd->cls,
+ (const void **) jurisdiction,
+ TALER_TESTING_TRAIT_MERCHANT_JURISDICTION,
+ index);
+}
+
+
+/**
+ * Offer merchant jurisdiction in a trait.
+ *
+ * @param index index number associate with the jurisdiction
+ * on offer.
+ * @param jurisdiction jurisdiction to offer.
+ * @return the trait.
+ */
+struct TALER_TESTING_Trait
+TALER_TESTING_make_trait_merchant_jurisdiction (unsigned int index,
+ const json_t *jurisdiction)
+{
+ struct TALER_TESTING_Trait ret = {
+ .index = index,
+ .trait_name = TALER_TESTING_TRAIT_MERCHANT_JURISDICTION,
+ .ptr = (const void *) jurisdiction
+ };
+ return ret;
+}