gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] 123/277: added tests for instance creation and lookup


From: gnunet
Subject: [taler-merchant] 123/277: added tests for instance creation and lookup
Date: Sun, 05 Jul 2020 20:50:36 +0200

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

grothoff pushed a commit to branch master
in repository merchant.

commit 601abc17e4d63fed52de91402c15bb4d9ba3e014
Author: Jonathan Buchanan <jonathan.russ.buchanan@gmail.com>
AuthorDate: Tue May 19 16:29:13 2020 -0400

    added tests for instance creation and lookup
---
 src/backenddb/test_merchantdb.c | 90 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 90 insertions(+)

diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c
index fdcf879..d159893 100644
--- a/src/backenddb/test_merchantdb.c
+++ b/src/backenddb/test_merchantdb.c
@@ -36,6 +36,24 @@ static int result;
  */
 static struct TALER_MERCHANTDB_Plugin *plugin;
 
+/**
+ * Number of instances detected.
+ */
+static int instance_count;
+
+void
+lookup_instances_callback (void *cls, const struct
+                           TALER_MerchantPublicKeyP *merchant_pub,
+                           const struct
+                           TALER_MerchantPrivateKeyP *merchant_priv, const
+                           struct
+                           TALER_MERCHANTDB_InstanceSettings *is,
+                           unsigned int accounts_length, const struct
+                           TALER_MERCHANTDB_AccountDetails accounts[])
+{
+  instance_count += 1;
+}
+
 
 /**
  * Main function that will be run by the scheduler.
@@ -48,11 +66,81 @@ run (void *cls)
   struct GNUNET_CONFIGURATION_Handle *cfg = cls;
   /* Data for 'store_payment()' */
 
+  /* Load the plugin */
   if (NULL == (plugin = TALER_MERCHANTDB_plugin_load (cfg)))
   {
     result = 77;
     return;
   }
+
+  /* Run the preflight */
+  plugin->preflight (plugin->cls);
+
+  /* Test lookup instances- is our new instance there? */
+  instance_count = 0;
+  if (0 > plugin->lookup_instances (plugin->cls, false,
+                                    lookup_instances_callback, cls))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Lookup instances failed\n");
+    result = 1;
+    return;
+  }
+  if (instance_count != 0)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Non-zero number of instances found after initialization\n");
+    result = 1;
+    return;
+  }
+
+  /* Test making an instance */
+  struct TALER_MerchantPublicKeyP merchant_pub;
+  struct TALER_MerchantPrivateKeyP merchant_priv;
+  GNUNET_CRYPTO_eddsa_key_create (&merchant_priv.eddsa_priv);
+  GNUNET_CRYPTO_eddsa_key_get_public (&merchant_priv.eddsa_priv,
+                                      &merchant_pub.eddsa_pub);
+  struct TALER_MERCHANTDB_InstanceSettings is;
+  is.id = "t";
+  is.name = "Test";
+  is.address = json_array ();
+  json_array_append (is.address, json_string ("123 Example St"));
+  is.jurisdiction = json_array ();
+  json_array_append (is.jurisdiction, json_string ("Ohio"));
+  TALER_string_to_amount ("USD:1200.40", &is.default_max_deposit_fee);
+  TALER_string_to_amount ("USD:1200.40", &is.default_max_wire_fee);
+  is.default_wire_fee_amortization = 1;
+  is.default_wire_transfer_delay = GNUNET_TIME_relative_get_minute_ ();
+  is.default_pay_delay = GNUNET_TIME_relative_get_second_ ();
+
+  if (0 > plugin->insert_instance (plugin->cls, &merchant_pub, &merchant_priv,
+                                   &is))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Instance insertion failed\n");
+    result = 1;
+    return;
+  }
+
+  /* Test lookup instances- is our new instance there? */
+  instance_count = 0;
+  if (0 > plugin->lookup_instances (plugin->cls, false,
+                                    lookup_instances_callback, cls))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Lookup instances failed\n");
+    result = 1;
+    return;
+  }
+  if (instance_count != 1)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Instance count doesn't match number of instances inserted\n");
+    result = 1;
+    return;
+  }
+
+  /* Test dropping tables */
   if (GNUNET_OK != plugin->drop_tables (plugin->cls))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -60,6 +148,8 @@ run (void *cls)
     result = 77;
     return;
   }
+
+  /* Unload the plugin */
   TALER_MERCHANTDB_plugin_unload (plugin);
   if (NULL == (plugin = TALER_MERCHANTDB_plugin_load (cfg)))
   {

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