commit a8f7e14d76df842cb13f1a2a4e8561b57d5abfc0
parent a445ea311cd92de18b3a126b59db72896e69e3d3
Author: bohdan-potuzhnyi <bohdan.potuzhnyi@gmail.com>
Date: Mon, 14 Apr 2025 13:54:20 +0200
adding functions for donau pay order test
Diffstat:
3 files changed, 243 insertions(+), 101 deletions(-)
diff --git a/src/include/taler_merchant_testing_lib.h b/src/include/taler_merchant_testing_lib.h
@@ -1045,6 +1045,43 @@ TALER_TESTING_cmd_merchant_pay_order_choices (
int choice_index,
const char *input_reference);
+#ifdef HAVE_DONAU_DONAU_SERVICE_H
+
+/**
+ * Make a "pay" test command for an order with choices.
+ *
+ * @param label command label.
+ * @param merchant_url merchant base url
+ * @param http_status expected HTTP response code.
+ * @param proposal_reference the proposal whose payment status
+ * is going to be checked.
+ * @param coin_reference reference to any command which is able
+ * to provide coins to use for paying.
+ * @param amount_with_fee amount to pay, including the deposit
+ * fee
+ * @param amount_without_fee amount to pay, no fees included.
+ * @param session_id the session id to use for the payment (can be NULL).
+ * @param choice_index index of the selected choice for the payment.
+ * @param year year of the donation
+ * @param donor_tax_id tax ID of the donor
+ * @param salt salt for the donation
+ * @return the command
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_merchant_pay_order_donau (const char *label,
+ const char *merchant_url,
+ unsigned int http_status,
+ const char *proposal_reference,
+ const char *coin_reference,
+ const char *amount_with_fee,
+ const char *amount_without_fee,
+ const char *session_id,
+ int choice_index,
+ const char *charity_reference,
+ const uint64_t year,
+ const char *donor_tax_id,
+ const char *salt);
+#endif
/**
* Make an "order paid" test command.
diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c
@@ -1851,8 +1851,6 @@ run (void *cls,
MHD_HTTP_OK),
//FIXME_2: Add check for the donau charity instance info being corrected
// with info from the donau
- //FIXME: Add the order payment for the donau(choices tax-receipt)
- //TALER_TESTING_cmd_merchant_post_orders_choices (act post_orders_donau)
TALER_TESTING_cmd_merchant_post_orders_donau (
"create-donau-order",
cred.cfg,
@@ -1862,8 +1860,7 @@ run (void *cls,
GNUNET_TIME_UNIT_ZERO_TS,
GNUNET_TIME_UNIT_FOREVER_TS,
"EUR:10.0"),
- //FIXME: Add the claiming phase
- //TALER_TESTING_cmd_merchant_claim_order
+
//FIXME: Most probably we need to merge the functionality of the
//TALER_TESTING_cmd_merchant_pay_order and TALER_TESTING_cmd_issue_receipts from DONAU
//Most probably we only need to copy the part of creation of the BUDIs
diff --git a/src/testing/testing_api_cmd_pay_order.c b/src/testing/testing_api_cmd_pay_order.c
@@ -35,6 +35,126 @@
#include "taler_merchant_service.h"
#include "taler_merchant_testing_lib.h"
+#ifdef HAVE_DONAU_DONAU_SERVICE_H
+#include <donau/donau_service.h>
+#include <donau/donau_testing_lib.h>
+#endif /* HAVE_DONAU_DONAU_SERVICE_H */
+
+#ifdef HAVE_DONAU_DONAU_SERVICE_H
+struct MerchantDonauPayData
+{
+ /**
+ * Donau URL.
+ */
+ const char *donau_url;
+
+ /**
+ * Donau keys
+ */
+ struct DONAU_Keys *keys;
+
+ /**
+ * Charity reference
+ */
+ const char *charity_reference;
+
+ /**
+ * Charity id
+ */
+ uint64_t charity_id;
+
+ /**
+ * Charity private key
+ */
+ struct DONAU_CharityPrivateKeyP charity_priv;
+
+ /**
+ * Number of BUDIs to create or fetch. Example only.
+ */
+ size_t num_budis;
+
+ /**
+ * Year of the donation
+ */
+ uint64_t year;
+
+ /**
+ * BUDI keypairs used in the payment (blinded_udi + pubkey).
+ */
+ struct DONAU_BlindedUniqueDonorIdentifierKeyPair *bkp;
+
+ /**
+ * Blinding secrets, if needed for each BUDI (CS vs. RSA).
+ */
+ union GNUNET_CRYPTO_BlindingSecretP *blinding_secrets;
+
+ /**
+ * Hash of the salted donor tax id, if relevant.
+ */
+ struct DONAU_HashDonorTaxId h_donor_tax_id;
+
+ /**
+ * If using the CS approach, we might track how many
+ * asynchronous calls are still pending, etc.
+ */
+ unsigned int cs_pending;
+
+};
+
+//FIXME: Here I need a command which will parse the data from this system, and donau system
+// and will prepare all necessary data for the donau pay order
+static enum GNUNET_GenericReturnValue
+prepare_donau_data(struct TALER_TESTING_Interpreter *is,
+ struct MerchantDonauPayData *ss){
+
+ /* Get charity id and the charity private key from trait */
+ {
+ const struct TALER_TESTING_Command *charity_post_cmd;
+ const unsigned long long *charity_id;
+ const struct DONAU_CharityPrivateKeyP *charity_priv;
+
+
+ charity_post_cmd = TALER_TESTING_interpreter_lookup_command (is,
+ ss->
+ charity_reference);
+
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_charity_id (charity_post_cmd, &charity_id) ||
+ GNUNET_OK != TALER_TESTING_get_trait_charity_priv (charity_post_cmd,
+ &charity_priv))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ ss->charity_id = (uint64_t) *(charity_id);
+ ss->charity_priv = *(charity_priv);
+ }
+
+ /* Get donau keys from trait */
+ {
+ const struct TALER_TESTING_Command *keys_cmd;
+ struct DONAU_Keys *keys;
+
+ keys_cmd = TALER_TESTING_interpreter_lookup_command (is,
+ "get-donau");
+
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_donau_keys (keys_cmd, &keys))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ ss->keys = keys;
+ }
+
+ /* Get BUDIsKP */
+ {
+ //FIXME: Define me pleeeease
+ }
+
+ return GNUNET_OK;
+};
+#endif /* HAVE_DONAU_DONAU_SERVICE_H */
/**
* State for a /pay CMD.
@@ -135,6 +255,12 @@ struct PayState
*/
int choice_index;
+ #ifdef HAVE_DONAU_DONAU_SERVICE_H
+ /**
+ * Donau data, if required.
+ */
+ struct MerchantDonauPayData donau_data;
+ #endif /* HAVE_DONAU_DONAU_SERVICE_H */
};
@@ -780,7 +906,7 @@ pay_run (void *cls,
{
const json_t *donau_urls;
- // For test we care only about the presence of it
+ // For test, we care only about the presence of it
struct GNUNET_JSON_Specification donauspec[] = {
GNUNET_JSON_spec_array_const ("donau_urls",
&donau_urls),
@@ -804,11 +930,11 @@ pay_run (void *cls,
}
#ifdef HAVE_DONAU_DONAU_SERVICE_H
- //FIXME
- //Theoretically everything is fine, and now we want to finish preparing the payment for the donau
+ // FIXME: I suspect we want to call function here that will get the stuff for the donau_data
+
#else /* HAVE_DONAU_DONAU_SERVICE_H */
//Theoretically we have thought about paying without donau_url being selected, so could proceed...
- //
+ // or maybe not
#endif /* HAVE_DONAU_DONAU_SERVICE_H */
}
@@ -1158,99 +1284,81 @@ TALER_TESTING_cmd_merchant_pay_order_choices (const char *label,
}
-//#ifdef HAVE_DONAU_DONAU_SERVICE_H
-//
-//struct MerchantDonauPayData
-//{
-// /**
-// * Donau URL.
-// */
-// const char *donau_url;
-//
-// /**
-// * Number of BUDIs to create or fetch. Example only.
-// */
-// size_t num_budis;
-//
-// /**
-// * BUDI keypairs used in the payment (blinded_udi + pubkey).
-// */
-// struct DONAU_BlindedUniqueDonorIdentifierKeyPair *bkp;
-//
-// /**
-// * Blinding secrets, if needed for each BUDI (CS vs. RSA).
-// */
-// union GNUNET_CRYPTO_BlindingSecretP *blinding_secrets;
-//
-// /**
-// * Hash of the salted donor tax id, if relevant.
-// */
-// struct DONAU_HashDonorTaxId h_donor_tax_id;
-//
-// /**
-// * Possibly store references to the Donau keys, or anything
-// * else needed to blind or sign UDIs, etc.
-// */
-// struct DONAU_Keys *donau_keys;
-//
-// /**
-// * If using the CS approach, we might track how many
-// * asynchronous calls are still pending, etc.
-// */
-// unsigned int cs_pending;
-//
-//};
-//
-////FIXME: Here I need a command which will parse the data from this system, and donau system
-//// and will prepare all necessary data for the donau pay order
-//static enum GNUNET_GenericReturnValue
-//prepare_donau_data(){
-//
-//};
-//
-////FIXME: Maybe it make sense to have it here, to preload some data and
-//// then proceed on the next steps
-//struct TALER_TESTING_Command
-//TALER_TESTING_cmd_merchant_pay_order_donau (const char *label,
-// const char *merchant_url,
-// unsigned int http_status,
-// const char *proposal_reference,
-// const char *coin_reference,
-// const char *amount_with_fee,
-// const char *amount_without_fee,
-// const char *session_id,
-// int choice_index)
-//{
-// struct PayState *ps;
-//
-// struct MerchantDonauPayData *mdpd;
-//
-// //FIXME: Maybe we can fill the mdpd with some data inside
-// // and then pass it to the pay order
-//
-// ps = GNUNET_new (struct PayState);
-// ps->http_status = http_status;
-// ps->proposal_reference = proposal_reference;
-// ps->coin_reference = coin_reference;
-// ps->merchant_url = merchant_url;
-// ps->amount_with_fee = amount_with_fee;
-// ps->amount_without_fee = amount_without_fee;
-// ps->session_id = session_id;
-// ps->token_reference = NULL;
-// ps->choice_index = choice_index;
-// {
-// struct TALER_TESTING_Command cmd = {
-// .cls = ps,
-// .label = label,
-// .run = &donau_pay_run,
-// .cleanup = &pay_cleanup,
-// .traits = &pay_traits
-// };
-//
-// return cmd;
-// }
-//}
-//#endif /* HAVE_DONAU_DONAU_SERVICE_H */
+#ifdef HAVE_DONAU_DONAU_SERVICE_H
+
+ struct TALER_TESTING_Command
+ TALER_TESTING_cmd_merchant_pay_order_donau (const char *label,
+ const char *merchant_url,
+ unsigned int http_status,
+ const char *proposal_reference,
+ const char *coin_reference,
+ const char *amount_with_fee,
+ const char *amount_without_fee,
+ const char *session_id,
+ int choice_index,
+ const char *charity_reference,
+ const uint64_t year,
+ const char *donor_tax_id,
+ const char *salt)
+ {
+ struct PayState *ps;
+
+ struct MerchantDonauPayData *mdpd;
+
+ mdpd = GNUNET_new (struct MerchantDonauPayData);
+
+ mdpd->year = year;
+ mdpd->num_budis = 3;
+ mdpd->charity_reference = charity_reference;
+
+ /* Here we generate the h_donor_tax_id*/
+ {
+ unsigned char hash[512 / 8];
+ crypto_hash_sha512_state state;
+ crypto_hash_sha512_init (&state);
+
+ unsigned int tax_length;
+ for (tax_length = 0; donor_tax_id[tax_length]!= '\0'; ++tax_length)
+ ;
+ unsigned int salt_length;
+ for (salt_length = 0; salt[salt_length]!= '\0'; ++salt_length)
+ ;
+
+ crypto_hash_sha512_update (&state, (const unsigned char*) donor_tax_id,
+ tax_length);
+ crypto_hash_sha512_update (&state, (const unsigned char*) salt, salt_length);
+
+ crypto_hash_sha512_final (&state, hash);
+ GNUNET_memcpy (mdpd->h_donor_tax_id.hash, hash, sizeof(hash));
+ }
+ /* End of hash generation */
+
+ ps = GNUNET_new (struct PayState);
+ ps->http_status = http_status;
+ ps->proposal_reference = proposal_reference;
+ ps->coin_reference = coin_reference;
+ ps->merchant_url = merchant_url;
+ ps->amount_with_fee = amount_with_fee;
+ ps->amount_without_fee = amount_without_fee;
+ ps->session_id = session_id;
+ ps->token_reference = NULL;
+ ps->choice_index = choice_index;
+ ps->donau_data = *mdpd; /* Adding prefilled data, for future processing*/
+
+ {
+ struct TALER_TESTING_Command cmd = {
+ .cls = ps,
+ .label = label,
+ .run = &pay_run,
+ .cleanup = &pay_cleanup,
+ .traits = &pay_traits
+ };
+
+ return cmd;
+ }
+ }
+
+#endif /* HAVE_DONAU_DONAU_SERVICE_H */
struct TALER_TESTING_Command