summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/testing/Makefile.am6
-rw-r--r--src/testing/test_merchant_api.c101
-rw-r--r--src/testing/testing_api_cmd_check_payment.c495
-rw-r--r--src/testing/testing_api_cmd_history.c359
-rw-r--r--src/testing/testing_api_cmd_poll_payment.c491
-rw-r--r--src/testing/testing_api_cmd_refund_lookup.c457
-rw-r--r--src/testing/testing_api_cmd_track_transaction.c295
7 files changed, 0 insertions, 2204 deletions
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
index 6e52b33f..f159bde4 100644
--- a/src/testing/Makefile.am
+++ b/src/testing/Makefile.am
@@ -56,12 +56,6 @@ libtalermerchanttesting_la_SOURCES = \
testing_api_trait_planchet.c \
testing_api_trait_refund_entry.c
-# testing_api_cmd_history.c \
-# testing_api_cmd_check_payment.c \
-# testing_api_cmd_poll_payment.c \
-# testing_api_cmd_refund_lookup.c
-# testing_api_cmd_track_transaction.c
-
libtalermerchanttesting_la_LIBADD = \
$(top_srcdir)/src/lib/libtalermerchant.la \
-ltalerexchange \
diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c
index b02d8c8b..ae13da9c 100644
--- a/src/testing/test_merchant_api.c
+++ b/src/testing/test_merchant_api.c
@@ -433,84 +433,6 @@ run (void *cls,
#endif
TALER_TESTING_cmd_end ()
};
- struct TALER_TESTING_Command track[] = {
-#if 0
- TALER_TESTING_cmd_merchant_track_transaction ("track-transaction-1",
- merchant_url,
- MHD_HTTP_OK,
- "deposit-simple"),
- TALER_TESTING_cmd_merchant_track_transfer ("track-transfer-1",
- merchant_url,
- MHD_HTTP_OK,
- "check_bank_transfer-498c"),
- TALER_TESTING_cmd_merchant_track_transfer ("track-transfer-again",
- merchant_url,
- MHD_HTTP_OK,
- "check_bank_transfer-498c"),
-#endif
- cmd_transfer_to_exchange ("create-reserve-2",
- "EUR:1"),
- TALER_TESTING_cmd_admin_add_incoming_with_ref ("create-reserve-2b",
- "EUR:4.01",
- &bc.exchange_auth,
- payer_payto,
- "create-reserve-2"),
- cmd_exec_wirewatch ("wirewatch-2"),
- TALER_TESTING_cmd_check_bank_admin_transfer ("check_bank_transfer-2a",
- "EUR:1",
- payer_payto,
- exchange_payto,
- "create-reserve-2"),
- TALER_TESTING_cmd_check_bank_admin_transfer ("check_bank_transfer-2b",
- "EUR:4.01",
- payer_payto,
- exchange_payto,
- "create-reserve-2"),
- TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-2",
- "create-reserve-2",
- "EUR:5",
- MHD_HTTP_OK),
- TALER_TESTING_cmd_merchant_pay_order ("deposit-simple-2",
- merchant_url,
- MHD_HTTP_OK,
- "create-proposal-2",
- "withdraw-coin-2",
- "EUR:5",
- "EUR:4.99"),
- CMD_EXEC_AGGREGATOR ("run-aggregator-2"),
- TALER_TESTING_cmd_check_bank_transfer ("check_bank_transfer-498c-2",
- EXCHANGE_URL,
- "EUR:4.98",
- exchange_payto,
- merchant_payto),
- TALER_TESTING_cmd_check_bank_empty ("check_bank_empty"),
-#if 0
- TALER_TESTING_cmd_merchant_track_transfer ("track-transfer-2",
- merchant_url,
- MHD_HTTP_OK,
- "check_bank_transfer-498c-2"),
- TALER_TESTING_cmd_merchant_track_transfer ("track-transfer-2-again",
- merchant_url,
- MHD_HTTP_OK,
- "check_bank_transfer-498c-2"),
- TALER_TESTING_cmd_merchant_track_transaction ("track-transaction-2",
- merchant_url,
- MHD_HTTP_OK,
- "deposit-simple-2"),
- TALER_TESTING_cmd_history ("history-1",
- merchant_url,
- MHD_HTTP_OK,
- GNUNET_TIME_UNIT_ZERO_ABS,
- /**
- * Now we expect BOTH contracts (create-proposal-{1,2})
- * to be included in /history response, because
- * create-proposal-2 has now been correctly paid.
- */2,
- 10,
- -10),
-#endif
- TALER_TESTING_cmd_end ()
- };
struct TALER_TESTING_Command refund[] = {
cmd_transfer_to_exchange ("create-reserve-1r",
@@ -1165,21 +1087,6 @@ run (void *cls,
pay),
TALER_TESTING_cmd_batch ("double-spending",
double_spending),
-#if 0
- TALER_TESTING_cmd_batch ("track",
- track),
- TALER_TESTING_cmd_history ("history-2",
- merchant_url,
- MHD_HTTP_OK,
- GNUNET_TIME_absolute_add (
- GNUNET_TIME_UNIT_ZERO_ABS,
- GNUNET_TIME_UNIT_MICROSECONDS),
- /* zero results expected, there isn't any row with id
- * bigger than 10. */
- 0,
- 10,
- 10),
-#endif
TALER_TESTING_cmd_batch ("pay-again",
pay_again),
TALER_TESTING_cmd_batch ("pay-abort",
@@ -1188,14 +1095,6 @@ run (void *cls,
refund),
TALER_TESTING_cmd_batch ("tip",
tip),
-#if 0
- TALER_TESTING_cmd_history_default_start ("history-default-start",
- merchant_url,
- MHD_HTTP_OK,
- GNUNET_TIME_UNIT_ZERO_ABS,
- 5, /* Expected number of records */
- -100), /* Delta */
-#endif
/**
* End the suite. Fixme: better to have a label for this
* too, as it shows a "(null)" token on logs.
diff --git a/src/testing/testing_api_cmd_check_payment.c b/src/testing/testing_api_cmd_check_payment.c
deleted file mode 100644
index 8d59129e..00000000
--- a/src/testing/testing_api_cmd_check_payment.c
+++ /dev/null
@@ -1,495 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014-2019 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 lib/testing_api_cmd_check_payment.c
- * @brief command to test the /check-payment feature.
- * @author Marcello Stanisci
- */
-#include "platform.h"
-#include <taler/taler_exchange_service.h>
-#include <taler/taler_testing_lib.h>
-#include <taler/taler_signatures.h>
-#include "taler_merchant_service.h"
-#include "taler_merchant_testing_lib.h"
-
-
-/**
- * State for a /check-payment conclude CMD.
- */
-struct CheckPaymentConcludeState;
-
-/**
- * State for a /check-payment CMD.
- */
-struct CheckPaymentState
-{
-
- /**
- * Operation handle.
- */
- struct TALER_MERCHANT_CheckPaymentOperation *cpo;
-
- /**
- * The interpreter state.
- */
- struct TALER_TESTING_Interpreter *is;
-
- /**
- * The merchant base URL.
- */
- const char *merchant_url;
-
- /**
- * Reference to a command that can provide a order id,
- * typically a /proposal test command.
- */
- const char *proposal_reference;
-
- /**
- * State for a /check-payment conclude CMD.
- */
- struct CheckPaymentConcludeState *cs;
-
- /**
- * 0 if long-polling is not desired.
- */
- struct GNUNET_TIME_Relative timeout;
-
- /**
- * Set to the start time of the @e cpo plus the @e timeout.
- */
- struct GNUNET_TIME_Absolute deadline;
-
- /**
- * #GNUNET_YES if we expect the proposal was paid, synchronous variant.
- */
- int expect_paid;
-
- /**
- * #GNUNET_YES if the proposal was paid.
- */
- int paid;
-
- /**
- * #GNUNET_YES if the proposal was paid and then refunded
- */
- int refunded;
-
- /**
- * Observed HTTP response status code.
- */
- unsigned int http_status;
-
- /**
- * Expected HTTP response status code, synchronous variant.
- */
- unsigned int expected_http_status;
-
-};
-
-
-/**
- * State for a /check-payment conclude CMD.
- */
-struct CheckPaymentConcludeState
-{
-
- /**
- * The interpreter state.
- */
- struct TALER_TESTING_Interpreter *is;
-
- /**
- * Reference to a command that can provide a check payment start command.
- */
- const char *start_reference;
-
- /**
- * Task to wait for the deadline.
- */
- struct GNUNET_SCHEDULER_Task *task;
-
- /**
- * Expected HTTP response status code.
- */
- unsigned int expected_http_status;
-
- /**
- * #GNUNET_YES if the proposal was expected to be paid.
- */
- int expected_paid;
-
-};
-
-
-/**
- * Free a /check-payment CMD, and possibly cancel a pending
- * operation thereof.
- *
- * @param cls closure
- * @param cmd the command currently getting freed.
- */
-static void
-check_payment_cleanup (void *cls,
- const struct TALER_TESTING_Command *cmd)
-{
- struct CheckPaymentState *cps = cls;
-
- if (NULL != cps->cpo)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Command `%s' was not terminated\n",
- TALER_TESTING_interpreter_get_current_label (
- cps->is));
- TALER_MERCHANT_check_payment_cancel (cps->cpo);
- }
- GNUNET_free (cps);
-}
-
-
-/**
- * Task called when either the timeout for the /check-payment
- * command expired or we got a response. Checks if the
- * result is what we expected.
- *
- * @param cls a `struct CheckPaymentConcludeState`
- */
-static void
-conclude_task (void *cls)
-{
- struct CheckPaymentConcludeState *cpc = cls;
- const struct TALER_TESTING_Command *check_cmd;
- struct CheckPaymentState *cps;
- struct GNUNET_TIME_Absolute now;
-
- cpc->task = NULL;
- check_cmd =
- TALER_TESTING_interpreter_lookup_command (cpc->is,
- cpc->start_reference);
- if (NULL == check_cmd)
- TALER_TESTING_FAIL (cpc->is);
- cps = check_cmd->cls;
- if (NULL != cps->cpo)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Expected /poll/payment to have completed, but it did not!\n");
- TALER_TESTING_FAIL (cpc->is);
- }
- if (cps->http_status != cpc->expected_http_status)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Expected HTTP status %u, got %u\n",
- cpc->expected_http_status,
- cps->http_status);
- TALER_TESTING_FAIL (cps->is);
- }
- now = GNUNET_TIME_absolute_get ();
- if ( (GNUNET_NO == cps->paid) &&
- (GNUNET_TIME_absolute_add (cps->deadline,
- GNUNET_TIME_UNIT_SECONDS).abs_value_us <
- now.abs_value_us) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Expected answer to be delayed until %llu, but got response at %llu\n",
- (unsigned long long) cps->deadline.abs_value_us,
- (unsigned long long) now.abs_value_us);
- TALER_TESTING_FAIL (cps->is);
- }
- if (cps->paid != cpc->expected_paid)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Expected paid status %u, got %u\n",
- cpc->expected_paid,
- cps->paid);
- TALER_TESTING_FAIL (cps->is);
- }
- TALER_TESTING_interpreter_next (cps->is);
-}
-
-
-/**
- * Callback for a /check-payment request.
- *
- * @param cls closure.
- * @param hr HTTP response we got
- * @param paid #GNUNET_YES (#GNUNET_NO) if the contract was paid
- * (not paid).
- * @param refunded #GNUNET_YES (#GNUNET_NO) if the contract was
- * refunded (not refunded).
- * @param refund_amount the amount that was refunded to this
- * contract.
- * @param taler_pay_uri the URI that instructs the wallets to process
- * the payment
- */
-static void
-check_payment_cb (void *cls,
- const struct TALER_MERCHANT_HttpResponse *hr,
- int paid,
- int refunded,
- struct TALER_Amount *refund_amount,
- const char *taler_pay_uri)
-{
- struct CheckPaymentState *cps = cls;
-
- cps->cpo = NULL;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "check payment (%s): expected paid: %d, paid: %d, url: %s\n",
- TALER_TESTING_interpreter_get_current_label (cps->is),
- cps->expect_paid,
- paid,
- taler_pay_uri);
- cps->paid = paid;
- cps->http_status = hr->http_status;
- cps->refunded = refunded;
- if (0 == cps->timeout.rel_value_us)
- {
- /* synchronous variant */
- if (paid != cps->expect_paid)
- TALER_TESTING_FAIL (cps->is);
- if (cps->expected_http_status != hr->http_status)
- TALER_TESTING_FAIL (cps->is);
- TALER_TESTING_interpreter_next (cps->is);
- }
- else
- {
- /* asynchronous variant */
- if (NULL != cps->cs)
- {
- GNUNET_SCHEDULER_cancel (cps->cs->task);
- cps->cs->task = GNUNET_SCHEDULER_add_now (&conclude_task,
- cps->cs);
- }
- }
-}
-
-
-/**
- * Run a /check-payment CMD.
- *
- * @param cmd the command currently being run.
- * @param cls closure.
- * @param is interpreter state.
- */
-static void
-check_payment_run (void *cls,
- const struct TALER_TESTING_Command *cmd,
- struct TALER_TESTING_Interpreter *is)
-{
- struct CheckPaymentState *cps = cls;
- const struct TALER_TESTING_Command *proposal_cmd;
- const char *order_id;
-
- cps->is = is;
- proposal_cmd
- = TALER_TESTING_interpreter_lookup_command (is,
- cps->proposal_reference);
- if (NULL == proposal_cmd)
- TALER_TESTING_FAIL (is);
- if (GNUNET_OK != TALER_TESTING_get_trait_order_id (
- proposal_cmd, 0, &order_id))
- TALER_TESTING_FAIL (is);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Checking for order id `%s'\n",
- order_id);
- cps->cpo = TALER_MERCHANT_check_payment (is->ctx,
- cps->merchant_url,
- order_id,
- NULL,
- cps->timeout,
- &check_payment_cb,
- cps);
- GNUNET_assert (NULL != cps->cpo);
- if (0 != cps->timeout.rel_value_us)
- TALER_TESTING_interpreter_next (cps->is);
-}
-
-
-/**
- * Make a "check payment" test command.
- *
- * @param label command label.
- * @param merchant_url merchant base url
- * @param http_status expected HTTP response code.
- * @param proposal_reference the proposal whose payment status
- * is going to be checked.
- * @param expect_paid #GNUNET_YES if we expect the proposal to be
- * paid, #GNUNET_NO otherwise.
- * @return the command
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_check_payment (const char *label,
- const char *merchant_url,
- unsigned int http_status,
- const char *proposal_reference,
- unsigned int expect_paid)
-{
- struct CheckPaymentState *cps;
-
- cps = GNUNET_new (struct CheckPaymentState);
- cps->expected_http_status = http_status;
- cps->proposal_reference = proposal_reference;
- cps->expect_paid = expect_paid;
- cps->merchant_url = merchant_url;
- {
- struct TALER_TESTING_Command cmd = {
- .cls = cps,
- .label = label,
- .run = &check_payment_run,
- .cleanup = &check_payment_cleanup
- };
-
- return cmd;
- }
-}
-
-
-/**
- * Make a "check payment" test command with long polling support.
- *
- * @param label command label.
- * @param merchant_url merchant base url
- * @param proposal_reference the proposal whose payment status
- * is going to be checked.
- * @param timeout how long to wait during long polling for the reply
- * @return the command
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_check_payment_start (const char *label,
- const char *merchant_url,
- const char *proposal_reference,
- struct GNUNET_TIME_Relative timeout)
-{
- struct CheckPaymentState *cps;
-
- if (0 == timeout.rel_value_us)
- timeout.rel_value_us = 1; /* 0 reserved for blocking version */
- cps = GNUNET_new (struct CheckPaymentState);
- cps->timeout = timeout;
- cps->proposal_reference = proposal_reference;
- cps->merchant_url = merchant_url;
- {
- struct TALER_TESTING_Command cmd = {
- .cls = cps,
- .label = label,
- .run = &check_payment_run,
- .cleanup = &check_payment_cleanup
- };
-
- return cmd;
- }
-}
-
-
-/**
- * Free a /check-payment conclusion CMD, and possibly cancel a pending
- * operation thereof.
- *
- * @param cls closure
- * @param cmd the command currently getting freed.
- */
-static void
-check_payment_conclude_cleanup (void *cls,
- const struct TALER_TESTING_Command *cmd)
-{
- struct CheckPaymentConcludeState *cps = cls;
-
- if (NULL != cps->task)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Command `%s' was not terminated\n",
- TALER_TESTING_interpreter_get_current_label (
- cps->is));
- GNUNET_SCHEDULER_cancel (cps->task);
- cps->task = NULL;
- }
- GNUNET_free (cps);
-}
-
-
-/**
- * Run a /check-payment conclusion CMD.
- *
- * @param cmd the command currently being run.
- * @param cls closure.
- * @param is interpreter state.
- */
-static void
-check_payment_conclude_run (void *cls,
- const struct TALER_TESTING_Command *cmd,
- struct TALER_TESTING_Interpreter *is)
-{
- struct CheckPaymentConcludeState *cpc = cls;
- const struct TALER_TESTING_Command *check_cmd;
- struct CheckPaymentState *cps;
-
- cpc->is = is;
- check_cmd
- = TALER_TESTING_interpreter_lookup_command (is,
- cpc->start_reference);
- if (NULL == check_cmd)
- TALER_TESTING_FAIL (cpc->is);
- GNUNET_assert (check_cmd->run == &check_payment_run);
- cps = check_cmd->cls;
- if (NULL == cps->cpo)
- cpc->task = GNUNET_SCHEDULER_add_now (&conclude_task,
- cpc);
- else
- cpc->task = GNUNET_SCHEDULER_add_at (cps->deadline,
- &conclude_task,
- cpc);
-}
-
-
-/**
- * Expect completion of a long-polled "check payment" test command.
- *
- * @param label command label.
- * @param check_start_reference payment start operation that should have
- * completed
- * @param http_status expected HTTP response code.
- * @param expect_paid #GNUNET_YES if we expect the proposal to be
- * paid, #GNUNET_NO otherwise.
- * @return the command
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_check_payment_conclude (const char *label,
- unsigned int http_status,
- const char *poll_start_reference,
- unsigned int expect_paid)
-{
- struct CheckPaymentConcludeState *cps;
-
- cps = GNUNET_new (struct CheckPaymentConcludeState);
- cps->start_reference = poll_start_reference;
- cps->expected_paid = expect_paid;
- cps->expected_http_status = http_status;
- {
- struct TALER_TESTING_Command cmd = {
- .cls = cps,
- .label = label,
- .run = &check_payment_conclude_run,
- .cleanup = &check_payment_conclude_cleanup
- };
-
- return cmd;
- }
-}
-
-
-/* end of testing_api_cmd_check_payment.c */
diff --git a/src/testing/testing_api_cmd_history.c b/src/testing/testing_api_cmd_history.c
deleted file mode 100644
index dabbf3cc..00000000
--- a/src/testing/testing_api_cmd_history.c
+++ /dev/null
@@ -1,359 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014-2018 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 lib/testing_api_cmd_history.c
- * @brief command to test the /history API.
- * @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 "history" CMD.
- */
-struct HistoryState
-{
-
- /**
- * Expected status code.
- */
- unsigned int http_status;
-
- /**
- * URL of the merchant backend serving the /history request.
- */
- const char *merchant_url;
-
- /**
- * The interpreter state.
- */
- struct TALER_TESTING_Interpreter *is;
-
- /**
- * Handle to the /history operation.
- */
- struct TALER_MERCHANT_HistoryOperation *ho;
-
- /**
- * Only history entries younger than this
- * value will be returned.
- */
- struct GNUNET_TIME_Absolute time;
-
- /**
- * First row index we want in the results.
- */
- unsigned long long start;
-
- /**
- * When this flag is GNUNET_YES, then the interpreter
- * will request /history *omitting* the 'start' URL argument.
- */
- int use_default_start;
-
- /**
- * How many rows we want the response to contain, at most.
- */
- long long nrows;
-
- /**
- * Expected number of history entries returned by the
- * backend.
- */
- unsigned int nresult;
-};
-
-
-/**
- * Callback for a /history request; checks that (1) HTTP status
- * is expected, the number of rows returned is expected, and that
- * the rows are sorted from the youngest to the oldest record.
- *
- * @param cls closure
- * @param hr HTTP response we got
- */
-static void
-history_cb (void *cls,
- const struct TALER_MERCHANT_HttpResponse *hr)
-{
- struct HistoryState *hs = cls;
- unsigned int nresult;
- struct GNUNET_TIME_Absolute last_timestamp;
- struct GNUNET_TIME_Absolute entry_timestamp;
- json_t *arr;
-
- hs->ho = NULL;
-
- if (hs->http_status != hr->http_status)
- TALER_TESTING_FAIL (hs->is);
-
- if (MHD_HTTP_OK != hs->http_status)
- {
- /* move on without further checking. */
- TALER_TESTING_interpreter_next (hs->is);
- return;
- }
-
- arr = json_object_get (hr->reply,
- "history");
- nresult = json_array_size (arr);
- if (hs->nresult != nresult)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected number of history entries: Got %d, expected %d\n",
- nresult,
- hs->nresult);
- TALER_TESTING_FAIL (hs->is);
- }
-
- last_timestamp = GNUNET_TIME_absolute_get ();
- last_timestamp = GNUNET_TIME_absolute_add (last_timestamp,
- GNUNET_TIME_UNIT_DAYS);
- {
- json_t *entry;
- size_t index;
- json_array_foreach (arr, index, entry)
- {
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_absolute_time ("timestamp",
- &entry_timestamp),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (entry,
- spec,
- NULL, NULL))
- TALER_TESTING_FAIL (hs->is);
- if (last_timestamp.abs_value_us < entry_timestamp.abs_value_us)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "History entries are NOT sorted from younger to older\n");
- TALER_TESTING_interpreter_fail (hs->is);
- return;
- }
- last_timestamp = entry_timestamp;
- }
- }
- TALER_TESTING_interpreter_next (hs->is);
-}
-
-
-/**
- * Free the state for a "history" CMD, and possibly cancel
- * any pending operation thereof.
- *
- * @param cls closure
- * @param cmd command being freed now.
- */
-static void
-history_cleanup (void *cls,
- const struct TALER_TESTING_Command *cmd)
-{
- struct HistoryState *hs = cls;
-
- if (NULL != hs->ho)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "/history operation did not complete\n");
- TALER_MERCHANT_history_cancel (hs->ho);
- }
- GNUNET_free (hs);
-}
-
-
-/**
- * Run a "history" CMD.
- *
- * @param cls closure.
- * @param cmd current command.
- * @param is interpreter state.
- */
-static void
-history_run (void *cls,
- const struct TALER_TESTING_Command *cmd,
- struct TALER_TESTING_Interpreter *is)
-{
- struct HistoryState *hs = cls;
-
- hs->is = is;
- if (0 == hs->time.abs_value_us)
- {
- hs->time = GNUNET_TIME_absolute_add
- (GNUNET_TIME_absolute_get (),
- GNUNET_TIME_UNIT_HOURS);
- GNUNET_TIME_round_abs (&hs->time);
- }
-
- switch (hs->use_default_start)
- {
- case GNUNET_YES:
- hs->ho = TALER_MERCHANT_history_default_start
- (is->ctx,
- hs->merchant_url,
- hs->nrows,
- hs->time,
- &history_cb,
- hs);
- break;
-
- case GNUNET_NO:
- hs->ho = TALER_MERCHANT_history (is->ctx,
- hs->merchant_url,
- hs->start,
- hs->nrows,
- hs->time,
- &history_cb,
- hs);
- break;
- default:
- TALER_LOG_ERROR ("Bad value for 'use_default_start'\n");
- TALER_TESTING_FAIL (is);
- }
-
- if (NULL == hs->ho)
- TALER_TESTING_FAIL (is);
-}
-
-
-/**
- * Make a "history" command.
- *
- * @param label command label.
- * @param merchant_url base URL of the merchant serving the
- * request.
- * @param ctx CURL context.
- * @param http_status expected HTTP response code
- * @param time limit towards the past for the history
- * records we want returned.
- * @param nresult how many results are expected
- * @param start first row id we want in the result.
- * @param use_default_start if GNUNET_YES, then it will
- * use the API call that requests /history omitting
- * the 'start' argument. This makes easier to test
- * the server default behaviour.
- * @param nrows how many row we want to receive, at most.
- */
-static struct TALER_TESTING_Command
-cmd_history2 (const char *label,
- const char *merchant_url,
- unsigned int http_status,
- struct GNUNET_TIME_Absolute time,
- unsigned int nresult,
- unsigned long long start,
- int use_default_start,
- long long nrows)
-{
- struct HistoryState *hs;
-
- hs = GNUNET_new (struct HistoryState);
- hs->http_status = http_status;
- hs->time = time;
- hs->nresult = nresult;
- hs->start = start;
- hs->nrows = nrows;
- hs->merchant_url = merchant_url;
- hs->use_default_start = use_default_start;
- {
- struct TALER_TESTING_Command cmd = {
- .cls = hs,
- .label = label,
- .run = &history_run,
- .cleanup = &history_cleanup
- };
-
- return cmd;
- }
-}
-
-
-/**
- * Make a "history" command.
- *
- * @param label command label.
- * @param merchant_url base URL of the merchant serving the
- * request.
- * @param ctx CURL context.
- * @param http_status expected HTTP response code
- * @param time limit towards the past for the history
- * records we want returned.
- * @param nresult how many results are expected
- * @param nrows how many row we want to receive, at most.
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_history_default_start
- (const char *label,
- const char *merchant_url,
- unsigned int http_status,
- struct GNUNET_TIME_Absolute time,
- unsigned int nresult,
- long long nrows)
-{
- return cmd_history2 (label,
- merchant_url,
- http_status,
- time,
- nresult,
- -1, /* ignored */
- GNUNET_YES,
- nrows);
-}
-
-
-/**
- * Make a "history" command.
- *
- * @param label command label.
- * @param merchant_url base URL of the merchant serving the
- * request.
- * @param ctx CURL context.
- * @param http_status expected HTTP response code
- * @param time limit towards the past for the history
- * records we want returned.
- * @param nresult how many results are expected
- * @param start first row id we want in the result.
- * @param nrows how many row we want to receive, at most.
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_history (const char *label,
- const char *merchant_url,
- unsigned int http_status,
- struct GNUNET_TIME_Absolute time,
- unsigned int nresult,
- unsigned long long start,
- long long nrows)
-{
- return cmd_history2 (label,
- merchant_url,
- http_status,
- time,
- nresult,
- start,
- GNUNET_NO,
- nrows);
-}
-
-
-/* end of testing_api_cmd_history.c */
diff --git a/src/testing/testing_api_cmd_poll_payment.c b/src/testing/testing_api_cmd_poll_payment.c
deleted file mode 100644
index 9575e32e..00000000
--- a/src/testing/testing_api_cmd_poll_payment.c
+++ /dev/null
@@ -1,491 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014-2018 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 lib/testing_api_cmd_poll_payment.c
- * @brief command to test the /public/poll-payment feature.
- * @author Christian Grothoff
- * @author Marcello Stanisci
- */
-#include "platform.h"
-#include <taler/taler_exchange_service.h>
-#include <taler/taler_testing_lib.h>
-#include <taler/taler_signatures.h>
-#include "taler_merchant_service.h"
-#include "taler_merchant_testing_lib.h"
-
-
-/**
- * State for a /poll-payment conclude CMD.
- */
-struct PollPaymentConcludeState;
-
-
-/**
- * State for a /poll-payment start CMD.
- */
-struct PollPaymentStartState
-{
-
- /**
- * Operation handle.
- */
- struct TALER_MERCHANT_PollPaymentOperation *cpo;
-
- /**
- * The interpreter state.
- */
- struct TALER_TESTING_Interpreter *is;
-
- /**
- * Reference to a command that can provide a order id,
- * typically a /proposal test command.
- */
- const char *proposal_reference;
-
- /**
- * The merchant base URL.
- */
- const char *merchant_url;
-
- /**
- * Conclude state waiting for completion (if any).
- */
- struct PollPaymentConcludeState *cs;
-
- /**
- * How long is the long-polling allowed to take?
- */
- struct GNUNET_TIME_Relative timeout;
-
- /**
- * Set to the start time of the @e cpo plus the @e timeout.
- */
- struct GNUNET_TIME_Absolute deadline;
-
- /**
- * Amount refunded, set if @e refunded is #GNUNET_YES
- */
- struct TALER_Amount refund;
-
- /**
- * Refund to wait for, set if @e wait_for_refund is #GNUNET_YES
- */
- struct TALER_Amount min_refund;
-
- /**
- * Final HTTP response status code.
- */
- unsigned int http_status;
-
- /**
- * #GNUNET_YES if the proposal was paid.
- */
- int paid;
-
- /**
- * #GNUNET_YES if the proposal was paid and then refunded
- */
- int refunded;
-
- /**
- * #GNUNET_YES if we are waiting for a refund.
- */
- int wait_for_refund;
-
-};
-
-
-/**
- * State for a /poll-payment conclude CMD.
- */
-struct PollPaymentConcludeState
-{
-
- /**
- * The interpreter state.
- */
- struct TALER_TESTING_Interpreter *is;
-
- /**
- * Reference to a command that can provide a poll payment start command.
- */
- const char *start_reference;
-
- /**
- * Task to wait for the deadline.
- */
- struct GNUNET_SCHEDULER_Task *task;
-
- /**
- * Expected HTTP response status code.
- */
- unsigned int expected_http_status;
-
- /**
- * #GNUNET_YES if the proposal was expected to be paid.
- */
- int expected_paid;
-
-};
-
-
-/**
- * Free a /poll-payment CMD, and possibly cancel a pending
- * operation thereof.
- *
- * @param cls closure
- * @param cmd the command currently getting freed.
- */
-static void
-poll_payment_start_cleanup (void *cls,
- const struct TALER_TESTING_Command *cmd)
-{
- struct PollPaymentStartState *cps = cls;
-
- if (NULL != cps->cpo)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Command `%s' was not terminated\n",
- TALER_TESTING_interpreter_get_current_label (
- cps->is));
- TALER_MERCHANT_poll_payment_cancel (cps->cpo);
- }
- GNUNET_free (cps);
-}
-
-
-/**
- * Task called when either the timeout for the /poll-payment
- * command expired or we got a response. Checks if the
- * result is what we expected.
- *
- * @param cls a `struct PollPaymentConcludeState`
- */
-static void
-conclude_task (void *cls)
-{
- struct PollPaymentConcludeState *ppc = cls;
- const struct TALER_TESTING_Command *poll_cmd;
- struct PollPaymentStartState *cps;
- struct GNUNET_TIME_Absolute now;
-
- ppc->task = NULL;
- poll_cmd =
- TALER_TESTING_interpreter_lookup_command (ppc->is,
- ppc->start_reference);
- if (NULL == poll_cmd)
- TALER_TESTING_FAIL (ppc->is);
- cps = poll_cmd->cls;
- if (NULL != cps->cpo)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Expected /poll/payment to have completed, but it did not!\n");
- TALER_TESTING_FAIL (ppc->is);
- }
- if (cps->http_status != ppc->expected_http_status)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Expected HTTP status %u, got %u\n",
- ppc->expected_http_status,
- cps->http_status);
- TALER_TESTING_FAIL (ppc->is);
- }
- now = GNUNET_TIME_absolute_get ();
- if ( (GNUNET_NO == cps->paid) &&
- (GNUNET_TIME_absolute_add (cps->deadline,
- GNUNET_TIME_UNIT_SECONDS).abs_value_us <
- now.abs_value_us) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Expected answer to be delayed until %llu, but got response at %llu\n",
- (unsigned long long) cps->deadline.abs_value_us,
- (unsigned long long) now.abs_value_us);
- TALER_TESTING_FAIL (ppc->is);
- }
- if (cps->paid != ppc->expected_paid)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Expected paid status %u, got %u\n",
- ppc->expected_paid,
- cps->paid);
- TALER_TESTING_FAIL (ppc->is);
- }
- TALER_TESTING_interpreter_next (ppc->is);
-}
-
-
-/**
- * Callback for a /poll-payment request.
- *
- * @param cls closure.
- * @param hr HTTP response we got
- * @param paid #GNUNET_YES (#GNUNET_NO) if the contract was (not) paid
- * @param refunded #GNUNET_YES (#GNUNET_NO) if the contract was
- * (not) refunded.
- * @param refund_amount the amount that was refunded to this
- * contract.
- * @param taler_pay_uri the URI that instructs the wallets to process
- * the payment
- */
-static void
-poll_payment_cb (void *cls,
- const struct TALER_MERCHANT_HttpResponse *hr,
- int paid,
- int refunded,
- struct TALER_Amount *refund_amount,
- const char *taler_pay_uri)
-{
- struct PollPaymentStartState *cps = cls;
-
- cps->cpo = NULL;
- if ( (MHD_HTTP_OK != hr->http_status) &&
- (NULL != hr->reply) )
- {
- char *log = json_dumps (hr->reply,
- JSON_COMPACT);
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Poll payment returned %u: %s\n",
- hr->http_status,
- log);
- free (log);
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Poll payment returned %u (%d/%d)\n",
- hr->http_status,
- paid,
- refunded);
- }
- cps->paid = paid;
- cps->http_status = hr->http_status;
- cps->refunded = refunded;
- if (GNUNET_YES == refunded)
- cps->refund = *refund_amount;
- if (NULL != cps->cs)
- {
- GNUNET_SCHEDULER_cancel (cps->cs->task);
- cps->cs->task = GNUNET_SCHEDULER_add_now (&conclude_task,
- cps->cs);
- }
-}
-
-
-/**
- * Run a /poll-payment CMD.
- *
- * @param cmd the command currently being run.
- * @param cls closure.
- * @param is interpreter state.
- */
-static void
-poll_payment_start_run (void *cls,
- const struct TALER_TESTING_Command *cmd,
- struct TALER_TESTING_Interpreter *is)
-{
- struct PollPaymentStartState *cps = cls;
- const struct TALER_TESTING_Command *proposal_cmd;
- const char *order_id;
- const struct GNUNET_HashCode *h_contract;
-
- cps->is = is;
- proposal_cmd
- = TALER_TESTING_interpreter_lookup_command (is,
- cps->proposal_reference);
- if (NULL == proposal_cmd)
- TALER_TESTING_FAIL (is);
- if (GNUNET_OK !=
- TALER_TESTING_get_trait_order_id (proposal_cmd,
- 0,
- &order_id))
- TALER_TESTING_FAIL (is);
- if (GNUNET_OK !=
- TALER_TESTING_get_trait_h_contract_terms (proposal_cmd,
- 0,
- &h_contract))
- TALER_TESTING_FAIL (is);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Polling for order id `%s'\n",
- order_id);
- /* add 1s grace time to timeout */
- cps->deadline
- = GNUNET_TIME_absolute_add (GNUNET_TIME_relative_to_absolute (cps->timeout),
- GNUNET_TIME_UNIT_SECONDS);
- cps->cpo = TALER_MERCHANT_poll_payment (is->ctx,
- cps->merchant_url,
- order_id,
- h_contract,
- NULL, /* session id */
- cps->timeout,
- (GNUNET_YES == cps->wait_for_refund)
- ? &cps->min_refund
- : NULL,
- &poll_payment_cb,
- cps);
- GNUNET_assert (NULL != cps->cpo);
- /* We CONTINUE to run the interpreter while the long-polled command
- completes asynchronously! */
- TALER_TESTING_interpreter_next (cps->is);
-}
-
-
-/**
- * Start a long-polled "poll-payment" test command.
- *
- * @param label command label.
- * @param merchant_url merchant base url
- * @param proposal_reference the proposal whose payment status
- * is going to be checked.
- * @param min_refund minimum refund to wait for
- * @param timeout which timeout to use
- * @return the command
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_poll_payment_start (const char *label,
- const char *merchant_url,
- const char *proposal_reference,
- const char *min_refund,
- struct GNUNET_TIME_Relative timeout)
-{
- struct PollPaymentStartState *cps;
-
- cps = GNUNET_new (struct PollPaymentStartState);
- cps->proposal_reference = proposal_reference;
- cps->merchant_url = merchant_url;
- cps->timeout = timeout;
- if (NULL != min_refund)
- {
- GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (min_refund,
- &cps->min_refund));
- cps->wait_for_refund = GNUNET_YES;
- }
- {
- struct TALER_TESTING_Command cmd = {
- .cls = cps,
- .label = label,
- .run = &poll_payment_start_run,
- .cleanup = &poll_payment_start_cleanup
- };
-
- return cmd;
- }
-}
-
-
-/**
- * Free a /poll-payment CMD, and possibly cancel a pending
- * operation thereof.
- *
- * @param cls closure
- * @param cmd the command currently getting freed.
- */
-static void
-poll_payment_conclude_cleanup (void *cls,
- const struct TALER_TESTING_Command *cmd)
-{
- struct PollPaymentConcludeState *cps = cls;
-
- if (NULL != cps->task)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Command `%s' was not terminated\n",
- TALER_TESTING_interpreter_get_current_label (
- cps->is));
- GNUNET_SCHEDULER_cancel (cps->task);
- cps->task = NULL;
- }
- GNUNET_free (cps);
-}
-
-
-/**
- * Run a /poll-payment CMD.
- *
- * @param cmd the command currently being run.
- * @param cls closure.
- * @param is interpreter state.
- */
-static void
-poll_payment_conclude_run (void *cls,
- const struct TALER_TESTING_Command *cmd,
- struct TALER_TESTING_Interpreter *is)
-{
- struct PollPaymentConcludeState *ppc = cls;
- const struct TALER_TESTING_Command *poll_cmd;
- struct PollPaymentStartState *cps;
-
- ppc->is = is;
- poll_cmd =
- TALER_TESTING_interpreter_lookup_command (is,
- ppc->start_reference);
- if (NULL == poll_cmd)
- TALER_TESTING_FAIL (ppc->is);
- GNUNET_assert (poll_cmd->run == &poll_payment_start_run);
- cps = poll_cmd->cls;
- cps->cs = ppc;
- if (NULL == cps->cpo)
- ppc->task = GNUNET_SCHEDULER_add_now (&conclude_task,
- ppc);
- else
- ppc->task = GNUNET_SCHEDULER_add_at (cps->deadline,
- &conclude_task,
- ppc);
-}
-
-
-/**
- * Expect completion of a long-polled "poll payment" test command.
- *
- * @param label command label.
- * @param poll_start_reference payment start operation that should have
- * completed
- * @param http_status expected HTTP response code.
- * @param expect_paid #GNUNET_YES if we expect the proposal to be
- * paid, #GNUNET_NO otherwise.
- * @return the command
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_poll_payment_conclude (const char *label,
- unsigned int http_status,
- const char *poll_start_reference,
- unsigned int expect_paid)
-{
- struct PollPaymentConcludeState *cps;
-
- cps = GNUNET_new (struct PollPaymentConcludeState);
- cps->start_reference = poll_start_reference;
- cps->expected_paid = expect_paid;
- cps->expected_http_status = http_status;
- {
- struct TALER_TESTING_Command cmd = {
- .cls = cps,
- .label = label,
- .run = &poll_payment_conclude_run,
- .cleanup = &poll_payment_conclude_cleanup
- };
-
- return cmd;
- }
-}
-
-
-/* end of testing_api_cmd_poll_payment.c */
diff --git a/src/testing/testing_api_cmd_refund_lookup.c b/src/testing/testing_api_cmd_refund_lookup.c
deleted file mode 100644
index 7db933a4..00000000
--- a/src/testing/testing_api_cmd_refund_lookup.c
+++ /dev/null
@@ -1,457 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014-2018 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 lib/testing_api_cmd_refund_lookup.c
- * @brief command to test refunds.
- * @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 "refund lookup" CMD.
- */
-struct RefundLookupState
-{
- /**
- * Operation handle for a GET /public/refund request.
- */
- struct TALER_MERCHANT_RefundLookupOperation *rlo;
-
- /**
- * Base URL of the merchant serving the request.
- */
- const char *merchant_url;
-
- /**
- * Order id to look up.
- */
- const char *order_id;
-
- /**
- * Reference to a "pay" CMD, used to double-check if
- * refunded coins were actually spent:
- */
- const char *pay_reference;
-
- /**
- * Reference to a "refund increase" CMD that offer
- * the expected amount to be refunded; can be NULL.
- */
- const char *increase_reference;
-
- /**
- * Expected HTTP response code.
- */
- unsigned int http_code;
-
- /**
- * Interpreter state.
- */
- struct TALER_TESTING_Interpreter *is;
-
- /**
- * Explicit amount to be refunded, must be defined if @a
- * increase_reference is NULL.
- */
- const char *refund_amount;
-};
-
-
-/**
- * Free the state of a "refund lookup" CMD, and
- * possibly cancel a pending "refund lookup" operation.
- *
- * @param cls closure
- * @param cmd command currently being freed.
- */
-static void
-refund_lookup_cleanup (void *cls,
- const struct TALER_TESTING_Command *cmd)
-{
- struct RefundLookupState *rls = cls;
-
- if (NULL != rls->rlo)
- {
- TALER_LOG_WARNING ("Refund-lookup operation"
- " did not complete\n");
- TALER_MERCHANT_refund_lookup_cancel (rls->rlo);
- }
- GNUNET_free (rls);
-}
-
-
-/**
- * Process "GET /public/refund" (lookup) response;
- * mainly checking if the refunded amount matches the
- * expectation.
- *
- * @param cls closure
- * @param hr HTTP response we got
- * @param h_contract_terms hash of the contract terms to which the refund is applied
- * @param merchant_pub public key of the merchant
- * @param num_details length of the @a details array
- * @param details details about the refund processing
- */
-static void
-refund_lookup_cb (void *cls,
- const struct TALER_MERCHANT_HttpResponse *hr,
- const struct GNUNET_HashCode *h_contract_terms,
- const struct TALER_MerchantPublicKeyP *merchant_pub,
- unsigned int num_details,
- const struct TALER_MERCHANT_RefundDetail *details)
-{
- struct RefundLookupState *rls = cls;
- struct GNUNET_CONTAINER_MultiHashMap *map;
- const char *coin_reference;
- const char *icoin_reference;
- const char *refund_amount;
- struct TALER_Amount acc;
- struct TALER_Amount ra;
-
- rls->rlo = NULL;
- if (MHD_HTTP_GONE == rls->http_code)
- {
- /* special case: GONE is not the top-level code, but expected INSIDE the details */
- if (MHD_HTTP_OK != hr->http_status)
- TALER_TESTING_FAIL (rls->is);
- for (unsigned int i = 0; i<num_details; i++)
- if (MHD_HTTP_GONE != details[i].hr.http_status)
- TALER_TESTING_FAIL (rls->is);
- /* all good */
- TALER_TESTING_interpreter_next (rls->is);
- return;
- }
- if (rls->http_code != hr->http_status)
- TALER_TESTING_FAIL (rls->is);
- if (MHD_HTTP_OK != hr->http_status)
- {
- TALER_TESTING_interpreter_next (rls->is);
- return;
- }
- map = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO);
- /* Put in array every refunded coin. */
- for (unsigned int i = 0; i<num_details; i++)
- {
- struct GNUNET_HashCode h_coin_pub;
-
- if (MHD_HTTP_OK != details[i].hr.http_status)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Got unexpected status %u/%d for refunded coin %u\n",
- details[i].hr.http_status,
- (int) details[i].hr.ec,
- i);
- GNUNET_CONTAINER_multihashmap_destroy (map);
- TALER_TESTING_FAIL (rls->is);
- return;
- }
- TALER_LOG_DEBUG ("Coin %s refund is %s\n",
- TALER_B2S (&details[i].coin_pub),
- TALER_amount2s (&details[i].refund_amount));
- GNUNET_CRYPTO_hash (&details[i].coin_pub,
- sizeof (struct TALER_CoinSpendPublicKeyP),
- &h_coin_pub);
- if (GNUNET_OK !=
- GNUNET_CONTAINER_multihashmap_put (
- map,
- &h_coin_pub,
- (void *) &details[i],
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
- {
- GNUNET_CONTAINER_multihashmap_destroy (map);
- TALER_TESTING_FAIL (rls->is);
- }
- }
-
- /* Compare spent coins with refunded, and if they match,
- * increase an accumulator. */
- {
- const struct TALER_TESTING_Command *pay_cmd;
-
- if (NULL == (pay_cmd = TALER_TESTING_interpreter_lookup_command (
- rls->is,
- rls->pay_reference)))
- {
- GNUNET_CONTAINER_multihashmap_destroy (map);
- TALER_TESTING_FAIL (rls->is);
- }
-
- if (GNUNET_OK !=
- TALER_TESTING_get_trait_coin_reference (
- pay_cmd,
- 0,
- &coin_reference))
- {
- GNUNET_CONTAINER_multihashmap_destroy (map);
- TALER_TESTING_FAIL (rls->is);
- }
- }
-
- GNUNET_assert (GNUNET_OK ==
- TALER_amount_get_zero ("EUR",
- &acc));
- {
- char *coin_reference_dup;
-
- coin_reference_dup = GNUNET_strdup (coin_reference);
- for (icoin_reference = strtok (coin_reference_dup, ";");
- NULL != icoin_reference;
- icoin_reference = strtok (NULL, ";"))
- {
- const struct TALER_CoinSpendPrivateKeyP *icoin_priv;
- struct TALER_CoinSpendPublicKeyP icoin_pub;
- struct GNUNET_HashCode h_icoin_pub;
- const struct TALER_MERCHANT_RefundDetail *idetail;
- const struct TALER_TESTING_Command *icoin_cmd;
-
- if (NULL ==
- (icoin_cmd =
- TALER_TESTING_interpreter_lookup_command (rls->is,
- icoin_reference)) )
- {
- GNUNET_break (0);
- TALER_LOG_ERROR ("Bad reference `%s'\n",
- icoin_reference);
- TALER_TESTING_interpreter_fail (rls->is);
- GNUNET_CONTAINER_multihashmap_destroy (map);
- return;
- }
-
- if (GNUNET_OK !=
- TALER_TESTING_get_trait_coin_priv (icoin_cmd,
- 0,
- &icoin_priv))
- {
- GNUNET_break (0);
- TALER_LOG_ERROR ("Command `%s' failed to give coin priv trait\n",
- icoin_reference);
- TALER_TESTING_interpreter_fail (rls->is);
- GNUNET_CONTAINER_multihashmap_destroy (map);
- return;
- }
- GNUNET_CRYPTO_eddsa_key_get_public (&icoin_priv->eddsa_priv,
- &icoin_pub.eddsa_pub);
- TALER_LOG_DEBUG ("Looking at coin %s\n",
- TALER_B2S (&icoin_pub));
- GNUNET_CRYPTO_hash (&icoin_pub,
- sizeof (struct TALER_CoinSpendPublicKeyP),
- &h_icoin_pub);
-
- idetail = GNUNET_CONTAINER_multihashmap_get (map,
- &h_icoin_pub);
-
- /* Can be NULL: not all coins are involved in refund */
- if (NULL == idetail)
- continue;
- TALER_LOG_DEBUG ("Found coin %s refund of %s\n",
- TALER_B2S (&idetail->coin_pub),
- TALER_amount2s (&idetail->refund_amount));
- GNUNET_assert (0 <=
- TALER_amount_add (&acc,
- &acc,
- &idetail->refund_amount));
- }
- GNUNET_free (coin_reference_dup);
- }
-
-
- {
- const struct TALER_TESTING_Command *increase_cmd;
-
- if (NULL !=
- (increase_cmd
- = TALER_TESTING_interpreter_lookup_command (rls->is,
- rls->increase_reference)))
- {
- if (GNUNET_OK !=
- TALER_TESTING_get_trait_string (increase_cmd,
- 0,
- &refund_amount))
- TALER_TESTING_FAIL (rls->is);
-
- if (GNUNET_OK !=
- TALER_string_to_amount (refund_amount,
- &ra))
- TALER_TESTING_FAIL (rls->is);
- }
- else
- {
- GNUNET_assert (NULL != rls->refund_amount);
-
- if (GNUNET_OK !=
- TALER_string_to_amount (rls->refund_amount,
- &ra))
- TALER_TESTING_FAIL (rls->is);
- }
- }
- GNUNET_CONTAINER_multihashmap_destroy (map);
-
- /* Check that what the backend claims to have been refunded
- * actually matches _our_ refund expectation. */
- if (0 != TALER_amount_cmp (&acc,
- &ra))
- {
- char *a1;
-
- a1 = TALER_amount_to_string (&ra);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Incomplete refund: expected '%s', got '%s'\n",
- a1,
- TALER_amount2s (&acc));
- GNUNET_free (a1);
- TALER_TESTING_interpreter_fail (rls->is);
- return;
- }
-
- TALER_TESTING_interpreter_next (rls->is);
-}
-
-
-/**
- * Run the "refund lookup" CMD.
- *
- * @param cls closure.
- * @param cmd command being currently run.
- * @param is interpreter state.
- */
-static void
-refund_lookup_run (void *cls,
- const struct TALER_TESTING_Command *cmd,
- struct TALER_TESTING_Interpreter *is)
-{
- struct RefundLookupState *rls = cls;
-
- rls->is = is;
- rls->rlo = TALER_MERCHANT_refund_lookup (is->ctx,
- rls->merchant_url,
- rls->order_id,
- &refund_lookup_cb,
- rls);
- GNUNET_assert (NULL != rls->rlo);
-}
-
-
-/**
- * Define a "refund lookup" CMD.
- *
- * @param label command label.
- * @param merchant_url base URL of the merchant serving the
- * "refund lookup" request.
- * @param increase_reference reference to a "refund increase" CMD
- * that will offer the amount to check the looked up refund
- * against. Must NOT be NULL.
- * @param pay_reference reference to the "pay" CMD whose coins got
- * refunded. It is used to double-check if the refunded
- * coins were actually spent in the first place.
- * @param order_id order id whose refund status is to be looked up.
- * @param http_code expected HTTP response code.
- *
- * @return the command.
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_refund_lookup (
- const char *label,
- const char *merchant_url,
- const char *increase_reference,
- const char *pay_reference,
- const char *order_id,
- unsigned int http_code)
-{
- struct RefundLookupState *rls;
-
- rls = GNUNET_new (struct RefundLookupState);
- rls->merchant_url = merchant_url;
- rls->order_id = order_id;
- rls->pay_reference = pay_reference;
- rls->increase_reference = increase_reference;
- rls->http_code = http_code;
- {
- struct TALER_TESTING_Command cmd = {
- .cls = rls,
- .label = label,
- .run = &refund_lookup_run,
- .cleanup = &refund_lookup_cleanup
- };
-
- return cmd;
- }
-}
-
-
-/**
- * Define a "refund lookup" CMD, equipped with a expected refund
- * amount.
- *
- * @param label command label.
- * @param merchant_url base URL of the merchant serving the
- * "refund lookup" request.
- * @param increase_reference reference to a "refund increase" CMD
- * that will offer the amount to check the looked up refund
- * against. Can be NULL, takes precedence over @a
- * refund_amount.
- * @param pay_reference reference to the "pay" CMD whose coins got
- * refunded. It is used to double-check if the refunded
- * coins were actually spent in the first place.
- * @param order_id order id whose refund status is to be looked up.
- * @param http_code expected HTTP response code.
- * @param refund_amount expected refund amount. Must be defined
- * if @a increase_reference is NULL.
- *
- * @return the command.
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_refund_lookup_with_amount (
- const char *label,
- const char *merchant_url,
- const char *increase_reference,
- const char *pay_reference,
- const char *order_id,
- unsigned int http_code,
- const char *refund_amount)
-{
- struct RefundLookupState *rls;
-
- rls = GNUNET_new (struct RefundLookupState);
- rls->merchant_url = merchant_url;
- rls->order_id = order_id;
- rls->pay_reference = pay_reference;
- rls->increase_reference = increase_reference;
- rls->http_code = http_code;
- rls->refund_amount = refund_amount;
- {
- struct TALER_TESTING_Command cmd = {
- .cls = rls,
- .label = label,
- .run = &refund_lookup_run,
- .cleanup = &refund_lookup_cleanup
- };
-
- return cmd;
- }
-}
-
-
-/* end of testing_api_cmd_refund_lookup.c */
diff --git a/src/testing/testing_api_cmd_track_transaction.c b/src/testing/testing_api_cmd_track_transaction.c
deleted file mode 100644
index c9450500..00000000
--- a/src/testing/testing_api_cmd_track_transaction.c
+++ /dev/null
@@ -1,295 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014-2018 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 lib/testing_api_cmd_track_transaction.c
- * @brief command to test /track/transaction
- * @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 "track transaction" CMD.
- */
-struct TrackTransactionState
-{
- /**
- * Handle for a pending /track/transaction request.
- */
- struct TALER_MERCHANT_TrackTransactionHandle *tth;
-
- /**
- * The interpreter state.
- */
- struct TALER_TESTING_Interpreter *is;
-
- /**
- * Base URL of the merchant serving the request.
- */
- const char *merchant_url;
-
- /**
- * Expected HTTP response code.
- */
- unsigned int http_status;
-
- /**
- * Reference to a "pay" CMD, used to get the order
- * id to issue the track against.
- */
- const char *pay_reference;
-
- /**
- * Subject line of the wire transfer that paid
- * the tracked contract back. WARNING: impredictible
- * behaviour if _multiple_ wire transfers were
- * issued to pay this contract back.
- */
- const char *wtid_str;
-
- /**
- * Binary form of @a wtid_str, expected by other commands
- * in this form.
- */
- struct TALER_WireTransferIdentifierRawP wtid;
-
- /**
- * base URL of the exchange that issued (or was supposed to,
- * in case 202 Accepted was returned) the wire transfer to
- * pay the tracked contract back.
- */
- const char *exchange_url;
-
-};
-
-
-/**
- * Function called with detailed wire transfer data; checks
- * if HTTP response code matches the expectation, and stores
- * in the state what came from the backend.
- *
- * @param cls closure
- * @param hr HTTP response
- */
-static void
-track_transaction_cb (void *cls,
- const struct TALER_MERCHANT_HttpResponse *hr)
-{
- struct TrackTransactionState *tts = cls;
-
- tts->tth = NULL;
- if (tts->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 (tts->is));
- TALER_TESTING_interpreter_fail (tts->is);
- return;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "/track/transaction, response code: %u\n",
- hr->http_status);
- if (MHD_HTTP_OK == hr->http_status)
- {
- /* Only storing first element's wtid, as this works around
- * the disability of the real bank to provide a "bank check"
- * CMD as the fakebank does. */
- json_t *wtid_str;
- json_t *exchange_url;
-
- if (NULL == (wtid_str
- = json_object_get (json_array_get (hr->reply,
- 0),
- "wtid")))
- {
- TALER_TESTING_interpreter_fail (tts->is);
- return;
- }
-
- if (NULL == (exchange_url
- = json_object_get (json_array_get (hr->reply,
- 0),
- "exchange")))
- {
- TALER_TESTING_interpreter_fail (tts->is);
- return;
- }
-
- tts->exchange_url = GNUNET_strdup (json_string_value (exchange_url));
- tts->wtid_str = GNUNET_strdup (json_string_value (wtid_str));
- }
- TALER_TESTING_interpreter_next (tts->is);
-}
-
-
-/**
- * Run the "track transaction" CMD.
- *
- * @param cls closure.
- * @param cmd command being run now.
- * @param is interpreter state.
- */
-static void
-track_transaction_run (void *cls,
- const struct TALER_TESTING_Command *cmd,
- struct TALER_TESTING_Interpreter *is)
-{
- struct TrackTransactionState *tts = cls;
- const char *order_id;
- const struct TALER_TESTING_Command *pay_cmd;
-
- tts->is = is;
- if (NULL ==
- (pay_cmd = TALER_TESTING_interpreter_lookup_command (is,
- tts->pay_reference)))
- TALER_TESTING_FAIL (is);
- if (GNUNET_OK !=
- TALER_TESTING_get_trait_order_id (pay_cmd,
- 0,
- &order_id))
- TALER_TESTING_FAIL (is);
-
- tts->tth = TALER_MERCHANT_track_transaction (is->ctx,
- tts->merchant_url,
- order_id,
- &track_transaction_cb,
- tts);
- GNUNET_assert (NULL != tts->tth);
-}
-
-
-/**
- * Free the state of a "track transaction" CMD, and possibly
- * cancel a pending operation thereof.
- *
- * @param cls closure.
- * @param cmd command being run.
- */
-static void
-track_transaction_cleanup (void *cls,
- const struct TALER_TESTING_Command *cmd)
-{
- struct TrackTransactionState *tts = cls;
-
- if (NULL != tts->tth)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "/track/transaction (test) operation"
- " did not complete\n");
- TALER_MERCHANT_track_transaction_cancel (tts->tth);
- }
-
- /* Need to discard 'const' before freeing. */
- GNUNET_free_non_null ((char *) tts->exchange_url);
- GNUNET_free_non_null ((char *) tts->wtid_str);
- GNUNET_free (tts);
-}
-
-
-/**
- * Offer internal data of a "track transaction" CMD, for
- * other CMDs to use.
- *
- * @param cls closure.
- * @param ret[out] return value.
- * @param trait name of the trait.
- * @param index index of the trait.
- * @return #GNUNET_OK if it is successful.
- */
-static int
-track_transaction_traits (void *cls,
- const void **ret,
- const char *trait,
- unsigned int index)
-{
- struct TrackTransactionState *tts = cls;
- struct TALER_WireTransferIdentifierRawP *wtid_ptr;
-
- if (MHD_HTTP_OK != tts->http_status)
- return GNUNET_SYSERR;
- if ( (NULL != tts->wtid_str) &&
- (GNUNET_OK !=
- GNUNET_STRINGS_string_to_data (tts->wtid_str,
- strlen (tts->wtid_str),
- &tts->wtid,
- sizeof (struct
- TALER_WireTransferIdentifierRawP))) )
- wtid_ptr = NULL;
- else
- wtid_ptr = &tts->wtid;
- {
- struct TALER_TESTING_Trait traits[] = {
- TALER_TESTING_make_trait_wtid (0, wtid_ptr),
- TALER_TESTING_make_trait_url (0, tts->exchange_url),
- TALER_TESTING_trait_end ()
- };
-
- return TALER_TESTING_get_trait (traits,
- ret,
- trait,
- index);
- }
-}
-
-
-/**
- * Define a "track transaction" CMD.
- *
- * @param label command label.
- * @param merchant_url base URL of the merchant serving the
- * /track/transaction request.
- * @param http_status expected HTTP response code.
- * @param pay_reference used to retrieve the order id to track.
- * @return the command.
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_merchant_track_transaction (const char *label,
- const char *merchant_url,
- unsigned int http_status,
- const char *pay_reference)
-{
- struct TrackTransactionState *tts;
-
- tts = GNUNET_new (struct TrackTransactionState);
- tts->merchant_url = merchant_url;
- tts->http_status = http_status;
- tts->pay_reference = pay_reference;
- {
- struct TALER_TESTING_Command cmd = {
- .cls = tts,
- .label = label,
- .run = &track_transaction_run,
- .cleanup = &track_transaction_cleanup,
- .traits = &track_transaction_traits
- };
-
- return cmd;
- }
-}
-
-
-/* end of testing_api_cmd_track_transaction.c */