gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] 139/277: wrote db tests for accounts


From: gnunet
Subject: [taler-merchant] 139/277: wrote db tests for accounts
Date: Sun, 05 Jul 2020 20:50:52 +0200

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

grothoff pushed a commit to branch master
in repository merchant.

commit ad4b4872235bf081553ae618de5ae6ca5ad2e8cd
Author: Jonathan Buchanan <jonathan.russ.buchanan@gmail.com>
AuthorDate: Sat May 23 00:53:24 2020 -0400

    wrote db tests for accounts
---
 src/backenddb/test_merchantdb.c       | 156 +++++++++++++++++++++++++++++++++-
 src/include/taler_merchantdb_plugin.h |   2 +-
 2 files changed, 154 insertions(+), 4 deletions(-)

diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c
index 2ebe663..c2c0a7d 100644
--- a/src/backenddb/test_merchantdb.c
+++ b/src/backenddb/test_merchantdb.c
@@ -51,14 +51,24 @@ static int instance_count;
  */
 static struct TALER_MERCHANTDB_InstanceSettings instances_found[8];
 
+/**
+ * An array containing the number of accounts of each instance from lookup.
+ */
+static int instances_accounts_length[8];
+
+/**
+ * An array containing the array of accounts of each instance from lookup.
+ */
+static struct TALER_MERCHANTDB_AccountDetails *instances_accounts[8];
+
 static void
 copy_instance (struct TALER_MERCHANTDB_InstanceSettings *dest,
                const struct TALER_MERCHANTDB_InstanceSettings *src)
 {
-  dest->id = GNUNET_malloc (sizeof(char) * (strlen (src->id) + 1));
+  dest->id = GNUNET_malloc (sizeof (char) * (strlen (src->id) + 1));
   strcpy (dest->id,
           src->id);
-  dest->name = GNUNET_malloc (sizeof(char) * (strlen (src->name) + 1));
+  dest->name = GNUNET_malloc (sizeof (char) * (strlen (src->name) + 1));
   strcpy (dest->name,
           src->name);
   dest->address = json_copy (src->address);
@@ -95,6 +105,24 @@ lookup_instances_cb (void *cls,
     /* Duplicate the instance settings */
     copy_instance (&instances_found[instance_count - 1],
                    is);
+    instances_accounts_length[instance_count - 1] = accounts_length;
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO, "CB: %d\n", accounts_length);
+    instances_accounts[instance_count - 1] = GNUNET_new_array (accounts_length,
+                                                               struct
+                                                               
TALER_MERCHANTDB_AccountDetails);
+    for (int i = 0; accounts_length > i; ++i)
+    {
+      struct TALER_MERCHANTDB_AccountDetails *dest =
+        &instances_accounts[instance_count - 1][i];
+      dest->h_wire = accounts[i].h_wire;
+      dest->salt = accounts[i].salt;
+      dest->payto_uri = GNUNET_malloc (sizeof (char) * (strlen (
+                                                          
accounts[i].payto_uri)
+                                                        + 1));
+      strcpy (dest->payto_uri,
+              accounts[i].payto_uri);
+      dest->active = accounts[i].active;
+    }
   }
 }
 
@@ -128,6 +156,22 @@ check_instances_equal (const struct 
TALER_MERCHANTDB_InstanceSettings *a,
 }
 
 
+static int
+check_accounts_equal (const struct TALER_MERCHANTDB_AccountDetails *a,
+                      const struct TALER_MERCHANTDB_AccountDetails *b)
+{
+  if ((0 != GNUNET_CRYPTO_hash_cmp (&a->h_wire,
+                                    &b->h_wire)) ||
+      (0 != GNUNET_CRYPTO_hash_cmp (&a->salt,
+                                    &b->salt)) ||
+      (0 != strcmp (a->payto_uri,
+                    b->payto_uri)) ||
+      (a->active != b->active))
+    return 1;
+  return 0;
+}
+
+
 static int
 test_insert_instance (const struct TALER_MerchantPublicKeyP *merchant_pub,
                       const struct TALER_MerchantPrivateKeyP *merchant_priv,
@@ -164,6 +208,23 @@ test_lookup_instances (bool active_only)
 }
 
 
