summaryrefslogtreecommitdiff
path: root/src/backenddb
diff options
context:
space:
mode:
authorJonathan Buchanan <jonathan.russ.buchanan@gmail.com>2020-06-03 03:01:12 -0400
committerJonathan Buchanan <jonathan.russ.buchanan@gmail.com>2020-06-03 03:01:12 -0400
commit4bd45c1fc2618a4be74f6204577651365e3d2254 (patch)
tree32e6ba108c799a9e932c1b3b4108784b76a2c1cf /src/backenddb
parent2edb7ff575ec61fc570e80b6c492878c3bb97f70 (diff)
downloadmerchant-4bd45c1fc2618a4be74f6204577651365e3d2254.tar.gz
merchant-4bd45c1fc2618a4be74f6204577651365e3d2254.tar.bz2
merchant-4bd45c1fc2618a4be74f6204577651365e3d2254.zip
tests/fixes for tips and pickups in backenddb
Diffstat (limited to 'src/backenddb')
-rw-r--r--src/backenddb/plugin_merchantdb_postgres.c40
-rw-r--r--src/backenddb/test_merchantdb.c132
2 files changed, 137 insertions, 35 deletions
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c
index 0de83602..a5f6818b 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -4516,7 +4516,7 @@ RETRY:
postgres_rollback (pg);
return TALER_EC_TIP_AUTHORIZE_DB_RESERVE_INVARIANT_FAILURE;
}
- if (0 <
+ if (0 >
TALER_amount_cmp (&remaining,
amount))
{
@@ -4555,13 +4555,18 @@ RETRY:
tip_id,
sizeof (*tip_id));
{
+ struct TALER_Amount amount_zero;
+ TALER_amount_get_zero (pg->currency,
+ &amount_zero);
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_string (instance_id),
GNUNET_PQ_query_param_auto_from_type (reserve_pubp),
GNUNET_PQ_query_param_auto_from_type (tip_id),
GNUNET_PQ_query_param_string (justification),
GNUNET_PQ_query_param_string (next_url),
+ GNUNET_PQ_query_param_absolute_time (expiration),
TALER_PQ_query_param_amount (amount),
+ TALER_PQ_query_param_amount (&amount_zero),
GNUNET_PQ_query_param_end
};
@@ -5041,14 +5046,14 @@ RETRY:
{
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_string (instance_id),
- GNUNET_PQ_query_param_auto_from_type (&tip_id),
+ GNUNET_PQ_query_param_auto_from_type (tip_id),
GNUNET_PQ_query_param_end
};
struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("tips_picked_up",
- &reserve_picked_up),
GNUNET_PQ_result_spec_uint64 ("reserve_serial",
&reserve_serial),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("tips_picked_up",
+ &reserve_picked_up),
GNUNET_PQ_result_spec_end
};
@@ -5066,12 +5071,13 @@ RETRY:
return qs;
}
}
- if (0 <=
+ if (0 >=
TALER_amount_add (&reserve_picked_up,
&reserve_picked_up,
total_requested))
{
GNUNET_break (0);
+ postgres_rollback (pg);
return GNUNET_DB_STATUS_HARD_ERROR;
}
@@ -6902,7 +6908,7 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
GNUNET_PQ_make_prepare ("activate_reserve",
"UPDATE merchant_tip_reserves SET"
" exchange_initial_balance_val=$3"
- " exchange_initial_balance_frac=$4"
+ ",exchange_initial_balance_frac=$4"
" WHERE reserve_pub=$2"
" AND merchant_serial="
" (SELECT merchant_serial"
@@ -7052,17 +7058,20 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
GNUNET_PQ_make_prepare ("insert_tip",
"INSERT INTO merchant_tips"
"(reserve_serial"
+ ",tip_id"
",justification"
",next_url"
",expiration"
",amount_val"
",amount_frac"
+ ",picked_up_val"
+ ",picked_up_frac"
") "
"SELECT"
- " reserve_serial, $3, $4, $5, $6, $7"
+ " reserve_serial, $3, $4, $5, $6, $7, $8, $9, $10"
" FROM merchant_tip_reserves"
" WHERE reserve_pub=$2"
- " AND reserve_serial = "
+ " AND merchant_serial = "
" (SELECT merchant_serial"
" FROM merchant_instances"
" WHERE merchant_id=$1)",
@@ -7077,8 +7086,8 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
" JOIN merchant_tips USING (tip_serial)"
" JOIN merchant_tip_reserves USING (reserve_serial)"
" JOIN merchant_tip_reserve_keys USING (reserve_serial)"
- " WHERE pickup_id = $2"
- " AND tip_id = $3"
+ " WHERE pickup_id = $3"
+ " AND tip_id = $2"
" AND merchant_serial ="
" (SELECT merchant_serial"
" FROM merchant_instances"
@@ -7137,9 +7146,13 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
" pickup_id"
",amount_val"
",amount_frac"
- ",COUNT(blind_sig) AS num_planchets"
+ ",(SELECT"
+ " COUNT(blind_sig)"
+ " FROM merchant_tip_pickups"
+ " JOIN merchant_tip_pickup_signatures USING (pickup_serial)"
+ " WHERE tip_serial = $1)"
+ " AS num_planchets"
" FROM merchant_tip_pickups"
- " JOIN merchant_tip_pickup_signatures USING (pickup_serial)"
" WHERE tip_serial = $1",
1),
/* for postgres_insert_pickup() */
@@ -7153,8 +7166,9 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
"SELECT"
" tip_serial, $3, $4, $5"
" FROM merchant_tips"
+ " JOIN merchant_tip_reserves USING (reserve_serial)"
" WHERE tip_id=$2"
- " AND reserve_serial = "
+ " AND merchant_serial = "
" (SELECT merchant_serial"
" FROM merchant_instances"
" WHERE merchant_id=$1)",
diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c
index 49b086be..d225fecc 100644
--- a/src/backenddb/test_merchantdb.c
+++ b/src/backenddb/test_merchantdb.c
@@ -3086,7 +3086,7 @@ test_lookup_tip (const char *instance_id,
struct TALER_Amount total_authorized;
struct TALER_Amount total_picked_up;
struct GNUNET_TIME_Absolute expiration;
- char *exchange_url;
+ char *exchange_url = NULL;
struct TALER_ReservePrivateKeyP reserve_priv;
if (1 != plugin->lookup_tip (plugin->cls,
instance_id,
@@ -3259,14 +3259,14 @@ test_lookup_pickup (const char *instance_id,
memset (sigs,
0,
sizeof (struct GNUNET_CRYPTO_RsaSignature *) * expected_sigs_length);
- if (1 != plugin->lookup_pickup (plugin->cls,
- instance_id,
- tip_id,
- pickup_id,
- &exchange_url,
- &reserve_priv,
- expected_sigs_length,
- sigs))
+ if (0 > plugin->lookup_pickup (plugin->cls,
+ instance_id,
+ tip_id,
+ pickup_id,
+ &exchange_url,
+ &reserve_priv,
+ expected_sigs_length,
+ sigs))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Lookup pickup failed\n");
@@ -3343,6 +3343,13 @@ struct TestTips_Closure
*/
struct ReserveData reserve;
+ /* Tip and pickup data */
+ struct TALER_Amount tip_amount;
+ struct GNUNET_HashCode tip_id;
+ struct GNUNET_HashCode pickup_id;
+ struct GNUNET_CRYPTO_RsaPrivateKey *pickup_priv;
+ struct GNUNET_CRYPTO_RsaSignature *pickup_sig;
+
};
@@ -3384,6 +3391,18 @@ pre_test_tips (struct TestTips_Closure *cls)
cls->reserve.expiration =
GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
GNUNET_TIME_UNIT_WEEKS);
+
+ /* Tip/pickup */
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount ("EUR:0.99",
+ &cls->tip_amount));
+ GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG,
+ &cls->tip_id);
+ GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG,
+ &cls->tip_id);
+ cls->pickup_priv = GNUNET_CRYPTO_rsa_private_key_create (2048);
+ cls->pickup_sig = GNUNET_CRYPTO_rsa_sign_fdh (cls->pickup_priv,
+ &cls->pickup_id);
}
@@ -3392,12 +3411,18 @@ post_test_tips (struct TestTips_Closure *cls)
{
json_decref (cls->is.address);
json_decref (cls->is.jurisdiction);
+
+ GNUNET_CRYPTO_rsa_private_key_free (cls->pickup_priv);
+ GNUNET_CRYPTO_rsa_signature_free (cls->pickup_sig);
}
static int
run_test_tips (struct TestTips_Closure *cls)
{
+ struct TALER_Amount zero;
+ TALER_amount_get_zero ("EUR", &zero);
+
TEST_RET_ON_FAIL (test_insert_instance (&cls->merchant_pub,
&cls->merchant_priv,
&cls->is));
@@ -3421,29 +3446,84 @@ run_test_tips (struct TestTips_Closure *cls)
&cls->reserve.reserve_pub,
&cls->reserve));
+ /* Test reserve activation */
+ if (1 != plugin->activate_reserve (plugin->cls,
+ cls->is.id,
+ &cls->reserve.reserve_pub,
+ &cls->reserve.initial_amount))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Active reserve failed\n");
+ return 1;
+ }
+
/* Test inserting a tip */
- /*
- struct TALER_Amount tip_amount;
- GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount ("EUR:0.99",
- &tip_amount));
- struct GNUNET_HashCode tip_id;
- GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG,
- &tip_id);
if (TALER_EC_NONE != plugin->authorize_tip (plugin->cls,
cls->is.id,
- &cls->reserve_pub,
- &tip_amount,
+ &cls->reserve.reserve_pub,
+ &cls->tip_amount,
"because",
"https://taler.net",
- &tip_id,
- &expiration))
+ &cls->tip_id,
+ &cls->reserve.expiration))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Authorize tip failed\n");
return 1;
}
- */
+
+ /* Test lookup tip */
+ TEST_RET_ON_FAIL (test_lookup_tip (cls->is.id,
+ &cls->tip_id,
+ &cls->tip_amount,
+ &zero,
+ &cls->reserve.expiration,
+ cls->reserve.exchange_url,
+ &cls->reserve.reserve_priv));
+
+ /* Test lookup tip details */
+ TEST_RET_ON_FAIL (test_lookup_tip_details (cls->is.id,
+ cls->tip_id,
+ &cls->tip_amount,
+ &zero,
+ "because",
+ &cls->reserve.expiration,
+ &cls->reserve.reserve_pub,
+ 0,
+ NULL));
+
+ /* Test insert pickup */
+ if (1 != plugin->insert_pickup (plugin->cls,
+ cls->is.id,
+ &cls->tip_id,
+ &cls->tip_amount,
+ &cls->pickup_id,
+ &cls->tip_amount))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Error inserting pickup\n");
+ return 1;
+ }
+
+ /* Test lookup pickup */
+ TEST_RET_ON_FAIL (test_lookup_pickup (cls->is.id,
+ &cls->tip_id,
+ &cls->pickup_id,
+ cls->reserve.exchange_url,
+ &cls->reserve.reserve_priv,
+ 0,
+ NULL));
+
+ /* Test insert pickup blind signature */
+ if (1 != plugin->insert_pickup_blind_signature (plugin->cls,
+ &cls->pickup_id,
+ 0,
+ cls->pickup_sig))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Error inserting pickup blind signature\n");
+ return 1;
+ }
/* Test lookup reserves */
TEST_RET_ON_FAIL (test_lookup_reserves (cls->is.id,
@@ -3845,6 +3925,14 @@ pre_test_refunds (struct TestRefunds_Closure *cls)
cls->is.default_wire_transfer_delay = GNUNET_TIME_relative_get_minute_ ();
cls->is.default_pay_delay = GNUNET_TIME_relative_get_second_ ();
+ /* Account */
+ GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG,
+ &cls->account.h_wire);
+ GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG,
+ &cls->account.salt);
+ cls->account.payto_uri = "payto://x-taler-bank/bank.demo.taler.net/4";
+ cls->account.active = true;
+
/* Signing key */
GNUNET_CRYPTO_eddsa_key_create (&cls->exchange_priv.eddsa_priv);
GNUNET_CRYPTO_eddsa_key_get_public (&cls->exchange_priv.eddsa_priv,