diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-12-01 15:50:41 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-12-01 15:50:41 +0100 |
commit | 440135668be79231ebab8afc1f34350bbfe07ad4 (patch) | |
tree | 45581f029e5811a6cfd7b2c858c3869b2ef9e4ec /src | |
parent | d77fa62ab6c0bad1394ba5217f51e3d142e10948 (diff) | |
download | sync-440135668be79231ebab8afc1f34350bbfe07ad4.tar.gz sync-440135668be79231ebab8afc1f34350bbfe07ad4.tar.bz2 sync-440135668be79231ebab8afc1f34350bbfe07ad4.zip |
test syncdb
Diffstat (limited to 'src')
-rw-r--r-- | src/syncdb/plugin_syncdb_postgres.c | 18 | ||||
-rw-r--r-- | 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); |