summaryrefslogtreecommitdiff
path: root/src/testing/testing_api_cmd_refund.c
diff options
context:
space:
mode:
authorChristian Grothoff <grothoff@gnunet.org>2023-11-09 16:07:28 +0100
committerChristian Grothoff <grothoff@gnunet.org>2023-11-09 16:07:28 +0100
commit00ef89003d1995ab4a6de23bdba23c710bdc7946 (patch)
tree03cb6f054bdf53e8218480bb2e601e980f926573 /src/testing/testing_api_cmd_refund.c
parent5ebc9d465458541f28b3673620a172a4a7fb24c2 (diff)
downloadexchange-00ef89003d1995ab4a6de23bdba23c710bdc7946.tar.gz
exchange-00ef89003d1995ab4a6de23bdba23c710bdc7946.tar.bz2
exchange-00ef89003d1995ab4a6de23bdba23c710bdc7946.zip
-add support for refund in coin history tests
Diffstat (limited to 'src/testing/testing_api_cmd_refund.c')
-rw-r--r--src/testing/testing_api_cmd_refund.c83
1 files changed, 74 insertions, 9 deletions
diff --git a/src/testing/testing_api_cmd_refund.c b/src/testing/testing_api_cmd_refund.c
index 5a218bcf4..578bee46b 100644
--- a/src/testing/testing_api_cmd_refund.c
+++ b/src/testing/testing_api_cmd_refund.c
@@ -54,6 +54,16 @@ struct RefundState
uint64_t refund_transaction_id;
/**
+ * Entry in the coin's history generated by this operation.
+ */
+ struct TALER_EXCHANGE_CoinHistoryEntry che;
+
+ /**
+ * Public key of the refunded coin.
+ */
+ struct TALER_CoinSpendPublicKeyP coin;
+
+ /**
* Handle to the refund operation.
*/
struct TALER_EXCHANGE_RefundHandle *rh;
@@ -105,12 +115,12 @@ 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_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->is = is;
if (GNUNET_OK !=
@@ -145,10 +155,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);
@@ -156,7 +171,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))
@@ -165,13 +180,30 @@ refund_run (void *cls,
TALER_TESTING_interpreter_fail (is);
return;
}
+ 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;
+ TALER_amount_subtract (&rs->che.amount,
+ &refund_amount,
+ &rs->che.details.refund.refund_fee);
+ 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,
- &coin,
+ &rs->coin,
rs->refund_transaction_id,
merchant_priv,
&refund_cb,
@@ -181,6 +213,37 @@ refund_run (void *cls,
/**
+ * 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.
*
@@ -221,7 +284,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;
@@ -249,7 +313,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;