aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2020-03-27 20:47:30 +0530
committerFlorian Dold <florian.dold@gmail.com>2020-03-27 20:47:30 +0530
commite267cb985bd5b7bc16b14fd6d19c338c8dfe52c5 (patch)
tree3200bdf83a24b3e3aed06478a4139f56c5e5351b
parent1a15cd29e87f27a29c69f385725baf33022a6e60 (diff)
cover actual aggregation in exchange test
-rw-r--r--src/include/taler_testing_lib.h34
-rw-r--r--src/testing/test_exchange_api.c49
-rw-r--r--src/testing/testing_api_cmd_deposit.c119
3 files changed, 202 insertions, 0 deletions
diff --git a/src/include/taler_testing_lib.h b/src/include/taler_testing_lib.h
index c3a3cea11..9e473f756 100644
--- a/src/include/taler_testing_lib.h
+++ b/src/include/taler_testing_lib.h
@@ -1319,6 +1319,40 @@ TALER_TESTING_cmd_deposit (const char *label,
const char *amount,
unsigned int expected_response_code);
+/**
+ * Create a "deposit" command that references an existing merchant key.
+ *
+ * @param label command label.
+ * @param coin_reference reference to any operation that can
+ * provide a coin.
+ * @param coin_index if @a withdraw_reference offers an array of
+ * coins, this parameter selects which one in that array.
+ * This value is currently ignored, as only one-coin
+ * withdrawals are implemented.
+ * @param target_account_payto target account for the "deposit"
+ * request.
+ * @param contract_terms contract terms to be signed over by the
+ * coin.
+ * @param refund_deadline refund deadline, zero means 'no refunds'.
+ * Note, if time were absolute, then it would have come
+ * one day and disrupt tests meaning.
+ * @param amount how much is going to be deposited.
+ * @param expected_response_code expected HTTP response code.
+ * @param merchant_priv_reference reference to another operation
+ * that has a merchant private key trait
+ *
+ * @return the command.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_deposit_with_ref (const char *label,
+ const char *coin_reference,
+ unsigned int coin_index,
+ const char *target_account_payto,
+ const char *contract_terms,
+ struct GNUNET_TIME_Relative refund_deadline,
+ const char *amount,
+ unsigned int expected_response_code,
+ const char *merchant_priv_reference);
/**
* Modify a deposit command to enable retries when we get transient
diff --git a/src/testing/test_exchange_api.c b/src/testing/test_exchange_api.c
index 5162e1ddb..7832e7366 100644
--- a/src/testing/test_exchange_api.c
+++ b/src/testing/test_exchange_api.c
@@ -436,6 +436,53 @@ run (void *cls,
TALER_TESTING_cmd_end ()
};
+
+ /**
+ * This block exercises the aggretation logic by making two payments
+ * to the same merchant.
+ */
+ struct TALER_TESTING_Command aggregation[] = {
+ CMD_TRANSFER_TO_EXCHANGE ("create-reserve-aggtest",
+ "EUR:5.01"),
+ /* "consume" reserve creation transfer. */
+ TALER_TESTING_cmd_check_bank_admin_transfer (
+ "check-create-reserve-aggtest",
+ "EUR:5.01",
+ bc.user42_payto,
+ bc.exchange_payto,
+ "create-reserve-aggtest"),
+ CMD_EXEC_WIREWATCH ("wirewatch-aggtest"),
+ TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-aggtest",
+ "create-reserve-aggtest",
+ "EUR:5",
+ MHD_HTTP_OK),
+ TALER_TESTING_cmd_deposit ("deposit-aggtest-1",
+ "withdraw-coin-aggtest",
+ 0,
+ bc.user43_payto,
+ "{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}",
+ GNUNET_TIME_UNIT_ZERO,
+ "EUR:2",
+ MHD_HTTP_OK),
+ TALER_TESTING_cmd_deposit_with_ref ("deposit-aggtest-2",
+ "withdraw-coin-aggtest",
+ 0,
+ bc.user43_payto,
+ "{\"items\":[{\"name\":\"foo bar\",\"value\":1}]}",
+ GNUNET_TIME_UNIT_ZERO,
+ "EUR:2",
+ MHD_HTTP_OK,
+ "deposit-aggtest-1"),
+ CMD_EXEC_AGGREGATOR ("aggregation-aggtest"),
+ TALER_TESTING_cmd_check_bank_transfer ("check-bank-transfer-aggtest",
+ ec.exchange_url,
+ "EUR:3.97",
+ bc.exchange_payto,
+ bc.user43_payto),
+ TALER_TESTING_cmd_check_bank_empty ("check-bank-empty-aggtest"),
+ TALER_TESTING_cmd_end ()
+ };
+
struct TALER_TESTING_Command refund[] = {
/**
* Fill reserve with EUR:5.01, as withdraw fee is 1 ct per
@@ -786,6 +833,8 @@ run (void *cls,
track),
TALER_TESTING_cmd_batch ("unaggregation",
unaggregation),
+ TALER_TESTING_cmd_batch ("aggregation",
+ aggregation),
TALER_TESTING_cmd_batch ("refund",
refund),
TALER_TESTING_cmd_batch ("recoup",
diff --git a/src/testing/testing_api_cmd_deposit.c b/src/testing/testing_api_cmd_deposit.c
index ba4dc3075..4f3a385d5 100644
--- a/src/testing/testing_api_cmd_deposit.c
+++ b/src/testing/testing_api_cmd_deposit.c
@@ -151,6 +151,12 @@ struct DepositState
* this will only be set after the command has been started.
*/
int command_initialized;
+
+ /**
+ * Reference to fetch the merchant private key from.
+ * If NULL, we generate our own, fresh merchant key.
+ */
+ const char *merchant_priv_reference;
};
@@ -307,6 +313,31 @@ deposit_run (void *cls,
ds->merchant_priv = ods->merchant_priv;
ds->command_initialized = GNUNET_YES;
}
+ else if (NULL != ds->merchant_priv_reference)
+ {
+ // We're copying the merchant key from another deposit operation
+ const struct TALER_MerchantPrivateKeyP *merchant_priv;
+ const struct TALER_TESTING_Command *cmd;
+ cmd = TALER_TESTING_interpreter_lookup_command
+ (is,
+ ds->merchant_priv_reference);
+ if (NULL == cmd)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ if ( (GNUNET_OK !=
+ TALER_TESTING_get_trait_merchant_priv (cmd,
+ 0,
+ &merchant_priv)) )
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ ds->merchant_priv = *merchant_priv;
+ }
GNUNET_assert (ds->coin_reference);
coin_cmd = TALER_TESTING_interpreter_lookup_command
(is,
@@ -609,6 +640,94 @@ TALER_TESTING_cmd_deposit (const char *label,
/**
+ * Create a "deposit" command that references an existing merchant key.
+ *
+ * @param label command label.
+ * @param coin_reference reference to any operation that can
+ * provide a coin.
+ * @param coin_index if @a withdraw_reference offers an array of
+ * coins, this parameter selects which one in that array.
+ * This value is currently ignored, as only one-coin
+ * withdrawals are implemented.
+ * @param target_account_payto target account for the "deposit"
+ * request.
+ * @param contract_terms contract terms to be signed over by the
+ * coin.
+ * @param refund_deadline refund deadline, zero means 'no refunds'.
+ * Note, if time were absolute, then it would have come
+ * one day and disrupt tests meaning.
+ * @param amount how much is going to be deposited.
+ * @param expected_response_code expected HTTP response code.
+ * @param merchant_priv_reference reference to another operation
+ * that has a merchant private key trait
+ *
+ * @return the command.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_deposit_with_ref (const char *label,
+ const char *coin_reference,
+ unsigned int coin_index,
+ const char *target_account_payto,
+ const char *contract_terms,
+ struct GNUNET_TIME_Relative refund_deadline,
+ const char *amount,
+ unsigned int expected_response_code,
+ const char *merchant_priv_reference)
+{
+ struct DepositState *ds;
+ json_t *wire_details;
+
+ wire_details = TALER_TESTING_make_wire_details (target_account_payto);
+ ds = GNUNET_new (struct DepositState);
+ ds->merchant_priv_reference = merchant_priv_reference;
+ ds->coin_reference = coin_reference;
+ ds->coin_index = coin_index;
+ ds->wire_details = wire_details;
+ ds->contract_terms = json_loads (contract_terms,
+ JSON_REJECT_DUPLICATES,
+ NULL);
+ if (NULL == ds->contract_terms)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to parse contract terms `%s' for CMD `%s'\n",
+ contract_terms,
+ label);
+ GNUNET_assert (0);
+ }
+ ds->timestamp = GNUNET_TIME_absolute_get ();
+ (void) GNUNET_TIME_round_abs (&ds->timestamp);
+
+ json_object_set_new (ds->contract_terms,
+ "timestamp",
+ GNUNET_JSON_from_time_abs (ds->timestamp));
+ if (0 != refund_deadline.rel_value_us)
+ {
+ ds->refund_deadline = GNUNET_TIME_relative_to_absolute (refund_deadline);
+ (void) GNUNET_TIME_round_abs (&ds->refund_deadline);
+ json_object_set_new (ds->contract_terms,
+ "refund_deadline",
+ GNUNET_JSON_from_time_abs (ds->refund_deadline));
+ }
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (amount,
+ &ds->amount));
+ ds->expected_response_code = expected_response_code;
+ ds->command_initialized = GNUNET_YES;
+ {
+ struct TALER_TESTING_Command cmd = {
+ .cls = ds,
+ .label = label,
+ .run = &deposit_run,
+ .cleanup = &deposit_cleanup,
+ .traits = &deposit_traits
+ };
+
+ return cmd;
+ }
+}
+
+
+/**
* Create a "deposit" command that repeats an existing
* deposit command.
*