diff options
author | Christian Grothoff <christian@grothoff.org> | 2024-02-05 01:37:15 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2024-02-05 01:37:15 +0100 |
commit | 7283bdc7e95afc669ce4d2cd741b65efc985c13b (patch) | |
tree | 0264a8921d5b01be1c915c6014e07a93bc1e9bee /src/testing | |
parent | 75a919bf198ea5fda2705de500108c74c78c4772 (diff) |
remove reserves/rewards from public C APIs and tests
Diffstat (limited to 'src/testing')
-rw-r--r-- | src/testing/Makefile.am | 12 | ||||
-rw-r--r-- | src/testing/test_merchant_api.c | 221 | ||||
-rwxr-xr-x | src/testing/test_merchant_reserve_creation.sh | 233 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_delete_reserve.c | 228 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_get_reserve.c | 334 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_get_reserves.c | 285 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_get_rewards.c | 311 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_merchant_get_reward.c | 373 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_post_reserves.c | 278 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_reward_authorize.c | 485 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_reward_pickup.c | 415 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_wallet_get_reward.c | 259 |
12 files changed, 18 insertions, 3416 deletions
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am index 8a0afc9b..e462be16 100644 --- a/src/testing/Makefile.am +++ b/src/testing/Makefile.am @@ -13,7 +13,6 @@ check_SCRIPTS = \ test_merchant_instance_creation.sh \ test_merchant_instance_response.sh \ test_merchant_instance_purge.sh \ - test_merchant_reserve_creation.sh \ test_merchant_product_creation.sh \ test_merchant_order_creation.sh \ test_merchant_transfer_tracking.sh \ @@ -25,7 +24,7 @@ lib_LTLIBRARIES = \ libtalermerchanttesting.la libtalermerchanttesting_la_LDFLAGS = \ - -version-info 2:0:0 \ + -version-info 3:0:0 \ -no-undefined libtalermerchanttesting_la_SOURCES = \ @@ -40,9 +39,6 @@ libtalermerchanttesting_la_SOURCES = \ testing_api_cmd_get_otp_devices.c \ testing_api_cmd_get_product.c \ testing_api_cmd_get_products.c \ - testing_api_cmd_get_reserve.c \ - testing_api_cmd_get_reserves.c \ - testing_api_cmd_get_rewards.c \ testing_api_cmd_get_transfers.c \ testing_api_cmd_get_templates.c \ testing_api_cmd_get_template.c \ @@ -55,14 +51,12 @@ libtalermerchanttesting_la_SOURCES = \ testing_api_cmd_delete_product.c \ testing_api_cmd_delete_template.c \ testing_api_cmd_delete_webhook.c \ - testing_api_cmd_delete_reserve.c \ testing_api_cmd_delete_transfer.c \ testing_api_cmd_forget_order.c \ testing_api_cmd_kyc_get.c \ testing_api_cmd_lock_product.c \ testing_api_cmd_instance_auth.c \ testing_api_cmd_merchant_get_order.c \ - testing_api_cmd_merchant_get_reward.c \ testing_api_cmd_patch_instance.c \ testing_api_cmd_patch_otp_device.c \ testing_api_cmd_patch_product.c \ @@ -75,17 +69,13 @@ libtalermerchanttesting_la_SOURCES = \ testing_api_cmd_post_orders.c \ testing_api_cmd_post_otp_devices.c \ testing_api_cmd_post_products.c \ - testing_api_cmd_post_reserves.c \ testing_api_cmd_post_transfers.c \ testing_api_cmd_post_templates.c \ testing_api_cmd_post_using_templates.c \ testing_api_cmd_post_webhooks.c \ testing_api_cmd_refund_order.c \ - testing_api_cmd_reward_authorize.c \ - testing_api_cmd_reward_pickup.c \ testing_api_cmd_tme.c \ testing_api_cmd_wallet_get_order.c \ - testing_api_cmd_wallet_get_reward.c \ testing_api_cmd_wallet_post_orders_refund.c \ testing_api_cmd_webhook.c \ testing_api_cmd_testserver.c \ diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c index 2a51c29f..5610b987 100644 --- a/src/testing/test_merchant_api.c +++ b/src/testing/test_merchant_api.c @@ -66,10 +66,6 @@ static char *config_file; */ #define EXCHANGE_URL "http://localhost:8081/" -static const char *pickup_amounts_1[] = {"EUR:5", NULL}; - -static const char *pickup_amounts_2[] = {"EUR:0.01", NULL}; - /** * Payto URI of the customer (payer). */ @@ -216,11 +212,11 @@ run (void *cls, "default", MHD_HTTP_NO_CONTENT), TALER_TESTING_cmd_merchant_post_account ( - "instance-create-default-account", - merchant_url, - PAYTO_I1, - NULL, NULL, - MHD_HTTP_OK), + "instance-create-default-account", + merchant_url, + PAYTO_I1, + NULL, NULL, + MHD_HTTP_OK), TALER_TESTING_cmd_merchant_kyc_get ("instance-create-kyc-0", merchant_url, NULL, @@ -937,11 +933,11 @@ run (void *cls, "i1a", MHD_HTTP_NO_CONTENT), TALER_TESTING_cmd_merchant_post_account ( - "instance-create-i1a-account", - merchant_url_i1a, - PAYTO_I1, - NULL, NULL, - MHD_HTTP_OK), + "instance-create-i1a-account", + merchant_url_i1a, + PAYTO_I1, + NULL, NULL, + MHD_HTTP_OK), TALER_TESTING_cmd_merchant_get_product ("get-nx-product-i1a-1", merchant_url_i1a, "nx-product", @@ -1029,187 +1025,6 @@ run (void *cls, TALER_TESTING_cmd_end () }; - struct TALER_TESTING_Command reward[] = { - TALER_TESTING_cmd_merchant_post_reserves ("create-reserve-reward-1", - merchant_url, - "EUR:20.04", - EXCHANGE_URL, - "x-taler-bank", - MHD_HTTP_OK), - TALER_TESTING_cmd_admin_add_incoming_with_ref ( - "create-reserve-reward-1-exch", - "EUR:20.04", - &cred.ba, - payer_payto, - "create-reserve-reward-1", - MHD_HTTP_OK), - /* We need to wait until the merchant re-tries fetching the - reserve from the exchange. */ - cmd_exec_wirewatch ("wirewatch-3"), - TALER_TESTING_cmd_sleep ("reward-sleep", 3), - TALER_TESTING_cmd_reward_authorize ("authorize-reward-1", - merchant_url, - EXCHANGE_URL, - MHD_HTTP_OK, - "reward 1", - "EUR:5.01"), - TALER_TESTING_cmd_reward_authorize_from_reserve ("authorize-reward-2", - merchant_url, - EXCHANGE_URL, - "create-reserve-reward-1-exch", - MHD_HTTP_OK, - "reward 2", - "EUR:5.01"), - TALER_TESTING_cmd_wallet_get_reward ("get-reward-1", - merchant_url, - "authorize-reward-1", - MHD_HTTP_OK), - TALER_TESTING_cmd_merchant_get_reward ("merchant-get-reward-1", - merchant_url, - "authorize-reward-1", - MHD_HTTP_OK), - TALER_TESTING_cmd_get_rewards ("get-rewards-1", - merchant_url, - MHD_HTTP_OK, - "authorize-reward-2", - "authorize-reward-1", - NULL), - TALER_TESTING_cmd_get_rewards2 ("get-rewards-1-asc", - merchant_url, - 0, - 20, - MHD_HTTP_OK, - "authorize-reward-1", - "authorize-reward-2", - NULL), - TALER_TESTING_cmd_get_rewards2 ("get-rewards-1-asc-offset", - merchant_url, - 1, - 20, - MHD_HTTP_OK, - "authorize-reward-2", - NULL), - TALER_TESTING_cmd_merchant_get_reserves ("get-reserves-1", - merchant_url, - MHD_HTTP_OK, - "create-reserve-reward-1-exch", - NULL), - TALER_TESTING_cmd_merchant_get_reserve ("get-reserve-1", - merchant_url, - MHD_HTTP_OK, - "create-reserve-reward-1-exch"), - TALER_TESTING_cmd_merchant_get_reserve_with_rewards ("get-reserve-2", - merchant_url, - MHD_HTTP_OK, - "create-reserve-reward-1-exch", - "authorize-reward-1", - "authorize-reward-2", - NULL), - TALER_TESTING_cmd_reward_pickup ("pickup-reward-1", - merchant_url, - MHD_HTTP_OK, - "authorize-reward-1", - pickup_amounts_1), - TALER_TESTING_cmd_wallet_get_reward2 ("query-reward-2", - merchant_url, - "authorize-reward-1", - "EUR:0.01", - MHD_HTTP_OK), - TALER_TESTING_cmd_reward_pickup ("pickup-reward-2", - merchant_url, - MHD_HTTP_OK, - "authorize-reward-2", - pickup_amounts_1), - - TALER_TESTING_cmd_reward_pickup_with_ec ("pickup-reward-3-too-much", - merchant_url, - MHD_HTTP_BAD_REQUEST, - "authorize-reward-1", - pickup_amounts_1, - TALER_EC_MERCHANT_REWARD_PICKUP_AMOUNT_EXCEEDS_REWARD_REMAINING), - - TALER_TESTING_cmd_reward_pickup ("pickup-reward-4", - merchant_url, - MHD_HTTP_OK, - "authorize-reward-1", - pickup_amounts_2), - TALER_TESTING_cmd_merchant_get_reward_with_pickups ("merchant-get-reward-2", - merchant_url, - "authorize-reward-1", - MHD_HTTP_OK, - "pickup-reward-1", - "pickup-reward-4", - NULL), - - /* This command tests the authorization of reward - * against a reserve that does not exist. This is - * implemented by passing a "reward instance" that - * specifies a reserve key that was never used to - * actually create a reserve. */ - TALER_TESTING_cmd_merchant_post_reserves_fake ( - "create-reserve-reward-2-fake"), - TALER_TESTING_cmd_reward_authorize_from_reserve_with_ec ( - "authorize-reward-null", - merchant_url, - EXCHANGE_URL, - "create-reserve-reward-2-fake", - MHD_HTTP_NOT_FOUND, - "reward 3", - "EUR:5.01", - TALER_EC_MERCHANT_PRIVATE_POST_REWARD_AUTHORIZE_RESERVE_NOT_FOUND), - - /* Test reserve with insufficient funds */ - TALER_TESTING_cmd_merchant_post_reserves ("create-reserve-reward-2", - merchant_url, - "EUR:1.04", - EXCHANGE_URL, - "x-taler-bank", - MHD_HTTP_OK), - TALER_TESTING_cmd_admin_add_incoming_with_ref ( - "create-reserve-reward-2-exch", - "EUR:1.04", - &cred.ba, - payer_payto, - "create-reserve-reward-2", - MHD_HTTP_OK), - cmd_exec_wirewatch ("wirewatch-4"), - TALER_TESTING_cmd_reward_authorize_from_reserve_with_ec ( - "authorize-reward-insufficient-funds", - merchant_url, - EXCHANGE_URL, - "create-reserve-reward-2", - MHD_HTTP_PRECONDITION_FAILED, - "reward 4", - "EUR:5.01", - TALER_EC_MERCHANT_PRIVATE_POST_REWARD_AUTHORIZE_INSUFFICIENT_FUNDS), - TALER_TESTING_cmd_reward_authorize_fake ("fake-reward-authorization"), - TALER_TESTING_cmd_reward_pickup_with_ec ("pickup-non-existent-id", - merchant_url, - MHD_HTTP_NOT_FOUND, - "fake-reward-authorization", - pickup_amounts_1, - TALER_EC_MERCHANT_GENERIC_REWARD_ID_UNKNOWN), - TALER_TESTING_cmd_merchant_get_reserves ("get-reserves-2", - merchant_url, - MHD_HTTP_OK, - "create-reserve-reward-1", - "create-reserve-reward-2", - NULL), - TALER_TESTING_cmd_merchant_delete_reserve ("delete-reserve-reward-1", - merchant_url, - "create-reserve-reward-1", - MHD_HTTP_NO_CONTENT), - TALER_TESTING_cmd_merchant_purge_reserve ("delete-reserve-reward-2", - merchant_url, - "create-reserve-reward-1", - MHD_HTTP_NO_CONTENT), - TALER_TESTING_cmd_merchant_purge_reserve ("delete-reserve-reward-3", - merchant_url, - "create-reserve-reward-1", - MHD_HTTP_NOT_FOUND), - TALER_TESTING_cmd_end () - }; - struct TALER_TESTING_Command pay_again[] = { cmd_transfer_to_exchange ("create-reserve-20", "EUR:20.04"), @@ -1434,7 +1249,7 @@ run (void *cls, merchant_url, "otp-dev", "my OTP device", - "otp-key", + "FEE4P2J", TALER_MCA_WITH_PRICE, 0, MHD_HTTP_NO_CONTENT), @@ -1454,7 +1269,7 @@ run (void *cls, merchant_url, "template-amount", "a different template with an amount", - NULL, + NULL, GNUNET_JSON_PACK ( GNUNET_JSON_pack_uint64 ("minimum_age", 0), GNUNET_JSON_pack_time_rel ("pay_duration", @@ -1693,11 +1508,11 @@ run (void *cls, "default", MHD_HTTP_NO_CONTENT), TALER_TESTING_cmd_merchant_post_account ( - "instance-create-default-account", - merchant_url, - PAYTO_I1, - NULL, NULL, - MHD_HTTP_OK), + "instance-create-default-account", + merchant_url, + PAYTO_I1, + NULL, NULL, + MHD_HTTP_OK), TALER_TESTING_cmd_merchant_post_instances ("instance-create-i1", merchant_url, "i1", @@ -1937,8 +1752,6 @@ run (void *cls, pay_abort), TALER_TESTING_cmd_batch ("refund", refund), - TALER_TESTING_cmd_batch ("reward", - reward), TALER_TESTING_cmd_batch ("templates", templates), TALER_TESTING_cmd_batch ("webhooks", diff --git a/src/testing/test_merchant_reserve_creation.sh b/src/testing/test_merchant_reserve_creation.sh deleted file mode 100755 index 207fd821..00000000 --- a/src/testing/test_merchant_reserve_creation.sh +++ /dev/null @@ -1,233 +0,0 @@ -#!/bin/bash -# This file is part of TALER -# Copyright (C) 2014-2023 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/> -# - -set -eu - -# Replace with 0 for nexus... -USE_FAKEBANK=1 -if [ 1 = "$USE_FAKEBANK" ] -then - ACCOUNT="exchange-account-2" - WIRE_METHOD="x-taler-bank" - BANK_FLAGS="-f -d $WIRE_METHOD -u $ACCOUNT" - BANK_URL="http://localhost:8082/" -else - ACCOUNT="exchange-account-1" - WIRE_METHOD="iban" - BANK_FLAGS="-ns -d $WIRE_METHOD -u $ACCOUNT" - BANK_URL="http://localhost:18082/" -fi - -. setup.sh -# Launch exchange, merchant and bank. -setup -c "test_template.conf" \ - -em \ - $BANK_FLAGS -LAST_RESPONSE=$(mktemp -p "${TMPDIR:-/tmp}" test_response.conf-XXXXXX) -CONF="test_template.conf.edited" - -echo -n "Configuring merchant instance ..." - -STATUS=$(curl -H "Content-Type: application/json" -X POST \ - -H 'Authorization: Bearer secret-token:super_secret' \ - http://localhost:9966/management/instances \ - -d '{"auth":{"method":"external"},"id":"default","name":"default","user_type":"business","address":{},"jurisdiction":{},"use_stefan":true,"default_wire_transfer_delay":{"d_us" : 50000000},"default_pay_delay":{"d_us": 60000000}}' \ - -w "%{http_code}" -s -o /dev/null) - -if [ "$STATUS" != "204" ] -then - exit_fail "Expected 204, instance created. Got instead: $STATUS" -fi -echo "Ok" -echo -n "Configuring merchant account ..." -STATUS=$(curl -H "Content-Type: application/json" -X POST \ - -H 'Authorization: Bearer secret-token:super_secret' \ - http://localhost:9966/instances/default/private/accounts \ - -d '{"payto_uri":"payto://x-taler-bank/localhost:18082/fortythree"}' \ - -w "%{http_code}" -s -o /dev/null) - -if [ "$STATUS" != "200" ] -then - exit_fail "Expected 200 OK. Got: $STATUS" -fi - -echo "OK" - -echo -n "Creating reserve ..." - -STATUS=$(curl 'http://localhost:9966/instances/default/private/reserves' \ - -d '{"initial_balance":"TESTKUDOS:2","exchange_url":"http://localhost:8081/","wire_method":"'"$WIRE_METHOD"'"}' \ - -w "%{http_code}" -s -o "$LAST_RESPONSE") - -if [ "$STATUS" != "200" ] -then - cat "$LAST_RESPONSE" - exit_fail "Expected 200, reserve created. Got instead: $STATUS" -fi - -echo "OK" - -RESERVE_PUB=$(jq -r .reserve_pub < "$LAST_RESPONSE") - -STATUS=$(curl 'http://localhost:9966/instances/default/private/reserves/'"$RESERVE_PUB" \ - -w "%{http_code}" -s -o "$LAST_RESPONSE") - -FUNDED=$(jq -r '.merchant_initial_amount == .exchange_initial_amount' < "$LAST_RESPONSE") - -if [ "$FUNDED" != "false" ] -then - cat "$LAST_RESPONSE" - exit_fail "Should not yet be funded if we just created. Got: $STATUS is founded: $FUNDED" -fi - - -echo -n "Wire transferring... " -# Exchange wants TESTKUDOS:2 from account 43, under RESERVE_PUB. - -if [ 1 = "$USE_FAKEBANK" ] -then - BODY='{"reserve_pub":"'"$RESERVE_PUB"'","debit_account":"payto://x-taler-bank/localhost/fortythree","amount":"TESTKUDOS:2"}' - curl -X POST \ - -d "$BODY" \ - -s \ - http://localhost:8082/accounts/exchange/taler-wire-gateway/admin/add-incoming \ - > /dev/null -else - echo "FIXME: not implemented for current libeufin" - exit 1 - EXCHANGE_PAYTO=$(get_payto_uri exchange x) - export LIBEUFIN_SANDBOX_USERNAME=fortythree - export LIBEUFIN_SANDBOX_PASSWORD=x - export LIBEUFIN_SANDBOX_URL="http://localhost:18082/" - libeufin-cli sandbox demobank new-transaction \ - --bank-account "fortythree" \ - --payto-with-subject "$EXCHANGE_PAYTO&message=$RESERVE_PUB" \ - --amount "TESTKUDOS:2" - unset LIBEUFIN_SANDBOX_USERNAME - unset LIBEUFIN_SANDBOX_PASSWORD - unset LIBEUFIN_SANDBOX_URL - echo "OK" - echo -n "Give Nexus time to detect the payment (FIXME)... " - sleep 10 # FIXME-MS: replace with call to Nexus to right now poll the sandbox ... - # This seems to not work (exchange user unknown). Not sure why. - #export LIBEUFIN_NEXUS_USERNAME=exchange - #export LIBEUFIN_NEXUS_PASSWORD=x - #export LIBEUFIN_NEXUS_URL="http://localhost:8082/" - #libeufin-cli \ - # accounts \ - # fetch-transactions \ - # exchange \ - # &> libeufin-transfer-fetch.out - #unset LIBEUFIN_NEXUS_USERNAME - #unset LIBEUFIN_NEXUS_PASSWORD - #unset LIBEUFIN_NEXUS_URL -fi -echo "OK" - -echo "Fetch transaction for exchange" -# Run wirewatch here, now, and only once -taler-exchange-wirewatch \ - -c "$CONF" \ - -t \ - -L "INFO" \ - &> taler-exchange-wirewatch.log - -STATUS=$(curl 'http://localhost:9966/instances/default/private/reserves/'"$RESERVE_PUB" \ - -w "%{http_code}" -s -o "$LAST_RESPONSE") -FUNDED=$(jq -r '.merchant_initial_amount == .exchange_initial_amount' < "$LAST_RESPONSE") - -if [ "$FUNDED" != "true" ] -then - cat "$LAST_RESPONSE" - exit_fail "should be funded. got: $STATUS is founded: $FUNDED" -fi - -ACCOUNTS=$(jq -r '.accounts|length' < "$LAST_RESPONSE") -if [ "x$ACCOUNTS" != "x1" ] -then - cat "$LAST_RESPONSE" - exit_fail "Expected 1 account in response. got: $ACCOUNTS" -fi - -echo -n "authorizing reward ..." - -STATUS=$(curl 'http://localhost:9966/instances/default/private/reserves/'"$RESERVE_PUB"'/authorize-reward' \ - -d '{"amount":"TESTKUDOS:1","justification":"off course","next_url":"https://taler.net/"}' \ - -w "%{http_code}" -s -o "$LAST_RESPONSE") - -if [ "$STATUS" != "200" ] -then - exit_fail "should respond failed, we did not fund yet. got: $STATUS" -fi -echo "OK" - -echo -n "Checking reward ..." -STATUS=$(curl 'http://localhost:9966/instances/default/private/reserves/'"$RESERVE_PUB"'?rewards=yes' \ - -w "%{http_code}" -s -o "$LAST_RESPONSE") - -REWARDS_SIZE=$(jq -r ".rewards | length" < "$LAST_RESPONSE") - -if [ "$REWARDS_SIZE" != "1" ] -then - cat "$LAST_RESPONSE" - exit_fail "Expected 1 reward. got: $REWARDS_SIZE" -fi - -REWARD_ID=$(jq -r .rewards[0].reward_id < "$LAST_RESPONSE") - -echo "Found" - -echo -n "Checking reward status ..." - -STATUS=$(curl 'http://localhost:9966/instances/default/private/rewards/'"$REWARD_ID" \ - -w "%{http_code}" -s -o "$LAST_RESPONSE") - -if [ "$STATUS" != "200" ] -then - cat "$LAST_RESPONSE" - exit_fail "Expected 200, reward found. got: $STATUS" -fi - -echo -n " ... " - -STATUS=$(curl 'http://localhost:9966/instances/default/private/rewards/'"$REWARD_ID"'?pickups=yes' \ - -w "%{http_code}" -s -o "$LAST_RESPONSE") - -if [ "$STATUS" != "200" ] -then - cat "$LAST_RESPONSE" - exit_fail "Expected 200, reward found. got: $STATUS" -fi -echo "OK" - -echo -n "trying to create invalid reserve ..." - -STATUS=$(curl 'http://localhost:9966/instances/default/private/reserves' \ - -d '{"initial_balance":"INVALID:2","exchange_url":"http://localhost:8081/","wire_method":"iban"}' \ - -w "%{http_code}" -s -o "$LAST_RESPONSE") - -if [ "$STATUS" != "409" ] -then - exit_fail "Expected 409, bad currency. got: $STATUS" -fi -echo "FAILED (which is expected)" - -echo "Test PASSED" - -exit 0 diff --git a/src/testing/testing_api_cmd_delete_reserve.c b/src/testing/testing_api_cmd_delete_reserve.c deleted file mode 100644 index 38742630..00000000 --- a/src/testing/testing_api_cmd_delete_reserve.c +++ /dev/null @@ -1,228 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 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 testing_api_cmd_delete_reserve.c - * @brief command to test DELETE /reserves/$RESERVE_PUB - * @author Jonathan Buchanan - */ -#include "platform.h" -#include <taler/taler_exchange_service.h> -#include <taler/taler_testing_lib.h> -#include "taler_merchant_service.h" -#include "taler_merchant_testing_lib.h" - - -/** - * State of a "DELETE /reserves/$RESERVE_PUB" CMD. - */ -struct DeleteReserveState -{ - - /** - * Handle for a "DELETE reserve" request. - */ - struct TALER_MERCHANT_ReserveDeleteHandle *rdh; - - /** - * The interpreter state. - */ - struct TALER_TESTING_Interpreter *is; - - /** - * Base URL of the merchant serving the request. - */ - const char *merchant_url; - - /** - * Reference to a command that provides a reserve. - */ - const char *reserve_reference; - - /** - * Expected HTTP response code. - */ - unsigned int http_status; - - /** - * Use purge, not delete. - */ - bool purge; - -}; - - -/** - * Callback for a DELETE /reserves/$RESERVE_PUB operation. - * - * @param cls closure for this function - * @param hr response being processed - */ -static void -delete_reserve_cb (void *cls, - const struct TALER_MERCHANT_HttpResponse *hr) -{ - struct DeleteReserveState *drs = cls; - - drs->rdh = NULL; - if (drs->http_status != hr->http_status) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Unexpected response code %u (%d) to command %s\n", - hr->http_status, - (int) hr->ec, - TALER_TESTING_interpreter_get_current_label (drs->is)); - TALER_TESTING_interpreter_fail (drs->is); - return; - } - switch (hr->http_status) - { - case MHD_HTTP_NO_CONTENT: - break; - case MHD_HTTP_NOT_FOUND: - break; - case MHD_HTTP_CONFLICT: - break; - default: - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Unhandled HTTP status %u for DELETE reserve.\n", - hr->http_status); - } - TALER_TESTING_interpreter_next (drs->is); -} - - -/** - * Run the "DELETE reserve" CMD. - * - * @param cls closure. - * @param cmd command being run now. - * @param is interpreter state. - */ -static void -delete_reserve_run (void *cls, - const struct TALER_TESTING_Command *cmd, - struct TALER_TESTING_Interpreter *is) -{ - struct DeleteReserveState *drs = cls; - const struct TALER_TESTING_Command *reserve_cmd; - const struct TALER_ReservePublicKeyP *reserve_pub; - - reserve_cmd = TALER_TESTING_interpreter_lookup_command ( - is, - drs->reserve_reference); - if (GNUNET_OK != - TALER_TESTING_get_trait_reserve_pub (reserve_cmd, - &reserve_pub)) - TALER_TESTING_FAIL (is); - - drs->is = is; - if (drs->purge) - drs->rdh = TALER_MERCHANT_reserve_purge ( - TALER_TESTING_interpreter_get_context (is), - drs->merchant_url, - reserve_pub, - &delete_reserve_cb, - drs); - else - drs->rdh = TALER_MERCHANT_reserve_delete ( - TALER_TESTING_interpreter_get_context (is), - drs->merchant_url, - reserve_pub, - &delete_reserve_cb, - drs); - - GNUNET_assert (NULL != drs->rdh); -} - - -/** - * Free the state of a "DELETE reserve" CMD, and possibly - * cancel a pending operation thereof. - * - * @param cls closure. - * @param cmd command being run. - */ -static void -delete_reserve_cleanup (void *cls, - const struct TALER_TESTING_Command *cmd) -{ - struct DeleteReserveState *drs = cls; - - if (NULL != drs->rdh) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "DELETE /reserves/$RESERVE_PUB operation did not complete\n"); - TALER_MERCHANT_reserve_delete_cancel (drs->rdh); - } - GNUNET_free (drs); -} - - -struct TALER_TESTING_Command -TALER_TESTING_cmd_merchant_delete_reserve (const char *label, - const char *merchant_url, - const char *reserve_reference, - unsigned int http_status) -{ - struct DeleteReserveState *drs; - - drs = GNUNET_new (struct DeleteReserveState); - drs->merchant_url = merchant_url; - drs->reserve_reference = reserve_reference; - drs->http_status = http_status; - { - struct TALER_TESTING_Command cmd = { - .cls = drs, - .label = label, - .run = &delete_reserve_run, - .cleanup = &delete_reserve_cleanup - }; - - return cmd; - } -} - - -struct TALER_TESTING_Command -TALER_TESTING_cmd_merchant_purge_reserve (const char *label, - const char *merchant_url, - const char *reserve_reference, - unsigned int http_status) -{ - struct DeleteReserveState *drs; - - drs = GNUNET_new (struct DeleteReserveState); - drs->merchant_url = merchant_url; - drs->reserve_reference = reserve_reference; - drs->http_status = http_status; - drs->purge = true; - { - struct TALER_TESTING_Command cmd = { - .cls = drs, - .label = label, - .run = &delete_reserve_run, - .cleanup = &delete_reserve_cleanup - }; - - return cmd; - } -} - - -/* end of testing_api_cmd_delete_reserve.c */ diff --git a/src/testing/testing_api_cmd_get_reserve.c b/src/testing/testing_api_cmd_get_reserve.c deleted file mode 100644 index e9589dbb..00000000 --- a/src/testing/testing_api_cmd_get_reserve.c +++ /dev/null @@ -1,334 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2020-2023 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 testing_api_cmd_get_reserve.c - * @brief command to test GET /private/reserves/$RESERVE_PUB - * @author Jonathan Buchanan - */ -#include "platform.h" -#include <taler/taler_exchange_service.h> -#include <taler/taler_testing_lib.h> -#include "taler_merchant_service.h" -#include "taler_merchant_testing_lib.h" - - -struct GetReserveState -{ - - /** - * Handle for a "GET reserve" request. - */ - struct TALER_MERCHANT_ReserveGetHandle *rgh; - - /** - * The interpreter state. - */ - struct TALER_TESTING_Interpreter *is; - - /** - * Base URL of the merchant serving the request. - */ - const char *merchant_url; - - /** - * Label for a command that created a reserve. - */ - const char *reserve_reference; - - /** - * Expected HTTP response code. - */ - unsigned int http_status; - - /** - * Fetch rewards - */ - bool fetch_rewards; - - /** - * Length of @e rewards. - */ - unsigned int rewards_length; - - /** - * The list of references to rewards. - */ - const char **rewards; -}; - - -static void -get_reserve_cb (void *cls, - const struct TALER_MERCHANT_ReserveGetResponse *rgr) -{ - struct GetReserveState *grs = cls; - const struct TALER_MERCHANT_HttpResponse *hr = &rgr->hr; - const struct TALER_TESTING_Command *reserve_cmd; - - reserve_cmd = TALER_TESTING_interpreter_lookup_command ( - grs->is, - grs->reserve_reference); - - grs->rgh = NULL; - if (grs->http_status != hr->http_status) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Unexpected response code %u (%d) to command %s\n", - hr->http_status, - (int) hr->ec, - TALER_TESTING_interpreter_get_current_label (grs->is)); - TALER_TESTING_interpreter_fail (grs->is); - return; - } - switch (hr->http_status) - { - case MHD_HTTP_OK: - { - const struct TALER_MERCHANT_ReserveSummary *rs = &rgr->details.ok.rs; - const struct TALER_Amount *initial_amount; - if (GNUNET_OK != - TALER_TESTING_get_trait_amount (reserve_cmd, - &initial_amount)) - TALER_TESTING_interpreter_fail (grs->is); - if ((GNUNET_OK != - TALER_amount_cmp_currency (&rs->merchant_initial_amount, - initial_amount)) || - (0 != TALER_amount_cmp (&rs->merchant_initial_amount, - initial_amount))) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Reserve initial amount does not match\n"); - TALER_TESTING_interpreter_fail (grs->is); - return; - } - } - { - unsigned int rewards_length = rgr->details.ok.rewards_length; - const struct TALER_MERCHANT_RewardDetails *rewards = - rgr->details.ok.rewards; - - if (rewards_length != grs->rewards_length) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Number of rewards authorized does not match\n"); - TALER_TESTING_interpreter_fail (grs->is); - return; - } - for (unsigned int i = 0; i < rewards_length; ++i) - { - const struct TALER_TESTING_Command *reward_cmd; - - reward_cmd = TALER_TESTING_interpreter_lookup_command (grs->is, - grs->rewards[i]); - { - const struct TALER_RewardIdentifierP *reward_id; - - if (GNUNET_OK != - TALER_TESTING_get_trait_reward_id (reward_cmd, - &reward_id)) - TALER_TESTING_interpreter_fail (grs->is); - - if (0 != GNUNET_memcmp (&rewards[i].reward_id, - reward_id)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Reserve reward id does not match\n"); - TALER_TESTING_interpreter_fail (grs->is); - return; - } - } - { - const struct TALER_Amount *total_amount; - - if (GNUNET_OK != - TALER_TESTING_get_trait_amount (reward_cmd, - &total_amount)) - TALER_TESTING_interpreter_fail (grs->is); - - if ((GNUNET_OK != - TALER_amount_cmp_currency (&rewards[i].amount, - total_amount)) || - (0 != TALER_amount_cmp (&rewards[i].amount, - total_amount))) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Reserve reward amount does not match\n"); - TALER_TESTING_interpreter_fail (grs->is); - return; - } - } - { - const char *reason; - - if (GNUNET_OK != - TALER_TESTING_get_trait_reason (reward_cmd, - &reason)) - TALER_TESTING_interpreter_fail (grs->is); - - if (0 != strcmp (rewards[i].reason, - reason)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Reserve reward reason does not match\n"); - TALER_TESTING_interpreter_fail (grs->is); - return; - } - } - } - } - break; - default: - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Unhandled HTTP status.\n"); - } - TALER_TESTING_interpreter_next (grs->is); -} - - -/** - * Run the "GET /private/reserves/$RESERVE_PUB" CMD. - * - * @param cls closure. - * @param cmd command being run now. - * @param is interpreter state. - */ -static void -get_reserve_run (void *cls, - const struct TALER_TESTING_Command *cmd, - struct TALER_TESTING_Interpreter *is) -{ - struct GetReserveState *grs = cls; - const struct TALER_TESTING_Command *reserve_cmd; - const struct TALER_ReservePublicKeyP *reserve_pub; - - reserve_cmd = TALER_TESTING_interpreter_lookup_command ( - is, - grs->reserve_reference); - if (GNUNET_OK != - TALER_TESTING_get_trait_reserve_pub (reserve_cmd, - &reserve_pub)) - TALER_TESTING_FAIL (is); - - grs->is = is; - grs->rgh = TALER_MERCHANT_reserve_get (TALER_TESTING_interpreter_get_context ( - is), - grs->merchant_url, - reserve_pub, - grs->fetch_rewards, - &get_reserve_cb, - grs); - - GNUNET_assert (NULL != grs->rgh); -} - - -/** - * Free the state of a "GET reserve" CMD, and possibly - * cancel a pending operation thereof. - * - * @param cls closure. - * @param cmd command being run. - */ -static void -get_reserve_cleanup (void *cls, - const struct TALER_TESTING_Command *cmd) -{ - struct GetReserveState *grs = cls; - - if (NULL != grs->rgh) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "GET /private/reserve/$RESERVE_PUB operation did not complete\n"); - TALER_MERCHANT_reserve_get_cancel (grs->rgh); - } - GNUNET_array_grow (grs->rewards, - grs->rewards_length, - 0); - GNUNET_free (grs); -} - - -struct TALER_TESTING_Command -TALER_TESTING_cmd_merchant_get_reserve (const char *label, - const char *merchant_url, - unsigned int http_status, - const char *reserve_reference) -{ - struct GetReserveState *grs; - - grs = GNUNET_new (struct GetReserveState); - grs->merchant_url = merchant_url; - grs->http_status = http_status; - grs->reserve_reference = reserve_reference; - grs->fetch_rewards = false; - { - struct TALER_TESTING_Command cmd = { - .cls = grs, - .label = label, - .run = &get_reserve_run, - .cleanup = &get_reserve_cleanup - }; - - return cmd; - } -} - - -struct TALER_TESTING_Command -TALER_TESTING_cmd_merchant_get_reserve_with_rewards (const char *label, - const char *merchant_url, - unsigned int http_status, - const char * - reserve_reference, - ...) -{ - struct GetReserveState *grs; - - grs = GNUNET_new (struct GetReserveState); - grs->merchant_url = merchant_url; - grs->http_status = http_status; - grs->reserve_reference = reserve_reference; - grs->fetch_rewards = true; - { - const char *clabel; - va_list ap; - - va_start (ap, reserve_reference); - while (NULL != (clabel = va_arg (ap, const char *))) - { - GNUNET_array_append (grs->rewards, - grs->rewards_length, - clabel); - } - va_end (ap); - } - { - struct TALER_TESTING_Command cmd = { - .cls = grs, - .label = label, - .run = &get_reserve_run, - .cleanup = &get_reserve_cleanup - }; - - return cmd; - } -} - - -/* end of testing_api_cmd_get_reserve.c */ diff --git a/src/testing/testing_api_cmd_get_reserves.c b/src/testing/testing_api_cmd_get_reserves.c deleted file mode 100644 index d62a73e3..00000000 --- a/src/testing/testing_api_cmd_get_reserves.c +++ /dev/null @@ -1,285 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2020-2023 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 testing_api_cmd_get_reserves.c - * @brief command to test GET /private/reserves - * @author Jonathan Buchanan - */ -#include "platform.h" -#include <taler/taler_exchange_service.h> -#include <taler/taler_testing_lib.h> -#include "taler_merchant_service.h" -#include "taler_merchant_testing_lib.h" - - -/** - * State of a "GET reserves" CMD - */ -struct GetReservesState -{ - - /** - * Handle for a "GET reserves" request. - */ - struct TALER_MERCHANT_ReservesGetHandle *rgh; - - /** - * The interpreter state. - */ - struct TALER_TESTING_Interpreter *is; - - /** - * A list of reserves to compare with. - */ - const char **reserves; - - /** - * Length of @e reserve_refs. - */ - unsigned int reserves_length; - - /** - * Base URL of the merchant serving the request. - */ - const char *merchant_url; - - /** - * Expected HTTP response code. - */ - unsigned int http_status; -}; - - -static void -get_reserves_cb (void *cls, - const struct TALER_MERCHANT_ReservesGetResponse *rgr) -{ - struct GetReservesState *grs = cls; - - grs->rgh = NULL; - if (grs->http_status != rgr->hr.http_status) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Unexpected response code %u (%d) to command %s\n", - rgr->hr.http_status, - (int) rgr->hr.ec, - TALER_TESTING_interpreter_get_current_label (grs->is)); - TALER_TESTING_interpreter_fail (grs->is); - return; - } - switch (rgr->hr.http_status) - { - case MHD_HTTP_OK: - { - bool matched[GNUNET_NZL (rgr->details.ok.reserves_length)]; - bool fail = false; - - if (rgr->details.ok.reserves_length != grs->reserves_length) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Length of reserves found does not match\n"); - TALER_TESTING_interpreter_fail (grs->is); - return; - } - /* check if the data returned matches that from the POST / PATCH */ - memset (matched, - 0, - sizeof (matched)); - for (unsigned int i = 0; i < rgr->details.ok.reserves_length; ++i) - { - const struct TALER_MERCHANT_ReserveSummary *reserve - = &rgr->details.ok.reserves[i]; - - for (unsigned int j = 0; j < grs->reserves_length; ++j) - { - const struct TALER_TESTING_Command *reserve_cmd; - bool match = true; - - reserve_cmd = TALER_TESTING_interpreter_lookup_command ( - grs->is, - grs->reserves[j]); - { - const struct TALER_ReservePublicKeyP *reserve_pub; - - if (GNUNET_OK != - TALER_TESTING_get_trait_reserve_pub (reserve_cmd, - &reserve_pub)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Could not fetch reserve public key\n"); - TALER_TESTING_interpreter_fail (grs->is); - return; - } - if (0 != GNUNET_memcmp (&reserve->reserve_pub, - reserve_pub)) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Reserve public key does not match, got %s\n", - TALER_B2S (&reserve->reserve_pub)); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Reserve public key does not match, expected %s\n", - TALER_B2S (reserve_pub)); - match = false; - } - } - { - const struct TALER_Amount *initial; - - if (GNUNET_OK != - TALER_TESTING_get_trait_amount (reserve_cmd, - &initial)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Could not fetch reserve initial balance\n"); - TALER_TESTING_interpreter_fail (grs->is); - return; - } - if ((GNUNET_OK != - TALER_amount_cmp_currency ( - &reserve->merchant_initial_amount, - initial)) || - (0 != TALER_amount_cmp (&reserve->merchant_initial_amount, - initial))) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Reserve initial amount does not match, got %s\n", - TALER_amount2s ( - &reserve->merchant_initial_amount)); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Reserve initial amount does not match, wanted %s\n", - TALER_amount2s (initial)); - match = false; - } - } - if (match) - matched[i] = true; - } - } - for (unsigned int i = 0; i < rgr->details.ok.reserves_length; ++i) - if (! matched[i]) - fail = true; - if (fail) - { - TALER_TESTING_interpreter_fail (grs->is); - return; - } - break; - } - default: - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Unhandled HTTP status %u.\n", - rgr->hr.http_status); - break; - } - TALER_TESTING_interpreter_next (grs->is); -} - - -/** - * Run the "GET /private/reserves" CMD. - * - * @param cls closure. - * @param cmd command being run now. - * @param is interpreter state. - */ -static void -get_reserves_run (void *cls, - const struct TALER_TESTING_Command *cmd, - struct TALER_TESTING_Interpreter *is) -{ - struct GetReservesState *grs = cls; - - grs->is = is; - grs->rgh = TALER_MERCHANT_reserves_get ( - TALER_TESTING_interpreter_get_context (is), - grs->merchant_url, - GNUNET_TIME_UNIT_ZERO_TS, - TALER_EXCHANGE_YNA_ALL, - TALER_EXCHANGE_YNA_ALL, - &get_reserves_cb, - grs); - - GNUNET_assert (NULL != grs->rgh); -} - - -/** - * Free the state of a "GET reserves" CMD, and possibly - * cancel a pending operation thereof. - * - * @param cls closure. - * @param cmd command being run. - */ -static void -get_reserves_cleanup (void *cls, - const struct TALER_TESTING_Command *cmd) -{ - struct GetReservesState *grs = cls; - - if (NULL != grs->rgh) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "GET /private/reserves operation did not complete\n"); - TALER_MERCHANT_reserves_get_cancel (grs->rgh); - } - GNUNET_array_grow (grs->reserves, - grs->reserves_length, - 0); - GNUNET_free (grs); -} - - -struct TALER_TESTING_Command -TALER_TESTING_cmd_merchant_get_reserves (const char *label, - const char *merchant_url, - unsigned int http_status, - ...) -{ - struct GetReservesState *grs; - - grs = GNUNET_new (struct GetReservesState); - grs->merchant_url = merchant_url; - grs->http_status = http_status; - { - const char *clabel; - va_list ap; - - va_start (ap, http_status); - while (NULL != (clabel = va_arg (ap, const char *))) - { - GNUNET_array_append (grs->reserves, - grs->reserves_length, - clabel); - } - va_end (ap); - } - { - struct TALER_TESTING_Command cmd = { - .cls = grs, - .label = label, - .run = &get_reserves_run, - .cleanup = &get_reserves_cleanup - }; - - return cmd; - } -} - - -/* end of testing_api_cmd_get_reserves.c */ diff --git a/src/testing/testing_api_cmd_get_rewards.c b/src/testing/testing_api_cmd_get_rewards.c deleted file mode 100644 index 4bc72f79..00000000 --- a/src/testing/testing_api_cmd_get_rewards.c +++ /dev/null @@ -1,311 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2020-2023 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 testing_api_cmd_get_rewards.c - * @brief command to test GET /private/rewards - * @author Jonathan Buchanan - */ -#include "platform.h" -#include <taler/taler_exchange_service.h> -#include <taler/taler_testing_lib.h> -#include "taler_merchant_service.h" -#include "taler_merchant_testing_lib.h" - - -/** - * State of a "GET rewards" CMD. - */ -struct GetRewardsState -{ - - /** - * Handle for a "GET rewards" request. - */ - struct TALER_MERCHANT_RewardsGetHandle *tgh; - - /** - * The interpreter state. - */ - struct TALER_TESTING_Interpreter *is; - - /** - * Base URL of the merchant serving the request. - */ - const char *merchant_url; - - /** - * Row to start querying the database from. - */ - uint64_t offset; - - /** - * How many rows to return (with direction). - */ - int64_t limit; - - /** - * Expected HTTP response code. - */ - unsigned int http_status; - - /** - * Length of @e rewards. - */ - unsigned int rewards_length; - - /** - * References to rewards that we expect to be found. - */ - const char **rewards; - -}; - -/** - * Callback for a GET /private/rewards operation. - * - * @param cls closure for this function - * @param tgr response details - */ -static void -get_rewards_cb (void *cls, - const struct TALER_MERCHANT_RewardsGetResponse *tgr) -{ - struct GetRewardsState *gts = cls; - - gts->tgh = NULL; - if (gts->http_status != tgr->hr.http_status) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Unexpected response code %u (%d) to command %s\n", - tgr->hr.http_status, - (int) tgr->hr.ec, - TALER_TESTING_interpreter_get_current_label (gts->is)); - TALER_TESTING_interpreter_fail (gts->is); - return; - } - switch (tgr->hr.http_status) - { - case MHD_HTTP_OK: - if (tgr->details.ok.rewards_length != gts->rewards_length) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Rewards length does not match\n"); - TALER_TESTING_interpreter_fail (gts->is); - return; - } - for (unsigned int i = 0; i < tgr->details.ok.rewards_length; ++i) - { - const struct TALER_MERCHANT_RewardEntry *reward - = &tgr->details.ok.rewards[i]; - const struct TALER_TESTING_Command *reward_cmd; - - reward_cmd = TALER_TESTING_interpreter_lookup_command ( - gts->is, - gts->rewards[i]); - { - const struct TALER_RewardIdentifierP *reward_id; - - if (GNUNET_OK != - TALER_TESTING_get_trait_reward_id (reward_cmd, - &reward_id)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Could not fetch reward id\n"); - TALER_TESTING_interpreter_fail (gts->is); - return; - } - if (0 != GNUNET_memcmp (reward_id, - &reward->reward_id)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Reward id does not match\n"); - TALER_TESTING_interpreter_fail (gts->is); - return; - } - } - { - const struct TALER_Amount *reward_amount; - - if (GNUNET_OK != - TALER_TESTING_get_trait_amount (reward_cmd, - &reward_amount)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Could not fetch reward amount\n"); - TALER_TESTING_interpreter_fail (gts->is); - return; - } - if ( (GNUNET_OK != - TALER_amount_cmp_currency (reward_amount, - &reward->reward_amount)) || - (0 != - TALER_amount_cmp (reward_amount, - &reward->reward_amount)) ) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Reward amount does not match\n"); - TALER_TESTING_interpreter_fail (gts->is); - return; - } - } - } - break; - default: - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Unhandled HTTP status.\n"); - } - TALER_TESTING_interpreter_next (gts->is); -} - - -/** - * Run the "GET /private/rewards" CMD. - * - * @param cls closure. - * @param cmd command being run now. - * @param is interpreter state. - */ -static void -get_rewards_run (void *cls, - const struct TALER_TESTING_Command *cmd, - struct TALER_TESTING_Interpreter *is) -{ - struct GetRewardsState *gts = cls; - - gts->is = is; - gts->tgh = TALER_MERCHANT_rewards_get2 ( - TALER_TESTING_interpreter_get_context (is), - gts->merchant_url, - TALER_EXCHANGE_YNA_NO, - gts->limit, - gts->offset, - &get_rewards_cb, - gts); - - GNUNET_assert (NULL != gts->tgh); -} - - -/** - * Free the state of a "GET rewards" CMD, and possibly - * cancel a pending operation thereof. - * - * @param cls closure. - * @param cmd command being run. - */ -static void -get_rewards_cleanup (void *cls, - const struct TALER_TESTING_Command *cmd) -{ - struct GetRewardsState *gts = cls; - - if (NULL != gts->tgh) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "GET /private/rewards operation did not complete\n"); - TALER_MERCHANT_rewards_get_cancel (gts->tgh); - } - GNUNET_array_grow (gts->rewards, - gts->rewards_length, - 0); - GNUNET_free (gts); -} - - -struct TALER_TESTING_Command -TALER_TESTING_cmd_get_rewards (const char *label, - const char *merchant_url, - unsigned int http_status, - ...) -{ - struct GetRewardsState *gts; - - gts = GNUNET_new (struct GetRewardsState); - gts->merchant_url = merchant_url; - gts->offset = INT64_MAX; - gts->limit = -20; - gts->http_status = http_status; - { - const char *clabel; - va_list ap; - - va_start (ap, http_status); - while (NULL != (clabel = va_arg (ap, const char *))) - { - GNUNET_array_append (gts->rewards, - gts->rewards_length, - clabel); - } - va_end (ap); - } - { - struct TALER_TESTING_Command cmd = { - .cls = gts, - .label = label, - .run = &get_rewards_run, - .cleanup = &get_rewards_cleanup - }; - - return cmd; - } -} - - -struct TALER_TESTING_Command -TALER_TESTING_cmd_get_rewards2 (const char *label, - const char *merchant_url, - uint64_t offset, - int64_t limit, - unsigned int http_status, - ...) -{ - struct GetRewardsState *gts; - - gts = GNUNET_new (struct GetRewardsState); - gts->merchant_url = merchant_url; - gts->offset = offset; - gts->limit = limit; - gts->http_status = http_status; - { - const char *clabel; - va_list ap; - - va_start (ap, http_status); - while (NULL != (clabel = va_arg (ap, const char *))) - { - GNUNET_array_append (gts->rewards, - gts->rewards_length, - clabel); - } - va_end (ap); - } - { - struct TALER_TESTING_Command cmd = { - .cls = gts, - .label = label, - .run = &get_rewards_run, - .cleanup = &get_rewards_cleanup - }; - - return cmd; - } -} - - -/* end of testing_api_cmd_get_rewards.c */ diff --git a/src/testing/testing_api_cmd_merchant_get_reward.c b/src/testing/testing_api_cmd_merchant_get_reward.c deleted file mode 100644 index 1c8b5c00..00000000 --- a/src/testing/testing_api_cmd_merchant_get_reward.c +++ /dev/null @@ -1,373 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 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 testing_api_cmd_merchant_get_reward.c - * @brief command to test GET /private/rewards/$REWARD_ID. - * @author Jonathan Buchanan - */ -#include "platform.h" -#include <taler/taler_exchange_service.h> -#include <taler/taler_testing_lib.h> -#include "taler_merchant_service.h" -#include "taler_merchant_testing_lib.h" - -/** - * State for a GET /private/rewards/$REWARD_ID CMD. - */ -struct MerchantRewardGetState -{ - - /** - * The merchant base URL. - */ - const char *merchant_url; - - /** - * Expected HTTP response code for this CMD. - */ - unsigned int http_status; - - /** - * Whether to fetch and compare pickups. - */ - bool fetch_pickups; - - /** - * The length of @e pickups. - */ - unsigned int pickups_length; - - /** - * The NULL-terminated list of pickup commands associated with the reward. - */ - const char **pickups; - - /** - * The handle to the current GET /rewards/$REWARD_ID request. - */ - struct TALER_MERCHANT_RewardMerchantGetHandle *tgh; - - /** - * The interpreter state. - */ - struct TALER_TESTING_Interpreter *is; - - /** - * Reference to a command that created a reward. - */ - const char *reward_reference; -}; - - -/** - * Callback for a GET /private/rewards/$REWARD_ID operation. - * - * @param cls closure for this function - * @param tsr response - */ -static void -merchant_get_reward_cb (void *cls, - const struct TALER_MERCHANT_RewardStatusResponse *tsr) -{ - struct MerchantRewardGetState *gts = cls; - const struct TALER_TESTING_Command *authorize_cmd; - struct TALER_Amount expected_total_picked_up; - - authorize_cmd = TALER_TESTING_interpreter_lookup_command (gts->is, - gts-> - reward_reference); - - gts->tgh = NULL; - if (gts->http_status != tsr->hr.http_status) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Unexpected response code %u (%d) to command %s\n", - tsr->hr.http_status, - (int) tsr->hr.ec, - TALER_TESTING_interpreter_get_current_label (gts->is)); - TALER_TESTING_interpreter_fail (gts->is); - return; - } - switch (tsr->hr.http_status) - { - case MHD_HTTP_OK: - { - const struct TALER_Amount *initial_amount; - - GNUNET_assert (GNUNET_OK == - TALER_amount_set_zero ( - tsr->details.ok.total_picked_up.currency, - &expected_total_picked_up)); - if (GNUNET_OK != - TALER_TESTING_get_trait_amount (authorize_cmd, - &initial_amount)) - TALER_TESTING_FAIL (gts->is); - if ((GNUNET_OK != - TALER_amount_cmp_currency (&tsr->details.ok.total_authorized, - initial_amount)) || - (0 != TALER_amount_cmp (&tsr->details.ok.total_authorized, - initial_amount))) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Reward authorized amount does not match\n"); - TALER_TESTING_interpreter_fail (gts->is); - return; - } - } - { - const char *justification; - - if (GNUNET_OK != - TALER_TESTING_get_trait_reason (authorize_cmd, - &justification)) - TALER_TESTING_FAIL (gts->is); - if (0 != strcmp (tsr->details.ok.reason, - justification)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Reward authorized reason does not match\n"); - TALER_TESTING_interpreter_fail (gts->is); - return; - } - } - { - const struct GNUNET_TIME_Timestamp *reward_expiration; - - if (GNUNET_OK != - TALER_TESTING_get_trait_timestamp (authorize_cmd, - 0, - &reward_expiration)) - TALER_TESTING_FAIL (gts->is); - if (GNUNET_TIME_timestamp_cmp (*reward_expiration, - !=, - tsr->details.ok.expiration)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Reward authorized expiration does not match\n"); - TALER_TESTING_interpreter_fail (gts->is); - return; - } - } - if (tsr->details.ok.pickups_length != gts->pickups_length) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Length of pickups array does not match\n"); - TALER_TESTING_interpreter_fail (gts->is); - return; - } - { - for (unsigned int i = 0; i < gts->pickups_length; ++i) - { - const struct TALER_TESTING_Command *pickup_cmd; - - pickup_cmd = TALER_TESTING_interpreter_lookup_command (gts->is, - gts->pickups[i]); - { - const uint32_t *num_planchets; - - if (GNUNET_OK != - TALER_TESTING_get_trait_num_planchets (pickup_cmd, - &num_planchets)) - TALER_TESTING_FAIL (gts->is); - - if (*num_planchets != tsr->details.ok.pickups[i].num_planchets) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Pickup planchet count does not match\n"); - TALER_TESTING_interpreter_fail (gts->is); - return; - } - } - { - const struct TALER_Amount *total; - - if (GNUNET_OK != - TALER_TESTING_get_trait_amount (pickup_cmd, - &total)) - TALER_TESTING_FAIL (gts->is); - - if ( (GNUNET_OK != - TALER_amount_cmp_currency (total, - &tsr->details.ok.pickups[i]. - requested_amount)) || - (0 != TALER_amount_cmp (total, - &tsr->details.ok.pickups[i]. - requested_amount))) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Pickup planchet sum does not match\n"); - TALER_TESTING_interpreter_fail (gts->is); - return; - } - GNUNET_assert (0 < TALER_amount_add (&expected_total_picked_up, - &expected_total_picked_up, - total)); - } - } - if ( (GNUNET_OK != - TALER_amount_cmp_currency (&expected_total_picked_up, - &tsr->details.ok.total_picked_up)) || - (0 != - TALER_amount_cmp (&expected_total_picked_up, - &tsr->details.ok.total_picked_up)) ) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Reward picked up amount does not match\n"); - TALER_TESTING_interpreter_fail (gts->is); - return; - } - } - break; - default: - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Unhandled HTTP status.\n"); - } - TALER_TESTING_interpreter_next (gts->is); -} - - -/** - * Run the "GET reward" CMD. - * - * @param cls closure. - * @param cmd command being run now. - * @param is interpreter state. - */ -static void -merchant_get_reward_run (void *cls, - const struct TALER_TESTING_Command *cmd, - struct TALER_TESTING_Interpreter *is) -{ - struct MerchantRewardGetState *tgs = cls; - const struct TALER_TESTING_Command *reward_cmd; - const struct TALER_RewardIdentifierP *reward_id; - - reward_cmd = TALER_TESTING_interpreter_lookup_command (is, - tgs->reward_reference); - - if (GNUNET_OK != - TALER_TESTING_get_trait_reward_id (reward_cmd, - &reward_id)) - TALER_TESTING_FAIL (is); - - tgs->is = is; - tgs->tgh = TALER_MERCHANT_merchant_reward_get ( - TALER_TESTING_interpreter_get_context (is), - tgs->merchant_url, - reward_id, - NULL, - GNUNET_TIME_UNIT_ZERO, - tgs->fetch_pickups, - &merchant_get_reward_cb, - tgs); - GNUNET_assert (NULL != tgs->tgh); -} - - -/** -* Free the state of a "GET reward" CMD, and possibly -* cancel a pending operation thereof. -* -* @param cls closure. -* @param cmd command being run. -*/ -static void -merchant_get_reward_cleanup (void *cls, - const struct TALER_TESTING_Command *cmd) -{ - struct MerchantRewardGetState *tgs = cls; - - if (NULL != tgs->tgh) - { - TALER_LOG_WARNING ("Get reward operation did not complete\n"); - TALER_MERCHANT_merchant_reward_get_cancel (tgs->tgh); - } - GNUNET_array_grow (tgs->pickups, - tgs->pickups_length, - 0); - GNUNET_free (tgs); -} - - -struct TALER_TESTING_Command -TALER_TESTING_cmd_merchant_get_reward (const char *label, - const char *merchant_url, - const char *reward_reference, - unsigned int http_status) -{ - struct MerchantRewardGetState *tgs; - - tgs = GNUNET_new (struct MerchantRewardGetState); - tgs->merchant_url = merchant_url; - tgs->reward_reference = reward_reference; - tgs->http_status = http_status; - { - struct TALER_TESTING_Command cmd = { - .cls = tgs, - .label = label, - .run = &merchant_get_reward_run, - .cleanup = &merchant_get_reward_cleanup - }; - - return cmd; - } -} - - -struct TALER_TESTING_Command -TALER_TESTING_cmd_merchant_get_reward_with_pickups (const char *label, - const char *merchant_url, - const char *reward_reference, - unsigned int http_status, - ...) -{ - struct MerchantRewardGetState *tgs; - - tgs = GNUNET_new (struct MerchantRewardGetState); - tgs->merchant_url = merchant_url; - tgs->reward_reference = reward_reference; - tgs->fetch_pickups = true; - tgs->http_status = http_status; - { - const char *clabel; - va_list ap; - - va_start (ap, http_status); - while (NULL != (clabel = va_arg (ap, const char *))) - { - GNUNET_array_append (tgs->pickups, - tgs->pickups_length, - clabel); - } - va_end (ap); - } - { - struct TALER_TESTING_Command cmd = { - .cls = tgs, - .label = label, - .run = &merchant_get_reward_run, - .cleanup = &merchant_get_reward_cleanup - }; - - return cmd; - } -} - - -/* end of testing_api_cmd_merchant_get_reward.c */ diff --git a/src/testing/testing_api_cmd_post_reserves.c b/src/testing/testing_api_cmd_post_reserves.c deleted file mode 100644 index c8fe914d..00000000 --- a/src/testing/testing_api_cmd_post_reserves.c +++ /dev/null @@ -1,278 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 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 testing_api_cmd_post_reserves.c - * @brief command to test POST /reserves - * @author Jonathan Buchanan - */ -#include "platform.h" -#include <taler/taler_exchange_service.h> -#include <taler/taler_testing_lib.h> -#include "taler_merchant_service.h" -#include "taler_merchant_testing_lib.h" - -/** - * State of a "POST /reserves" CMD. - */ -struct PostReservesState -{ - /** - * Handle for a "POST /reserves" request. - */ - struct TALER_MERCHANT_PostReservesHandle *prh; - - /** - * The interpreter state. - */ - struct TALER_TESTING_Interpreter *is; - - /** - * Base URL of the merchant - */ - const char *merchant_url; - - /** - * Base URL of the exchange. - */ - const char *exchange_url; - - /** - * Wire method for the reserve. - */ - const char *wire_method; - - /** - * The initial balance of the reserve. - */ - struct TALER_Amount initial_balance; - - /** - * Expected HTTP response code. - */ - unsigned int http_status; - - /** - * Public key assigned to the reserve - */ - struct TALER_ReservePublicKeyP reserve_pub; -}; - - -/** - * Callbacks of this type are used to work the result of submitting a - * POST /reserves request to a merchant - * - * @param cls closure - * @param prr response details - */ -static void -post_reserves_cb (void *cls, - const struct TALER_MERCHANT_PostReservesResponse *prr) -{ - struct PostReservesState *prs = cls; - - prs->prh = NULL; - if (prs->http_status != prr->hr.http_status) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Unexpected response code %u (%d) to command %s\n", - prr->hr.http_status, - (int) prr->hr.ec, - TALER_TESTING_interpreter_get_current_label (prs->is)); - TALER_TESTING_interpreter_fail (prs->is); - return; - } - switch (prr->hr.http_status) - { - case MHD_HTTP_OK: - prs->reserve_pub = prr->details.ok.reserve_pub; - break; - case MHD_HTTP_ACCEPTED: - break; - case MHD_HTTP_UNAUTHORIZED: - break; - case MHD_HTTP_NOT_FOUND: - break; - default: - GNUNET_break (0); - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Unhandled HTTP status %u for POST /reserves.\n", - prr->hr.http_status); - break; - } - TALER_TESTING_interpreter_next (prs->is); -} - - -/** - * Offers information from the POST /reserves CMD state to other - * commands. - * - * @param cls closure - * @param[out] ret result (could be anything) - * @param trait name of the trait - * @param index index number of the object to extract. - * @return #GNUNET_OK on success - */ -static enum GNUNET_GenericReturnValue -post_reserves_traits (void *cls, - const void **ret, - const char *trait, - unsigned int index) -{ - struct PostReservesState *prs = cls; - struct TALER_TESTING_Trait traits[] = { - TALER_TESTING_make_trait_reserve_pub (&prs->reserve_pub), - TALER_TESTING_make_trait_amount (&prs->initial_balance), - TALER_TESTING_trait_end (), - }; - - return TALER_TESTING_get_trait (traits, - ret, - trait, - index); -} - - -/** - * Run the "POST /reserves" CMD. - * - * @param cls closure. - * @param cmd command being run now. - * @param is interpreter state. - */ -static void -post_reserves_run (void *cls, - const struct TALER_TESTING_Command *cmd, - struct TALER_TESTING_Interpreter *is) -{ - struct PostReservesState *prs = cls; - - prs->is = is; - prs->prh = TALER_MERCHANT_reserves_post ( - TALER_TESTING_interpreter_get_context (is), - prs->merchant_url, - &prs->initial_balance, - prs->exchange_url, - prs->wire_method, - &post_reserves_cb, - prs); - GNUNET_assert (NULL != prs->prh); -} - - -/** - * Run the fake "POST /reserves" CMD. - * - * @param cls closure. - * @param cmd command being run now. - * @param is interpreter state. - */ -static void -post_reserves_fake_run (void *cls, - const struct TALER_TESTING_Command *cmd, - struct TALER_TESTING_Interpreter *is) -{ - struct PostReservesState *prs = cls; - struct TALER_ReservePrivateKeyP reserve_priv; - - prs->is = is; - GNUNET_CRYPTO_eddsa_key_create (&reserve_priv.eddsa_priv); - GNUNET_CRYPTO_eddsa_key_get_public (&reserve_priv.eddsa_priv, - &prs->reserve_pub.eddsa_pub); - - GNUNET_assert (GNUNET_OK == TALER_string_to_amount ("EUR:100.00", - &prs->initial_balance)); - TALER_TESTING_interpreter_next (prs->is); -} - - -/** - * Free the state of a "POST /reserves" CMD, and possibly - * cancel a pending operation thereof. - * - * @param cls closure. - * @param cmd command being run. - */ -static void -post_reserves_cleanup (void *cls, - const struct TALER_TESTING_Command *cmd) -{ - struct PostReservesState *prs = cls; - - if (NULL != prs->prh) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "POST /reserves operation did not complete\n"); - TALER_MERCHANT_reserves_post_cancel (prs->prh); - } - GNUNET_free (prs); -} - - -struct TALER_TESTING_Command -TALER_TESTING_cmd_merchant_post_reserves (const char *label, - const char *merchant_url, - const char *initial_balance, - const char *exchange_url, - const char *wire_method, - unsigned int http_status) -{ - struct PostReservesState *prs; - - prs = GNUNET_new (struct PostReservesState); - prs->merchant_url = merchant_url; - prs->exchange_url = exchange_url; - prs->wire_method = wire_method; - prs->http_status = http_status; - GNUNET_assert (GNUNET_OK == - TALER_string_to_amount (initial_balance, - &prs->initial_balance)); - { - struct TALER_TESTING_Command cmd = { - .cls = prs, - .label = label, - .run = &post_reserves_run, - .cleanup = &post_reserves_cleanup, - .traits = &post_reserves_traits - }; - - return cmd; - } -} - - -struct TALER_TESTING_Command -TALER_TESTING_cmd_merchant_post_reserves_fake (const char *label) -{ - struct PostReservesState *prs; - - prs = GNUNET_new (struct PostReservesState); - { - struct TALER_TESTING_Command cmd = { - .cls = prs, - .label = label, - .run = &post_reserves_fake_run, - .cleanup = &post_reserves_cleanup, - .traits = &post_reserves_traits - }; - - return cmd; - } -} diff --git a/src/testing/testing_api_cmd_reward_authorize.c b/src/testing/testing_api_cmd_reward_authorize.c deleted file mode 100644 index 1e8579ab..00000000 --- a/src/testing/testing_api_cmd_reward_authorize.c +++ /dev/null @@ -1,485 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2014-2023 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 testing_api_cmd_reward_authorize.c - * @brief command to test the rewardping. - * @author Marcello Stanisci - */ - -#include "platform.h" -#include <taler/taler_exchange_service.h> -#include <taler/taler_testing_lib.h> -#include "taler_merchant_service.h" -#include "taler_merchant_testing_lib.h" - - -/** - * State for a /reward-authorize CMD. - */ -struct RewardAuthorizeState -{ - - /** - * Merchant base URL. - */ - const char *merchant_url; - - /** - * Expected HTTP response code. - */ - unsigned int http_status; - - /** - * Reference to the reserve to authorize the reward - * from (if NULL, the merchant decides). - */ - const char *reserve_reference; - - /** - * Human-readable justification for the - * reward authorization carried on by this CMD. - */ - const char *justification; - - /** - * Amount that should be authorized for rewardping. - */ - struct TALER_Amount amount; - - /** - * Expected Taler error code for this CMD. - */ - enum TALER_ErrorCode expected_ec; - - /** - * Reward taler:// URI. - */ - char *reward_uri; - - /** - * The reward id; set when the CMD succeeds. - */ - struct TALER_RewardIdentifierP reward_id; - - /** - * Expiration date for this reward. - */ - struct GNUNET_TIME_Timestamp reward_expiration; - - /** - * Handle to the on-going /reward-authorize request. - */ - struct TALER_MERCHANT_RewardAuthorizeHandle *tao; - - /** - * The interpreter state. - */ - struct TALER_TESTING_Interpreter *is; - - /** - * Task used for retries. - */ - struct GNUNET_SCHEDULER_Task *retry_task; - - /** - * How long do we wait between retries? - */ - struct GNUNET_TIME_Relative backoff; - - /** - * How many retries are left? - */ - unsigned int retries_left; - -}; - - -/** - * Run the main logic of talking to the merchant. - * - * @param cls a `struct RewardAuthorizeState`. - */ -static void -do_retry (void *cls); - - -/** - * Callback for a /reward-authorize request. Set into the state - * what was returned from the backend (@a reward_id and @a - * reward_expiration). - * - * @param cls closure - * @param tar response we got - */ -static void -reward_authorize_cb (void *cls, - const struct TALER_MERCHANT_RewardAuthorizeResponse *tar) -{ - struct RewardAuthorizeState *tas = cls; - - tas->tao = NULL; - if (tas->http_status != tar->hr.http_status) - { - if ( (MHD_HTTP_NOT_FOUND == tar->hr.http_status) && - (0 < tas->retries_left) ) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Reserve authorization failed. Reserve may not yet be ready, retrying %u more times.\n", - tas->retries_left); - tas->retries_left--; - tas->backoff = GNUNET_TIME_randomized_backoff (tas->backoff, - GNUNET_TIME_UNIT_SECONDS); - tas->retry_task = GNUNET_SCHEDULER_add_delayed (tas->backoff, - &do_retry, - tas); - return; - } - - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Unexpected response code %u (%d) to command %s\n", - tar->hr.http_status, - tar->hr.ec, - TALER_TESTING_interpreter_get_current_label (tas->is)); - TALER_TESTING_interpreter_fail (tas->is); - return; - } - - if (tas->expected_ec != tar->hr.ec) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Unexpected error code %d (%u) to command %s\n", - (int) tar->hr.ec, - tar->hr.http_status, - TALER_TESTING_interpreter_get_current_label (tas->is)); - TALER_TESTING_interpreter_fail (tas->is); - return; - } - if ( (MHD_HTTP_OK == tar->hr.http_status) && - (TALER_EC_NONE == tar->hr.ec) ) - { - tas->reward_uri = GNUNET_strdup (tar->details.ok.reward_uri); - tas->reward_id = tar->details.ok.reward_id; - tas->reward_expiration = tar->details.ok.reward_expiration; - } - TALER_TESTING_interpreter_next (tas->is); -} - - -/** - * Offers information from the /reward-authorize CMD state to other - * commands. - * - * @param cls closure - * @param[out] ret result (could be anything) - * @param trait name of the trait - * @param index index number of the object to extract. - * @return #GNUNET_OK on success - */ -static enum GNUNET_GenericReturnValue -reward_authorize_traits (void *cls, - const void **ret, - const char *trait, - unsigned int index) -{ - struct RewardAuthorizeState *tas = cls; - struct TALER_TESTING_Trait traits[] = { - TALER_TESTING_make_trait_reward_id (&tas->reward_id), - TALER_TESTING_make_trait_amount (&tas->amount), - TALER_TESTING_make_trait_reason (tas->justification), - TALER_TESTING_make_trait_timestamp (0, - &tas->reward_expiration), - TALER_TESTING_trait_end (), - }; - - return TALER_TESTING_get_trait (traits, - ret, - trait, - index); -} - - -/** - * Runs the /reward-authorize CMD - * - * @param cls closure - * @param cmd the CMD representing _this_ command - * @param is interpreter state - */ -static void -reward_authorize_run (void *cls, - const struct TALER_TESTING_Command *cmd, - struct TALER_TESTING_Interpreter *is) -{ - struct RewardAuthorizeState *tas = cls; - - tas->retries_left = 16; - tas->is = is; - tas->retry_task = GNUNET_SCHEDULER_add_now (&do_retry, - tas); -} - - -static void -do_retry (void *cls) -{ - struct RewardAuthorizeState *tas = cls; - - tas->retry_task = NULL; - if (NULL == tas->reserve_reference) - { - tas->tao = TALER_MERCHANT_reward_authorize ( - TALER_TESTING_interpreter_get_context (tas->is), - tas->merchant_url, - "http://merchant.com/pickup", - &tas->amount, - tas->justification, - &reward_authorize_cb, - tas); - } - else - { - const struct TALER_TESTING_Command *reserve_cmd; - const struct TALER_ReservePublicKeyP *reserve_pub; - - reserve_cmd = TALER_TESTING_interpreter_lookup_command ( - tas->is, - tas->reserve_reference); - GNUNET_assert (GNUNET_OK == - TALER_TESTING_get_trait_reserve_pub (reserve_cmd, - &reserve_pub)); - tas->tao = TALER_MERCHANT_reward_authorize2 ( - TALER_TESTING_interpreter_get_context (tas->is), - tas->merchant_url, - reserve_pub, - "http://merchant.com/pickup", - &tas->amount, - tas->justification, - &reward_authorize_cb, - tas); - } - GNUNET_assert (NULL != tas->tao); -} - - -/** - * Run the /reward-authorize CMD, the "fake" version of it. - * - * @param cls closure - * @param cmd the CMD representing _this_ command - * @param is interpreter state * - */ -static void -reward_authorize_fake_run (void *cls, - const struct TALER_TESTING_Command *cmd, - struct TALER_TESTING_Interpreter *is) -{ - struct RewardAuthorizeState *tas = cls; - - /* Make up a reward id. */ - GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, - &tas->reward_id, - sizeof (struct TALER_RewardIdentifierP)); - TALER_TESTING_interpreter_next (is); -} - - -/** - * Free the state from a /reward-authorize CMD, and possibly - * cancel any pending operation. - * - * @param cls closure - * @param cmd the /reward-authorize CMD that is about to be freed. - */ -static void -reward_authorize_cleanup (void *cls, - const struct TALER_TESTING_Command *cmd) -{ - struct RewardAuthorizeState *tas = cls; - - if (NULL != tas->tao) - { - TALER_LOG_WARNING ("Reward-autorize operation" - " did not complete\n"); - TALER_MERCHANT_reward_authorize_cancel (tas->tao); - } - if (NULL != tas->retry_task) - { - GNUNET_SCHEDULER_cancel (tas->retry_task); - tas->retry_task = NULL; - } - GNUNET_free (tas->reward_uri); - GNUNET_free (tas); -} - - -struct TALER_TESTING_Command -TALER_TESTING_cmd_reward_authorize_with_ec (const char *label, - const char *merchant_url, - const char *exchange_url, - unsigned int http_status, - const char *justification, - const char *amount, - enum TALER_ErrorCode ec) -{ - struct RewardAuthorizeState *tas; - - tas = GNUNET_new (struct RewardAuthorizeState); - tas->merchant_url = merchant_url; - tas->justification = justification; - tas->http_status = http_status; - tas->expected_ec = ec; - GNUNET_assert (GNUNET_OK == - TALER_string_to_amount (amount, - &tas->amount)); - { - struct TALER_TESTING_Command cmd = { - .label = label, - .cls = tas, - .run = &reward_authorize_run, - .cleanup = &reward_authorize_cleanup, - .traits = &reward_authorize_traits - }; - - return cmd; - } -} - - -struct TALER_TESTING_Command -TALER_TESTING_cmd_reward_authorize_from_reserve_with_ec ( - const char *label, - const char *merchant_url, - const char *exchange_url, - const char *reserve_reference, - unsigned int http_status, - const char *justification, - const char *amount, - enum TALER_ErrorCode ec) -{ - struct RewardAuthorizeState *tas; - - tas = GNUNET_new (struct RewardAuthorizeState); - tas->merchant_url = merchant_url; - tas->justification = justification; - tas->http_status = http_status; - tas->expected_ec = ec; - tas->reserve_reference = reserve_reference; - GNUNET_assert (GNUNET_OK == - TALER_string_to_amount (amount, - &tas->amount)); - { - struct TALER_TESTING_Command cmd = { - .label = label, - .cls = tas, - .run = &reward_authorize_run, - .cleanup = &reward_authorize_cleanup, - .traits = &reward_authorize_traits - }; - - return cmd; - } -} - - -struct TALER_TESTING_Command -TALER_TESTING_cmd_reward_authorize (const char *label, - const char *merchant_url, - const char *exchange_url, - unsigned int http_status, - const char *justification, - const char *amount) -{ - struct RewardAuthorizeState *tas; - - tas = GNUNET_new (struct RewardAuthorizeState); - tas->merchant_url = merchant_url; - tas->justification = justification; - tas->http_status = http_status; - GNUNET_assert (GNUNET_OK == - TALER_string_to_amount (amount, - &tas->amount)); - { - struct TALER_TESTING_Command cmd = { - .label = label, - .cls = tas, - .run = &reward_authorize_run, - .cleanup = &reward_authorize_cleanup, - .traits = &reward_authorize_traits - }; - - return cmd; - } -} - - -struct TALER_TESTING_Command -TALER_TESTING_cmd_reward_authorize_from_reserve (const char *label, - const char *merchant_url, - const char *exchange_url, - const char *reserve_reference, - unsigned int http_status, - const char *justification, - const char *amount) -{ - struct RewardAuthorizeState *tas; - - tas = GNUNET_new (struct RewardAuthorizeState); - tas->merchant_url = merchant_url; - tas->reserve_reference = reserve_reference; - tas->justification = justification; - tas->http_status = http_status; - GNUNET_assert (GNUNET_OK == - TALER_string_to_amount (amount, - &tas->amount)); - { - struct TALER_TESTING_Command cmd = { - .label = label, - .cls = tas, - .run = &reward_authorize_run, - .cleanup = &reward_authorize_cleanup, - .traits = &reward_authorize_traits - }; - - return cmd; - } -} - - -struct TALER_TESTING_Command -TALER_TESTING_cmd_reward_authorize_fake (const char *label) -{ - struct RewardAuthorizeState *tas; - - tas = GNUNET_new (struct RewardAuthorizeState); - { - struct TALER_TESTING_Command cmd = { - .label = label, - .cls = tas, - .run = &reward_authorize_fake_run, - .cleanup = &reward_authorize_cleanup, - .traits = &reward_authorize_traits - }; - - return cmd; - } -} - - -/* end of testing_api_cmd_reward_authorize.c */ diff --git a/src/testing/testing_api_cmd_reward_pickup.c b/src/testing/testing_api_cmd_reward_pickup.c deleted file mode 100644 index 0b53b717..00000000 --- a/src/testing/testing_api_cmd_reward_pickup.c +++ /dev/null @@ -1,415 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2014-2022 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 testing_api_cmd_reward_pickup.c - * @brief command to test picking up a reward. - * @author Marcello Stanisci - */ -#include "platform.h" -#include <taler/taler_exchange_service.h> -#include <taler/taler_testing_lib.h> -#include "taler_merchant_service.h" -#include "taler_merchant_testing_lib.h" - -/** - * State for a /reward-pickup CMD. - */ -struct RewardPickupState -{ - /** - * Merchant base URL. - */ - const char *merchant_url; - - /** - * Exchange base URL. - */ - const char *exchange_url; - - /** - * Expected HTTP response code. - */ - unsigned int http_status; - - /** - * Reference to a /reward/authorize CMD. This will be used to - * get the reward id to make the request with. - */ - const char *authorize_reference; - - /** - * If set to non NULL, it references another pickup CMD - * that will provide all the data which is needed to issue - * the request (like planchet secrets, denomination keys..). - */ - const char *replay_reference; - - /** - * Handle to a on-going /reward/pickup request. - */ - struct TALER_MERCHANT_RewardPickupHandle *tpo; - - /** - * The interpreter state. - */ - struct TALER_TESTING_Interpreter *is; - - /** - * An array of string-defined amounts that indicates - * which denominations are going to be used to receive - * rewards. - */ - const char **amounts; - - /** - * The object version of the above @a amounts. - */ - struct TALER_Amount *amounts_obj; - - /** - * The sum of the the amounts above. - */ - struct TALER_Amount total_amount; - - /** - * The array of denomination keys, in the same order of @a - * amounts. - */ - const struct TALER_EXCHANGE_DenomPublicKey **dks; - - /** - * The array of planchet secrets, in the same order of @a - * amounts. - */ - struct TALER_PlanchetMasterSecretP *psa; - - /** - * Set (by the interpreter) to an array of @a num_coins - * details on coins created from the (successful) reward operation. - */ - struct TALER_EXCHANGE_PrivateCoinDetails *pcds; - - /** - * How many coins are involved in the rewardping operation. - */ - uint32_t num_coins; - - /** - * Expected Taler error code (NOTE: this is NOT the HTTP - * response code). - */ - enum TALER_ErrorCode expected_ec; -}; - - -/** - * Callback for a /reward-pickup request, it mainly checks if - * values returned from the backend are as expected, and if so - * (and if the status was 200 OK) proceede with the withdrawal. - * - * @param cls closure - * @param pd details about the result of the operation - */ -static void -pickup_cb (void *cls, - const struct TALER_MERCHANT_PickupDetails *pd) -{ - struct RewardPickupState *tps = cls; - - tps->tpo = NULL; - if (pd->hr.http_status != tps->http_status) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Unexpected response code %u (%d) to command %s\n", - pd->hr.http_status, - (int) pd->hr.ec, - TALER_TESTING_interpreter_get_current_label (tps->is)); - TALER_TESTING_FAIL (tps->is); - } - - if (pd->hr.ec != tps->expected_ec) - TALER_TESTING_FAIL (tps->is); - - /* Safe to go ahead: http status was expected. */ - if ( (MHD_HTTP_OK != pd->hr.http_status) || - (TALER_EC_NONE != pd->hr.ec) ) - { - TALER_TESTING_interpreter_next (tps->is); - return; - } - if (pd->details.ok.num_sigs != tps->num_coins) - TALER_TESTING_FAIL (tps->is); - tps->pcds = GNUNET_new_array (tps->num_coins, - struct TALER_EXCHANGE_PrivateCoinDetails); - for (unsigned int i = 0; i<tps->num_coins; i++) - { - struct TALER_EXCHANGE_PrivateCoinDetails *pcd = - &pd->details.ok.pcds[i]; - - tps->pcds[i] = *pcd; - TALER_denom_sig_copy (&tps->pcds[i].sig, - &pcd->sig); - } - TALER_TESTING_interpreter_next (tps->is); -} - - -/** - * Run a /reward-pickup CMD. - * - * @param cls closure - * @param cmd the current /reward-pickup CMD. - * @param is interpreter state. - */ -static void -reward_pickup_run (void *cls, - const struct TALER_TESTING_Command *cmd, - struct TALER_TESTING_Interpreter *is) -{ - struct RewardPickupState *tps = cls; - unsigned int num_planchets; - const struct TALER_TESTING_Command *replay_cmd; - const struct TALER_TESTING_Command *authorize_cmd; - const struct TALER_RewardIdentifierP *reward_id; - - tps->is = is; - tps->exchange_url = TALER_TESTING_get_exchange_url (is); - if (NULL == tps->replay_reference) - { - replay_cmd = NULL; - - /* Count planchets. */ - for (num_planchets = 0; - NULL != tps->amounts[num_planchets]; - num_planchets++) - ; - } - else - { - const uint32_t *np; - - if (NULL == /* looking for "parent" reward-pickup command */ - (replay_cmd - = TALER_TESTING_interpreter_lookup_command (is, - tps->replay_reference)) ) - TALER_TESTING_FAIL (is); - - if (GNUNET_OK != - TALER_TESTING_get_trait_num_planchets (replay_cmd, - &np)) - TALER_TESTING_FAIL (is); - num_planchets = *np; - } - - if (NULL == - (authorize_cmd - = TALER_TESTING_interpreter_lookup_command (is, - tps->authorize_reference)) ) - TALER_TESTING_FAIL (is); - - tps->num_coins = num_planchets; - { - struct TALER_MERCHANT_PlanchetData planchets[num_planchets]; - - tps->psa = GNUNET_new_array (num_planchets, - struct TALER_PlanchetMasterSecretP); - tps->dks = GNUNET_new_array (num_planchets, - const struct TALER_EXCHANGE_DenomPublicKey *); - tps->amounts_obj = GNUNET_new_array (num_planchets, - struct TALER_Amount); - for (unsigned int i = 0; i<num_planchets; i++) - { - if (NULL == replay_cmd) - { - GNUNET_assert (GNUNET_OK == - TALER_string_to_amount (tps->amounts[i], - &tps->amounts_obj[i])); - if (0 == i) - GNUNET_assert (GNUNET_OK == - TALER_amount_set_zero (tps->amounts_obj[i].currency, - &tps->total_amount)); - - GNUNET_assert (0 < - TALER_amount_add (&tps->total_amount, - &tps->total_amount, - &tps->amounts_obj[i])); - tps->dks[i] = TALER_TESTING_find_pk ( - TALER_TESTING_get_keys (is), - &tps->amounts_obj[i], - false); - if (NULL == tps->dks[i]) - TALER_TESTING_FAIL (is); - TALER_planchet_master_setup_random (&tps->psa[i]); - } - else - { - const struct TALER_PlanchetMasterSecretP *ps; - - if (GNUNET_OK != - TALER_TESTING_get_trait_denom_pub (replay_cmd, - i, - &tps->dks[i])) - TALER_TESTING_FAIL (is); - if (GNUNET_OK != - TALER_TESTING_get_trait_planchet_secrets (replay_cmd, - i, - &ps)) - TALER_TESTING_FAIL (is); - tps->psa[i] = *ps; - } - planchets[i].pk = tps->dks[i]; - planchets[i].ps = tps->psa[i]; - } - if (GNUNET_OK != - TALER_TESTING_get_trait_reward_id (authorize_cmd, - &reward_id)) - TALER_TESTING_FAIL (is); - tps->tpo = TALER_MERCHANT_reward_pickup ( - TALER_TESTING_interpreter_get_context (is), - TALER_TESTING_get_exchange_url (is), - tps->merchant_url, - reward_id, - num_planchets, - planchets, - &pickup_cb, - tps); - GNUNET_assert (NULL != tps->tpo); - } -} - - -/** - * Free a /reward-pickup CMD state, and possibly cancel a - * pending /reward-pickup request. - * - * @param cls closure. - * @param cmd current CMD to be freed. - */ -static void -reward_pickup_cleanup (void *cls, - const struct TALER_TESTING_Command *cmd) -{ - struct RewardPickupState *tps = cls; - - GNUNET_free (tps->amounts_obj); - GNUNET_free (tps->dks); - GNUNET_free (tps->psa); - if (NULL != tps->pcds) - { - for (unsigned int i = 0; i<tps->num_coins; i++) - TALER_denom_sig_free (&tps->pcds[i].sig); - GNUNET_free (tps->pcds); - } - if (NULL != tps->tpo) - { - TALER_LOG_WARNING ("Reward-pickup operation did not complete\n"); - TALER_MERCHANT_reward_pickup_cancel (tps->tpo); - } - GNUNET_free (tps); -} - - -static enum GNUNET_GenericReturnValue -reward_pickup_traits (void *cls, - const void **ret, - const char *trait, - unsigned int index) -{ - struct RewardPickupState *tps = cls; - - if (index >= tps->num_coins) - return GNUNET_SYSERR; - { - struct TALER_TESTING_Trait traits[] = { - TALER_TESTING_make_trait_planchet_secrets (index, - &tps->psa[index]), - TALER_TESTING_make_trait_coin_priv (index, - &tps->pcds[index].coin_priv), - TALER_TESTING_make_trait_denom_pub (index, - tps->dks[index]), - TALER_TESTING_make_trait_denom_sig (index, - &tps->pcds[index].sig), - TALER_TESTING_make_trait_amounts (index, - &tps->amounts_obj[index]), - TALER_TESTING_make_trait_amount (&tps->total_amount), - TALER_TESTING_make_trait_num_planchets (&tps->num_coins), - TALER_TESTING_make_trait_exchange_url (tps->exchange_url), - TALER_TESTING_trait_end () - }; - - return TALER_TESTING_get_trait (traits, - ret, - trait, - index); - } -} - - -struct TALER_TESTING_Command -TALER_TESTING_cmd_reward_pickup (const char *label, - const char *merchant_url, - unsigned int http_status, - const char *authorize_reference, - const char **amounts) -{ - struct RewardPickupState *tps; - - tps = GNUNET_new (struct RewardPickupState); - tps->merchant_url = merchant_url; - tps->authorize_reference = authorize_reference; - tps->amounts = amounts; - tps->http_status = http_status; - { - struct TALER_TESTING_Command cmd = { - .cls = tps, - .label = label, - .run = &reward_pickup_run, - .cleanup = &reward_pickup_cleanup, - .traits = &reward_pickup_traits - }; - - return cmd; - } -} - - -struct TALER_TESTING_Command -TALER_TESTING_cmd_reward_pickup_with_ec (const char *label, - const char *merchant_url, - unsigned int http_status, - const char *authorize_reference, - const char **amounts, - enum TALER_ErrorCode ec) -{ - struct TALER_TESTING_Command cmd; - struct RewardPickupState *tps; - - cmd = TALER_TESTING_cmd_reward_pickup (label, - merchant_url, - http_status, - authorize_reference, - amounts); - tps = cmd.cls; - tps->expected_ec = ec; - return cmd; -} - - -/* end of testing_api_cmd_reward_pickup.c */ diff --git a/src/testing/testing_api_cmd_wallet_get_reward.c b/src/testing/testing_api_cmd_wallet_get_reward.c deleted file mode 100644 index 661b31f2..00000000 --- a/src/testing/testing_api_cmd_wallet_get_reward.c +++ /dev/null @@ -1,259 +0,0 @@ -/* - This file is part of TALER - 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 - 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 testing_api_cmd_wallet_get_reward.c - * @brief command to test the rewardping. - * @author Marcello Stanisci - */ -#include "platform.h" -#include <taler/taler_exchange_service.h> -#include <taler/taler_testing_lib.h> -#include "taler_merchant_service.h" -#include "taler_merchant_testing_lib.h" - - -/** - * State for a GET /rewards/$REWARD_ID CMD. - */ -struct WalletRewardGetState -{ - - /** - * The merchant base URL. - */ - const char *merchant_url; - - /** - * Expected HTTP response code for this CMD. - */ - unsigned int http_status; - - /** - * Whether to compare amounts or not. - */ - bool cmp_amounts; - - /** - * The expected amount remaining. - */ - struct TALER_Amount amount_remaining; - - /** - * The handle to the current GET /rewards/$REWARD_ID request. - */ - struct TALER_MERCHANT_RewardWalletGetHandle *tgh; - - /** - * The interpreter state. - */ - struct TALER_TESTING_Interpreter *is; - - /** - * Reference to a command that created a reward. - */ - const char *reward_reference; -}; - - -/** - * Callback to process a GET /rewards/$REWARD_ID request, it mainly - * checks that what the backend returned matches the command's - * expectations. - * - * @param cls closure - * @param wgr response - */ -static void -wallet_reward_get_cb (void *cls, - const struct TALER_MERCHANT_RewardWalletGetResponse *wgr) -{ - struct WalletRewardGetState *gts = cls; - const struct TALER_TESTING_Command *reward_cmd; - - reward_cmd = TALER_TESTING_interpreter_lookup_command ( - gts->is, - gts->reward_reference); - - gts->tgh = NULL; - if (gts->http_status != wgr->hr.http_status) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Unexpected response code %u (%d) to command %s\n", - wgr->hr.http_status, - (int) wgr->hr.ec, - TALER_TESTING_interpreter_get_current_label (gts->is)); - TALER_TESTING_interpreter_fail (gts->is); - return; - } - switch (wgr->hr.http_status) - { - case MHD_HTTP_OK: - if (gts->cmp_amounts) - { - if ((GNUNET_OK != - TALER_amount_cmp_currency (>s->amount_remaining, - &wgr->details.ok.amount_remaining)) - || - (0 != TALER_amount_cmp (>s->amount_remaining, - &wgr->details.ok.amount_remaining))) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Amount remaining on reward does not match\n"); - TALER_TESTING_interpreter_fail (gts->is); - return; - } - } - { - const struct GNUNET_TIME_Timestamp *expiration; - - if (GNUNET_OK != - TALER_TESTING_get_trait_timestamp (reward_cmd, - 0, - &expiration)) - TALER_TESTING_interpreter_fail (gts->is); - if (GNUNET_TIME_timestamp_cmp (*expiration, - !=, - wgr->details.ok.expiration)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Reward expiration does not match\n"); - TALER_TESTING_interpreter_fail (gts->is); - return; - } - } - break; - default: - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Unhandled HTTP status.\n"); - } - TALER_TESTING_interpreter_next (gts->is); -} - - -/** - * Run the "GET reward" CMD. - * - * @param cls closure. - * @param cmd command being run now. - * @param is interpreter state. - */ -static void -wallet_get_reward_run (void *cls, - const struct TALER_TESTING_Command *cmd, - struct TALER_TESTING_Interpreter *is) -{ - struct WalletRewardGetState *tgs = cls; - const struct TALER_TESTING_Command *reward_cmd; - const struct TALER_RewardIdentifierP *reward_id; - - reward_cmd = TALER_TESTING_interpreter_lookup_command (is, - tgs->reward_reference); - - if (GNUNET_OK != - TALER_TESTING_get_trait_reward_id (reward_cmd, - &reward_id)) - TALER_TESTING_FAIL (is); - - tgs->is = is; - tgs->tgh = TALER_MERCHANT_wallet_reward_get ( - TALER_TESTING_interpreter_get_context (is), - tgs->merchant_url, - reward_id, - &wallet_reward_get_cb, - tgs); -} - - -/** - * Free the state of a "GET reward" CMD, and possibly - * cancel a pending operation thereof. - * - * @param cls closure. - * @param cmd command being run. - */ -static void -wallet_get_reward_cleanup (void *cls, - const struct TALER_TESTING_Command *cmd) -{ - struct WalletRewardGetState *tgs = cls; - - if (NULL != tgs->tgh) - { - TALER_LOG_WARNING ("Get reward operation did not complete\n"); - TALER_MERCHANT_wallet_reward_get_cancel (tgs->tgh); - } - GNUNET_free (tgs); -} - - -struct TALER_TESTING_Command -TALER_TESTING_cmd_wallet_get_reward (const char *label, - const char *merchant_url, - const char *reward_reference, - unsigned int http_status) -{ - struct WalletRewardGetState *tgs; - - tgs = GNUNET_new (struct WalletRewardGetState); - tgs->merchant_url = merchant_url; - tgs->reward_reference = reward_reference; - tgs->http_status = http_status; - { - struct TALER_TESTING_Command cmd = { - .cls = tgs, - .label = label, - .run = &wallet_get_reward_run, - .cleanup = &wallet_get_reward_cleanup - }; - - return cmd; - } -} - - -struct TALER_TESTING_Command -TALER_TESTING_cmd_wallet_get_reward2 (const char *label, - const char *merchant_url, - const char *reward_reference, - const char *amount_remaining, - unsigned int http_status) -{ - struct WalletRewardGetState *tgs; - - tgs = GNUNET_new (struct WalletRewardGetState); - tgs->merchant_url = merchant_url; - tgs->reward_reference = reward_reference; - tgs->cmp_amounts = true; - GNUNET_assert (GNUNET_OK == TALER_string_to_amount (amount_remaining, - &tgs->amount_remaining)); - tgs->http_status = http_status; - { - struct TALER_TESTING_Command cmd = { - .cls = tgs, - .label = label, - .run = &wallet_get_reward_run, - .cleanup = &wallet_get_reward_cleanup - }; - - return cmd; - } -} - - -/* end of testing_api_cmd_wallet_get_reward.c */ |