summaryrefslogtreecommitdiff
path: root/src/testing/testing_api_cmd_refund.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/testing_api_cmd_refund.c')
-rw-r--r--src/testing/testing_api_cmd_refund.c167
1 files changed, 117 insertions, 50 deletions
diff --git a/src/testing/testing_api_cmd_refund.c b/src/testing/testing_api_cmd_refund.c
index c288e9e15..29b68ef08 100644
--- a/src/testing/testing_api_cmd_refund.c
+++ b/src/testing/testing_api_cmd_refund.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2020 Taler Systems SA
+ Copyright (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as
@@ -54,9 +54,14 @@ struct RefundState
uint64_t refund_transaction_id;
/**
- * Connection to the exchange.
+ * Entry in the coin's history generated by this operation.
*/
- struct TALER_EXCHANGE_Handle *exchange;
+ struct TALER_EXCHANGE_CoinHistoryEntry che;
+
+ /**
+ * Public key of the refunded coin.
+ */
+ struct TALER_CoinSpendPublicKeyP coin;
/**
* Handle to the refund operation.
@@ -75,38 +80,51 @@ struct RefundState
* response code is acceptable.
*
* @param cls closure
- * @param hr HTTP response details
- * @param exchange_pub public key the exchange
- * used for signing @a obj.
- * @param exchange_sig actual signature confirming the refund
+ * @param rr response details
*/
static void
refund_cb (void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr,
- const struct TALER_ExchangePublicKeyP *exchange_pub,
- const struct TALER_ExchangeSignatureP *exchange_sig)
+ const struct TALER_EXCHANGE_RefundResponse *rr)
{
-
struct RefundState *rs = cls;
- struct TALER_TESTING_Command *refund_cmd;
+ const struct TALER_EXCHANGE_HttpResponse *hr = &rr->hr;
- refund_cmd = &rs->is->commands[rs->is->ip];
rs->rh = NULL;
if (rs->expected_response_code != hr->http_status)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u/%d to command %s in %s:%u\n",
- hr->http_status,
- hr->ec,
- refund_cmd->label,
- __FILE__,
- __LINE__);
- json_dumpf (hr->reply,
- stderr,
- 0);
- TALER_TESTING_interpreter_fail (rs->is);
+ TALER_TESTING_unexpected_status (rs->is,
+ hr->http_status,
+ rs->expected_response_code);
return;
}
+ if (MHD_HTTP_OK == hr->http_status)
+ {
+ struct TALER_Amount refund_amount;
+
+ if (GNUNET_OK !=
+ TALER_string_to_amount (rs->refund_amount,
+ &refund_amount))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to parse amount `%s'\n",
+ rs->refund_amount);
+ TALER_TESTING_interpreter_fail (rs->is);
+ return;
+ }
+ if (0 >
+ TALER_amount_subtract (&rs->che.amount,
+ &refund_amount,
+ &rs->che.details.refund.refund_fee))
+ {
+ GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to subtract %s from %s\n",
+ TALER_amount2s (&rs->che.details.refund.refund_fee),
+ rs->refund_amount);
+ TALER_TESTING_interpreter_fail (rs->is);
+ return;
+ }
+ }
TALER_TESTING_interpreter_next (rs->is);
}
@@ -125,24 +143,21 @@ refund_run (void *cls,
{
struct RefundState *rs = cls;
const struct TALER_CoinSpendPrivateKeyP *coin_priv;
- struct TALER_CoinSpendPublicKeyP coin;
const json_t *contract_terms;
- struct TALER_PrivateContractHash h_contract_terms;
+ struct TALER_PrivateContractHashP h_contract_terms;
struct TALER_Amount refund_amount;
const struct TALER_MerchantPrivateKeyP *merchant_priv;
const struct TALER_TESTING_Command *coin_cmd;
+ const struct TALER_EXCHANGE_DenomPublicKey *denom_pub;
- rs->exchange = is->exchange;
rs->is = is;
-
if (GNUNET_OK !=
TALER_string_to_amount (rs->refund_amount,
&refund_amount))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to parse amount `%s' at %u/%s\n",
+ "Failed to parse amount `%s' at %s\n",
rs->refund_amount,
- is->ip,
cmd->label);
TALER_TESTING_interpreter_fail (is);
return;
@@ -168,10 +183,15 @@ refund_run (void *cls,
&h_contract_terms));
/* Hunting for a coin .. */
- if (GNUNET_OK !=
- TALER_TESTING_get_trait_coin_priv (coin_cmd,
- 0,
- &coin_priv))
+ if ( (GNUNET_OK !=
+ TALER_TESTING_get_trait_coin_priv (coin_cmd,
+ 0,
+ &coin_priv)) ||
+ (GNUNET_OK !=
+ TALER_TESTING_get_trait_denom_pub (coin_cmd,
+ 0,
+ &denom_pub)) )
+
{
GNUNET_break (0);
TALER_TESTING_interpreter_fail (is);
@@ -179,7 +199,7 @@ refund_run (void *cls,
}
GNUNET_CRYPTO_eddsa_key_get_public (&coin_priv->eddsa_priv,
- &coin.eddsa_pub);
+ &rs->coin.eddsa_pub);
if (GNUNET_OK !=
TALER_TESTING_get_trait_merchant_priv (coin_cmd,
&merchant_priv))
@@ -188,19 +208,67 @@ refund_run (void *cls,
TALER_TESTING_interpreter_fail (is);
return;
}
- rs->rh = TALER_EXCHANGE_refund (rs->exchange,
- &refund_amount,
- &h_contract_terms,
- &coin,
- rs->refund_transaction_id,
- merchant_priv,
- &refund_cb,
- rs);
+ rs->che.type = TALER_EXCHANGE_CTT_REFUND;
+ rs->che.details.refund.h_contract_terms = h_contract_terms;
+ GNUNET_CRYPTO_eddsa_key_get_public (
+ &merchant_priv->eddsa_priv,
+ &rs->che.details.refund.merchant_pub.eddsa_pub);
+ rs->che.details.refund.refund_fee = denom_pub->fees.refund;
+ rs->che.details.refund.sig_amount = refund_amount;
+ rs->che.details.refund.rtransaction_id = rs->refund_transaction_id;
+ TALER_merchant_refund_sign (&rs->coin,
+ &h_contract_terms,
+ rs->refund_transaction_id,
+ &refund_amount,
+ merchant_priv,
+ &rs->che.details.refund.sig);
+ rs->rh = TALER_EXCHANGE_refund (
+ TALER_TESTING_interpreter_get_context (is),
+ TALER_TESTING_get_exchange_url (is),
+ TALER_TESTING_get_keys (is),
+ &refund_amount,
+ &h_contract_terms,
+ &rs->coin,
+ rs->refund_transaction_id,
+ merchant_priv,
+ &refund_cb,
+ rs);
GNUNET_assert (NULL != rs->rh);
}
/**
+ * Offer internal data from a "refund" CMD, to other commands.
+ *
+ * @param cls closure.
+ * @param[out] ret result.
+ * @param trait name of the trait.
+ * @param index index number of the object to offer.
+ * @return #GNUNET_OK on success.
+ */
+static enum GNUNET_GenericReturnValue
+refund_traits (void *cls,
+ const void **ret,
+ const char *trait,
+ unsigned int index)
+{
+ struct RefundState *rs = cls;
+ struct TALER_TESTING_Trait traits[] = {
+ TALER_TESTING_make_trait_coin_history (0,
+ &rs->che),
+ TALER_TESTING_make_trait_coin_pub (0,
+ &rs->coin),
+ TALER_TESTING_trait_end ()
+ };
+
+ return TALER_TESTING_get_trait (traits,
+ ret,
+ trait,
+ index);
+}
+
+
+/**
* Free the state from a "refund" CMD, and possibly cancel
* a pending operation thereof.
*
@@ -215,10 +283,8 @@ refund_cleanup (void *cls,
if (NULL != rs->rh)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Command %u (%s) did not complete\n",
- rs->is->ip,
- cmd->label);
+ TALER_TESTING_command_incomplete (rs->is,
+ cmd->label);
TALER_EXCHANGE_refund_cancel (rs->rh);
rs->rh = NULL;
}
@@ -235,7 +301,6 @@ TALER_TESTING_cmd_refund (const char *label,
struct RefundState *rs;
rs = GNUNET_new (struct RefundState);
-
rs->expected_response_code = expected_response_code;
rs->refund_amount = refund_amount;
rs->coin_reference = coin_reference;
@@ -244,7 +309,8 @@ TALER_TESTING_cmd_refund (const char *label,
.cls = rs,
.label = label,
.run = &refund_run,
- .cleanup = &refund_cleanup
+ .cleanup = &refund_cleanup,
+ .traits = &refund_traits
};
return cmd;
@@ -272,7 +338,8 @@ TALER_TESTING_cmd_refund_with_id (
.cls = rs,
.label = label,
.run = &refund_run,
- .cleanup = &refund_cleanup
+ .cleanup = &refund_cleanup,
+ .traits = &refund_traits
};
return cmd;