diff options
author | Christian Grothoff <christian@grothoff.org> | 2020-01-11 15:19:56 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-01-11 15:20:17 +0100 |
commit | 9443c10d7feb0d91323869dd08ec61ca781564f4 (patch) | |
tree | fd617ea56cc1d2ea370ce7e5467574a536b52d28 /src/lib | |
parent | 554da10133eb491b352a106b98ebeaed797133bb (diff) |
major refactoring, eliminating wire-plugins and moving towards new bank API. main code compiles, testcases known to fail, code sure not to fully work yet
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/Makefile.am | 1 | ||||
-rw-r--r-- | src/lib/exchange_api_handle.c | 2 | ||||
-rw-r--r-- | src/lib/testing_api_cmd_bank_check.c | 69 | ||||
-rw-r--r-- | src/lib/testing_api_cmd_fakebank_transfer.c | 402 | ||||
-rw-r--r-- | src/lib/testing_api_cmd_status.c | 36 | ||||
-rw-r--r-- | src/lib/testing_api_cmd_track.c | 21 | ||||
-rw-r--r-- | src/lib/testing_api_trait_reserve_pub.c | 77 | ||||
-rw-r--r-- | src/lib/testing_api_trait_string.c | 29 |
8 files changed, 290 insertions, 347 deletions
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index de0c8935c..ee8389f60 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -103,6 +103,7 @@ libtalertesting_la_SOURCES = \ testing_api_trait_exchange_sig.c \ testing_api_trait_json.c \ testing_api_trait_process.c \ + testing_api_trait_reserve_pub.c \ testing_api_trait_reserve_priv.c \ testing_api_trait_number.c \ testing_api_trait_fresh_coin.c \ diff --git a/src/lib/exchange_api_handle.c b/src/lib/exchange_api_handle.c index abb95816c..6b51519fd 100644 --- a/src/lib/exchange_api_handle.c +++ b/src/lib/exchange_api_handle.c @@ -1262,7 +1262,7 @@ keys_completed_cb (void *cls, for (unsigned int i = 0; i<kd_old.num_denom_keys; i++) kd.denom_keys[i].key.rsa_public_key = GNUNET_CRYPTO_rsa_public_key_dup ( - kd_old.denom_keys[i].key.rsa_public_key); + kd_old.denom_keys[i].key.rsa_public_key); kd.num_auditors = kd_old.num_auditors; kd.auditors = GNUNET_new_array (kd.num_auditors, diff --git a/src/lib/testing_api_cmd_bank_check.c b/src/lib/testing_api_cmd_bank_check.c index f51c535a1..f74f7afec 100644 --- a/src/lib/testing_api_cmd_bank_check.c +++ b/src/lib/testing_api_cmd_bank_check.c @@ -52,12 +52,12 @@ struct BankCheckState /** * Expected debit bank account. */ - uint64_t debit_account; + const char *debit_account; /** * Expected credit bank account. */ - uint64_t credit_account; + const char *credit_account; /** * Wire transfer subject (set by fakebank-lib). @@ -95,18 +95,16 @@ check_bank_transfer_run (void *cls, struct TALER_TESTING_Interpreter *is) { struct BankCheckState *bcs = cls; - struct TALER_Amount amount; - const uint64_t *debit_account; - const uint64_t *credit_account; + const char *debit_account; + const char *credit_account; const char *exchange_base_url; - if (NULL == bcs->deposit_reference) { TALER_LOG_INFO ("Deposit reference NOT given\n"); - debit_account = &bcs->debit_account; - credit_account = &bcs->credit_account; + debit_account = bcs->debit_account; + credit_account = bcs->credit_account; exchange_base_url = bcs->exchange_base_url; if (GNUNET_OK != @@ -154,14 +152,13 @@ check_bank_transfer_run (void *cls, GNUNET_assert (GNUNET_OK == TALER_TESTING_get_trait_url (deposit_cmd, 0, &exchange_base_url)); // check 0 works! - } if (GNUNET_OK != TALER_FAKEBANK_check (is->fakebank, &amount, - *debit_account, - *credit_account, + debit_account, + credit_account, exchange_base_url, &bcs->subject)) { @@ -217,18 +214,18 @@ check_bank_transfer_traits (void *cls, wtid_ptr = NULL; else wtid_ptr = &bcs->wtid; - - struct TALER_TESTING_Trait traits[] = { - TALER_TESTING_make_trait_transfer_subject (0, bcs->subject), - TALER_TESTING_make_trait_wtid (0, wtid_ptr), - TALER_TESTING_make_trait_url (0, bcs->exchange_base_url), - TALER_TESTING_trait_end () - }; - - return TALER_TESTING_get_trait (traits, - ret, - trait, - index); + { + struct TALER_TESTING_Trait traits[] = { + TALER_TESTING_make_trait_wtid (0, wtid_ptr), + TALER_TESTING_make_trait_url (0, bcs->exchange_base_url), + TALER_TESTING_trait_end () + }; + + return TALER_TESTING_get_trait (traits, + ret, + trait, + index); + } } @@ -250,8 +247,8 @@ TALER_TESTING_cmd_check_bank_transfer (const char *label, const char *exchange_base_url, const char *amount, - uint64_t debit_account, - uint64_t credit_account) + const char *debit_account, + const char *credit_account) { struct BankCheckState *bcs; @@ -260,18 +257,18 @@ TALER_TESTING_cmd_check_bank_transfer bcs->amount = amount; bcs->debit_account = debit_account; bcs->credit_account = credit_account; - bcs->deposit_reference = NULL; - - struct TALER_TESTING_Command cmd = { - .label = label, - .cls = bcs, - .run = &check_bank_transfer_run, - .cleanup = &check_bank_transfer_cleanup, - .traits = &check_bank_transfer_traits - }; - - return cmd; + { + struct TALER_TESTING_Command cmd = { + .label = label, + .cls = bcs, + .run = &check_bank_transfer_run, + .cleanup = &check_bank_transfer_cleanup, + .traits = &check_bank_transfer_traits + }; + + return cmd; + } } diff --git a/src/lib/testing_api_cmd_fakebank_transfer.c b/src/lib/testing_api_cmd_fakebank_transfer.c index 81378238c..e212fd31f 100644 --- a/src/lib/testing_api_cmd_fakebank_transfer.c +++ b/src/lib/testing_api_cmd_fakebank_transfer.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 @@ -51,24 +51,14 @@ struct FakebankTransferState struct TALER_Amount amount; /** - * Wire transfer subject. + * Base URL of the debit account. */ - const char *subject; + const char *debit_url; /** - * Base URL of the bank serving the request. + * Money receiver account URL. */ - const char *bank_url; - - /** - * Money sender account number. - */ - uint64_t debit_account_no; - - /** - * Money receiver account number. - */ - uint64_t credit_account_no; + const char *payto_credit_account; /** * Username to use for authentication. @@ -87,6 +77,11 @@ struct FakebankTransferState struct TALER_ReservePrivateKeyP reserve_priv; /** + * Reserve public key matching @e reserve_priv. + */ + struct TALER_ReservePublicKeyP reserve_pub; + + /** * Handle to the pending request at the fakebank. */ struct TALER_BANK_AdminAddIncomingHandle *aih; @@ -188,16 +183,15 @@ do_retry (void *cls) * @param ec taler-specific error code, #TALER_EC_NONE on success * @param serial_id unique ID of the wire transfer * @param timestamp time stamp of the transaction made. - * @param full_response full response from the exchange (for - * logging, in case of errors) + * @param json raw response */ static void -add_incoming_cb (void *cls, +confirmation_cb (void *cls, unsigned int http_status, enum TALER_ErrorCode ec, uint64_t serial_id, struct GNUNET_TIME_Absolute timestamp, - const json_t *full_response) + const json_t *json) { struct FakebankTransferState *fts = cls; struct TALER_TESTING_Interpreter *is = fts->is; @@ -256,130 +250,115 @@ fakebank_transfer_run (void *cls, struct TALER_TESTING_Interpreter *is) { struct FakebankTransferState *fts = cls; - char *subject; struct TALER_BANK_AuthenticationData auth; - struct TALER_ReservePublicKeyP reserve_pub; - if (NULL != fts->subject) + /* Use reserve public key as subject */ + if (NULL != fts->reserve_reference) { - subject = GNUNET_strdup (fts->subject); + const struct TALER_TESTING_Command *ref; + const struct TALER_ReservePrivateKeyP *reserve_priv; + + ref = TALER_TESTING_interpreter_lookup_command + (is, fts->reserve_reference); + if (NULL == ref) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (is); + return; + } + if (GNUNET_OK != + TALER_TESTING_get_trait_reserve_priv (ref, + 0, + &reserve_priv)) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (is); + return; + } + fts->reserve_priv.eddsa_priv = reserve_priv->eddsa_priv; } else { - /* Use reserve public key as subject */ - if (NULL != fts->reserve_reference) + if (NULL != fts->instance) { - const struct TALER_TESTING_Command *ref; - const struct TALER_ReservePrivateKeyP *reserve_priv; + char *section; + char *keys; + struct GNUNET_CRYPTO_EddsaPrivateKey *priv; + struct GNUNET_CONFIGURATION_Handle *cfg; - ref = TALER_TESTING_interpreter_lookup_command - (is, fts->reserve_reference); - if (NULL == ref) + GNUNET_assert (NULL != fts->config_filename); + cfg = GNUNET_CONFIGURATION_create (); + if (GNUNET_OK != + GNUNET_CONFIGURATION_load (cfg, + fts->config_filename)) { GNUNET_break (0); TALER_TESTING_interpreter_fail (is); return; } + + GNUNET_asprintf (§ion, + "instance-%s", + fts->instance); if (GNUNET_OK != - TALER_TESTING_get_trait_reserve_priv (ref, - 0, - &reserve_priv)) + GNUNET_CONFIGURATION_get_value_filename + (cfg, + section, + "TIP_RESERVE_PRIV_FILENAME", + &keys)) { - GNUNET_break (0); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Configuration fails to specify reserve" + " private key filename in section %s\n", + section); + GNUNET_free (section); TALER_TESTING_interpreter_fail (is); return; } - fts->reserve_priv.eddsa_priv = reserve_priv->eddsa_priv; - } - else - { - if (NULL != fts->instance) + priv = GNUNET_CRYPTO_eddsa_key_create_from_file (keys); + GNUNET_free (keys); + if (NULL == priv) { - char *section; - char *keys; - struct GNUNET_CRYPTO_EddsaPrivateKey *priv; - struct GNUNET_CONFIGURATION_Handle *cfg; - - GNUNET_assert (NULL != fts->config_filename); - cfg = GNUNET_CONFIGURATION_create (); - if (GNUNET_OK != - GNUNET_CONFIGURATION_load (cfg, - fts->config_filename)) - { - GNUNET_break (0); - TALER_TESTING_interpreter_fail (is); - return; - } - - GNUNET_asprintf (§ion, - "instance-%s", - fts->instance); - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename - (cfg, - section, - "TIP_RESERVE_PRIV_FILENAME", - &keys)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Configuration fails to specify reserve" - " private key filename in section %s\n", - section); - GNUNET_free (section); - TALER_TESTING_interpreter_fail (is); - return; - } - priv = GNUNET_CRYPTO_eddsa_key_create_from_file (keys); - GNUNET_free (keys); - if (NULL == priv) - { - GNUNET_log_config_invalid - (GNUNET_ERROR_TYPE_ERROR, - section, - "TIP_RESERVE_PRIV_FILENAME", - "Failed to read private key"); - GNUNET_free (section); - TALER_TESTING_interpreter_fail (is); - return; - } - fts->reserve_priv.eddsa_priv = *priv; + GNUNET_log_config_invalid + (GNUNET_ERROR_TYPE_ERROR, + section, + "TIP_RESERVE_PRIV_FILENAME", + "Failed to read private key"); GNUNET_free (section); - GNUNET_free (priv); - GNUNET_CONFIGURATION_destroy (cfg); + TALER_TESTING_interpreter_fail (is); + return; } - else - { - /* No referenced reserve, no instance to take priv - * from, no explicit subject given: create new key! */ - struct GNUNET_CRYPTO_EddsaPrivateKey *priv; + fts->reserve_priv.eddsa_priv = *priv; + GNUNET_free (section); + GNUNET_free (priv); + GNUNET_CONFIGURATION_destroy (cfg); + } + else + { + /* No referenced reserve, no instance to take priv + * from, no explicit subject given: create new key! */ + struct GNUNET_CRYPTO_EddsaPrivateKey *priv; - priv = GNUNET_CRYPTO_eddsa_key_create (); - fts->reserve_priv.eddsa_priv = *priv; - GNUNET_free (priv); - } + priv = GNUNET_CRYPTO_eddsa_key_create (); + fts->reserve_priv.eddsa_priv = *priv; + GNUNET_free (priv); } - GNUNET_CRYPTO_eddsa_key_get_public - (&fts->reserve_priv.eddsa_priv, &reserve_pub.eddsa_pub); - subject = GNUNET_STRINGS_data_to_string_alloc - (&reserve_pub, sizeof (reserve_pub)); } - + GNUNET_CRYPTO_eddsa_key_get_public (&fts->reserve_priv.eddsa_priv, + &fts->reserve_pub.eddsa_pub); auth.method = TALER_BANK_AUTH_BASIC; auth.details.basic.username = (char *) fts->auth_username; auth.details.basic.password = (char *) fts->auth_password; fts->is = is; fts->aih = TALER_BANK_admin_add_incoming (TALER_TESTING_interpreter_get_context (is), - fts->bank_url, + fts->debit_url, &auth, - fts->exchange_url, - subject, + &fts->reserve_pub, &fts->amount, - fts->debit_account_no, - fts->credit_account_no, - &add_incoming_cb, + fts->payto_credit_account, + &confirmation_cb, fts); - GNUNET_free (subject); if (NULL == fts->aih) { GNUNET_break (0); @@ -408,6 +387,7 @@ fakebank_transfer_cleanup (void *cls, "Command %s did not complete\n", cmd->label); TALER_BANK_admin_add_incoming_cancel (fts->aih); + fts->aih = NULL; } if (NULL != fts->retry_task) { @@ -435,32 +415,21 @@ fakebank_transfer_traits (void *cls, unsigned int index) { struct FakebankTransferState *fts = cls; - #define MANDATORY 7 - struct TALER_TESTING_Trait traits[MANDATORY + 1] = { - TALER_TESTING_MAKE_TRAIT_DEBIT_ACCOUNT - (&fts->debit_account_no), - TALER_TESTING_MAKE_TRAIT_CREDIT_ACCOUNT - (&fts->credit_account_no), + struct TALER_TESTING_Trait traits[] = { TALER_TESTING_make_trait_url (0, fts->exchange_url), + TALER_TESTING_make_trait_url (1, fts->debit_url), TALER_TESTING_MAKE_TRAIT_ROW_ID (&fts->serial_id), + TALER_TESTING_MAKE_TRAIT_CREDIT_ACCOUNT (fts->payto_credit_account), + TALER_TESTING_MAKE_TRAIT_DEBIT_ACCOUNT (fts->debit_url), TALER_TESTING_make_trait_amount_obj (0, &fts->amount), - TALER_TESTING_make_trait_absolute_time (0, &fts->timestamp) + TALER_TESTING_make_trait_absolute_time (0, &fts->timestamp), + TALER_TESTING_make_trait_reserve_priv (0, + &fts->reserve_priv), + TALER_TESTING_make_trait_reserve_pub (0, + &fts->reserve_pub), + TALER_TESTING_trait_end () }; - /** - * The user gave explicit subject, - * there must be NO reserve priv. */ - if (NULL != fts->subject) - traits[MANDATORY - 1] = - TALER_TESTING_make_trait_transfer_subject (0, - fts->subject); - /* A reserve priv must exist if no subject was given. */ - else - traits[MANDATORY - 1] = TALER_TESTING_make_trait_reserve_priv - (0, &fts->reserve_priv), - - traits[MANDATORY] = TALER_TESTING_trait_end (); - return TALER_TESTING_get_trait (traits, ret, trait, @@ -475,27 +444,21 @@ fakebank_transfer_traits (void *cls, * * @param label command label. * @param amount amount to transfer. - * @param bank_url base URL of the bank that implements this - * wire transer. For simplicity, both credit and debit - * bank account exist at the same bank. - * @param debit_account_no which account (expressed as a number) - * gives money. - * @param credit_account_no which account (expressed as a number) - * receives money. + * @param account_base_url base URL of the account that implements this + * wire transer (which account gives money). + * @param payto_credit_account which account receives money. * @param auth_username username identifying the @a * debit_account_no at the bank. * @param auth_password password for @a auth_username. * @param exchange_url which exchange is involved in this transfer. - * * @return the command. */ struct TALER_TESTING_Command TALER_TESTING_cmd_fakebank_transfer (const char *label, const char *amount, - const char *bank_url, - uint64_t debit_account_no, - uint64_t credit_account_no, + const char *account_base_url, + const char *payto_credit_account, const char *auth_username, const char *auth_password, const char *exchange_url) @@ -503,9 +466,8 @@ TALER_TESTING_cmd_fakebank_transfer struct FakebankTransferState *fts; fts = GNUNET_new (struct FakebankTransferState); - fts->bank_url = bank_url; - fts->credit_account_no = credit_account_no; - fts->debit_account_no = debit_account_no; + fts->debit_url = account_base_url; + fts->payto_credit_account = payto_credit_account; fts->auth_username = auth_username; fts->auth_password = auth_password; fts->exchange_url = exchange_url; @@ -520,87 +482,17 @@ TALER_TESTING_cmd_fakebank_transfer GNUNET_assert (0); } - struct TALER_TESTING_Command cmd = { - .cls = fts, - .label = label, - .run = &fakebank_transfer_run, - .cleanup = &fakebank_transfer_cleanup, - .traits = &fakebank_transfer_traits - }; - - return cmd; -} - - -/** - * Create "fakebank transfer" CMD, letting the caller specifying - * the subject line. - * - * @param label command label. - * @param amount amount to transfer. - * @param bank_url base URL of the bank that implements this - * wire transer. For simplicity, both credit and debit - * bank account exist at the same bank. - * @param debit_account_no which account (expressed as a number) - * gives money. - * @param credit_account_no which account (expressed as a number) - * receives money. - * - * @param auth_username username identifying the @a - * debit_account_no at the bank. - * @param auth_password password for @a auth_username. - * @param subject wire transfer's subject line. - * @param exchange_url which exchange is involved in this transfer. - * - * @return the command. - */ -struct TALER_TESTING_Command -TALER_TESTING_cmd_fakebank_transfer_with_subject - (const char *label, - const char *amount, - const char *bank_url, - uint64_t debit_account_no, - uint64_t credit_account_no, - const char *auth_username, - const char *auth_password, - const char *subject, - const char *exchange_url) -{ - struct FakebankTransferState *fts; - - fts = GNUNET_new (struct FakebankTransferState); - - TALER_LOG_DEBUG ("%s:FTS@%p\n", - label, - fts); - - fts->bank_url = bank_url; - fts->credit_account_no = credit_account_no; - fts->debit_account_no = debit_account_no; - fts->auth_username = auth_username; - fts->auth_password = auth_password; - fts->subject = subject; - fts->exchange_url = exchange_url; - if (GNUNET_OK != - TALER_string_to_amount (amount, - &fts->amount)) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to parse amount `%s' at %s\n", - amount, - label); - GNUNET_assert (0); + struct TALER_TESTING_Command cmd = { + .cls = fts, + .label = label, + .run = &fakebank_transfer_run, + .cleanup = &fakebank_transfer_cleanup, + .traits = &fakebank_transfer_traits + }; + + return cmd; } - - struct TALER_TESTING_Command cmd = { - .cls = fts, - .label = label, - .run = &fakebank_transfer_run, - .cleanup = &fakebank_transfer_cleanup, - .traits = &fakebank_transfer_traits - }; - - return cmd; } @@ -631,9 +523,8 @@ struct TALER_TESTING_Command TALER_TESTING_cmd_fakebank_transfer_with_ref (const char *label, const char *amount, - const char *bank_url, - uint64_t debit_account_no, - uint64_t credit_account_no, + const char *account_base_url, + const char *payto_credit_account, const char *auth_username, const char *auth_password, const char *ref, @@ -642,9 +533,8 @@ TALER_TESTING_cmd_fakebank_transfer_with_ref struct FakebankTransferState *fts; fts = GNUNET_new (struct FakebankTransferState); - fts->bank_url = bank_url; - fts->credit_account_no = credit_account_no; - fts->debit_account_no = debit_account_no; + fts->debit_url = account_base_url; + fts->payto_credit_account = payto_credit_account; fts->auth_username = auth_username; fts->auth_password = auth_password; fts->reserve_reference = ref; @@ -659,16 +549,17 @@ TALER_TESTING_cmd_fakebank_transfer_with_ref label); GNUNET_assert (0); } - - struct TALER_TESTING_Command cmd = { - .cls = fts, - .label = label, - .run = &fakebank_transfer_run, - .cleanup = &fakebank_transfer_cleanup, - .traits = &fakebank_transfer_traits - }; - - return cmd; + { + struct TALER_TESTING_Command cmd = { + .cls = fts, + .label = label, + .run = &fakebank_transfer_run, + .cleanup = &fakebank_transfer_cleanup, + .traits = &fakebank_transfer_traits + }; + + return cmd; + } } @@ -705,9 +596,8 @@ struct TALER_TESTING_Command TALER_TESTING_cmd_fakebank_transfer_with_instance (const char *label, const char *amount, - const char *bank_url, - uint64_t debit_account_no, - uint64_t credit_account_no, + const char *account_base_url, + const char *payto_credit_account, const char *auth_username, const char *auth_password, const char *instance, @@ -717,9 +607,8 @@ TALER_TESTING_cmd_fakebank_transfer_with_instance struct FakebankTransferState *fts; fts = GNUNET_new (struct FakebankTransferState); - fts->bank_url = bank_url; - fts->credit_account_no = credit_account_no; - fts->debit_account_no = debit_account_no; + fts->debit_url = account_base_url; + fts->payto_credit_account = payto_credit_account; fts->auth_username = auth_username; fts->auth_password = auth_password; fts->instance = instance; @@ -735,16 +624,17 @@ TALER_TESTING_cmd_fakebank_transfer_with_instance label); GNUNET_assert (0); } - - struct TALER_TESTING_Command cmd = { - .cls = fts, - .label = label, - .run = &fakebank_transfer_run, - .cleanup = &fakebank_transfer_cleanup, - .traits = &fakebank_transfer_traits - }; - - return cmd; + { + struct TALER_TESTING_Command cmd = { + .cls = fts, + .label = label, + .run = &fakebank_transfer_run, + .cleanup = &fakebank_transfer_cleanup, + .traits = &fakebank_transfer_traits + }; + + return cmd; + } } diff --git a/src/lib/testing_api_cmd_status.c b/src/lib/testing_api_cmd_status.c index 398221a10..2da404fb8 100644 --- a/src/lib/testing_api_cmd_status.c +++ b/src/lib/testing_api_cmd_status.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2014-2018 Taler Systems SA + Copyright (C) 2014-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 @@ -146,6 +146,7 @@ status_run (void *cls, const struct TALER_TESTING_Command *create_reserve; const struct TALER_ReservePrivateKeyP *reserve_priv; struct TALER_ReservePublicKeyP reserve_pub; + const struct TALER_ReservePublicKeyP *reserve_pubp; ss->is = is; GNUNET_assert (NULL != ss->reserve_reference); @@ -163,44 +164,31 @@ status_run (void *cls, /* NOTE: the following line might generate a ERROR log * statements, but it can be ignored. */ - if (GNUNET_OK == TALER_TESTING_get_trait_reserve_priv - (create_reserve, - 0, - &reserve_priv)) + if (GNUNET_OK == + TALER_TESTING_get_trait_reserve_priv (create_reserve, + 0, + &reserve_priv)) { GNUNET_CRYPTO_eddsa_key_get_public (&reserve_priv->eddsa_priv, &reserve_pub.eddsa_pub); + reserve_pubp = &reserve_pub; } else { - const char *transfer_subject; - - if (GNUNET_OK != TALER_TESTING_get_trait_transfer_subject - (create_reserve, - 0, - &transfer_subject)) - { - GNUNET_break (0); - TALER_LOG_ERROR ("The reserve has neither a priv nor a subject line.\n"); - TALER_TESTING_interpreter_fail (is); - return; - } - if (GNUNET_OK != - GNUNET_STRINGS_string_to_data (transfer_subject, - strlen (transfer_subject), - &reserve_pub.eddsa_pub, - sizeof (struct TALER_ReservePublicKeyP))) + TALER_TESTING_get_trait_reserve_pub (create_reserve, + 0, + &reserve_pubp)) { GNUNET_break (0); - TALER_LOG_ERROR ("Transfer subject is not a public key.\n"); + TALER_LOG_ERROR ("The reserve has neither a priv nor a pub.\n"); TALER_TESTING_interpreter_fail (is); return; } } ss->rsh = TALER_EXCHANGE_reserve_status (is->exchange, - &reserve_pub, + reserve_pubp, &reserve_status_cb, ss); } diff --git a/src/lib/testing_api_cmd_track.c b/src/lib/testing_api_cmd_track.c index 41c6be171..070218cfa 100644 --- a/src/lib/testing_api_cmd_track.c +++ b/src/lib/testing_api_cmd_track.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2014-2018 Taler Systems SA + Copyright (C) 2014-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 @@ -190,15 +190,11 @@ deposit_wtid_cb if (NULL != tts->bank_transfer_reference) { const struct TALER_TESTING_Command *bank_transfer_cmd; - char *ws; + const struct TALER_WireTransferIdentifierRawP *wtid_want; /* _this_ wire transfer subject line. */ - ws = GNUNET_STRINGS_data_to_string_alloc (wtid, - sizeof (*wtid)); - bank_transfer_cmd = TALER_TESTING_interpreter_lookup_command (is, tts->bank_transfer_reference); - if (NULL == bank_transfer_cmd) { GNUNET_break (0); @@ -206,12 +202,9 @@ deposit_wtid_cb return; } - /* expected wire transfer subject line. */ - const char *transfer_subject; - if (GNUNET_OK != - TALER_TESTING_get_trait_transfer_subject - (bank_transfer_cmd, 0, &transfer_subject)) + TALER_TESTING_get_trait_wtid + (bank_transfer_cmd, 0, &wtid_want)) { GNUNET_break (0); TALER_TESTING_interpreter_fail (is); @@ -219,15 +212,13 @@ deposit_wtid_cb } /* Compare that expected and gotten subjects match. */ - if (0 != strcmp (ws, transfer_subject)) + if (0 != GNUNET_memcmp (wtid, + wtid_want)) { GNUNET_break (0); - GNUNET_free (ws); TALER_TESTING_interpreter_fail (tts->is); return; } - - GNUNET_free (ws); } break; case MHD_HTTP_ACCEPTED: diff --git a/src/lib/testing_api_trait_reserve_pub.c b/src/lib/testing_api_trait_reserve_pub.c new file mode 100644 index 000000000..b9cd070d3 --- /dev/null +++ b/src/lib/testing_api_trait_reserve_pub.c @@ -0,0 +1,77 @@ +/* + This file is part of TALER + 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 the Free Software Foundation; either version 3, or + (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public + License along with TALER; see the file COPYING. If not, see + <http://www.gnu.org/licenses/> +*/ +/** + * @file exchange-lib/testing_api_trait_reserve_pub.c + * @brief implements reserve public key trait + * @author Christian Grothoff + * @author Marcello Stanisci + */ +#include "platform.h" +#include "taler_json_lib.h" +#include <gnunet/gnunet_curl_lib.h> +#include "exchange_api_handle.h" +#include "taler_signatures.h" +#include "taler_testing_lib.h" + +#define TALER_TESTING_TRAIT_RESERVE_PUBLIC_KEY \ + "reserve-public-key" + +/** + * Obtain a reserve public key from a @a cmd. + * + * @param cmd command to extract the reserve pub from. + * @param index reserve pub's index number. + * @param reserve_pub[out] set to the reserve pub. + * @return #GNUNET_OK on success. + */ +int +TALER_TESTING_get_trait_reserve_pub + (const struct TALER_TESTING_Command *cmd, + unsigned int index, + const struct TALER_ReservePublicKeyP **reserve_pub) +{ + return cmd->traits (cmd->cls, + (const void **) reserve_pub, + TALER_TESTING_TRAIT_RESERVE_PUBLIC_KEY, + index); +} + + +/** + * Offer a reserve public key. + * + * @param index reserve pub's index number. + * @param reserve_pub reserve public key to offer. + * @return the trait. + */ +struct TALER_TESTING_Trait +TALER_TESTING_make_trait_reserve_pub + (unsigned int index, + const struct TALER_ReservePublicKeyP *reserve_pub) +{ + struct TALER_TESTING_Trait ret = { + .index = index, + .trait_name = TALER_TESTING_TRAIT_RESERVE_PUBLIC_KEY, + .ptr = (const void *) reserve_pub + }; + return ret; +} + + +/* end of testing_api_trait_reserve_pub.c */ diff --git a/src/lib/testing_api_trait_string.c b/src/lib/testing_api_trait_string.c index 8d3d5df04..b9f57ab78 100644 --- a/src/lib/testing_api_trait_string.c +++ b/src/lib/testing_api_trait_string.c @@ -30,7 +30,7 @@ #include "taler_testing_lib.h" #define TALER_TESTING_TRAIT_CONTRACT_TERMS "contract-terms" -#define TALER_TESTING_TRAIT_TRANSFER_SUBJECT "transfer-subject" +#define TALER_TESTING_TRAIT_STRING "string" #define TALER_TESTING_TRAIT_AMOUNT "amount" #define TALER_TESTING_TRAIT_URL "url" #define TALER_TESTING_TRAIT_ORDER_ID "order-id" @@ -80,46 +80,45 @@ TALER_TESTING_make_trait_contract_terms /** - * Obtain a transfer subject from @a cmd. + * Obtain a string from @a cmd. * * @param cmd command to extract the subject from. * @param index index number associated with the transfer * subject to offer. - * @param transfer_subject[out] where to write the offered - * transfer subject. + * @param s[out] where to write the offered + * string * @return #GNUNET_OK on success. */ int -TALER_TESTING_get_trait_transfer_subject +TALER_TESTING_get_trait_string (const struct TALER_TESTING_Command *cmd, unsigned int index, - const char **transfer_subject) + const char **s) { return cmd->traits (cmd->cls, - (const void **) transfer_subject, - TALER_TESTING_TRAIT_TRANSFER_SUBJECT, + (const void **) s, + TALER_TESTING_TRAIT_STRING, index); } /** - * Offer transfer subject. + * Offer string. * * @param index index number associated with the transfer * subject being offered. - * @param transfer_subject transfer subject to offer. - * + * @param s transfer subject to offer. * @return the trait. */ struct TALER_TESTING_Trait -TALER_TESTING_make_trait_transfer_subject +TALER_TESTING_make_trait_string (unsigned int index, - const char *transfer_subject) + const char *s) { struct TALER_TESTING_Trait ret = { .index = index, - .trait_name = TALER_TESTING_TRAIT_TRANSFER_SUBJECT, - .ptr = (const void *) transfer_subject + .trait_name = TALER_TESTING_TRAIT_STRING, + .ptr = (const void *) s }; return ret; } |