summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJonathan Buchanan <jonathan.russ.buchanan@gmail.com>2020-06-05 21:29:36 -0400
committerJonathan Buchanan <jonathan.russ.buchanan@gmail.com>2020-06-05 21:29:36 -0400
commitab6ee1680d16905ef938380e49c86710fb5c7155 (patch)
treec26413faaa32fb16c4d3a887feb53387ffa45926 /src
parent03146baf2929365c2b8ac88a96300525de80a104 (diff)
downloadmerchant-ab6ee1680d16905ef938380e49c86710fb5c7155.tar.gz
merchant-ab6ee1680d16905ef938380e49c86710fb5c7155.tar.bz2
merchant-ab6ee1680d16905ef938380e49c86710fb5c7155.zip
More complete tests for deposits, transfers, refund, lookup orders
Diffstat (limited to 'src')
-rw-r--r--src/backenddb/plugin_merchantdb_postgres.c4
-rw-r--r--src/backenddb/test_merchantdb.c791
2 files changed, 446 insertions, 349 deletions
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c
index 8c484ff4..9d2e5077 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -5638,6 +5638,7 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
" order_id"
",order_serial"
",creation_time"
+ ",CAST($7 as BOOL)" /* otherwise $7 is unused and Postgres unhappy */
" FROM merchant_orders"
" WHERE merchant_orders.merchant_serial="
" (SELECT merchant_serial "
@@ -5658,6 +5659,7 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
" order_id"
",order_serial"
",creation_time"
+ ",CAST($7 as BOOL)" /* otherwise $7 is unused and Postgres unhappy */
" FROM merchant_contract_terms"
" WHERE merchant_contract_terms.merchant_serial="
" (SELECT merchant_serial "
@@ -5996,6 +5998,7 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
" order_id"
",order_serial"
",creation_time"
+ ",CAST($7 as BOOL)" /* otherwise $7 is unused and Postgres unhappy */
" FROM merchant_orders"
" WHERE merchant_orders.merchant_serial="
" (SELECT merchant_serial "
@@ -6016,6 +6019,7 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
" order_id"
",order_serial"
",creation_time"
+ ",CAST($7 as BOOL)" /* otherwise $7 is unused and Postgres unhappy */
" FROM merchant_contract_terms"
" WHERE merchant_contract_terms.merchant_serial="
" (SELECT merchant_serial "
diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c
index 97545662..31856759 100644
--- a/src/backenddb/test_merchantdb.c
+++ b/src/backenddb/test_merchantdb.c
@@ -1748,34 +1748,32 @@ test_insert_exchange_signkey (const struct ExchangeSignkeyData *signkey,
static int
-test_insert_deposit (const char *is,
- const struct TALER_ExchangePublicKeyP *exchange_pub,
- const struct DepositData *deposit)
-{
- if (1 != plugin->insert_deposit (plugin->cls,
- is,
- deposit->timestamp,
- &deposit->h_contract_terms,
- &deposit->coin_pub,
- deposit->exchange_url,
- &deposit->amount_with_fee,
- &deposit->deposit_fee,
- &deposit->refund_fee,
- &deposit->wire_fee,
- &deposit->h_wire,
- &deposit->exchange_sig,
- exchange_pub))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Insert deposit failed\n");
- return 1;
- }
+test_insert_deposit (const struct InstanceData *instance,
+ const struct ExchangeSignkeyData *signkey,
+ const struct DepositData *deposit,
+ enum GNUNET_DB_QueryStatus expected_result)
+{
+ TEST_COND_RET_ON_FAIL (expected_result ==
+ plugin->insert_deposit (plugin->cls,
+ instance->instance.id,
+ deposit->timestamp,
+ &deposit->h_contract_terms,
+ &deposit->coin_pub,
+ deposit->exchange_url,
+ &deposit->amount_with_fee,
+ &deposit->deposit_fee,
+ &deposit->refund_fee,
+ &deposit->wire_fee,
+ &deposit->h_wire,
+ &deposit->exchange_sig,
+ &signkey->exchange_pub),
+ "Insert deposit failed\n");
return 0;
}
static int
-test_lookup_deposits (const char *is,
+test_lookup_deposits (const struct InstanceData *instance,
const struct GNUNET_HashCode *h_contract_terms,
unsigned int deposits_length,
const struct DepositData *deposits)
@@ -1787,17 +1785,16 @@ test_lookup_deposits (const char *is,
.results_matching = results_matching,
.results_length = 0
};
- memset (results_matching, 0, sizeof (unsigned int) * deposits_length);
- if (0 > plugin->lookup_deposits (plugin->cls,
- is,
- h_contract_terms,
- &lookup_deposits_cb,
- &cmp))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Lookup deposits failed\n");
- return 1;
- }
+ memset (results_matching,
+ 0,
+ sizeof (unsigned int) * deposits_length);
+ TEST_COND_RET_ON_FAIL (deposits_length ==
+ plugin->lookup_deposits (plugin->cls,
+ instance->instance.id,
+ h_contract_terms,
+ &lookup_deposits_cb,
+ &cmp),
+ "Lookup deposits failed\n");
if (deposits_length != cmp.results_length)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -1818,7 +1815,7 @@ test_lookup_deposits (const char *is,
static int
-test_lookup_deposits_contract_and_coin (const char *instance_id,
+test_lookup_deposits_contract_and_coin (const struct InstanceData *instance,
const struct
GNUNET_HashCode *h_contract,
const struct
@@ -1833,19 +1830,20 @@ test_lookup_deposits_contract_and_coin (const char *instance_id,
.results_matching = results_matching,
.results_length = 0
};
- memset (results_matching, 0, sizeof (unsigned int) * deposits_length);
- if (0 > plugin->lookup_deposits_by_contract_and_coin (plugin->cls,
- instance_id,
- h_contract,
- coin_pub,
- &
- lookup_deposits_contract_coin_cb,
- &cmp))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Lookup deposits by contract and coin failed\n");
- return 1;
- }
+ memset (results_matching,
+ 0,
+ sizeof (unsigned int) * deposits_length);
+ TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
+ plugin->lookup_deposits_by_contract_and_coin (
+ plugin->cls,
+ instance
+ ->instance.id,
+ h_contract,
+ coin_pub,
+ &
+ lookup_deposits_contract_coin_cb,
+ &cmp),
+ "Lookup deposits by contract and coin failed\n");
if (deposits_length != cmp.results_length)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -1920,6 +1918,14 @@ pre_test_deposits (struct TestDeposits_Closure *cls)
&cls->order,
&cls->signkey,
&cls->deposits[0]);
+ make_deposit (&cls->instance,
+ &cls->account,
+ &cls->order,
+ &cls->signkey,
+ &cls->deposits[1]);
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount ("EUR:29.00",
+ &cls->deposits[1].amount_with_fee));
}
@@ -1927,8 +1933,6 @@ static void
post_test_deposits (struct TestDeposits_Closure *cls)
{
free_instance_data (&cls->instance);
-
- /* Order */
json_decref (cls->order.contract);
}
@@ -1939,47 +1943,52 @@ run_test_deposits (struct TestDeposits_Closure *cls)
/* Insert the instance */
TEST_RET_ON_FAIL (test_insert_instance (&cls->instance,
GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
-
/* Insert an account */
TEST_RET_ON_FAIL (test_insert_account (&cls->instance,
&cls->account,
GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
-
/* Insert a signing key */
TEST_RET_ON_FAIL (test_insert_exchange_signkey (&cls->signkey,
GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
-
/* Insert an order */
TEST_RET_ON_FAIL (test_insert_order (&cls->instance,
&cls->order,
GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
-
/* Insert contract terms */
TEST_RET_ON_FAIL (test_insert_contract_terms (&cls->instance,
&cls->order,
GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
-
/* Test inserting a deposit */
- TEST_RET_ON_FAIL (test_insert_deposit (cls->instance.instance.id,
- &cls->signkey.exchange_pub,
- &cls->deposits[0]));
-
+ TEST_RET_ON_FAIL (test_insert_deposit (&cls->instance,
+ &cls->signkey,
+ &cls->deposits[0],
+ GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
+ /* Test double inserts fail */
+ TEST_RET_ON_FAIL (test_insert_deposit (&cls->instance,
+ &cls->signkey,
+ &cls->deposits[0],
+ GNUNET_DB_STATUS_SUCCESS_NO_RESULTS));
/* Test lookup deposits */
- TEST_RET_ON_FAIL (test_lookup_deposits (cls->instance.instance.id,
+ TEST_RET_ON_FAIL (test_lookup_deposits (&cls->instance,
&cls->deposits[0].h_contract_terms,
1,
cls->deposits));
-
/* Test lookup deposits by contract and coins */
TEST_RET_ON_FAIL (test_lookup_deposits_contract_and_coin (
- cls->instance.instance.id,
- &cls->deposits[0].
- h_contract_terms,
- &cls->deposits[0].
- coin_pub,
+ &cls->instance,
+ &cls->deposits[0].h_contract_terms,
+ &cls->deposits[0].coin_pub,
1,
cls->deposits));
-
+ /* Test multiple deposits */
+ TEST_RET_ON_FAIL (test_insert_deposit (&cls->instance,
+ &cls->signkey,
+ &cls->deposits[1],
+ GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
+ TEST_RET_ON_FAIL (test_lookup_deposits (&cls->instance,
+ &cls->deposits[0].h_contract_terms,
+ 2,
+ cls->deposits));
return 0;
}
@@ -1995,6 +2004,60 @@ test_deposits (void *cls)
}
+/* Transfers */
+
+
+struct WireFeeData
+{
+ const char *wire_method;
+ struct GNUNET_HashCode h_wire_method;
+ struct TALER_Amount wire_fee;
+ struct TALER_Amount closing_fee;
+ struct GNUNET_TIME_Absolute wire_fee_start;
+ struct GNUNET_TIME_Absolute wire_fee_end;
+ struct TALER_MasterSignatureP fee_sig;
+};
+
+
+static void
+make_wire_fee (const struct ExchangeSignkeyData *signkey,
+ struct WireFeeData *wire_fee)
+{
+ struct TALER_MasterWireFeePS fee_sign = {
+ .purpose = {
+ .size = htonl (sizeof (struct TALER_MasterWireFeePS)),
+ .purpose = htonl (TALER_SIGNATURE_MASTER_WIRE_FEES)
+ }
+
+
+ };
+
+ wire_fee->wire_method = "wire-method";
+ GNUNET_CRYPTO_hash (wire_fee->wire_method,
+ strlen (wire_fee->wire_method) + 1,
+ &wire_fee->h_wire_method);
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount ("EUR:0.49",
+ &wire_fee->wire_fee));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount ("EUR:0.49",
+ &wire_fee->closing_fee));
+ wire_fee->wire_fee_start = GNUNET_TIME_absolute_get ();
+ wire_fee->wire_fee_end = GNUNET_TIME_absolute_add (wire_fee->wire_fee_start,
+ GNUNET_TIME_UNIT_MONTHS);
+ fee_sign.h_wire_method = wire_fee->h_wire_method;
+ TALER_amount_hton (&fee_sign.wire_fee,
+ &wire_fee->wire_fee);
+ TALER_amount_hton (&fee_sign.closing_fee,
+ &wire_fee->closing_fee);
+ fee_sign.start_date = GNUNET_TIME_absolute_hton (wire_fee->wire_fee_start);
+ fee_sign.end_date = GNUNET_TIME_absolute_hton (wire_fee->wire_fee_end);
+ GNUNET_CRYPTO_eddsa_sign (&signkey->master_priv.eddsa_priv,
+ &fee_sign,
+ &wire_fee->fee_sig.eddsa_signature);
+}
+
+
struct TransferWithDetails
{
struct TALER_WireTransferIdentifierRawP wtid;
@@ -2200,14 +2263,32 @@ test_lookup_transfer_details (const char *exchange_url,
static int
-test_lookup_wire_fee (const struct TALER_MasterPublicKeyP *master_pub,
- const char *wire_method,
- struct GNUNET_TIME_Absolute contract_date,
- struct TALER_Amount *expected_wire_fee,
- struct TALER_Amount *expected_closing_fee,
- struct GNUNET_TIME_Absolute *expected_start_date,
- struct GNUNET_TIME_Absolute *expected_end_date,
- struct TALER_MasterSignatureP *expected_master_sig)
+test_insert_wire_fee (const struct ExchangeSignkeyData *signkey,
+ const struct WireFeeData *wire_fee,
+ enum GNUNET_DB_QueryStatus expected_result)
+{
+ TEST_COND_RET_ON_FAIL (expected_result ==
+ plugin->store_wire_fee_by_exchange (plugin->cls,
+ &signkey->
+ master_pub,
+ &wire_fee->
+ h_wire_method,
+ &wire_fee->wire_fee,
+ &wire_fee->
+ closing_fee,
+ wire_fee->
+ wire_fee_start,
+ wire_fee->
+ wire_fee_end,
+ &wire_fee->fee_sig),
+ "Store wire fee by exchange failed\n");
+ return 0;
+}
+
+
+static int
+test_lookup_wire_fee (const struct ExchangeSignkeyData *signkey,
+ const struct WireFeeData *wire_fee_data)
{
struct TALER_Amount wire_fee;
struct TALER_Amount closing_fee;
@@ -2215,9 +2296,9 @@ test_lookup_wire_fee (const struct TALER_MasterPublicKeyP *master_pub,
struct GNUNET_TIME_Absolute end_date;
struct TALER_MasterSignatureP master_sig;
if (1 != plugin->lookup_wire_fee (plugin->cls,
- master_pub,
- wire_method,
- contract_date,
+ &signkey->master_pub,
+ wire_fee_data->wire_method,
+ GNUNET_TIME_absolute_get (),
&wire_fee,
&closing_fee,
&start_date,
@@ -2228,17 +2309,17 @@ test_lookup_wire_fee (const struct TALER_MasterPublicKeyP *master_pub,
"Lookup wire fee failed\n");
return 1;
}
- if ((GNUNET_OK != TALER_amount_cmp_currency (expected_wire_fee,
+ if ((GNUNET_OK != TALER_amount_cmp_currency (&wire_fee_data->wire_fee,
&wire_fee)) ||
- (0 != TALER_amount_cmp (expected_wire_fee,
+ (0 != TALER_amount_cmp (&wire_fee_data->wire_fee,
&wire_fee)) ||
- (GNUNET_OK != TALER_amount_cmp_currency (expected_closing_fee,
+ (GNUNET_OK != TALER_amount_cmp_currency (&wire_fee_data->closing_fee,
&closing_fee)) ||
- (0 != TALER_amount_cmp (expected_closing_fee,
+ (0 != TALER_amount_cmp (&wire_fee_data->closing_fee,
&closing_fee)) ||
- (expected_start_date->abs_value_us != start_date.abs_value_us) ||
- (expected_end_date->abs_value_us != end_date.abs_value_us) ||
- (0 != GNUNET_memcmp (expected_master_sig,
+ (wire_fee_data->wire_fee_start.abs_value_us != start_date.abs_value_us) ||
+ (wire_fee_data->wire_fee_end.abs_value_us != end_date.abs_value_us) ||
+ (0 != GNUNET_memcmp (&wire_fee_data->fee_sig,
&master_sig)))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -2375,28 +2456,13 @@ struct TestTransfers_Closure
/**
* 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;
+ struct WireFeeData wire_fee;
};
static void
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 */
make_instance ("test_inst_transfers",
&cls->instance);
@@ -2419,29 +2485,8 @@ pre_test_transfers (struct TestTransfers_Closure *cls)
&cls->deposit);
/* 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->signkey.master_priv.eddsa_priv,
- &fee_sign,
- &cls->exch_fee_sig.eddsa_signature);
+ make_wire_fee (&cls->signkey,
+ &cls->wire_fee);
}
@@ -2449,8 +2494,7 @@ static void
post_test_transfers (struct TestTransfers_Closure *cls)
{
free_instance_data (&cls->instance);
-
- json_decref (cls->order.contract);
+ free_order_data (&cls->order);
}
@@ -2477,80 +2521,77 @@ run_test_transfers (struct TestTransfers_Closure *cls)
.wtid = wtid
};
+ /* Test lookup wire fee fails when it isn't in the db */
+ TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS ==
+ plugin->lookup_wire_fee (plugin->cls,
+ &cls->signkey.master_pub,
+ cls->wire_fee.wire_method,
+ GNUNET_TIME_absolute_get (),
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL),
+ "Lookup wire fee failed\n");
/* Test store wire fee by exchange */
- if (1 != plugin->store_wire_fee_by_exchange (plugin->cls,
- &cls->signkey.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_RET_ON_FAIL (test_insert_wire_fee (&cls->signkey,
+ &cls->wire_fee,
+ GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
+ /* Test double insertion fails */
+ TEST_RET_ON_FAIL (test_insert_wire_fee (&cls->signkey,
+ &cls->wire_fee,
+ GNUNET_DB_STATUS_SUCCESS_NO_RESULTS));
/* Test lookup wire fee by exchange */
- TEST_RET_ON_FAIL (test_lookup_wire_fee (&cls->signkey.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));
-
+ TEST_RET_ON_FAIL (test_lookup_wire_fee (&cls->signkey,
+ &cls->wire_fee));
/* Insert the instance */
TEST_RET_ON_FAIL (test_insert_instance (&cls->instance,
GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
-
/* Insert the account */
TEST_RET_ON_FAIL (test_insert_account (&cls->instance,
&cls->account,
GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
-
/* Insert a signing key */
TEST_RET_ON_FAIL (test_insert_exchange_signkey (&cls->signkey,
GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
-
/* Insert an order */
TEST_RET_ON_FAIL (test_insert_order (&cls->instance,
&cls->order,
GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
-
/* Insert contract terms */
TEST_RET_ON_FAIL (test_insert_contract_terms (&cls->instance,
&cls->order,
GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
-
/* Insert the deposit */
- TEST_RET_ON_FAIL (test_insert_deposit (cls->instance.instance.id,
- &cls->signkey.exchange_pub,
- &cls->deposit));
+ TEST_RET_ON_FAIL (test_insert_deposit (&cls->instance,
+ &cls->signkey,
+ &cls->deposit,
+ GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
transfer_data.details_length = 1;
transfer_data.details = &transfer_detail;
-
/* Insert the transfer */
GNUNET_assert (GNUNET_OK ==
TALER_string_to_amount ("EUR:50.00",
&amount));
- if (1 != plugin->insert_transfer (plugin->cls,
- cls->instance.instance.id,
- exchange_url,
- &wtid,
- &amount,
- cls->account.payto_uri,
- false))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Insert transfer failed\n");
- return 1;
- }
-
+ TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
+ plugin->insert_transfer (plugin->cls,
+ cls->instance.instance.id,
+ exchange_url,
+ &wtid,
+ &amount,
+ cls->account.payto_uri,
+ false),
+ "Insert transfer failed\n");
+ /* Test that double insert fails */
+ TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS ==
+ plugin->insert_transfer (plugin->cls,
+ cls->instance.instance.id,
+ exchange_url,
+ &wtid,
+ &amount,
+ cls->account.payto_uri,
+ false),
+ "Insert transfer failed\n");
/* Test transfer details */
GNUNET_assert (GNUNET_OK ==
TALER_string_to_amount ("EUR:50.00",
@@ -2558,21 +2599,15 @@ run_test_transfers (struct TestTransfers_Closure *cls)
GNUNET_assert (GNUNET_OK ==
TALER_string_to_amount ("EUR:0.49",
&transfer_data.wire_fee));
- if (1 != plugin->insert_transfer_details (plugin->cls,
- cls->instance.instance.id,
- "exch-url",
- cls->account.payto_uri,
- &wtid,
- &transfer_data))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Insert transfer details failed\n");
- return 1;
- }
-
- /* Test lookup wire fee */
-
-
+ TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
+ plugin->insert_transfer_details (plugin->cls,
+ cls->instance.instance
+ .id,
+ "exch-url",
+ cls->account.payto_uri,
+ &wtid,
+ &transfer_data),
+ "Insert transfer details failed\n");
/* Test lookup transfer */
GNUNET_assert (0 <= TALER_amount_add (&total_with_fee,
&transfer_data.total_amount,
@@ -2583,36 +2618,29 @@ run_test_transfers (struct TestTransfers_Closure *cls)
&transfer_data.wire_fee,
&transfer_data.execution_time,
false));
-
/* Test set status to verified */
- if (1 != plugin->set_transfer_status_to_verified (plugin->cls,
- exchange_url,
- &wtid))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Set transfer to verified failed\n");
- return 1;
- }
+ TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
+ plugin->set_transfer_status_to_verified (plugin->cls,
+ exchange_url,
+ &wtid),
+ "Set transfer status to verified failed\n");
TEST_RET_ON_FAIL (test_lookup_transfer (exchange_url,
&wtid,
&total_with_fee,
&transfer_data.wire_fee,
&transfer_data.execution_time,
true));
-
/* Test lookup transfer summary */
TEST_RET_ON_FAIL (test_lookup_transfer_summary (exchange_url,
&wtid,
cls->order.id,
&cls->deposit.amount_with_fee,
&cls->deposit.deposit_fee));
-
/* Test lookup transfer details */
TEST_RET_ON_FAIL (test_lookup_transfer_details (exchange_url,
&wtid,
1,
&transfer_detail));
-
/* Test lookup transfers */
full_transfer_data.details = transfer_data;
TEST_RET_ON_FAIL (test_lookup_transfers (cls->instance.instance.id,
@@ -2640,6 +2668,9 @@ test_transfers (void *cls)
}
+/* Reserves and tips */
+
+
struct ReserveData
{
/**
@@ -2669,6 +2700,24 @@ struct ReserveData
};
+static int
+test_insert_reserve (const struct InstanceData *instance,
+ const struct ReserveData *reserve,
+ enum GNUNET_DB_QueryStatus expected_result)
+{
+ TEST_COND_RET_ON_FAIL (expected_result ==
+ plugin->insert_reserve (plugin->cls,
+ instance->instance.id,
+ &reserve->reserve_priv,
+ &reserve->reserve_pub,
+ reserve->exchange_url,
+ &reserve->initial_amount,
+ reserve->expiration),
+ "Insert reserve failed\n");
+ return 0;
+}
+
+
struct TestLookupReserve_Closure
{
const struct ReserveData *reserve_to_cmp;
@@ -3119,6 +3168,8 @@ struct TestTips_Closure
struct GNUNET_CRYPTO_RsaPrivateKey *pickup_priv;
struct GNUNET_CRYPTO_RsaSignature *pickup_sig;
+ struct TALER_Amount tip_2_amount;
+ struct GNUNET_HashCode tip_2_id;
};
@@ -3152,6 +3203,12 @@ pre_test_tips (struct TestTips_Closure *cls)
cls->pickup_priv = GNUNET_CRYPTO_rsa_private_key_create (2048);
cls->pickup_sig = GNUNET_CRYPTO_rsa_sign_fdh (cls->pickup_priv,
&cls->pickup_id);
+
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount ("EUR:99.90",
+ &cls->tip_2_amount));
+ GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG,
+ &cls->tip_2_id);
}
@@ -3173,52 +3230,32 @@ run_test_tips (struct TestTips_Closure *cls)
TEST_RET_ON_FAIL (test_insert_instance (&cls->instance,
GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
-
/* Test insert reserve */
- if (TALER_EC_NONE != plugin->insert_reserve (plugin->cls,
- cls->instance.instance.id,
- &cls->reserve.reserve_priv,
- &cls->reserve.reserve_pub,
- cls->reserve.exchange_url,
- &cls->reserve.initial_amount,
- cls->reserve.expiration))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Insert reserve failed\n");
- return 1;
- }
-
+ TEST_RET_ON_FAIL (test_insert_reserve (&cls->instance,
+ &cls->reserve,
+ TALER_EC_NONE));
/* Test lookup reserve */
TEST_RET_ON_FAIL (test_lookup_reserve (cls->instance.instance.id,
&cls->reserve.reserve_pub,
&cls->reserve));
-
/* Test reserve activation */
- if (1 != plugin->activate_reserve (plugin->cls,
- cls->instance.instance.id,
- &cls->reserve.reserve_pub,
- &cls->reserve.initial_amount))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Active reserve failed\n");
- return 1;
- }
-
+ TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
+ plugin->activate_reserve (plugin->cls,
+ cls->instance.instance.id,
+ &cls->reserve.reserve_pub,
+ &cls->reserve.initial_amount),
+ "Activate reserve failed\n");
/* Test inserting a tip */
- if (TALER_EC_NONE != plugin->authorize_tip (plugin->cls,
- cls->instance.instance.id,
- &cls->reserve.reserve_pub,
- &cls->tip_amount,
- "because",
- "https://taler.net",
- &cls->tip_id,
- &cls->reserve.expiration))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Authorize tip failed\n");
- return 1;
- }
-
+ TEST_COND_RET_ON_FAIL (TALER_EC_NONE ==
+ plugin->authorize_tip (plugin->cls,
+ cls->instance.instance.id,
+ &cls->reserve.reserve_pub,
+ &cls->tip_amount,
+ "because",
+ "https://taler.net",
+ &cls->tip_id,
+ &cls->reserve.expiration),
+ "Authorize tip failed\n");
/* Test lookup tip */
TEST_RET_ON_FAIL (test_lookup_tip (cls->instance.instance.id,
&cls->tip_id,
@@ -3227,7 +3264,6 @@ run_test_tips (struct TestTips_Closure *cls)
&cls->reserve.expiration,
cls->reserve.exchange_url,
&cls->reserve.reserve_priv));
-
/* Test lookup tip details */
TEST_RET_ON_FAIL (test_lookup_tip_details (cls->instance.instance.id,
cls->tip_id,
@@ -3238,20 +3274,15 @@ run_test_tips (struct TestTips_Closure *cls)
&cls->reserve.reserve_pub,
0,
NULL));
-
/* Test insert pickup */
- if (1 != plugin->insert_pickup (plugin->cls,
- cls->instance.instance.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_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
+ plugin->insert_pickup (plugin->cls,
+ cls->instance.instance.id,
+ &cls->tip_id,
+ &cls->tip_amount,
+ &cls->pickup_id,
+ &cls->tip_amount),
+ "Insert pickup failed\n");
/* Test lookup pickup */
TEST_RET_ON_FAIL (test_lookup_pickup (cls->instance.instance.id,
&cls->tip_id,
@@ -3260,42 +3291,50 @@ run_test_tips (struct TestTips_Closure *cls)
&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_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
+ plugin->insert_pickup_blind_signature (plugin->cls,
+ &cls->pickup_id,
+ 0,
+ cls->pickup_sig),
+ "Insert pickup blind signature failed\n");
+ /* Test that overdrawing the reserve fails */
+ TEST_COND_RET_ON_FAIL (TALER_EC_NONE !=
+ plugin->authorize_tip (plugin->cls,
+ cls->instance.instance.id,
+ &cls->reserve.reserve_pub,
+ &cls->tip_2_amount,
+ "because",
+ "https://taler.net",
+ &cls->tip_2_id,
+ &cls->reserve.expiration),
+ "Authorize tip failed\n");
/* Test lookup reserves */
TEST_RET_ON_FAIL (test_lookup_reserves (cls->instance.instance.id,
1,
&cls->reserve));
-
/* Test delete reserve private key */
- if (1 != plugin->delete_reserve (plugin->cls,
- cls->instance.instance.id,
- &cls->reserve.reserve_pub))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Delete reserve private key failed\n");
- return 1;
- }
-
+ TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
+ plugin->delete_reserve (plugin->cls,
+ cls->instance.instance.id,
+ &cls->reserve.reserve_pub),
+ "Delete reserve private key failed\n");
+ TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS ==
+ plugin->delete_reserve (plugin->cls,
+ cls->instance.instance.id,
+ &cls->reserve.reserve_pub),
+ "Delete reserve private key failed\n");
/* Test purging a reserve */
- if (1 != plugin->purge_reserve (plugin->cls,
- cls->instance.instance.id,
- &cls->reserve.reserve_pub))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Purge reserve failed\n");
- return 1;
- }
+ TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
+ plugin->purge_reserve (plugin->cls,
+ cls->instance.instance.id,
+ &cls->reserve.reserve_pub),
+ "Purge reserve failed\n");
+ TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS ==
+ plugin->purge_reserve (plugin->cls,
+ cls->instance.instance.id,
+ &cls->reserve.reserve_pub),
+ "Purge reserve failed\n");
return 0;
}
@@ -3645,103 +3684,110 @@ post_test_refunds (struct TestRefunds_Closure *cls)
static int
run_test_refunds (struct TestRefunds_Closure *cls)
{
+ struct TALER_Amount inc;
+
/* Insert an instance */
TEST_RET_ON_FAIL (test_insert_instance (&cls->instance,
GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
-
/* Insert an account */
TEST_RET_ON_FAIL (test_insert_account (&cls->instance,
&cls->account,
GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
-
/* Insert an order */
TEST_RET_ON_FAIL (test_insert_order (&cls->instance,
&cls->order,
GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
-
/* Insert contract terms */
TEST_RET_ON_FAIL (test_insert_contract_terms (&cls->instance,
&cls->order,
GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
-
/* Insert a signing key */
TEST_RET_ON_FAIL (test_insert_exchange_signkey (&cls->signkey,
GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
-
/* Insert a deposit */
- TEST_RET_ON_FAIL (test_insert_deposit (cls->instance.instance.id,
- &cls->signkey.exchange_pub,
- &cls->deposits[0]));
- TEST_RET_ON_FAIL (test_insert_deposit (cls->instance.instance.id,
- &cls->signkey.exchange_pub,
- &cls->deposits[1]));
-
+ TEST_RET_ON_FAIL (test_insert_deposit (&cls->instance,
+ &cls->signkey,
+ &cls->deposits[0],
+ GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
+ TEST_RET_ON_FAIL (test_insert_deposit (&cls->instance,
+ &cls->signkey,
+ &cls->deposits[1],
+ GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
/* Mark as paid */
- if (1 != plugin->mark_contract_paid (plugin->cls,
- cls->instance.instance.id,
- &cls->deposits[0].h_contract_terms,
- "test_orders_session"))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Mark contract as paid failed\n");
- return 1;
- }
-
+ TEST_RET_ON_FAIL (test_mark_contract_paid (&cls->instance,
+ &cls->order,
+ GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
/* Test refund coin */
- if (1 != plugin->refund_coin (plugin->cls,
- cls->instance.instance.id,
- &cls->deposits[0].h_contract_terms,
- cls->refund.timestamp,
- cls->refund.coin_pub,
- cls->refund.reason))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Refund coin failed\n");
- return 1;
- }
-
+ TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
+ plugin->refund_coin (plugin->cls,
+ cls->instance.instance.id,
+ &cls->deposits[0].h_contract_terms,
+ cls->refund.timestamp,
+ cls->refund.coin_pub,
+ cls->refund.reason),
+ "Refund coin failed\n");
+ /* Test double refund fails */
+ TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS ==
+ plugin->refund_coin (plugin->cls,
+ cls->instance.instance.id,
+ &cls->deposits[0].h_contract_terms,
+ cls->refund.timestamp,
+ cls->refund.coin_pub,
+ cls->refund.reason),
+ "Refund coin failed\n");
/* Test lookup refunds */
TEST_RET_ON_FAIL (test_lookup_refunds (cls->instance.instance.id,
&cls->deposits[0].h_contract_terms,
1,
cls->refund.coin_pub,
&cls->refund.refund_amount));
-
/* Test lookup refunds detailed */
TEST_RET_ON_FAIL (test_lookup_refunds_detailed (cls->instance.instance.id,
&cls->deposits[0].
h_contract_terms,
1,
&cls->refund));
-
/* Test insert refund proof */
- if (1 != plugin->insert_refund_proof (plugin->cls,
- 1, // TODO: get this from lookup
- &cls->refund_proof.refund_fee,
- &cls->refund_proof.exchange_sig,
- &cls->signkey.exchange_pub))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Insert refund proof failed\n");
- return 1;
- }
-
+ TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
+ plugin->insert_refund_proof (plugin->cls,
+ 1, // TODO: get this from lookup
+ &cls->refund_proof.
+ refund_fee,
+ &cls->refund_proof.
+ exchange_sig,
+ &cls->signkey.exchange_pub),
+ "Insert refund proof failed\n");
+ TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS ==
+ plugin->insert_refund_proof (plugin->cls,
+ 1, // TODO: get this from lookup
+ &cls->refund_proof.
+ refund_fee,
+ &cls->refund_proof.
+ exchange_sig,
+ &cls->signkey.exchange_pub),
+ "Insert refund proof failed\n");
+ /* Test that we can't give too much in refunds */
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount ("EUR:1000.00",
+ &inc));
+ TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ plugin->increase_refund (plugin->cls,
+ cls->instance.instance.id,
+ cls->order.id,
+ &inc,
+ "more"),
+ "Increase refund failed\n");
/* Test increase refund */
- struct TALER_Amount inc;
GNUNET_assert (GNUNET_OK ==
TALER_string_to_amount ("EUR:1.00",
&inc));
- if (1 != plugin->increase_refund (plugin->cls,
- cls->instance.instance.id,
- cls->order.id,
- &inc,
- "more"))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Increase refund failed\n");
- return 1;
- }
-
+ TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
+ plugin->increase_refund (plugin->cls,
+ cls->instance.instance.id,
+ cls->order.id,
+ &inc,
+ "more"),
+ "Increase refund failed\n");
/* Test lookup refund proof */
TEST_RET_ON_FAIL (test_lookup_refund_proof (1,
&cls->refund_proof.exchange_sig,
@@ -3766,6 +3812,22 @@ test_refunds (void *cls)
* Convenience function for testing lookup orders with filters
*/
static void
+order_data_subarray (unsigned int indices_length,
+ const unsigned int *indices,
+ struct OrderData *dst,
+ const struct OrderData *src)
+{
+ for (unsigned int i = 0; i < indices_length; ++i)
+ {
+ dst[i] = src[indices[i]];
+ }
+}
+
+
+/**
+ * Convenience function for testing lookup orders with filters
+ */
+static void
reverse_order_data_array (unsigned int orders_length,
struct OrderData *orders)
{
@@ -3876,12 +3938,14 @@ run_test_lookup_orders_all_filters (struct
TEST_RET_ON_FAIL (test_mark_contract_paid (&cls->instance,
&cls->orders[i],
GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
- /* Refund every fouth order */
- if (0 == i % 4)
+ /* Refund every fouth order and a couple unpaid orders */
+ if ((0 == i % 4) ||
+ (i < 2))
{
- TEST_RET_ON_FAIL (test_insert_deposit (cls->instance.instance.id,
- &cls->signkey.exchange_pub,
- &cls->deposits[i]));
+ TEST_RET_ON_FAIL (test_insert_deposit (&cls->instance,
+ &cls->signkey,
+ &cls->deposits[i],
+ GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
TEST_COND_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
plugin->refund_coin (plugin->cls,
cls->instance.instance.id,
@@ -3926,21 +3990,50 @@ run_test_lookup_orders_all_filters (struct
/* lookup_orders_inc_refunded */
filter_inc.paid = TALER_MERCHANTDB_YNA_ALL;
filter_inc.refunded = TALER_MERCHANTDB_YNA_YES;
- for (unsigned int i = 0; i < 4; ++i)
- expected_orders[i] = cls->orders[4 * i];
+ unsigned int indices[] = {
+ 0, 1, 4, 8, 12
+ };
+ order_data_subarray (5,
+ indices,
+ expected_orders,
+ cls->orders);
TEST_RET_ON_FAIL (test_lookup_orders (&cls->instance,
&filter_inc,
- 4,
+ 5,
expected_orders));
/* lookup_orders_dec_refunded */
filter_dec.paid = TALER_MERCHANTDB_YNA_ALL;
filter_dec.refunded = TALER_MERCHANTDB_YNA_YES;
+ reverse_order_data_array (5,
+ expected_orders);
+ TEST_RET_ON_FAIL (test_lookup_orders (&cls->instance,
+ &filter_dec,
+ 5,
+ expected_orders));
+ /* lookup_orders_inc_wired */
+ /* lookup_orders_dec_wired */
+ /* lookup_orders_inc_paid_refunded */
+ filter_inc.paid = TALER_MERCHANTDB_YNA_YES;
+ for (unsigned int i = 0; i < 4; ++i)
+ expected_orders[i] = cls->orders[4 * i];
+ TEST_RET_ON_FAIL (test_lookup_orders (&cls->instance,
+ &filter_inc,
+ 4,
+ expected_orders));
+ /* lookup_orders_dec_paid_refunded */
+ filter_dec.paid = TALER_MERCHANTDB_YNA_YES;
reverse_order_data_array (4,
expected_orders);
TEST_RET_ON_FAIL (test_lookup_orders (&cls->instance,
&filter_dec,
4,
expected_orders));
+ /* lookup_orders_inc_paid_wired */
+ /* lookup_orders_dec_paid_wired */
+ /* lookup_orders_inc_refunded_wired */
+ /* lookup_orders_dec_refunded_wired */
+ /* lookup_orders_inc_paid_refunded_wired */
+ /* lookup_orders_dec_paid_refunded_wired */
return 0;
}