diff options
author | Marcello Stanisci <marcello.stanisci@inria.fr> | 2016-10-04 22:59:46 +0200 |
---|---|---|
committer | Marcello Stanisci <marcello.stanisci@inria.fr> | 2016-10-04 22:59:46 +0200 |
commit | d9953edb7156a373f21da0795659cfa5e43a3ed1 (patch) | |
tree | 580ae8ff7e06a0ce4e2a692da66fb59831bef6a3 | |
parent | 4a01b89bfdc4aa8dd97928a32af5e2252ef79df1 (diff) |
calling /history API from testcase. Loops ..
-rw-r--r-- | src/include/taler_merchant_service.h | 2 | ||||
-rw-r--r-- | src/lib/merchant_api_history.c | 40 | ||||
-rw-r--r-- | src/lib/test_merchant_api.c | 83 |
3 files changed, 107 insertions, 18 deletions
diff --git a/src/include/taler_merchant_service.h b/src/include/taler_merchant_service.h index e14aa207..b61b9cb7 100644 --- a/src/include/taler_merchant_service.h +++ b/src/include/taler_merchant_service.h @@ -516,6 +516,6 @@ TALER_MERCHANT_history (struct GNUNET_CURL_Context *ctx, * @param handle from the operation to cancel */ void -TALER_MERCHANT_history_cancel (struct TALER_MERCHANT_HistoryOperation *handle); +TALER_MERCHANT_history_cancel (struct TALER_MERCHANT_HistoryOperation *ho); #endif /* _TALER_MERCHANT_SERVICE_H */ diff --git a/src/lib/merchant_api_history.c b/src/lib/merchant_api_history.c index f53e2dc5..d03535a9 100644 --- a/src/lib/merchant_api_history.c +++ b/src/lib/merchant_api_history.c @@ -16,8 +16,8 @@ */ /** * @file lib/merchant_api_contract.c - * @brief Implementation of the /contract request of the merchant's HTTP API - * @author Christian Grothoff + * @brief Implementation of the /history request of the merchant's HTTP API + * @author Marcello Stanisci */ #include "platform.h" #include <curl/curl.h> @@ -67,9 +67,15 @@ struct TALER_MERCHANT_HistoryOperation * @param handle from the operation to cancel */ void -TALER_MERCHANT_history_cancel (struct TALER_MERCHANT_HistoryOperation *handle) +TALER_MERCHANT_history_cancel (struct TALER_MERCHANT_HistoryOperation *ho) { - /*TBD*/ + if (NULL != ho->job) + { + GNUNET_CURL_job_cancel (ho->job); + ho->job = NULL; + } + GNUNET_free (ho->url); + GNUNET_free (ho); } @@ -153,17 +159,25 @@ TALER_MERCHANT_history (struct GNUNET_CURL_Context *ctx, backend_uri, seconds); eh = curl_easy_init (); - GNUNET_assert (CURLE_OK == - curl_easy_setopt (eh, - CURLOPT_URL, - ho->url)); + if (CURLE_OK != curl_easy_setopt (eh, + CURLOPT_URL, + ho->url)) + { + GNUNET_break (0); + return NULL; + } + - ho->job = GNUNET_CURL_job_add (ctx, - eh, - GNUNET_YES, - &history_raw_cb, - ho); + if (NULL == (ho->job = GNUNET_CURL_job_add (ctx, + eh, + GNUNET_YES, + &history_raw_cb, + ho))) + { + GNUNET_break (0); + return NULL; + } return ho; } diff --git a/src/lib/test_merchant_api.c b/src/lib/test_merchant_api.c index 747c2d74..e5a9a666 100644 --- a/src/lib/test_merchant_api.c +++ b/src/lib/test_merchant_api.c @@ -31,6 +31,11 @@ #include <microhttpd.h> /** + * Shortcut + */ +#define LOG_INFO(...) GNUNET_log(GNUNET_ERROR_TYPE_INFO, __VA_ARGS__) + +/** * URI under which the merchant is reachable during the testcase. */ #define MERCHANT_URI "http://localhost:8082" @@ -546,7 +551,10 @@ struct Command * Handle to the merchant */ - /*TBD*/ + /** + * Handle to /history request + */ + struct TALER_MERCHANT_HistoryOperation *ho; } history; @@ -733,6 +741,31 @@ add_incoming_cb (void *cls, /** + * Callback for a /history request. It's up to this function how + * to render the array containing transactions details (FIXME link to + * documentation) + * + * @param cls closure + * @param http_status HTTP status returned by the merchant backend + * @param json actual body containing history + */ +void +history_cb (void *cls, + unsigned int http_status, + const json_t *json) +{ + struct InterpreterState *is = cls; + + if (MHD_HTTP_OK != http_status) + { + fail (is); + return; + } + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got 200 OK from /history!\n"); + +} + +/** * Check if the given historic event @a h corresponds to the given * command @a cmd. * @@ -1812,6 +1845,7 @@ interpreter_run (void *cls) ref = find_command (is, cmd->details.track_transaction.pay_ref); GNUNET_assert (NULL != ref); + /*FIXME check/assert return code */ cmd->details.track_transaction.tth = TALER_MERCHANT_track_transaction (ctx, MERCHANT_URI, @@ -1820,6 +1854,23 @@ interpreter_run (void *cls) &track_transaction_cb, is); return; + case OC_HISTORY: + + LOG_INFO("Processing history\n"); + return; + + if (NULL == + (cmd->details.history.ho = TALER_MERCHANT_history (ctx, + MERCHANT_URI, + cmd->details.history.date, + history_cb, + is))) + { + fail (is); + return; + } + break; + default: GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unknown instruction %d at %u (%s)\n", @@ -1971,6 +2022,15 @@ do_shutdown (void *cls) cmd->details.track_transaction.tth = NULL; } break; + case OC_HISTORY: + + if (NULL != cmd->details.history.ho) + { + TALER_MERCHANT_history_cancel (cmd->details.history.ho); + cmd->details.history.ho = NULL; + } + break; + default: GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Shutdown: unknown instruction %d at %u (%s)\n", @@ -2237,8 +2297,7 @@ run (void *cls) .details.track_transaction.expected_transfer_ref = "check_bank_transfer-499c-2" }, { .oc = OC_TRACK_TRANSACTION, - .label = "track-transaction-2-again", - .expected_response_code = MHD_HTTP_OK, + .label = "track-transaction-2-again", .expected_response_code = MHD_HTTP_OK, .details.track_transaction.pay_ref = "deposit-simple-2", .details.track_transaction.expected_transfer_ref = "check_bank_transfer-499c-2" }, @@ -2256,7 +2315,23 @@ run (void *cls) .details.track_transfer.check_bank_ref = "check_bank_transfer-499c-2", .details.track_transfer.expected_pay_ref = "deposit-simple-2" }, - + /** + * NOTE: could NOT initialize timestamps by calling GNUNET_TIME_xy () + * because that used to give a 'Initializer element is not constant' + * error at compile time. + */ + { .oc = OC_HISTORY, + .label = "history-1", + .expected_response_code = MHD_HTTP_OK, + .details.history.date.abs_value_us = 0, + .details.history.nresult = 2 + }, + { .oc = OC_HISTORY, + .label = "history-2", + .expected_response_code = MHD_HTTP_OK, + .details.history.date.abs_value_us = 2000000000 * 1000LL *1000LL, + .details.history.nresult = 0 + }, /* end of testcase */ { .oc = OC_END } }; |