+static int
+test_insert_account (const char *instance_id,
+                     const struct TALER_MERCHANTDB_AccountDetails *account)
+{
+  if (1 > plugin->insert_account (plugin->cls,
+                                  instance_id,
+                                  account))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Insert account failed\n");
+    plugin->drop_tables (plugin->cls);
+    return 1;
+  }
+  return 0;
+}
+
+
 /**
  * Function that tests instances.
  *
@@ -217,6 +278,13 @@ test_instances (void *cls)
     return 1;
   }
   free_instance (&instances_found[0]);
+  if (0 != instances_accounts_length[0])
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Lookup instance failed: incorrect accounts returned\n");
+    plugin->drop_tables (plugin->cls);
+    return 1;
+  }
 
   /* Test update instance */
   is.name = "Test - updated";
@@ -230,7 +298,7 @@ test_instances (void *cls)
   }
   instance_count = 0;
   TEST_RET_ON_FAIL (test_lookup_instances (false));
-  if (instance_count != 1)
+  if (1 != instance_count)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Update instance failed: Instance count doesn't match number 
of instances inserted/updated\n");
@@ -247,6 +315,88 @@ test_instances (void *cls)
   }
   free_instance (&instances_found[0]);
 
+  /* Test account creation */
+  struct TALER_MERCHANTDB_AccountDetails account;
+  GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG,
+                                    &account.h_wire);
+  GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG,
+                                    &account.salt);
+  account.payto_uri = "payto://x-taler-bank/bank.demo.taler.net/4";
+  account.active = true;
+  TEST_RET_ON_FAIL (test_insert_account ("test_inst", &account));
+
+  /* Test accounts from instance lookup */
+  instance_count = 0;
+  TEST_RET_ON_FAIL (test_lookup_instances (false));
+  free_instance (&instances_found[0]);
+  if (1 != instances_accounts_length[0])
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Lookup instance failed: incorrect number of accounts 
returned\n");
+    plugin->drop_tables (plugin->cls);
+    return 1;
+  }
+  if (0 != check_accounts_equal (&account,
+                                 &instances_accounts[0][0]))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Lookup instance failed: incorrect accounts returned\n");
+    plugin->drop_tables (plugin->cls);
+    return 1;
+  }
+  GNUNET_free (instances_accounts[0][0].payto_uri);
+
+  /* Test account inactivation */
+  if (0 > plugin->inactivate_account (plugin->cls,
+                                      &account.h_wire))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Inactivate account failed\n");
+    plugin->drop_tables (plugin->cls);
+    return 1;
+  }
+  account.active = false;
+  instance_count = 0;
+  TEST_RET_ON_FAIL (test_lookup_instances (false));
+  free_instance (&instances_found[0]);
+  if (1 != instances_accounts_length[0])
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Lookup instance failed: incorrect number of accounts 
returned\n");
+    plugin->drop_tables (plugin->cls);
+    return 1;
+  }
+  if (0 != check_accounts_equal (&account,
+                                 &instances_accounts[0][0]))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Lookup instance failed: incorrect accounts returned\n");
+    plugin->drop_tables (plugin->cls);
+    return 1;
+  }
+  GNUNET_free (instances_accounts[0][0].payto_uri);
+
+  /* Test multiple accounts */
+  /* This fails currently */
+  /*struct TALER_MERCHANTDB_AccountDetails account1;
+  GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG,
+                                    &account1.h_wire);
+  GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG,
+                                    &account1.salt);
+  account1.payto_uri = "payto://other-bank/bank.demo.taler.net/4";
+  account1.active = true;
+  TEST_RET_ON_FAIL (test_insert_account ("test_inst", &account1));
+  instance_count = 0;
+  TEST_RET_ON_FAIL (test_lookup_instances (false));
+  free_instance (&instances_found[0]);
+  if (2 != instances_accounts_length[0])
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Lookup instance failed: incorrect number of accounts returned 
%d\n", instances_accounts_length[0]);
+    //plugin->drop_tables (plugin->cls);
+    return 1;
+  }*/
+
   /* Test instance private key deletion */
   if (0 > plugin->delete_instance_private_key (plugin->cls,
                                                "test_inst"))
diff --git a/src/include/taler_merchantdb_plugin.h 
b/src/include/taler_merchantdb_plugin.h
index 1324b4d..bb8249c 100644
--- a/src/include/taler_merchantdb_plugin.h
+++ b/src/include/taler_merchantdb_plugin.h
@@ -51,7 +51,7 @@ struct TALER_MERCHANTDB_AccountDetails
   /**
    * Actual account address as a payto://-URI.
    */
-  const char *payto_uri;
+  char *payto_uri;
 
   /**
    * Is the account set for active use in new contracts?

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