summaryrefslogtreecommitdiff
path: root/src/testing/testing_api_cmd_exec_closer.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-03-28 20:45:53 +0100
committerChristian Grothoff <christian@grothoff.org>2020-03-28 20:45:53 +0100
commitd5351641f8124040c02ced06690fda36535bedcf (patch)
tree7dc39087a5a74fc29e255b7cc4e871a32d441d9e /src/testing/testing_api_cmd_exec_closer.c
parent9d9b0e0e571a7c6791cf83235f92d1a5d9369637 (diff)
downloadexchange-d5351641f8124040c02ced06690fda36535bedcf.tar.gz
exchange-d5351641f8124040c02ced06690fda36535bedcf.tar.bz2
exchange-d5351641f8124040c02ced06690fda36535bedcf.zip
implement #6049
Diffstat (limited to 'src/testing/testing_api_cmd_exec_closer.c')
-rw-r--r--src/testing/testing_api_cmd_exec_closer.c94
1 files changed, 91 insertions, 3 deletions
diff --git a/src/testing/testing_api_cmd_exec_closer.c b/src/testing/testing_api_cmd_exec_closer.c
index 17eed7a88..811bf1b8a 100644
--- a/src/testing/testing_api_cmd_exec_closer.c
+++ b/src/testing/testing_api_cmd_exec_closer.c
@@ -43,6 +43,29 @@ struct CloserState
* Configuration file used by the closer.
*/
const char *config_filename;
+
+ /**
+ * Reserve history entry that corresponds to this operation. Set if @e
+ * expect_close is true. Will be of type
+ * #TALER_EXCHANGE_RTT_RESERVE_CLOSED.
+ */
+ struct TALER_EXCHANGE_ReserveHistory reserve_history;
+
+ /**
+ * If the closer filled a reserve (@e expect_close is set), this is set to
+ * the reserve's public key.
+ */
+ struct TALER_ReservePublicKeyP reserve_pub;
+
+ /**
+ * Reference to a command to get the @e reserve_pub.
+ */
+ const char *reserve_ref;
+
+ /**
+ * Do we expect the command to actually close a reserve?
+ */
+ int expect_close;
};
@@ -61,6 +84,24 @@ closer_run (void *cls,
struct CloserState *as = cls;
(void) cmd;
+ if (NULL != as->reserve_ref)
+ {
+ const struct TALER_TESTING_Command *rcmd;
+ const struct TALER_ReservePublicKeyP *reserve_pubp;
+
+ rcmd = TALER_TESTING_interpreter_lookup_command (is,
+ as->reserve_ref);
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_reserve_pub (rcmd,
+ 0,
+ &reserve_pubp))
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ as->reserve_pub = *reserve_pubp;
+ }
as->closer_proc
= GNUNET_OS_start_process (GNUNET_NO,
GNUNET_OS_INHERIT_STD_ALL,
@@ -127,8 +168,18 @@ closer_traits (void *cls,
TALER_TESTING_make_trait_process (0, &as->closer_proc),
TALER_TESTING_trait_end ()
};
+ struct TALER_TESTING_Trait xtraits[] = {
+ TALER_TESTING_make_trait_process (0, &as->closer_proc),
+ TALER_TESTING_make_trait_reserve_pub (0,
+ &as->reserve_pub),
+ TALER_TESTING_make_trait_reserve_history (0,
+ &as->reserve_history),
+ TALER_TESTING_trait_end ()
+ };
- return TALER_TESTING_get_trait (traits,
+ return TALER_TESTING_get_trait ((as->expect_close)
+ ? xtraits
+ : traits,
ret,
trait,
index);
@@ -136,21 +187,58 @@ closer_traits (void *cls,
/**
- * Make a "closer" CMD.
+ * Make a "closer" CMD. Note that it is right now not supported to run the
+ * closer to close multiple reserves in combination with a subsequent reserve
+ * status call, as we cannot generate the traits necessary for multiple closed
+ * reserves. You can work around this by using multiple closer commands, one
+ * per reserve that is being closed.
*
* @param label command label.
* @param config_filename configuration file for the
* closer to use.
+ * @param expected_amount amount we expect to see wired from a @a expected_reserve_ref
+ * @param expected_fee closing fee we expect to see
+ * @param expected_reserve_ref reference to a reserve we expect the closer to drain;
+ * NULL if we do not expect the closer to do anything
* @return the command.
*/
struct TALER_TESTING_Command
TALER_TESTING_cmd_exec_closer (const char *label,
- const char *config_filename)
+ const char *config_filename,
+ const char *expected_amount,
+ const char *expected_fee,
+ const char *expected_reserve_ref)
{
struct CloserState *as;
as = GNUNET_new (struct CloserState);
as->config_filename = config_filename;
+ if (NULL != expected_reserve_ref)
+ {
+ as->expect_close = GNUNET_YES;
+ as->reserve_ref = expected_reserve_ref;
+ if (GNUNET_OK !=
+ TALER_string_to_amount (expected_amount,
+ &as->reserve_history.amount))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to parse amount `%s' at %s\n",
+ expected_amount,
+ label);
+ GNUNET_assert (0);
+ }
+ if (GNUNET_OK !=
+ TALER_string_to_amount (expected_fee,
+ &as->reserve_history.details.close_details.fee))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to parse amount `%s' at %s\n",
+ expected_fee,
+ label);
+ GNUNET_assert (0);
+ }
+ as->reserve_history.type = TALER_EXCHANGE_RTT_CLOSE;
+ }
{
struct TALER_TESTING_Command cmd = {
.cls = as,