diff options
author | Christian Grothoff <christian@grothoff.org> | 2020-01-12 23:13:46 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-01-12 23:13:46 +0100 |
commit | 6b0c121fc9818b4cce00bf4540c53cb79d968766 (patch) | |
tree | 79426109ec72094c0344e5b8d2112f6fad5bd817 | |
parent | 27911aaa17ed6341924e88b3cc2e9a40e23e539c (diff) |
clean up string traits"
-rw-r--r-- | src/include/taler_testing_lib.h | 70 | ||||
-rw-r--r-- | src/lib/testing_api_cmd_deposit.c | 85 | ||||
-rw-r--r-- | src/lib/testing_api_cmd_track.c | 15 | ||||
-rw-r--r-- | src/lib/testing_api_trait_amount.c | 1 | ||||
-rw-r--r-- | src/lib/testing_api_trait_string.c | 119 |
5 files changed, 110 insertions, 180 deletions
diff --git a/src/include/taler_testing_lib.h b/src/include/taler_testing_lib.h index bb5270042..aa3b537d7 100644 --- a/src/include/taler_testing_lib.h +++ b/src/include/taler_testing_lib.h @@ -2055,36 +2055,35 @@ TALER_TESTING_make_trait_wtid (unsigned int index, /** - * Offer amount in a trait. + * Offer HTTP url in a trait. * - * @param index which amount is to be offered, + * @param index which url is to be picked, * in case multiple are offered. - * @param amount the amount to offer. + * @param url the url to offer. * @return the trait. */ struct TALER_TESTING_Trait -TALER_TESTING_make_trait_amount (unsigned int index, - const char *amount); +TALER_TESTING_make_trait_url (unsigned int index, + const char *url); /** - * Obtain an amount from @a cmd. + * Obtain a HTTP url from @a cmd. * - * @param cmd command to extract the amount from. - * @param index which amount is to be picked, in case + * @param cmd command to extract the url from. + * @param index which url is to be picked, in case * multiple are offered. - * @param amount[out] where to write the wire details. - * + * @param url[out] where to write the url. * @return #GNUNET_OK on success. */ int -TALER_TESTING_get_trait_amount (const struct TALER_TESTING_Command *cmd, - unsigned int index, - const char **amount); +TALER_TESTING_get_trait_url (const struct TALER_TESTING_Command *cmd, + unsigned int index, + const char **url); /** - * Offer url in a trait. + * Offer PAYTO url in a trait. * * @param index which url is to be picked, * in case multiple are offered. @@ -2092,12 +2091,12 @@ TALER_TESTING_get_trait_amount (const struct TALER_TESTING_Command *cmd, * @return the trait. */ struct TALER_TESTING_Trait -TALER_TESTING_make_trait_url (unsigned int index, - const char *url); +TALER_TESTING_make_trait_payto (unsigned int index, + const char *url); /** - * Obtain a url from @a cmd. + * Obtain a PAYTO url from @a cmd. * * @param cmd command to extract the url from. * @param index which url is to be picked, in case @@ -2106,9 +2105,9 @@ TALER_TESTING_make_trait_url (unsigned int index, * @return #GNUNET_OK on success. */ int -TALER_TESTING_get_trait_url (const struct TALER_TESTING_Command *cmd, - unsigned int index, - const char **url); +TALER_TESTING_get_trait_payto (const struct TALER_TESTING_Command *cmd, + unsigned int index, + const char **url); /** @@ -2170,37 +2169,6 @@ TALER_TESTING_make_trait_amount_obj (unsigned int index, /** - * Offer a "reject" CMD reference. - * - * @param index which reference is to be offered, - * in case multiple are offered. - * @param rejected_reference the reference to offer. - * - * @return the trait. - */ -struct TALER_TESTING_Trait -TALER_TESTING_make_trait_rejected (unsigned int index, - const char *rejected); - - -/** - * Obtain the reference to a "reject" CMD. Usually offered - * by _rejected_ bank transfers. - * - * @param cmd command to extract the reference from. - * @param index which reference is to be picked, in case - * multiple are offered. - * @param rejected_reference[out] where to write the reference. - * - * @return #GNUNET_OK on success. - */ -int -TALER_TESTING_get_trait_rejected (const struct TALER_TESTING_Command *cmd, - unsigned int index, - const char **rejected_reference); - - -/** * Offer a command in a trait. * * @param index always zero. Commands offering this diff --git a/src/lib/testing_api_cmd_deposit.c b/src/lib/testing_api_cmd_deposit.c index fcc9a6375..c1c07a016 100644 --- a/src/lib/testing_api_cmd_deposit.c +++ b/src/lib/testing_api_cmd_deposit.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2018 Taler Systems SA + Copyright (C) 2018-2020 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 published by @@ -16,13 +16,11 @@ License along with TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ - /** * @file exchange-lib/testing_api_cmd_deposit.c * @brief command for testing /deposit. * @author Marcello Stanisci */ - #include "platform.h" #include "taler_json_lib.h" #include <gnunet/gnunet_curl_lib.h> @@ -41,7 +39,7 @@ struct DepositState /** * Amount to deposit. */ - const char *amount; + struct TALER_Amount amount; /** * Reference to any command that is able to provide a coin. @@ -243,7 +241,6 @@ deposit_run (void *cls, { struct DepositState *ds = cls; const struct TALER_TESTING_Command *coin_cmd; - struct TALER_TESTING_Command *this_cmd; const struct TALER_CoinSpendPrivateKeyP *coin_priv; struct TALER_CoinSpendPublicKeyP coin_pub; const struct TALER_EXCHANGE_DenomPublicKey *denom_pub; @@ -253,11 +250,8 @@ deposit_run (void *cls, struct GNUNET_CRYPTO_EddsaPrivateKey *merchant_priv; struct TALER_MerchantPublicKeyP merchant_pub; struct GNUNET_HashCode h_contract_terms; - struct TALER_Amount amount; ds->is = is; - this_cmd = &is->commands[is->ip]; - GNUNET_assert (ds->coin_reference); coin_cmd = TALER_TESTING_interpreter_lookup_command (is, @@ -287,16 +281,6 @@ deposit_run (void *cls, == TALER_TESTING_get_trait_denom_sig (coin_cmd, ds->coin_index, &denom_pub_sig)); - if (GNUNET_OK != - TALER_string_to_amount (ds->amount, - &amount)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to parse amount `%s' at '%u/%s'\n", - ds->amount, is->ip, this_cmd->label); - TALER_TESTING_interpreter_fail (is); - return; - } GNUNET_assert (GNUNET_OK == TALER_JSON_hash (ds->contract_terms, @@ -345,9 +329,10 @@ deposit_run (void *cls, dr.timestamp = GNUNET_TIME_absolute_hton (ds->timestamp); dr.refund_deadline = GNUNET_TIME_absolute_hton (ds->refund_deadline); - TALER_amount_hton (&dr.amount_with_fee, &amount); - TALER_amount_hton - (&dr.deposit_fee, &denom_pub->fee_deposit); + TALER_amount_hton (&dr.amount_with_fee, + &ds->amount); + TALER_amount_hton (&dr.deposit_fee, + &denom_pub->fee_deposit); dr.merchant = merchant_pub; dr.coin_pub = coin_pub; GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign @@ -355,21 +340,20 @@ deposit_run (void *cls, &dr.purpose, &coin_sig.eddsa_signature)); } - ds->dh = TALER_EXCHANGE_deposit - (is->exchange, - &amount, - wire_deadline, - ds->wire_details, - &h_contract_terms, - &coin_pub, - denom_pub_sig, - &denom_pub->key, - ds->timestamp, - &merchant_pub, - ds->refund_deadline, - &coin_sig, - &deposit_cb, - ds); + ds->dh = TALER_EXCHANGE_deposit (is->exchange, + &ds->amount, + wire_deadline, + ds->wire_details, + &h_contract_terms, + &coin_pub, + denom_pub_sig, + &denom_pub->key, + ds->timestamp, + &merchant_pub, + ds->refund_deadline, + &coin_sig, + &deposit_cb, + ds); if (NULL == ds->dh) { @@ -472,8 +456,8 @@ deposit_traits (void *cls, ds->contract_terms), TALER_TESTING_make_trait_peer_key (0, &ds->merchant_priv.eddsa_priv), - TALER_TESTING_make_trait_amount (0, - ds->amount), + TALER_TESTING_make_trait_amount_obj (0, + &ds->amount), TALER_TESTING_trait_end () }; @@ -551,18 +535,21 @@ TALER_TESTING_cmd_deposit "refund_deadline", GNUNET_JSON_from_time_abs (ds->refund_deadline)); } - ds->amount = amount; + GNUNET_assert (GNUNET_OK == + TALER_string_to_amount (amount, + &ds->amount)); ds->expected_response_code = expected_response_code; - - struct TALER_TESTING_Command cmd = { - .cls = ds, - .label = label, - .run = &deposit_run, - .cleanup = &deposit_cleanup, - .traits = &deposit_traits - }; - - return cmd; + { + struct TALER_TESTING_Command cmd = { + .cls = ds, + .label = label, + .run = &deposit_run, + .cleanup = &deposit_cleanup, + .traits = &deposit_traits + }; + + return cmd; + } } diff --git a/src/lib/testing_api_cmd_track.c b/src/lib/testing_api_cmd_track.c index 070218cfa..8784e686c 100644 --- a/src/lib/testing_api_cmd_track.c +++ b/src/lib/testing_api_cmd_track.c @@ -624,8 +624,7 @@ track_transfer_cb if (NULL != tts->total_amount_reference) { const struct TALER_TESTING_Command *total_amount_cmd; - const char *total_amount_from_reference_str; - struct TALER_Amount total_amount_from_reference; + const struct TALER_Amount *total_amount_from_reference; if (NULL == (total_amount_cmd = TALER_TESTING_interpreter_lookup_command @@ -636,20 +635,18 @@ track_transfer_cb return; } - if (GNUNET_OK != TALER_TESTING_get_trait_amount - (total_amount_cmd, 0, &total_amount_from_reference_str)) + if (GNUNET_OK != + TALER_TESTING_get_trait_amount_obj (total_amount_cmd, + 0, + &total_amount_from_reference)) { GNUNET_break (0); TALER_TESTING_interpreter_fail (is); return; } - GNUNET_assert (GNUNET_OK == TALER_string_to_amount - (total_amount_from_reference_str, - &total_amount_from_reference)); - if (0 != TALER_amount_cmp (total_amount, - &total_amount_from_reference)) + total_amount_from_reference)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Amount missmath to command %s\n", diff --git a/src/lib/testing_api_trait_amount.c b/src/lib/testing_api_trait_amount.c index 962948bc5..86611618c 100644 --- a/src/lib/testing_api_trait_amount.c +++ b/src/lib/testing_api_trait_amount.c @@ -16,7 +16,6 @@ License along with TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ - /** * @file exchange-lib/testing_api_trait_amount.c * @brief offer amounts as traits. diff --git a/src/lib/testing_api_trait_string.c b/src/lib/testing_api_trait_string.c index b9f57ab78..066a661e6 100644 --- a/src/lib/testing_api_trait_string.c +++ b/src/lib/testing_api_trait_string.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2018 Taler Systems SA + Copyright (C) 2018-2020 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 published @@ -16,11 +16,11 @@ License along with TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ - /** - * @file exchange-lib/testing_api_trait_string.c + * @file lib/testing_api_trait_string.c * @brief offers strings traits. * @author Marcello Stanisci + * @author Christian Grothoff */ #include "platform.h" #include "taler_json_lib.h" @@ -29,12 +29,31 @@ #include "taler_signatures.h" #include "taler_testing_lib.h" +/** + * FIXME: use json-t instead? + */ #define TALER_TESTING_TRAIT_CONTRACT_TERMS "contract-terms" + +/** + * Some string. Avoid, use something more precise! + */ #define TALER_TESTING_TRAIT_STRING "string" -#define TALER_TESTING_TRAIT_AMOUNT "amount" + +/** + * An HTTP-URL. + */ #define TALER_TESTING_TRAIT_URL "url" + +/** + * A PAYTO-URL. + */ +#define TALER_TESTING_TRAIT_PAYTO "payto" + +/** + * String identifying an order. + */ #define TALER_TESTING_TRAIT_ORDER_ID "order-id" -#define TALER_TESTING_TRAIT_REJECTED "rejected" + /** * Obtain contract terms from @a cmd. @@ -125,53 +144,7 @@ TALER_TESTING_make_trait_string /** - * Obtain an amount from @a cmd. - * - * @param cmd command to extract the amount from. - * @param index which amount is to be picked, in case - * multiple are offered. - * @param amount[out] where to write the wire details. - * - * @return #GNUNET_OK on success. - */ -int -TALER_TESTING_get_trait_amount - (const struct TALER_TESTING_Command *cmd, - unsigned int index, - const char **amount) -{ - return cmd->traits (cmd->cls, - (const void **) amount, - TALER_TESTING_TRAIT_AMOUNT, - index); -} - - -/** - * Offer amount in a trait. - * - * @param index which amount is to be offered, - * in case multiple are offered. - * @param amount the amount to offer. - * - * @return the trait. - */ -struct TALER_TESTING_Trait -TALER_TESTING_make_trait_amount - (unsigned int index, - const char *amount) -{ - struct TALER_TESTING_Trait ret = { - .index = index, - .trait_name = TALER_TESTING_TRAIT_AMOUNT, - .ptr = (const void *) amount - }; - return ret; -} - - -/** - * Obtain a url from @a cmd. + * Obtain a HTTP url from @a cmd. * * @param cmd command to extract the url from. * @param index which url is to be picked, in case @@ -194,7 +167,7 @@ TALER_TESTING_get_trait_url /** - * Offer url in a trait. + * Offer HTTP url in a trait. * * @param index which url is to be picked, * in case multiple are offered. @@ -212,6 +185,11 @@ TALER_TESTING_make_trait_url .trait_name = TALER_TESTING_TRAIT_URL, .ptr = (const void *) url }; + + GNUNET_assert (0 != strncasecmp (url, + "payto://", + strlen ("payto://"))); + return ret; } @@ -263,48 +241,49 @@ TALER_TESTING_make_trait_order_id /** - * Obtain the reference to a "reject" CMD. Usually offered - * by _rejected_ bank transfers. + * Obtain a PAYTO-url from @a cmd. * - * @param cmd command to extract the reference from. - * @param index which reference is to be picked, in case + * @param cmd command to extract the url from. + * @param index which url is to be picked, in case * multiple are offered. - * @param rejected_reference[out] where to write the reference. - * + * @param url[out] where to write the url. * @return #GNUNET_OK on success. */ int -TALER_TESTING_get_trait_rejected +TALER_TESTING_get_trait_payto (const struct TALER_TESTING_Command *cmd, unsigned int index, - const char **rejected_reference) + const char **url) { return cmd->traits (cmd->cls, - (const void **) rejected_reference, - TALER_TESTING_TRAIT_REJECTED, + (const void **) url, + TALER_TESTING_TRAIT_PAYTO, index); } /** - * Offer a "reject" CMD reference. + * Offer a "payto" URL reference. * * @param index which reference is to be offered, * in case multiple are offered. - * @param rejected_reference the reference to offer. - * + * @param payto the payto URL * @return the trait. */ struct TALER_TESTING_Trait -TALER_TESTING_make_trait_rejected +TALER_TESTING_make_trait_payto (unsigned int index, - const char *rejected) + const char *payto) { struct TALER_TESTING_Trait ret = { .index = index, - .trait_name = TALER_TESTING_TRAIT_REJECTED, - .ptr = (const void *) rejected + .trait_name = TALER_TESTING_TRAIT_PAYTO, + .ptr = (const void *) payto }; + + GNUNET_assert (0 == strncasecmp (payto, + "payto://", + strlen ("payto://"))); return ret; } |