gnunet-svn
[Top][All Lists]
Advanced

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

[taler-sync] branch master updated: test syncdb


From: gnunet
Subject: [taler-sync] branch master updated: test syncdb
Date: Sun, 01 Dec 2019 15:50:44 +0100

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

grothoff pushed a commit to branch master
in repository sync.

The following commit(s) were added to refs/heads/master by this push:
     new 4401356  test syncdb
4401356 is described below

commit 440135668be79231ebab8afc1f34350bbfe07ad4
Author: Christian Grothoff <address@hidden>
AuthorDate: Sun Dec 1 15:50:41 2019 +0100

    test syncdb
---
 src/syncdb/plugin_syncdb_postgres.c |  18 ++--
 src/syncdb/test_sync_db.c           | 168 +++++++++++++++++++++++++++++++++++-
 2 files changed, 173 insertions(+), 13 deletions(-)

diff --git a/src/syncdb/plugin_syncdb_postgres.c 
b/src/syncdb/plugin_syncdb_postgres.c
index 4273d75..790cd84 100644
--- a/src/syncdb/plugin_syncdb_postgres.c
+++ b/src/syncdb/plugin_syncdb_postgres.c
@@ -615,13 +615,13 @@ postgres_update_backup (void *cls,
     GNUNET_break (0);
     return SYNC_DB_SOFT_ERROR;
   case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
-    GNUNET_break (0);
-    return SYNC_DB_OLD_BACKUP_MISSING;
+    /* handle interesting case below */
+    break;
   case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
     return SYNC_DB_ONE_RESULT;
   case GNUNET_DB_STATUS_HARD_ERROR:
-    /* handle interesting case below */
-    break;
+    GNUNET_break (0);
+    return SYNC_DB_HARD_ERROR;
   default:
     GNUNET_break (0);
     return SYNC_DB_HARD_ERROR;
@@ -687,9 +687,7 @@ postgres_update_backup (void *cls,
     GNUNET_break (0);
     return SYNC_DB_SOFT_ERROR;
   case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
-    /* Well, trying to update where there is no original
-       is a hard erorr, even though an odd one */
-    return SYNC_DB_HARD_ERROR;
+    return SYNC_DB_OLD_BACKUP_MISSING;
   case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
     /* handle interesting case below */
     break;
@@ -701,8 +699,10 @@ postgres_update_backup (void *cls,
   /* had an existing backup, is it identical? */
   if (0 == GNUNET_memcmp (&bh,
                           backup_hash))
+  {
     /* backup identical to what was provided, no change */
-    return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
+    return SYNC_DB_NO_RESULTS;
+  }
   if (0 == GNUNET_memcmp (&bh,
                           old_backup_hash))
     /* all constraints seem satisified, original error must
@@ -1031,7 +1031,7 @@ libsync_plugin_db_postgres_init (void *cls)
                             ",paid BOOLEAN NOT NULL DEFAULT FALSE"
                             ");"),
     GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS backups"
-                            "(account_pub BYTEA PRIMARY KEY REFERENCES 
accounts (account_pub)"
+                            "(account_pub BYTEA PRIMARY KEY REFERENCES 
accounts (account_pub) ON DELETE CASCADE"
                             ",account_sig BYTEA NOT NULL CHECK 
(length(account_sig)=64)"
                             ",prev_hash BYTEA NOT NULL CHECK 
(length(prev_hash)=64)"
                             ",backup_hash BYTEA NOT NULL CHECK 
(length(backup_hash)=64)"
diff --git a/src/syncdb/test_sync_db.c b/src/syncdb/test_sync_db.c
index 7dc1698..0cbb8a5 100644
--- a/src/syncdb/test_sync_db.c
+++ b/src/syncdb/test_sync_db.c
@@ -47,10 +47,25 @@ static int result;
  */
 static struct SYNC_DatabasePlugin *plugin;
 
+
 /**
- * User public key, set to a random value
+ * Function called on all pending payments for an account.
+ *
+ * @param cls closure
+ * @param timestamp for how long have we been waiting
+ * @param order_id order id in the backend
+ * @param amount how much is the order for
  */
-static struct SYNC_AccountPublicKeyP accountPubP;
+static void
+payment_it (void *cls,
+            struct GNUNET_TIME_Absolute timestamp,
+            const char *order_id,
+            const struct TALER_Amount *amount)
+{
+  GNUNET_assert (NULL == cls);
+  GNUNET_assert (0 == strcmp (order_id,
+                              "fake-order-2"));
+}
 
 
 /**
@@ -62,6 +77,18 @@ static void
 run (void *cls)
 {
   struct GNUNET_CONFIGURATION_Handle *cfg = cls;
+  struct TALER_Amount amount;
+  struct SYNC_AccountPublicKeyP account_pub;
+  struct SYNC_AccountSignatureP account_sig;
+  struct SYNC_AccountSignatureP account_sig2;
+  struct GNUNET_HashCode h;
+  struct GNUNET_HashCode h2;
+  struct GNUNET_HashCode h3;
+  struct GNUNET_HashCode r;
+  struct GNUNET_HashCode r2;
+  struct GNUNET_TIME_Absolute ts;
+  size_t bs;
+  void *b = NULL;
 
   if (NULL == (plugin = SYNC_DB_plugin_load (cfg)))
   {
@@ -81,10 +108,143 @@ run (void *cls)
     result = 77;
     return;
   }
+  memset (&account_pub, 1, sizeof (account_pub));
+  memset (&account_sig, 2, sizeof (account_sig));
+  GNUNET_CRYPTO_hash ("data", 4, &h);
+  GNUNET_CRYPTO_hash ("DATA", 4, &h2);
+  GNUNET_CRYPTO_hash ("ATAD", 4, &h3);
+  GNUNET_assert (GNUNET_OK ==
+                 TALER_string_to_amount ("EUR:1",
+                                         &amount));
+  FAILIF (SYNC_DB_ONE_RESULT !=
+          plugin->store_payment_TR (plugin->cls,
+                                    &account_pub,
+                                    "fake-order",
+                                    &amount));
+  FAILIF (SYNC_DB_ONE_RESULT !=
+          plugin->increment_lifetime_TR (plugin->cls,
+                                         &account_pub,
+                                         "fake-order",
+                                         GNUNET_TIME_UNIT_MINUTES));
+  FAILIF (SYNC_DB_ONE_RESULT !=
+          plugin->store_backup_TR (plugin->cls,
+                                   &account_pub,
+                                   &account_sig,
+                                   &h,
+                                   4,
+                                   "data"));
+  FAILIF (SYNC_DB_NO_RESULTS !=
+          plugin->store_backup_TR (plugin->cls,
+                                   &account_pub,
+                                   &account_sig,
+                                   &h,
+                                   4,
+                                   "data"));
+  FAILIF (SYNC_DB_ONE_RESULT !=
+          plugin->update_backup_TR (plugin->cls,
+                                    &account_pub,
+                                    &h,
+                                    &account_sig,
+                                    &h2,
+                                    4,
+                                    "DATA"));
+  FAILIF (SYNC_DB_OLD_BACKUP_MISSMATCH !=
+          plugin->update_backup_TR (plugin->cls,
+                                    &account_pub,
+                                    &h,
+                                    &account_sig,
+                                    &h3,
+                                    4,
+                                    "ATAD"));
+  FAILIF (SYNC_DB_NO_RESULTS !=
+          plugin->update_backup_TR (plugin->cls,
+                                    &account_pub,
+                                    &h,
+                                    &account_sig,
+                                    &h2,
+                                    4,
+                                    "DATA"));
+  FAILIF (SYNC_DB_ONE_RESULT !=
+          plugin->lookup_account_TR (plugin->cls,
+                                     &account_pub,
+                                     &r));
+  FAILIF (0 != GNUNET_memcmp (&r,
+                              &h2));
+  FAILIF (SYNC_DB_ONE_RESULT !=
+          plugin->lookup_backup_TR (plugin->cls,
+                                    &account_pub,
+                                    &account_sig2,
+                                    &r,
+                                    &r2,
+                                    &bs,
+                                    &b));
+  FAILIF (0 != GNUNET_memcmp (&r,
+                              &h));
+  FAILIF (0 != GNUNET_memcmp (&r2,
+                              &h2));
+  FAILIF (0 != GNUNET_memcmp (&account_sig2,
+                              &account_sig));
+  FAILIF (bs != 4);
+  FAILIF (0 != memcmp (b,
+                       "DATA",
+                       4));
+  GNUNET_free (b);
+  b = NULL;
+  FAILIF (0 !=
+          plugin->lookup_pending_payments_by_account_TR (plugin->cls,
+                                                         &account_pub,
+                                                         &payment_it,
+                                                         NULL));
+  memset (&account_pub, 2, sizeof (account_pub));
+  FAILIF (SYNC_DB_ONE_RESULT !=
+          plugin->store_payment_TR (plugin->cls,
+                                    &account_pub,
+                                    "fake-order-2",
+                                    &amount));
+  FAILIF (1 !=
+          plugin->lookup_pending_payments_by_account_TR (plugin->cls,
+                                                         &account_pub,
+                                                         &payment_it,
+                                                         NULL));
+  FAILIF (SYNC_DB_PAYMENT_REQUIRED !=
+          plugin->store_backup_TR (plugin->cls,
+                                   &account_pub,
+                                   &account_sig,
+                                   &h,
+                                   4,
+                                   "data"));
+  FAILIF (SYNC_DB_ONE_RESULT !=
+          plugin->increment_lifetime_TR (plugin->cls,
+                                         &account_pub,
+                                         "fake-order-2",
+                                         GNUNET_TIME_UNIT_MINUTES));
+  FAILIF (SYNC_DB_OLD_BACKUP_MISSING !=
+          plugin->update_backup_TR (plugin->cls,
+                                    &account_pub,
+                                    &h,
+                                    &account_sig,
+                                    &h2,
+                                    4,
+                                    "DATA"));
+  ts = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_YEARS);
+  (void) GNUNET_TIME_round_abs (&ts);
+  FAILIF (0 >
+          plugin->gc (plugin->cls,
+                      ts,
+                      ts));
+  memset (&account_pub, 1, sizeof (account_pub));
+  FAILIF (SYNC_DB_NO_RESULTS !=
+          plugin->lookup_backup_TR (plugin->cls,
+                                    &account_pub,
+                                    &account_sig2,
+                                    &r,
+                                    &r2,
+                                    &bs,
+                                    &b));
 
-  // FIXME: test logic here!
   result = 0;
-
+drop:
+  GNUNET_free_non_null (b);
   GNUNET_break (GNUNET_OK ==
                 plugin->drop_tables (plugin->cls));
   SYNC_DB_plugin_unload (plugin);

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



reply via email to

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