5746.
Introduce a stand-alone test file for wire-plugins that use the legacy API offered by banks (notably, /history-range).
This commit is contained in:
parent
a07d036c80
commit
f4ee88a175
1
.gitignore
vendored
1
.gitignore
vendored
@ -113,3 +113,4 @@ src/lib/test_exchange_api
|
|||||||
src/lib/test_auditor_api
|
src/lib/test_auditor_api
|
||||||
src/lib/test_exchange_api_overlapping_keys_bug
|
src/lib/test_exchange_api_overlapping_keys_bug
|
||||||
src/lib/test_exchange_api_home/.local/share/taler/exchange/revocations/
|
src/lib/test_exchange_api_home/.local/share/taler/exchange/revocations/
|
||||||
|
src/wire-plugins/test_wire_plugin_legacy_taler_bank
|
||||||
|
@ -77,11 +77,7 @@ TESTS = \
|
|||||||
test_wire_plugin_transactions_taler_bank \
|
test_wire_plugin_transactions_taler_bank \
|
||||||
test_wire_plugin_legacy_taler_bank
|
test_wire_plugin_legacy_taler_bank
|
||||||
|
|
||||||
check_PROGRAMS= \
|
check_PROGRAMS= $(TESTS)
|
||||||
test_ebics_wireformat \
|
|
||||||
test_wire_plugin \
|
|
||||||
test_wire_plugin_transactions_taler_bank
|
|
||||||
|
|
||||||
|
|
||||||
test_ebics_wireformat_SOURCES = \
|
test_ebics_wireformat_SOURCES = \
|
||||||
test_ebics_wireformat.c
|
test_ebics_wireformat.c
|
||||||
|
@ -920,8 +920,6 @@ bhist_cb (void *cls,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
whh->hh = NULL;
|
whh->hh = NULL;
|
||||||
taler_bank_get_history_cancel (NULL,
|
|
||||||
whh);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,13 +28,11 @@
|
|||||||
#include "taler_fakebank_lib.h"
|
#include "taler_fakebank_lib.h"
|
||||||
#include <gnunet/gnunet_json_lib.h>
|
#include <gnunet/gnunet_json_lib.h>
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When does the test timeout? Right now, we expect this to be very
|
* How many wire transfers this test should accomplish, before
|
||||||
* fast.
|
* delving into actual checks.
|
||||||
*/
|
*/
|
||||||
#define TIMEOUT GNUNET_TIME_UNIT_SECONDS
|
#define NTRANSACTIONS 5
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destination account to use.
|
* Destination account to use.
|
||||||
@ -76,26 +74,11 @@ static struct TALER_WIRE_ExecuteHandle *eh;
|
|||||||
*/
|
*/
|
||||||
static struct TALER_FAKEBANK_Handle *fb;
|
static struct TALER_FAKEBANK_Handle *fb;
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle to the history request.
|
|
||||||
*/
|
|
||||||
static struct TALER_WIRE_HistoryHandle *hh;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle to the history-range request (the "legacy" bank API).
|
* Handle to the history-range request (the "legacy" bank API).
|
||||||
*/
|
*/
|
||||||
static struct TALER_WIRE_HistoryHandle *hhr;
|
static struct TALER_WIRE_HistoryHandle *hhr;
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle for the timeout task.
|
|
||||||
*/
|
|
||||||
static struct GNUNET_SCHEDULER_Task *tt;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Which serial ID do we expect to get from /history?
|
|
||||||
*/
|
|
||||||
static uint64_t serial_target;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wire transfer identifier we are using.
|
* Wire transfer identifier we are using.
|
||||||
*/
|
*/
|
||||||
@ -104,7 +87,7 @@ static struct TALER_WireTransferIdentifierRawP wtid;
|
|||||||
/**
|
/**
|
||||||
* Number of total transaction to make it happen in the test.
|
* Number of total transaction to make it happen in the test.
|
||||||
*/
|
*/
|
||||||
static int ntransactions = 5;
|
static int ntransactions = NTRANSACTIONS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function called on shutdown (regular, error or CTRL-C).
|
* Function called on shutdown (regular, error or CTRL-C).
|
||||||
@ -128,12 +111,6 @@ do_shutdown (void *cls)
|
|||||||
ph);
|
ph);
|
||||||
ph = NULL;
|
ph = NULL;
|
||||||
}
|
}
|
||||||
if (NULL != hh)
|
|
||||||
{
|
|
||||||
plugin->get_history_cancel (plugin->cls,
|
|
||||||
hh);
|
|
||||||
hh = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (NULL != hhr)
|
if (NULL != hhr)
|
||||||
{
|
{
|
||||||
@ -142,30 +119,11 @@ do_shutdown (void *cls)
|
|||||||
hhr = NULL;
|
hhr = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NULL != tt)
|
|
||||||
{
|
|
||||||
GNUNET_SCHEDULER_cancel (tt);
|
|
||||||
tt = NULL;
|
|
||||||
}
|
|
||||||
TALER_WIRE_plugin_unload (plugin);
|
TALER_WIRE_plugin_unload (plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Function called on timeout.
|
|
||||||
*
|
|
||||||
* @param cls NULL
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
timeout_cb (void *cls)
|
|
||||||
{
|
|
||||||
tt = NULL;
|
|
||||||
GNUNET_break (0);
|
|
||||||
global_ret = GNUNET_SYSERR;
|
|
||||||
GNUNET_SCHEDULER_shutdown ();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callbacks of this type are used to serve the result of asking
|
* Callbacks of this type are used to serve the result of asking
|
||||||
* the bank for the transaction history.
|
* the bank for the transaction history.
|
||||||
@ -189,57 +147,78 @@ history_result_cb
|
|||||||
size_t row_off_size,
|
size_t row_off_size,
|
||||||
const struct TALER_WIRE_TransferDetails *details)
|
const struct TALER_WIRE_TransferDetails *details)
|
||||||
{
|
{
|
||||||
uint64_t *serialp;
|
static int accumulator = 0;
|
||||||
uint64_t serialh;
|
|
||||||
struct TALER_Amount amount;
|
|
||||||
|
|
||||||
hh = NULL;
|
|
||||||
if ( (TALER_BANK_DIRECTION_NONE == dir) &&
|
if ( (TALER_BANK_DIRECTION_NONE == dir) &&
|
||||||
(GNUNET_OK == global_ret) )
|
(GNUNET_OK == global_ret) )
|
||||||
{
|
{
|
||||||
|
/* End-of-list, check all the transactions got accounted
|
||||||
|
* into the history. */
|
||||||
|
|
||||||
|
if (NTRANSACTIONS != accumulator)
|
||||||
|
{
|
||||||
|
GNUNET_break (0);
|
||||||
|
TALER_LOG_ERROR
|
||||||
|
("Unexpected # of transactions: %d, %d were expected.\n",
|
||||||
|
accumulator,
|
||||||
|
NTRANSACTIONS);
|
||||||
|
global_ret = GNUNET_NO;
|
||||||
|
}
|
||||||
|
|
||||||
GNUNET_SCHEDULER_shutdown ();
|
GNUNET_SCHEDULER_shutdown ();
|
||||||
return GNUNET_OK;
|
return GNUNET_OK;
|
||||||
}
|
}
|
||||||
if (sizeof (uint64_t) != row_off_size)
|
|
||||||
{
|
accumulator++;
|
||||||
GNUNET_break (0);
|
|
||||||
global_ret = GNUNET_SYSERR;
|
|
||||||
GNUNET_SCHEDULER_shutdown ();
|
|
||||||
return GNUNET_SYSERR;
|
|
||||||
}
|
|
||||||
serialp = (uint64_t *) row_off;
|
|
||||||
serialh = GNUNET_ntohll (*serialp);
|
|
||||||
if (serialh != serial_target)
|
|
||||||
{
|
|
||||||
GNUNET_break (0);
|
|
||||||
global_ret = GNUNET_SYSERR;
|
|
||||||
GNUNET_SCHEDULER_shutdown ();
|
|
||||||
return GNUNET_SYSERR;
|
|
||||||
}
|
|
||||||
GNUNET_assert (GNUNET_OK ==
|
|
||||||
TALER_string_to_amount ("KUDOS:5.01",
|
|
||||||
&amount));
|
|
||||||
if (0 != TALER_amount_cmp (&amount,
|
|
||||||
&details->amount))
|
|
||||||
{
|
|
||||||
GNUNET_break (0);
|
|
||||||
global_ret = GNUNET_SYSERR;
|
|
||||||
GNUNET_SCHEDULER_shutdown ();
|
|
||||||
return GNUNET_SYSERR;
|
|
||||||
}
|
|
||||||
if (0 != GNUNET_memcmp (&wtid,
|
|
||||||
&details->wtid))
|
|
||||||
{
|
|
||||||
GNUNET_break (0);
|
|
||||||
global_ret = GNUNET_SYSERR;
|
|
||||||
GNUNET_SCHEDULER_shutdown ();
|
|
||||||
return GNUNET_SYSERR;
|
|
||||||
}
|
|
||||||
global_ret = GNUNET_OK;
|
|
||||||
return GNUNET_OK;
|
return GNUNET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function called with the result from the execute step.
|
||||||
|
*
|
||||||
|
* @param cls closure
|
||||||
|
* @param success #GNUNET_OK on success,
|
||||||
|
* #GNUNET_SYSERR on failure
|
||||||
|
* @param row_id ID of the fresh transaction,
|
||||||
|
* in _network_ byte order.
|
||||||
|
* @param emsg NULL on success, otherwise an error message
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
confirmation_cb (void *cls,
|
||||||
|
int success,
|
||||||
|
const void *row_id,
|
||||||
|
size_t row_id_size,
|
||||||
|
const char *emsg);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback with prepared transaction.
|
||||||
|
*
|
||||||
|
* @param cls closure
|
||||||
|
* @param buf transaction data to persist, NULL on error
|
||||||
|
* @param buf_size number of bytes in @a buf, 0 on error
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
prepare_cb (void *cls,
|
||||||
|
const char *buf,
|
||||||
|
size_t buf_size)
|
||||||
|
{
|
||||||
|
ph = NULL;
|
||||||
|
if (NULL == buf)
|
||||||
|
{
|
||||||
|
GNUNET_break (0);
|
||||||
|
global_ret = GNUNET_SYSERR;
|
||||||
|
GNUNET_SCHEDULER_shutdown ();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
plugin->execute_wire_transfer (plugin->cls,
|
||||||
|
buf,
|
||||||
|
buf_size,
|
||||||
|
&confirmation_cb,
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function called with the result from the execute step.
|
* Function called with the result from the execute step.
|
||||||
*
|
*
|
||||||
@ -257,10 +236,8 @@ confirmation_cb (void *cls,
|
|||||||
size_t row_id_size,
|
size_t row_id_size,
|
||||||
const char *emsg)
|
const char *emsg)
|
||||||
{
|
{
|
||||||
uint64_t tmp;
|
|
||||||
struct TALER_Amount amount;
|
struct TALER_Amount amount;
|
||||||
|
|
||||||
|
|
||||||
eh = NULL;
|
eh = NULL;
|
||||||
if (GNUNET_OK != success)
|
if (GNUNET_OK != success)
|
||||||
{
|
{
|
||||||
@ -270,21 +247,17 @@ confirmation_cb (void *cls,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 => --ntransactions)
|
if (0 >= --ntransactions)
|
||||||
{
|
{
|
||||||
/* Done, check all is correct here. */
|
GNUNET_assert
|
||||||
|
(NULL != (hhr = plugin->get_history_range
|
||||||
if (GNUNET_YES)
|
(plugin->cls,
|
||||||
{
|
my_account,
|
||||||
/* Something went wrong. */
|
TALER_BANK_DIRECTION_BOTH,
|
||||||
GNUNET_break (0);
|
GNUNET_TIME_UNIT_ZERO_ABS,
|
||||||
global_ret = GNUNET_SYSERR;
|
GNUNET_TIME_UNIT_FOREVER_ABS,
|
||||||
GNUNET_SCHEDULER_shutdown ();
|
&history_result_cb,
|
||||||
return;
|
NULL)));
|
||||||
}
|
|
||||||
|
|
||||||
/* All correct, ending the test. */
|
|
||||||
GNUNET_SCHEDULER_shutdown ();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -303,35 +276,6 @@ confirmation_cb (void *cls,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Callback with prepared transaction.
|
|
||||||
*
|
|
||||||
* @param cls closure
|
|
||||||
* @param buf transaction data to persist, NULL on error
|
|
||||||
* @param buf_size number of bytes in @a buf, 0 on error
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
prepare_cb (void *cls,
|
|
||||||
const char *buf,
|
|
||||||
size_t buf_size)
|
|
||||||
{
|
|
||||||
|
|
||||||
ph = NULL;
|
|
||||||
if (NULL == buf)
|
|
||||||
{
|
|
||||||
GNUNET_break (0);
|
|
||||||
global_ret = GNUNET_SYSERR;
|
|
||||||
GNUNET_SCHEDULER_shutdown ();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
plugin->execute_wire_transfer (plugin->cls,
|
|
||||||
buf,
|
|
||||||
buf_size,
|
|
||||||
&confirmation_cb,
|
|
||||||
NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the test.
|
* Run the test.
|
||||||
*
|
*
|
||||||
@ -341,13 +285,9 @@ static void
|
|||||||
run (void *cls)
|
run (void *cls)
|
||||||
{
|
{
|
||||||
struct TALER_Amount amount;
|
struct TALER_Amount amount;
|
||||||
|
|
||||||
ntransactions = 5;
|
|
||||||
GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
|
GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
|
||||||
NULL);
|
NULL);
|
||||||
tt = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
|
|
||||||
&timeout_cb,
|
|
||||||
NULL);
|
|
||||||
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
|
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
|
||||||
&wtid,
|
&wtid,
|
||||||
sizeof (wtid));
|
sizeof (wtid));
|
||||||
|
Loading…
Reference in New Issue
Block a user