diff options
Diffstat (limited to 'src/exchange-lib')
| -rw-r--r-- | src/exchange-lib/testing_api_cmd_bank_check.c | 108 | ||||
| -rw-r--r-- | src/exchange-lib/testing_api_cmd_fakebank_transfer.c | 19 | ||||
| -rw-r--r-- | src/exchange-lib/testing_api_cmd_track.c | 2 | ||||
| -rw-r--r-- | src/exchange-lib/testing_api_helpers.c | 5 | ||||
| -rw-r--r-- | src/exchange-lib/testing_api_loop.c | 49 | ||||
| -rw-r--r-- | src/exchange-lib/testing_api_trait_amount.c | 2 | ||||
| -rw-r--r-- | src/exchange-lib/testing_api_trait_number.c | 49 | ||||
| -rw-r--r-- | src/exchange-lib/testing_api_trait_string.c | 50 | 
8 files changed, 234 insertions, 50 deletions
diff --git a/src/exchange-lib/testing_api_cmd_bank_check.c b/src/exchange-lib/testing_api_cmd_bank_check.c index 8c4ee2c4..9af156f9 100644 --- a/src/exchange-lib/testing_api_cmd_bank_check.c +++ b/src/exchange-lib/testing_api_cmd_bank_check.c @@ -47,12 +47,12 @@ struct BankCheckState    /**     * Expected account number that gave money     */ -  unsigned int debit_account; +  uint64_t debit_account;    /**     * Expected account number that received money     */ -  unsigned int credit_account; +  uint64_t credit_account;    /**     * Wire transfer subject (set by fakebank-lib). @@ -69,6 +69,11 @@ struct BankCheckState     * Interpreter state.     */    struct TALER_TESTING_Interpreter *is; + +  /** +   * FIXME. +   */ +  const char *deposit_reference;  };  /** @@ -84,26 +89,72 @@ check_bank_transfer_run (void *cls,                           struct TALER_TESTING_Interpreter *is)  {    struct BankCheckState *bcs = cls; +    struct TALER_Amount amount; +  const uint64_t *debit_account; +  const uint64_t *credit_account; +  const char *exchange_base_url; -  if (GNUNET_OK != -      TALER_string_to_amount (bcs->amount, -                              &amount)) +  if (NULL == bcs->deposit_reference)    { -    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, -                "Failed to parse amount `%s' at %u\n", -                bcs->amount, -                is->ip); -    TALER_TESTING_interpreter_fail (is); -    return; +    debit_account = &bcs->debit_account; +    credit_account = &bcs->credit_account; +    exchange_base_url = bcs->exchange_base_url; + +    if (GNUNET_OK != +        TALER_string_to_amount (bcs->amount, +                                &amount)) +    { +      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, +                  "Failed to parse amount `%s' at %u\n", +                  bcs->amount, +                  is->ip); +      TALER_TESTING_interpreter_fail (is); +      return; +    } +  } + +  if (NULL != bcs->deposit_reference) +  { +    const struct TALER_TESTING_Command *deposit_cmd; +    const struct TALER_Amount *amount_ptr; + +    TALER_LOG_INFO ("`%s' uses reference (%s)\n", +                    TALER_TESTING_interpreter_get_current_label +                      (is), +                    bcs->deposit_reference); +    deposit_cmd = TALER_TESTING_interpreter_lookup_command +      (is, bcs->deposit_reference); + +    if (NULL == deposit_cmd) +      TALER_TESTING_FAIL (is); + +    GNUNET_assert +      (GNUNET_OK == TALER_TESTING_get_trait_amount_obj +        (deposit_cmd, 0, &amount_ptr)); +    amount = *amount_ptr; + +    GNUNET_assert +      (GNUNET_OK == TALER_TESTING_GET_TRAIT_DEBIT_ACCOUNT +        (deposit_cmd, &debit_account)); + +    GNUNET_assert +      (GNUNET_OK == TALER_TESTING_GET_TRAIT_CREDIT_ACCOUNT +        (deposit_cmd, &credit_account)); + +    GNUNET_assert +      (GNUNET_OK == TALER_TESTING_get_trait_url +        (deposit_cmd, 0, &exchange_base_url)); // check 0 works! +    } +    if (GNUNET_OK !=        TALER_FAKEBANK_check (is->fakebank,                              &amount, -                            bcs->debit_account, -                            bcs->credit_account, -                            bcs->exchange_base_url, +                            *debit_account, +                            *credit_account, +                            exchange_base_url,                              &bcs->subject))    {      GNUNET_break (0); @@ -189,8 +240,8 @@ TALER_TESTING_cmd_check_bank_transfer    (const char *label,     const char *exchange_base_url,     const char *amount, -   unsigned int debit_account, -   unsigned int credit_account) +   uint64_t debit_account, +   uint64_t credit_account)  {    struct BankCheckState *bcs;    struct TALER_TESTING_Command cmd; @@ -205,7 +256,6 @@ TALER_TESTING_cmd_check_bank_transfer    cmd.cls = bcs;    cmd.run = &check_bank_transfer_run;    cmd.cleanup = &check_bank_transfer_cleanup; -  // traits?    cmd.traits = &check_bank_transfer_traits;    return cmd; @@ -265,3 +315,27 @@ TALER_TESTING_cmd_check_bank_empty (const char *label)    return cmd;  } + + +/** + * FIXME. + */ +struct TALER_TESTING_Command +TALER_TESTING_cmd_check_bank_transfer_with_ref +  (const char *label, +   const char *deposit_reference) +{ + +  struct BankCheckState *bcs; +  struct TALER_TESTING_Command cmd; + +  bcs = GNUNET_new (struct BankCheckState); +  bcs->deposit_reference = deposit_reference; +  cmd.label = label; +  cmd.cls = bcs; +  cmd.run = &check_bank_transfer_run; +  cmd.cleanup = &check_bank_transfer_cleanup; +  cmd.traits = &check_bank_transfer_traits; + +  return cmd; +} diff --git a/src/exchange-lib/testing_api_cmd_fakebank_transfer.c b/src/exchange-lib/testing_api_cmd_fakebank_transfer.c index 7da4bf09..a8bad860 100644 --- a/src/exchange-lib/testing_api_cmd_fakebank_transfer.c +++ b/src/exchange-lib/testing_api_cmd_fakebank_transfer.c @@ -31,6 +31,7 @@  #include "taler_fakebank_lib.h"  #include "taler_signatures.h"  #include "taler_testing_lib.h" +#include "taler_testing_bank_lib.h"  /**   * @@ -348,17 +349,19 @@ fakebank_transfer_traits (void *cls,  {    struct FakebankTransferState *fts = cls;    struct TALER_TESTING_Trait traits[] = { -    TALER_TESTING_make_trait_reserve_priv (0, -                                           &fts->reserve_priv), +    TALER_TESTING_make_trait_reserve_priv +      (0, &fts->reserve_priv), +    TALER_TESTING_MAKE_TRAIT_DEBIT_ACCOUNT +      (&fts->debit_account_no), +    TALER_TESTING_MAKE_TRAIT_CREDIT_ACCOUNT +      (&fts->credit_account_no), +    TALER_TESTING_make_trait_url (0, fts->exchange_url), +    TALER_TESTING_make_trait_transfer_subject (0, fts->subject), +    TALER_TESTING_MAKE_TRAIT_ROW_ID (&fts->serial_id), +    TALER_TESTING_make_trait_amount_obj (0, &fts->amount),      TALER_TESTING_trait_end ()    }; -  if (NULL != fts->subject) -  { -    GNUNET_break (0); -    /* we do NOT create a reserve private key */ -    return GNUNET_SYSERR;  -  }    return TALER_TESTING_get_trait (traits,                                    ret,                                    trait, diff --git a/src/exchange-lib/testing_api_cmd_track.c b/src/exchange-lib/testing_api_cmd_track.c index 40894872..8c289ed5 100644 --- a/src/exchange-lib/testing_api_cmd_track.c +++ b/src/exchange-lib/testing_api_cmd_track.c @@ -198,7 +198,7 @@ deposit_wtid_cb          return;        } -      char *transfer_subject; +      const char *transfer_subject;        if (GNUNET_OK != TALER_TESTING_get_trait_transfer_subject          (bank_transfer_cmd, 0, &transfer_subject)) diff --git a/src/exchange-lib/testing_api_helpers.c b/src/exchange-lib/testing_api_helpers.c index b6e1e989..690c222c 100644 --- a/src/exchange-lib/testing_api_helpers.c +++ b/src/exchange-lib/testing_api_helpers.c @@ -431,9 +431,8 @@ TALER_TESTING_prepare_fakebank (const char *config_filename)    char *fakebank_url;    cfg = GNUNET_CONFIGURATION_create (); -  if (GNUNET_OK != -      GNUNET_CONFIGURATION_load (cfg, -                                 config_filename)) +  if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, +                                              config_filename))      return NULL;    if (GNUNET_OK !=        GNUNET_CONFIGURATION_get_value_string (cfg, diff --git a/src/exchange-lib/testing_api_loop.c b/src/exchange-lib/testing_api_loop.c index 2bbf46ac..78ae3611 100644 --- a/src/exchange-lib/testing_api_loop.c +++ b/src/exchange-lib/testing_api_loop.c @@ -504,6 +504,22 @@ cert_cb (void *cls,                              main_ctx->is);  } +/** + * Initialize scheduler loop and curl context for the testcase, + * and responsible to run the "run" method. + * + * @param cls closure, typically the "run" method, the + *        interpreter state and a closure for "run". + */ +static void +main_wrapper_exchange_agnostic (void *cls) +{ +  struct MainContext *main_ctx = cls; + +  main_ctx->main_cb (main_ctx->main_cb_cls, +                     main_ctx->is); +} +  /**   * Initialize scheduler loop and curl context for the testcase, @@ -513,7 +529,7 @@ cert_cb (void *cls,   *        interpreter state and a closure for "run".   */  static void -main_wrapper (void *cls) +main_wrapper_exchange_connect (void *cls)  {    struct MainContext *main_ctx = cls;    struct TALER_TESTING_Interpreter *is = main_ctx->is; @@ -542,11 +558,6 @@ main_wrapper (void *cls)                     "http://localhost:%llu/",                     exchange_port); -  is->ctx = GNUNET_CURL_init -    (&GNUNET_CURL_gnunet_scheduler_reschedule, &is->rc); -  GNUNET_assert (NULL != is->ctx); -  is->rc = GNUNET_CURL_gnunet_rc_create (is->ctx); -    GNUNET_assert ( NULL !=      (is->exchange = TALER_EXCHANGE_connect (is->ctx,                                              exchange_url, @@ -568,7 +579,8 @@ main_wrapper (void *cls)   * @param exchanged exchange process handle: will be put in the   *        state as some commands - e.g. revoke - need to send   *        signal to it, for example to let it know to reload the - *        key state.. + *        key state.. if NULL, the interpreter will run without + *        trying to connect to the exchange first.   *   * @return FIXME: not sure what 'is.result' is at this stage.   */ @@ -585,10 +597,7 @@ TALER_TESTING_setup (TALER_TESTING_Main main_cb,      /* needed to init the curl ctx */      .is = &is,      /* needed to read values like exchange port -     * number and construct the exchange url.  The -     * port number _could_ have been passed here, but -     * we prefer to stay "general" as other values might -     * need to be passed around in the future. */ +     * number to construct the exchange url.*/      .config_filename = config_filename    };    struct GNUNET_SIGNAL_Context *shc_chld; @@ -602,16 +611,26 @@ TALER_TESTING_setup (TALER_TESTING_Main main_cb,    GNUNET_assert (NULL != sigpipe);    shc_chld = GNUNET_SIGNAL_handler_install      (GNUNET_SIGCHLD, &sighandler_child_death); + +  is.ctx = GNUNET_CURL_init +    (&GNUNET_CURL_gnunet_scheduler_reschedule, &is.rc); +  GNUNET_assert (NULL != is.ctx); +  is.rc = GNUNET_CURL_gnunet_rc_create (is.ctx); +    /* Blocking */ -  GNUNET_SCHEDULER_run (&main_wrapper, -                        &main_ctx); + +  if (NULL != exchanged) +    GNUNET_SCHEDULER_run (&main_wrapper_exchange_connect, +                          &main_ctx); +  else +     GNUNET_SCHEDULER_run (&main_wrapper_exchange_agnostic, +                           &main_ctx); +    GNUNET_SIGNAL_handler_uninstall (shc_chld);    GNUNET_DISK_pipe_close (sigpipe);    sigpipe = NULL; -  /*FIXME: ?? */    return is.result;  } -  /* end of testing_api_loop.c */ diff --git a/src/exchange-lib/testing_api_trait_amount.c b/src/exchange-lib/testing_api_trait_amount.c index a9c5b3bc..f21ec870 100644 --- a/src/exchange-lib/testing_api_trait_amount.c +++ b/src/exchange-lib/testing_api_trait_amount.c @@ -45,7 +45,7 @@ int  TALER_TESTING_get_trait_amount_obj (    const struct TALER_TESTING_Command *cmd,    unsigned int index, -  struct TALER_Amount **amount) +  const struct TALER_Amount **amount)  {    return cmd->traits (cmd->cls,                        (void **) amount, diff --git a/src/exchange-lib/testing_api_trait_number.c b/src/exchange-lib/testing_api_trait_number.c index 8f011dca..4db88792 100644 --- a/src/exchange-lib/testing_api_trait_number.c +++ b/src/exchange-lib/testing_api_trait_number.c @@ -29,7 +29,8 @@  #include "taler_signatures.h"  #include "taler_testing_lib.h" -#define TALER_TESTING_TRAIT_NUMBER "number" +#define TALER_TESTING_TRAIT_UINT "uint" +#define TALER_TESTING_TRAIT_UINT64 "uint-64"  /**   * Obtain a "number" value from @a cmd. @@ -48,7 +49,7 @@ TALER_TESTING_get_trait_uint  {    return cmd->traits (cmd->cls,                        (void **) n, -                      TALER_TESTING_TRAIT_NUMBER, +                      TALER_TESTING_TRAIT_UINT,                        index);  } @@ -65,10 +66,52 @@ TALER_TESTING_make_trait_uint  {    struct TALER_TESTING_Trait ret = {      .index = index, -    .trait_name = TALER_TESTING_TRAIT_NUMBER, +    .trait_name = TALER_TESTING_TRAIT_UINT,      .ptr = (const void *) n    };    return ret;  } +/** + * Obtain a "number" value from @a cmd. + * + * @param cmd command to extract trait from + * @param selector which coin to pick if @a cmd has multiple on + * offer + * @param n[out] set to the number coming from @a cmd. + * @return #GNUNET_OK on success + */ +int +TALER_TESTING_get_trait_uint64 +  (const struct TALER_TESTING_Command *cmd, +   unsigned int index, +   const uint64_t **n) +{ +  return cmd->traits (cmd->cls, +                      (void **) n, +                      TALER_TESTING_TRAIT_UINT64, +                      index); +} + +/** + * @param selector associate the object with this "tag" + * @param n which object should be returned + * + * @return the trait, to be put in the traits array of the command + */ +struct TALER_TESTING_Trait +TALER_TESTING_make_trait_uint64 +  (unsigned int index, +   const uint64_t *n) +{ +  struct TALER_TESTING_Trait ret = { +    .index = index, +    .trait_name = TALER_TESTING_TRAIT_UINT64, +    .ptr = (const void *) n +  }; +  return ret; +} + + +  /* end of testing_api_trait_number.c */ diff --git a/src/exchange-lib/testing_api_trait_string.c b/src/exchange-lib/testing_api_trait_string.c index 0675d5a8..1b1b4221 100644 --- a/src/exchange-lib/testing_api_trait_string.c +++ b/src/exchange-lib/testing_api_trait_string.c @@ -36,6 +36,7 @@  #define TALER_TESTING_TRAIT_AMOUNT "amount"  #define TALER_TESTING_TRAIT_URL "url"  #define TALER_TESTING_TRAIT_ORDER_ID "order-id" +#define TALER_TESTING_TRAIT_REJECTED "rejected"  /**   * Obtain contract terms from @a cmd. @@ -135,7 +136,7 @@ int  TALER_TESTING_get_trait_transfer_subject    (const struct TALER_TESTING_Command *cmd,     unsigned int index, -   char **transfer_subject) +   const char **transfer_subject)  {    return cmd->traits (cmd->cls,                        (void **) transfer_subject, @@ -154,7 +155,7 @@ TALER_TESTING_get_trait_transfer_subject  struct TALER_TESTING_Trait  TALER_TESTING_make_trait_transfer_subject    (unsigned int index, -   char *transfer_subject) +   const char *transfer_subject)  {    struct TALER_TESTING_Trait ret = {      .index = index, @@ -293,5 +294,50 @@ TALER_TESTING_make_trait_order_id    return ret;  } +/** + * Obtain the reference from a bank transfer which has + * been rejected. + * + * @param cmd command to extract trait from + * @param index which reference is to be picked, in case + *        multiple are offered. + * @param rejected_reference[out] where to write the order id. + * @return #GNUNET_OK on success + */ +int +TALER_TESTING_get_trait_rejected +  (const struct TALER_TESTING_Command *cmd, +   unsigned int index, +   const char **rejected_reference) +{ +  return cmd->traits (cmd->cls, +                      (void **) rejected_reference, +                      TALER_TESTING_TRAIT_REJECTED, +                      index); +} + +/** + * Offer reference to a bank transfer which has been + * rejected. + * + * @param index which reference is to be picked, in case + *        multiple are offered. + * @param rejected_reference the url to offer + * @return the trait, to be put in the traits array of the command + */ +struct TALER_TESTING_Trait +TALER_TESTING_make_trait_rejected +  (unsigned int index, +   const char *rejected) +{ +  struct TALER_TESTING_Trait ret = { +    .index = index, +    .trait_name = TALER_TESTING_TRAIT_REJECTED, +    .ptr = (const void *) rejected  +  }; +  return ret; +} + +  /* end of testing_api_trait_string.c */  | 
