split of check_empty logic

This commit is contained in:
Christian Grothoff 2020-01-12 19:45:45 +01:00
parent c085013ea7
commit 061eaac70f
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
5 changed files with 119 additions and 118 deletions

View File

@ -1081,7 +1081,6 @@ TALER_TESTING_cmd_track_transfer_empty (const char *label,
* @param expected_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
@ -1102,7 +1101,6 @@ TALER_TESTING_cmd_track_transfer (const char *label,
* @param amount the amount expected to be transferred.
* @param debit_account the account that gave money.
* @param credit_account the account that received money.
*
* @return the command
*/
struct TALER_TESTING_Command

View File

@ -85,6 +85,7 @@ libtalertesting_la_SOURCES = \
testing_api_cmd_refresh.c \
testing_api_cmd_track.c \
testing_api_cmd_bank_check.c \
testing_api_cmd_bank_check_empty.c \
testing_api_cmd_payback.c \
testing_api_cmd_signal.c \
testing_api_cmd_check_keys.c \

View File

@ -35,6 +35,7 @@
#include "taler_bank_service.h"
#include "taler_fakebank_lib.h"
#include "taler_testing_lib.h"
#include "taler_testing_bank_lib.h"
/**
* Configuration file we use. One (big) configuration is used
@ -65,25 +66,27 @@ static char *exchange_url;
*/
static char *auditor_url;
/**
* URL of the exchange's account at the bank. Obtained from CONFIG_FILE's
* "exchange-wire-test:BANK_URI" option plus the exchange account.
*/
static char *exchange_account_url; // FIXME: initialize!
/**
* Account number of the exchange at the bank.
*/
#define EXCHANGE_ACCOUNT_NO 2
#define EXCHANGE_ACCOUNT_NO "2" // FIXME: used?
/**
* Account number of some user.
* Payto URL of the user's account.
*/
#define USER_ACCOUNT_NO 42
static char *user_account_payto; // FIXME: initialize!
/**
* User name. Never checked by fakebank.
* Credentials for talking to the bank.
*/
#define USER_LOGIN_NAME "user42"
static struct TALER_BANK_AuthenticationData auth; // FIXME: initialize!
/**
* User password. Never checked by fakebank.
*/
#define USER_LOGIN_PASS "pass42"
/**
* Execute the taler-exchange-wirewatch command with
@ -112,23 +115,9 @@ static char *auditor_url;
*/
#define CMD_TRANSFER_TO_EXCHANGE(label,amount) \
TALER_TESTING_cmd_admin_add_incoming (label, amount, \
fakebank_url, USER_ACCOUNT_NO, \
EXCHANGE_ACCOUNT_NO, \
USER_LOGIN_NAME, USER_LOGIN_PASS, \
exchange_url)
/**
* Run wire transfer of funds from some user's account to the
* exchange.
*
* @param label label to use for the command.
* @param amount amount to transfer, i.e. "EUR:1"
*/
#define CMD_TRANSFER_TO_EXCHANGE_SUBJECT(label,amount,subject) \
TALER_TESTING_cmd_admin_add_incoming_with_subject \
(label, amount, fakebank_url, USER_ACCOUNT_NO, \
EXCHANGE_ACCOUNT_NO, USER_LOGIN_NAME, USER_LOGIN_PASS, \
subject, exchange_url)
exchange_account_url, \
&auth, \
user_account_payto)
/**
* Main function that will tell the interpreter what commands to
@ -832,21 +821,9 @@ run (void *cls,
TALER_TESTING_cmd_check_bank_transfer
("check_bank_transfer-pr3", exchange_url,
"EUR:1.01", 42, 2),
TALER_TESTING_cmd_check_bank_empty
("check-empty-again"),
/* Test rejection of bogus wire transfers */
CMD_TRANSFER_TO_EXCHANGE_SUBJECT
("bogus-subject",
"EUR:1.01",
"not a reserve public key"),
CMD_EXEC_WIREWATCH ("wirewatch-7"),
TALER_TESTING_cmd_check_bank_empty
("check-empty-from-reject"),
TALER_TESTING_cmd_end ()
};

View File

