summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJonathan Buchanan <jonathan.russ.buchanan@gmail.com>2020-05-19 16:29:13 -0400
committerJonathan Buchanan <jonathan.russ.buchanan@gmail.com>2020-05-19 16:29:13 -0400
commit601abc17e4d63fed52de91402c15bb4d9ba3e014 (patch)
tree51c37427a200b46f22e6c9b0aed151d733da4127 /src
parent39d2fb9ed2b1737fba10579dfddd08edae734edb (diff)
downloadmerchant-601abc17e4d63fed52de91402c15bb4d9ba3e014.tar.gz
merchant-601abc17e4d63fed52de91402c15bb4d9ba3e014.tar.bz2
merchant-601abc17e4d63fed52de91402c15bb4d9ba3e014.zip
added tests for instance creation and lookup
Diffstat (limited to 'src')
-rw-r--r--src/backenddb/test_merchantdb.c90
1 files changed, 90 insertions, 0 deletions
diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c
index fdcf879d..d159893b 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)))
{