From 00ef89003d1995ab4a6de23bdba23c710bdc7946 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 9 Nov 2023 16:07:28 +0100 Subject: -add support for refund in coin history tests --- src/testing/testing_api_cmd_batch_deposit.c | 20 ++++--- src/testing/testing_api_cmd_deposit.c | 20 ++++--- src/testing/testing_api_cmd_refund.c | 83 +++++++++++++++++++++++++---- 3 files changed, 100 insertions(+), 23 deletions(-) diff --git a/src/testing/testing_api_cmd_batch_deposit.c b/src/testing/testing_api_cmd_batch_deposit.c index 21d73bf5e..d8f8ef3b2 100644 --- a/src/testing/testing_api_cmd_batch_deposit.c +++ b/src/testing/testing_api_cmd_batch_deposit.c @@ -69,6 +69,11 @@ struct Coin */ char *coin_reference; + /** + * Denomination public key of the coin. + */ + const struct TALER_EXCHANGE_DenomPublicKey *denom_pub; + /** * The command being referenced. */ @@ -237,7 +242,6 @@ batch_deposit_run (void *cls, struct TALER_TESTING_Interpreter *is) { struct BatchDepositState *ds = cls; - const struct TALER_EXCHANGE_DenomPublicKey *denom_pub; const struct TALER_DenominationSignature *denom_pub_sig; struct TALER_MerchantPublicKeyP merchant_pub; struct TALER_PrivateContractHashP h_contract_terms; @@ -341,7 +345,7 @@ batch_deposit_run (void *cls, (GNUNET_OK != TALER_TESTING_get_trait_denom_pub (coin->coin_cmd, coin->coin_idx, - &denom_pub)) || + &coin->denom_pub)) || (GNUNET_OK != TALER_TESTING_get_trait_denom_sig (coin->coin_cmd, coin->coin_idx, @@ -356,19 +360,19 @@ batch_deposit_run (void *cls, TALER_age_commitment_hash (&age_commitment_proof->commitment, &cdd->h_age_commitment); } - coin->deposit_fee = denom_pub->fees.deposit; + coin->deposit_fee = coin->denom_pub->fees.deposit; GNUNET_CRYPTO_eddsa_key_get_public (&coin_priv->eddsa_priv, &cdd->coin_pub.eddsa_pub); cdd->denom_sig = *denom_pub_sig; - cdd->h_denom_pub = denom_pub->h_key; + cdd->h_denom_pub = coin->denom_pub->h_key; TALER_wallet_deposit_sign (&coin->amount, - &denom_pub->fees.deposit, + &coin->denom_pub->fees.deposit, &h_wire, &h_contract_terms, NULL, /* wallet_data_hash */ &cdd->h_age_commitment, NULL, /* hash of extensions */ - &denom_pub->h_key, + &coin->denom_pub->h_key, ds->wallet_timestamp, &merchant_pub, ds->refund_deadline, @@ -387,7 +391,7 @@ batch_deposit_run (void *cls, coin->che.details.deposit.sig = cdd->coin_sig; coin->che.details.deposit.no_hac = GNUNET_is_zero (&cdd->h_age_commitment); coin->che.details.deposit.hac = cdd->h_age_commitment; - coin->che.details.deposit.deposit_fee = denom_pub->fees.deposit; + coin->che.details.deposit.deposit_fee = coin->denom_pub->fees.deposit; } GNUNET_assert (NULL == ds->dh); @@ -526,6 +530,8 @@ batch_deposit_traits (void *cls, age_commitment_proof), TALER_TESTING_make_trait_coin_pub (index, &coin_spent_pub), + TALER_TESTING_make_trait_denom_pub (index, + coin->denom_pub), TALER_TESTING_make_trait_coin_priv (index, coin_spent_priv), TALER_TESTING_make_trait_coin_sig (index, diff --git a/src/testing/testing_api_cmd_deposit.c b/src/testing/testing_api_cmd_deposit.c index 41aa1c99a..849c78c70 100644 --- a/src/testing/testing_api_cmd_deposit.c +++ b/src/testing/testing_api_cmd_deposit.c @@ -105,6 +105,11 @@ struct DepositState */ struct TALER_EXCHANGE_BatchDepositHandle *dh; + /** + * Denomination public key of the deposited coin. + */ + const struct TALER_EXCHANGE_DenomPublicKey *denom_pub; + /** * Timestamp of the /deposit operation in the wallet (contract signing time). */ @@ -295,7 +300,6 @@ deposit_run (void *cls, const struct TALER_CoinSpendPrivateKeyP *coin_priv; struct TALER_CoinSpendPublicKeyP coin_pub; const struct TALER_AgeCommitmentHash *phac; - const struct TALER_EXCHANGE_DenomPublicKey *denom_pub; const struct TALER_DenominationSignature *denom_pub_sig; struct TALER_MerchantPublicKeyP merchant_pub; struct TALER_PrivateContractHashP h_contract_terms; @@ -420,7 +424,7 @@ deposit_run (void *cls, (GNUNET_OK != TALER_TESTING_get_trait_denom_pub (coin_cmd, ds->coin_index, - &denom_pub)) || + &ds->denom_pub)) || (GNUNET_OK != TALER_TESTING_get_trait_denom_sig (coin_cmd, ds->coin_index, @@ -434,7 +438,7 @@ deposit_run (void *cls, return; } - ds->deposit_fee = denom_pub->fees.deposit; + ds->deposit_fee = ds->denom_pub->fees.deposit; GNUNET_CRYPTO_eddsa_key_get_public (&coin_priv->eddsa_priv, &coin_pub.eddsa_pub); @@ -447,13 +451,13 @@ deposit_run (void *cls, TALER_JSON_merchant_wire_signature_hash (ds->wire_details, &h_wire)); TALER_wallet_deposit_sign (&ds->amount, - &denom_pub->fees.deposit, + &ds->denom_pub->fees.deposit, &h_wire, &h_contract_terms, NULL, /* wallet data hash */ phac, NULL, /* hash of extensions */ - &denom_pub->h_key, + &ds->denom_pub->h_key, ds->wallet_timestamp, &merchant_pub, ds->refund_deadline, @@ -470,7 +474,7 @@ deposit_run (void *cls, ds->che.details.deposit.refund_deadline = ds->refund_deadline; ds->che.details.deposit.sig = ds->coin_sig; ds->che.details.deposit.no_hac = true; - ds->che.details.deposit.deposit_fee = denom_pub->fees.deposit; + ds->che.details.deposit.deposit_fee = ds->denom_pub->fees.deposit; } GNUNET_assert (NULL == ds->dh); { @@ -479,7 +483,7 @@ deposit_run (void *cls, .coin_pub = coin_pub, .coin_sig = ds->coin_sig, .denom_sig = *denom_pub_sig, - .h_denom_pub = denom_pub->h_key, + .h_denom_pub = ds->denom_pub->h_key, .h_age_commitment = {{{0}}}, }; struct TALER_EXCHANGE_DepositContractDetail dcd = { @@ -624,6 +628,8 @@ deposit_traits (void *cls, coin_spent_priv), TALER_TESTING_make_trait_coin_pub (0, &coin_spent_pub), + TALER_TESTING_make_trait_denom_pub (0, + ds->denom_pub), TALER_TESTING_make_trait_coin_sig (0, &ds->coin_sig), TALER_TESTING_make_trait_age_commitment_proof (0, 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 @@ -53,6 +53,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. */ @@ -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, @@ -180,6 +212,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; -- cgit v1.2.3