@ -16,14 +16,12 @@
License along with TALER; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>
*/
/**
* @file exchange-lib/testing_api_cmd_bank_check.c
* @brief command to check if a particular wire transfer took
* place.
* @author Marcello Stanisci
*/
#include "platform.h"
#include "taler_json_lib.h"
#include <gnunet/gnunet_curl_lib.h>
@ -255,80 +253,6 @@ TALER_TESTING_cmd_check_bank_transfer
}
/**
* Cleanup the state, only defined to respect the API.
*
* @param cls closure.
* @param cmd the command which is being cleaned up.
*/
static void
check_bank_empty_cleanup
(void *cls,
const struct TALER_TESTING_Command *cmd)
{
return;
}
/**
* Run the command.
*
* @param cls closure.
* @param cmd the command to execute.
* @param is the interpreter state.
*/
static void
check_bank_empty_run (void *cls,
const struct TALER_TESTING_Command *cmd,
struct TALER_TESTING_Interpreter *is)
{
if (GNUNET_OK != TALER_FAKEBANK_check_empty (is->fakebank))
{
GNUNET_break (0);
TALER_TESTING_interpreter_fail (is);
return;
}
TALER_TESTING_interpreter_next (is);
}
/**
* Some commands (notably "bank history") could randomly
* look for traits; this way makes sure we don't segfault.
*/
static int
check_bank_empty_traits (void *cls,
const void **ret,
const char *trait,
unsigned int index)
{
return GNUNET_SYSERR;
}
/**
* Checks wheter all the wire transfers got "checked"
* by the "bank check" CMD.
*
* @param label command label.
*
* @return the command
*/
struct TALER_TESTING_Command
TALER_TESTING_cmd_check_bank_empty (const char *label)
{
struct TALER_TESTING_Command cmd = {
.label = label,
.run = &check_bank_empty_run,
.cleanup = &check_bank_empty_cleanup,
.traits = &check_bank_empty_traits
};
return cmd;
}
/**
* Define a "bank check" CMD that takes the input
* data from another CMD that offers it.
@ -337,7 +261,6 @@ TALER_TESTING_cmd_check_bank_empty (const char *label)
* @param deposit_reference reference to a CMD that is
* able to provide the "check bank transfer" operation
* input data.
*
* @return the command.
*/
struct TALER_TESTING_Command
@ -345,7 +268,6 @@ TALER_TESTING_cmd_check_bank_transfer_with_ref
(const char *label,
const char *deposit_reference)
{
struct BankCheckState *bcs;
bcs = GNUNET_new (struct BankCheckState);

View File

@ -0,0 +1,103 @@
/*
This file is part of TALER
Copyright (C) 2018-2020 Taler Systems SA
TALER is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 3, or
(at your option) any later version.
TALER is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with TALER; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>
*/
/**
* @file exchange-lib/testing_api_cmd_bank_check_empty.c
* @brief command to check if a particular wire transfer took
* place.
* @author Marcello Stanisci
*/
#include "platform.h"
#include "taler_json_lib.h"
#include <gnunet/gnunet_curl_lib.h>
#include "exchange_api_handle.h"
#include "taler_testing_lib.h"
#include "taler_fakebank_lib.h"
/**
* Cleanup the state, only defined to respect the API.
*
* @param cls closure.
* @param cmd the command which is being cleaned up.
*/
static void
check_bank_empty_cleanup
(void *cls,
const struct TALER_TESTING_Command *cmd)
{
return;
}
/**
* Run the command.
*
* @param cls closure.
* @param cmd the command to execute.
* @param is the interpreter state.
*/
static void
check_bank_empty_run (void *cls,
const struct TALER_TESTING_Command *cmd,
struct TALER_TESTING_Interpreter *is)
{
if (GNUNET_OK != TALER_FAKEBANK_check_empty (is->fakebank))
{
GNUNET_break (0);
TALER_TESTING_interpreter_fail (is);
return;
}
TALER_TESTING_interpreter_next (is);
}
/**
* Some commands (notably "bank history") could randomly
* look for traits; this way makes sure we don't segfault.
*/
static int
check_bank_empty_traits (void *cls,
const void **ret,
const char *trait,
unsigned int index)
{
return GNUNET_SYSERR;
}
/**
* Checks wheter all the wire transfers got "checked"
* by the "bank check" CMD.
*
* @param label command label.
*
* @return the command
*/
struct TALER_TESTING_Command
TALER_TESTING_cmd_check_bank_empty (const char *label)
{
struct TALER_TESTING_Command cmd = {
.label = label,
.run = &check_bank_empty_run,
.cleanup = &check_bank_empty_cleanup,
.traits = &check_bank_empty_traits
};
return cmd;
}