summaryrefslogtreecommitdiff
path: root/src/testing/testing_api_cmd_transfer_get.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/testing_api_cmd_transfer_get.c')
-rw-r--r--src/testing/testing_api_cmd_transfer_get.c320
1 files changed, 142 insertions, 178 deletions
diff --git a/src/testing/testing_api_cmd_transfer_get.c b/src/testing/testing_api_cmd_transfer_get.c
index 3ca319cb5..405c8b7f9 100644
--- a/src/testing/testing_api_cmd_transfer_get.c
+++ b/src/testing/testing_api_cmd_transfer_get.c
@@ -44,6 +44,11 @@ struct TrackTransferState
const char *expected_wire_fee;
/**
+ * Our command.
+ */
+ const struct TALER_TESTING_Command *cmd;
+
+ /**
* Reference to any operation that can provide a WTID.
* Will be the WTID to track.
*/
@@ -79,11 +84,6 @@ struct TrackTransferState
*/
unsigned int expected_response_code;
- /**
- * Index to the WTID to pick, in case @a wtid_reference has
- * many on offer.
- */
- unsigned int index;
};
@@ -103,10 +103,8 @@ track_transfer_cleanup (void *cls,
if (NULL != tts->tth)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Command %u (%s) did not complete\n",
- tts->is->ip,
- cmd->label);
+ TALER_TESTING_command_incomplete (tts->is,
+ cmd->label);
TALER_EXCHANGE_transfers_get_cancel (tts->tth);
tts->tth = NULL;
}
@@ -120,182 +118,178 @@ track_transfer_cleanup (void *cls,
* wire fees and hashed wire details as well.
*
* @param cls closure.
- * @param hr HTTP response details
- * @param ta transfer data returned by the exchange
+ * @param tgr response details
*/
static void
track_transfer_cb (void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr,
- const struct TALER_EXCHANGE_TransferData *ta)
+ const struct TALER_EXCHANGE_TransfersGetResponse *tgr)
{
struct TrackTransferState *tts = cls;
+ const struct TALER_EXCHANGE_HttpResponse *hr = &tgr->hr;
struct TALER_TESTING_Interpreter *is = tts->is;
- struct TALER_TESTING_Command *cmd = &is->commands[is->ip];
struct TALER_Amount expected_amount;
tts->tth = NULL;
if (tts->expected_response_code != hr->http_status)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u/%d to command %s in %s:%u\n",
- hr->http_status,
- (int) hr->ec,
- cmd->label,
- __FILE__,
- __LINE__);
- json_dumpf (hr->reply,
- stderr,
- 0);
- TALER_TESTING_interpreter_fail (is);
+ TALER_TESTING_unexpected_status (is,
+ hr->http_status,
+ tts->expected_response_code);
return;
}
switch (hr->http_status)
{
case MHD_HTTP_OK:
- if (NULL == tts->expected_total_amount)
- {
- GNUNET_break (0);
- TALER_TESTING_interpreter_fail (is);
- return;
- }
- if (NULL == tts->expected_wire_fee)
- {
- GNUNET_break (0);
- TALER_TESTING_interpreter_fail (is);
- return;
- }
-
- if (GNUNET_OK !=
- TALER_string_to_amount (tts->expected_total_amount,
- &expected_amount))
- {
- GNUNET_break (0);
- TALER_TESTING_interpreter_fail (is);
- return;
- }
- if (0 != TALER_amount_cmp (&ta->total_amount,
- &expected_amount))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Total amount mismatch to command %s - "
- "%s vs %s\n",
- cmd->label,
- TALER_amount_to_string (&ta->total_amount),
- TALER_amount_to_string (&expected_amount));
- json_dumpf (hr->reply,
- stderr,
- 0);
- fprintf (stderr, "\n");
- TALER_TESTING_interpreter_fail (is);
- return;
- }
-
- if (GNUNET_OK !=
- TALER_string_to_amount (tts->expected_wire_fee,
- &expected_amount))
{
- GNUNET_break (0);
- TALER_TESTING_interpreter_fail (is);
- return;
- }
-
- if (0 != TALER_amount_cmp (&ta->wire_fee,
- &expected_amount))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Wire fee mismatch to command %s\n",
- cmd->label);
- json_dumpf (hr->reply,
- stderr,
- 0);
- TALER_TESTING_interpreter_fail (is);
- return;
- }
+ const struct TALER_EXCHANGE_TransferData *ta
+ = &tgr->details.ok.td;
- /**
- * Optionally checking: (1) wire-details for this transfer
- * match the ones from a referenced "deposit" operation -
- * or any operation that could provide wire-details. (2)
- * Total amount for this transfer matches the one from any
- * referenced command that could provide one.
- */if (NULL != tts->wire_details_reference)
- {
- const struct TALER_TESTING_Command *wire_details_cmd;
- const json_t *wire_details;
- struct GNUNET_HashCode h_wire_details;
-
- wire_details_cmd
- = TALER_TESTING_interpreter_lookup_command (is,
- tts->wire_details_reference);
- if (NULL == wire_details_cmd)
+ if (NULL == tts->expected_total_amount)
{
GNUNET_break (0);
TALER_TESTING_interpreter_fail (is);
return;
}
+ if (NULL == tts->expected_wire_fee)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+
if (GNUNET_OK !=
- TALER_TESTING_get_trait_wire_details (wire_details_cmd,
- 0,
- &wire_details))
+ TALER_string_to_amount (tts->expected_total_amount,
+ &expected_amount))
{
GNUNET_break (0);
TALER_TESTING_interpreter_fail (is);
return;
}
- GNUNET_assert (GNUNET_OK ==
- TALER_JSON_merchant_wire_signature_hash (wire_details,
- &h_wire_details));
- if (0 != GNUNET_memcmp (&h_wire_details,
- &ta->h_wire))
+ if (0 != TALER_amount_cmp (&ta->total_amount,
+ &expected_amount))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Wire hash missmath to command %s\n",
- cmd->label);
+ "Total amount mismatch to command %s - "
+ "%s vs %s\n",
+ tts->cmd->label,
+ TALER_amount_to_string (&ta->total_amount),
+ TALER_amount_to_string (&expected_amount));
json_dumpf (hr->reply,
stderr,
0);
+ fprintf (stderr, "\n");
TALER_TESTING_interpreter_fail (is);
return;
}
- }
- if (NULL != tts->total_amount_reference)
- {
- const struct TALER_TESTING_Command *total_amount_cmd;
- const struct TALER_Amount *total_amount_from_reference;
- total_amount_cmd
- = TALER_TESTING_interpreter_lookup_command (is,
- tts->total_amount_reference);
- if (NULL == total_amount_cmd)
- {
- GNUNET_break (0);
- TALER_TESTING_interpreter_fail (is);
- return;
- }
if (GNUNET_OK !=
- TALER_TESTING_get_trait_amount_obj (total_amount_cmd,
- 0,
- &total_amount_from_reference))
+ TALER_string_to_amount (tts->expected_wire_fee,
+ &expected_amount))
{
GNUNET_break (0);
TALER_TESTING_interpreter_fail (is);
return;
}
- if (0 != TALER_amount_cmp (&ta->total_amount,
- total_amount_from_reference))
+
+ if (0 != TALER_amount_cmp (&ta->wire_fee,
+ &expected_amount))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Amount missmath to command %s\n",
- cmd->label);
+ "Wire fee mismatch to command %s\n",
+ tts->cmd->label);
json_dumpf (hr->reply,
stderr,
0);
TALER_TESTING_interpreter_fail (is);
return;
}
- }
- }
+
+ /**
+ * Optionally checking: (1) wire-details for this transfer
+ * match the ones from a referenced "deposit" operation -
+ * or any operation that could provide wire-details. (2)
+ * Total amount for this transfer matches the one from any
+ * referenced command that could provide one.
+ */
+ if (NULL != tts->wire_details_reference)
+ {
+ const struct TALER_TESTING_Command *wire_details_cmd;
+ const char *payto_uri;
+ struct TALER_PaytoHashP h_payto;
+
+ wire_details_cmd
+ = TALER_TESTING_interpreter_lookup_command (is,
+ tts->
+ wire_details_reference);
+ if (NULL == wire_details_cmd)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_payto_uri (wire_details_cmd,
+ &payto_uri))
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ TALER_payto_hash (payto_uri,
+ &h_payto);
+ if (0 != GNUNET_memcmp (&h_payto,
+ &ta->h_payto))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Wire hash missmath to command %s\n",
+ tts->cmd->label);
+ json_dumpf (hr->reply,
+ stderr,
+ 0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ }
+ if (NULL != tts->total_amount_reference)
+ {
+ const struct TALER_TESTING_Command *total_amount_cmd;
+ const struct TALER_Amount *total_amount_from_reference;
+
+ total_amount_cmd
+ = TALER_TESTING_interpreter_lookup_command (is,
+ tts->
+ total_amount_reference);
+ if (NULL == total_amount_cmd)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_amount (total_amount_cmd,
+ &total_amount_from_reference))
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ if (0 != TALER_amount_cmp (&ta->total_amount,
+ total_amount_from_reference))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Amount mismatch in command %s\n",
+ tts->cmd->label);
+ json_dumpf (hr->reply,
+ stderr,
+ 0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ }
+ break;
+ } /* case OK */
+ } /* switch on status */
TALER_TESTING_interpreter_next (is);
}
@@ -317,19 +311,20 @@ track_transfer_run (void *cls,
struct TALER_WireTransferIdentifierRawP wtid;
const struct TALER_WireTransferIdentifierRawP *wtid_ptr;
+ tts->cmd = cmd;
/* If no reference is given, we'll use a all-zeros
* WTID */
- memset (&wtid, 0, sizeof (wtid));
+ memset (&wtid,
+ 0,
+ sizeof (wtid));
wtid_ptr = &wtid;
-
tts->is = is;
if (NULL != tts->wtid_reference)
{
const struct TALER_TESTING_Command *wtid_cmd;
- wtid_cmd = TALER_TESTING_interpreter_lookup_command
- (tts->is, tts->wtid_reference);
-
+ wtid_cmd = TALER_TESTING_interpreter_lookup_command (tts->is,
+ tts->wtid_reference);
if (NULL == wtid_cmd)
{
GNUNET_break (0);
@@ -337,8 +332,9 @@ track_transfer_run (void *cls,
return;
}
- if (GNUNET_OK != TALER_TESTING_get_trait_wtid
- (wtid_cmd, tts->index, &wtid_ptr))
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_wtid (wtid_cmd,
+ &wtid_ptr))
{
GNUNET_break (0);
TALER_TESTING_interpreter_fail (tts->is);
@@ -346,41 +342,26 @@ track_transfer_run (void *cls,
}
GNUNET_assert (NULL != wtid_ptr);
}
- tts->tth = TALER_EXCHANGE_transfers_get (is->exchange,
- wtid_ptr,
- &track_transfer_cb,
- tts);
+ tts->tth = TALER_EXCHANGE_transfers_get (
+ TALER_TESTING_interpreter_get_context (is),
+ TALER_TESTING_get_exchange_url (is),
+ TALER_TESTING_get_keys (is),
+ wtid_ptr,
+ &track_transfer_cb,
+ tts);
GNUNET_assert (NULL != tts->tth);
}
-/**
- * Make a "track transfer" CMD where no "expected"-arguments,
- * except the HTTP response code, are given. The best use case
- * is when what matters to check is the HTTP response code, e.g.
- * when a bogus WTID was passed.
- *
- * @param label the command label
- * @param wtid_reference reference to any command which can provide
- * a wtid. If NULL is given, then a all zeroed WTID is
- * used that will at 99.9999% probability NOT match any
- * existing WTID known to the exchange.
- * @param index index number of the WTID to track, in case there
- * are multiple on offer.
- * @param expected_response_code expected HTTP response code.
- * @return the command.
- */
struct TALER_TESTING_Command
TALER_TESTING_cmd_track_transfer_empty (const char *label,
const char *wtid_reference,
- unsigned int index,
unsigned int expected_response_code)
{
struct TrackTransferState *tts;
tts = GNUNET_new (struct TrackTransferState);
tts->wtid_reference = wtid_reference;
- tts->index = index;
tts->expected_response_code = expected_response_code;
{
struct TALER_TESTING_Command cmd = {
@@ -395,25 +376,9 @@ TALER_TESTING_cmd_track_transfer_empty (const char *label,
}
-/**
- * Make a "track transfer" command, specifying which amount and
- * wire fee are expected.
- *
- * @param label the command label.
- * @param wtid_reference reference to any command which can provide
- * a wtid. Will be the one tracked.
- * @param index in case there are multiple WTID offered, this
- * parameter selects a particular one.
- * @param expected_response_code expected HTTP response code.
- * @param expected_total_amount how much money we expect being moved
- * with this wire-transfer.
- * @param expected_wire_fee expected wire fee.
- * @return the command
- */
struct TALER_TESTING_Command
TALER_TESTING_cmd_track_transfer (const char *label,
const char *wtid_reference,
- unsigned int index,
unsigned int expected_response_code,
const char *expected_total_amount,
const char *expected_wire_fee)
@@ -422,7 +387,6 @@ TALER_TESTING_cmd_track_transfer (const char *label,
tts = GNUNET_new (struct TrackTransferState);
tts->wtid_reference = wtid_reference;
- tts->index = index;
tts->expected_response_code = expected_response_code;
tts->expected_total_amount = expected_total_amount;
tts->expected_wire_fee = expected_wire_fee;