summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcello Stanisci <stanisci.m@gmail.com>2018-12-14 12:51:42 +0100
committerMarcello Stanisci <stanisci.m@gmail.com>2018-12-14 12:51:42 +0100
commit5cab5dc7b7a8dac374bb17108a041ac41d2bb4a9 (patch)
tree9ecf105a724924f43616f1e1ee4495d21937bd5e
parentd596237d498cc67c84998c5cfb3c41c771a0918a (diff)
downloadmerchant-5cab5dc7b7a8dac374bb17108a041ac41d2bb4a9.tar.gz
merchant-5cab5dc7b7a8dac374bb17108a041ac41d2bb4a9.tar.bz2
merchant-5cab5dc7b7a8dac374bb17108a041ac41d2bb4a9.zip
Addressing #4952.
-rw-r--r--src/lib/testing_api_cmd_track.c66
1 files changed, 65 insertions, 1 deletions
diff --git a/src/lib/testing_api_cmd_track.c b/src/lib/testing_api_cmd_track.c
index e90a942f..6c3e3149 100644
--- a/src/lib/testing_api_cmd_track.c
+++ b/src/lib/testing_api_cmd_track.c
@@ -243,8 +243,72 @@ track_transfer_cb
}
switch (http_status)
{
+ /**
+ * Check that all the deposits sum up to the total
+ * transferred amount. */
case MHD_HTTP_OK:
- break;
+ {
+ json_t *deposits;
+ const char *amount_str;
+ struct TALER_Amount total;
+ struct TALER_Amount wire_fee;
+ struct TALER_Amount amount_iter;
+ struct TALER_Amount deposit_fee_iter;
+ struct TALER_Amount sum;
+
+ size_t index;
+ json_t *value;
+
+ amount_str = json_string_value
+ (json_object_get (json,
+ "total"));
+ TALER_string_to_amount (amount_str,
+ &total);
+ amount_str = json_string_value
+ (json_object_get (json,
+ "wire_fee"));
+ TALER_string_to_amount (amount_str,
+ &wire_fee);
+ TALER_amount_get_zero (total.currency,
+ &sum);
+ deposits = json_object_get (json,
+ "deposits_sums");
+ json_array_foreach (deposits, index, value)
+ {
+ amount_str = json_string_value
+ (json_object_get (value,
+ "deposit_value"));
+ TALER_string_to_amount (amount_str,
+ &amount_iter);
+ amount_str = json_string_value
+ (json_object_get (value,
+ "deposit_fee"));
+ TALER_string_to_amount (amount_str,
+ &deposit_fee_iter);
+ TALER_amount_add (&sum,
+ &sum,
+ &amount_iter);
+ TALER_amount_subtract (&sum,
+ &sum,
+ &deposit_fee_iter);
+ }
+
+ TALER_amount_subtract (&sum,
+ &sum,
+ &wire_fee);
+ if (0 != TALER_amount_cmp (&sum,
+ &total))
+ {
+ GNUNET_break (0);
+ TALER_LOG_ERROR
+ ("Inconsistent amount transferred."
+ " Sum: %s, claimed: %s\n",
+ TALER_amount_to_string (&sum),
+ TALER_amount_to_string (&total));
+ TALER_TESTING_interpreter_fail (tts->is);
+ }
+ }
+ break;
default:
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Unhandled HTTP status.\n");