diff options
author | Jonathan Buchanan <jonathan.russ.buchanan@gmail.com> | 2020-06-01 01:32:26 -0400 |
---|---|---|
committer | Jonathan Buchanan <jonathan.russ.buchanan@gmail.com> | 2020-06-01 01:32:26 -0400 |
commit | cd3a94a3c143455350be8e8c0cddbb8dc691da33 (patch) | |
tree | fbb51e8c2b6a72669e0b69c6713b0a3ff8227f45 /src/backenddb | |
parent | 6f11901485a5af44c53a31ebbf4d0e93991983c9 (diff) | |
download | merchant-cd3a94a3c143455350be8e8c0cddbb8dc691da33.tar.gz merchant-cd3a94a3c143455350be8e8c0cddbb8dc691da33.tar.bz2 merchant-cd3a94a3c143455350be8e8c0cddbb8dc691da33.zip |
fixed db test building and added test for wire fee storage
Diffstat (limited to 'src/backenddb')
-rw-r--r-- | src/backenddb/plugin_merchantdb_postgres.c | 6 | ||||
-rw-r--r-- | src/backenddb/test_merchantdb.c | 126 |
2 files changed, 122 insertions, 10 deletions
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c index eba525bd..59810047 100644 --- a/src/backenddb/plugin_merchantdb_postgres.c +++ b/src/backenddb/plugin_merchantdb_postgres.c @@ -7078,7 +7078,7 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) ",picked_up_frac" ",justification" ",merchant_tips.expiration" - ",exchange_url" + // ",exchange_url" ",reserve_pub" " FROM merchant_tips" " JOIN merchant_tip_reserves USING (reserve_serial)" @@ -7094,8 +7094,8 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) " pickup_id" ",amount_val" ",amount_frac" - ",num_planchets" - ",COUNT(blind_sig)" + // ",num_planchets" + // ",COUNT(blind_sig)" " FROM merchant_tip_pickups" " JOIN merchant_tip_pickup_signatures USING (pickup_serial)" " WHERE tip_serial = $1", diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c index a834eff3..49b086be 100644 --- a/src/backenddb/test_merchantdb.c +++ b/src/backenddb/test_merchantdb.c @@ -201,6 +201,25 @@ test_insert_instance (const struct TALER_MerchantPublicKeyP *merchant_pub, static int +test_insert_instance_fails (const struct TALER_MerchantPublicKeyP *merchant_pub, + const struct + TALER_MerchantPrivateKeyP *merchant_priv, + const struct TALER_MERCHANTDB_InstanceSettings *is) +{ + if (0 != plugin->insert_instance (plugin->cls, + merchant_pub, + merchant_priv, + is)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Instance insertion succeeded when expected to fail\n"); + return 1; + } + return 0; +} + + +static int test_lookup_instances (bool active_only, unsigned int instances_length, struct InstanceWithAccounts instances[]) @@ -257,6 +276,23 @@ test_insert_account (const char *instance_id, } +static int +test_insert_account_fails (const char *instance_id, + const struct + TALER_MERCHANTDB_AccountDetails *account) +{ + if (0 != plugin->insert_account (plugin->cls, + instance_id, + account)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Insert account failed\n"); + return 1; + } + return 0; +} + + /** * Closure for instance tests */ @@ -290,6 +326,7 @@ struct TestInstances_Closure static void pre_test_instances (struct TestInstances_Closure *cls) { + /* Instance */ GNUNET_CRYPTO_eddsa_key_create (&cls->merchant_priv.eddsa_priv); GNUNET_CRYPTO_eddsa_key_get_public (&cls->merchant_priv.eddsa_priv, &cls->merchant_pub.eddsa_pub); @@ -313,6 +350,7 @@ pre_test_instances (struct TestInstances_Closure *cls) cls->is.default_wire_transfer_delay = GNUNET_TIME_relative_get_minute_ (); cls->is.default_pay_delay = GNUNET_TIME_relative_get_second_ (); + /* Accounts */ GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG, &cls->accounts[0].h_wire); GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG, @@ -362,6 +400,11 @@ run_test_instances (struct TestInstances_Closure *cls) &cls->merchant_priv, &cls->is)); + /* Test double insertion fails */ + TEST_RET_ON_FAIL (test_insert_instance_fails (&cls->merchant_pub, + &cls->merchant_priv, + &cls->is)); + /* Test lookup instances- is our new instance there? */ TEST_RET_ON_FAIL (test_lookup_instances (false, 1, @@ -384,6 +427,10 @@ run_test_instances (struct TestInstances_Closure *cls) TEST_RET_ON_FAIL (test_insert_account (cls->is.id, &cls->accounts[0])); + /* Test double account insertion fails */ + TEST_RET_ON_FAIL (test_insert_account_fails (cls->is.id, + &cls->accounts[0])); + /* Test accounts from instance lookup */ instances[0].accounts_length = 1; instances[0].accounts = cls->accounts; @@ -2434,6 +2481,17 @@ struct TestTransfers_Closure * The deposit data */ struct DepositData deposit; + + /** + * Wire fee data + */ + const char *exch_wire_method; + struct GNUNET_HashCode exch_h_wire_method; + struct TALER_Amount exch_wire_fee; + struct TALER_Amount exch_closing_fee; + struct GNUNET_TIME_Absolute exch_wire_fee_start; + struct GNUNET_TIME_Absolute exch_wire_fee_end; + struct TALER_MasterSignatureP exch_fee_sig; }; @@ -2459,6 +2517,14 @@ pre_test_transfers (struct TestTransfers_Closure *cls) }; + struct TALER_MasterWireFeePS fee_sign = { + .purpose = { + .size = htonl (sizeof (struct TALER_MasterWireFeePS)), + .purpose = htonl (TALER_SIGNATURE_MASTER_WIRE_FEES) + } + + + }; /* Instance */ GNUNET_CRYPTO_eddsa_key_create (&cls->merchant_priv.eddsa_priv); @@ -2563,6 +2629,31 @@ pre_test_transfers (struct TestTransfers_Closure *cls) cls->signkey_start = GNUNET_TIME_absolute_get (); cls->signkey_expire = GNUNET_TIME_absolute_get (); cls->signkey_end = GNUNET_TIME_absolute_get (); + + /* Wire fee */ + cls->exch_wire_method = "wire-method"; + GNUNET_CRYPTO_hash (cls->exch_wire_method, + strlen (cls->exch_wire_method) + 1, + &cls->exch_h_wire_method); + GNUNET_assert (GNUNET_OK == + TALER_string_to_amount ("EUR:0.49", + &cls->exch_wire_fee)); + GNUNET_assert (GNUNET_OK == + TALER_string_to_amount ("EUR:0.49", + &cls->exch_closing_fee)); + cls->exch_wire_fee_start = GNUNET_TIME_absolute_get (); + cls->exch_wire_fee_end = GNUNET_TIME_absolute_add (cls->exch_wire_fee_start, + GNUNET_TIME_UNIT_MONTHS); + fee_sign.h_wire_method = cls->exch_h_wire_method; + TALER_amount_hton (&fee_sign.wire_fee, + &cls->exch_wire_fee); + TALER_amount_hton (&fee_sign.closing_fee, + &cls->exch_closing_fee); + fee_sign.start_date = GNUNET_TIME_absolute_hton (cls->exch_wire_fee_start); + fee_sign.end_date = GNUNET_TIME_absolute_hton (cls->exch_wire_fee_end); + GNUNET_CRYPTO_eddsa_sign (&cls->master_priv.eddsa_priv, + &fee_sign, + &cls->exch_fee_sig.eddsa_signature); } @@ -2599,6 +2690,33 @@ run_test_transfers (struct TestTransfers_Closure *cls) .wtid = wtid }; + /* Test store wire fee by exchange */ + if (1 != plugin->store_wire_fee_by_exchange (plugin->cls, + &cls->master_pub, + &cls->exch_h_wire_method, + &cls->exch_wire_fee, + &cls->exch_closing_fee, + cls->exch_wire_fee_start, + cls->exch_wire_fee_end, + &cls->exch_fee_sig)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Error storing wire fee for exchange\n"); + return 1; + } + + /* Test lookup wire fee by exchange */ + TEST_RET_ON_FAIL (test_lookup_wire_fee (&cls->master_pub, + cls->exch_wire_method, + GNUNET_TIME_absolute_add ( + cls->exch_wire_fee_start, + GNUNET_TIME_UNIT_DAYS), + &cls->exch_wire_fee, + &cls->exch_closing_fee, + &cls->exch_wire_fee_start, + &cls->exch_wire_fee_end, + &cls->exch_fee_sig)); + /* Insert the instance */ TEST_RET_ON_FAIL (test_insert_instance (&cls->merchant_pub, &cls->merchant_priv, @@ -3034,7 +3152,7 @@ test_lookup_tip_details (const char *instance_id, unsigned int results_matching[expected_pickups_length]; if (TALER_EC_NONE != plugin->lookup_tip_details (plugin->cls, instance_id, - tip_id, + &tip_id, true, &total_authorized, &total_picked_up, @@ -3089,12 +3207,6 @@ test_lookup_tip_details (const char *instance_id, && (0 == TALER_amount_cmp (&expected_pickups[i].requested_amount, &pickups[j].requested_amount)) && - (GNUNET_OK == TALER_amount_cmp_currency ( - &expected_pickups[i].exchange_amount, - &pickups[j].requested_amount)) - && - (0 == TALER_amount_cmp (&expected_pickups[i].exchange_amount, - &pickups[j].exchange_amount)) && (expected_pickups[i].num_planchets == pickups[j].num_planchets)) { results_matching[i] += 1; |