start to add /history testing support to tests, fix some minor issues
This commit is contained in:
parent
0e632ffdd2
commit
69fa9b41d1
@ -250,12 +250,12 @@ TALER_BANK_history (struct GNUNET_CURL_Context *ctx,
|
|||||||
{
|
{
|
||||||
if (TALER_BANK_DIRECTION_BOTH == direction)
|
if (TALER_BANK_DIRECTION_BOTH == direction)
|
||||||
GNUNET_asprintf (&url,
|
GNUNET_asprintf (&url,
|
||||||
"/history?account_number=%llu&num_results=%lld",
|
"/history?auth=basic&account_number=%llu&delta=%lld",
|
||||||
(unsigned long long) account_number,
|
(unsigned long long) account_number,
|
||||||
(long long) num_results);
|
(long long) num_results);
|
||||||
else
|
else
|
||||||
GNUNET_asprintf (&url,
|
GNUNET_asprintf (&url,
|
||||||
"/history?account_number=%llu&num_results=%lld&direction=%s",
|
"/history?auth=basic&account_number=%llu&delta=%lld&direction=%s",
|
||||||
(unsigned long long) account_number,
|
(unsigned long long) account_number,
|
||||||
(long long) num_results,
|
(long long) num_results,
|
||||||
(TALER_BANK_DIRECTION_CREDIT == direction) ? "credit" : "debit");
|
(TALER_BANK_DIRECTION_CREDIT == direction) ? "credit" : "debit");
|
||||||
@ -265,13 +265,13 @@ TALER_BANK_history (struct GNUNET_CURL_Context *ctx,
|
|||||||
{
|
{
|
||||||
if (TALER_BANK_DIRECTION_BOTH == direction)
|
if (TALER_BANK_DIRECTION_BOTH == direction)
|
||||||
GNUNET_asprintf (&url,
|
GNUNET_asprintf (&url,
|
||||||
"/history?account_number=%llu&num_results=%lld&start_row=%llu",
|
"/history?auth=basic&account_number=%llu&delta=%lld&start_row=%llu",
|
||||||
(unsigned long long) account_number,
|
(unsigned long long) account_number,
|
||||||
(long long) num_results,
|
(long long) num_results,
|
||||||
(unsigned long long) start_row);
|
(unsigned long long) start_row);
|
||||||
else
|
else
|
||||||
GNUNET_asprintf (&url,
|
GNUNET_asprintf (&url,
|
||||||
"/history?account_number=%llu&num_results=%lld&start_row=%llu&direction=%s",
|
"/history?auth=basic&account_number=%llu&delta=%lld&start_row=%llu&direction=%s",
|
||||||
(unsigned long long) account_number,
|
(unsigned long long) account_number,
|
||||||
(long long) num_results,
|
(long long) num_results,
|
||||||
(unsigned long long) start_row,
|
(unsigned long long) start_row,
|
||||||
|
@ -400,6 +400,8 @@ handle_history (struct TALER_FAKEBANK_Handle *h,
|
|||||||
MHD_GET_ARGUMENT_KIND,
|
MHD_GET_ARGUMENT_KIND,
|
||||||
"account_number");
|
"account_number");
|
||||||
if ( (NULL == auth) ||
|
if ( (NULL == auth) ||
|
||||||
|
(0 != strcasecmp (auth,
|
||||||
|
"basic")) ||
|
||||||
(NULL == acc) ||
|
(NULL == acc) ||
|
||||||
(NULL == delta) )
|
(NULL == delta) )
|
||||||
{
|
{
|
||||||
@ -456,7 +458,6 @@ handle_history (struct TALER_FAKEBANK_Handle *h,
|
|||||||
}
|
}
|
||||||
pos = pos->next;
|
pos = pos->next;
|
||||||
}
|
}
|
||||||
GNUNET_assert (pos->serial_id == start_number);
|
|
||||||
}
|
}
|
||||||
history = json_array ();
|
history = json_array ();
|
||||||
while ( (NULL != pos) &&
|
while ( (NULL != pos) &&
|
||||||
|
@ -40,13 +40,48 @@ run (void *cls)
|
|||||||
static struct TBI_Command commands[] =
|
static struct TBI_Command commands[] =
|
||||||
{
|
{
|
||||||
/* Add EUR:5.01 to account 42 */
|
/* Add EUR:5.01 to account 42 */
|
||||||
|
{ .oc = TBI_OC_HISTORY,
|
||||||
|
.label = "history-0",
|
||||||
|
.details.history.account_number = 1,
|
||||||
|
.details.history.direction = TALER_BANK_DIRECTION_BOTH,
|
||||||
|
.details.history.start_row = 0,
|
||||||
|
.details.history.num_results = 5 },
|
||||||
{ .oc = TBI_OC_ADMIN_ADD_INCOMING,
|
{ .oc = TBI_OC_ADMIN_ADD_INCOMING,
|
||||||
.label = "deposit-1",
|
.label = "deposit-1",
|
||||||
.details.admin_add_incoming.expected_response_code = MHD_HTTP_OK,
|
.details.admin_add_incoming.expected_response_code = MHD_HTTP_OK,
|
||||||
.details.admin_add_incoming.credit_account_no = 1,
|
.details.admin_add_incoming.credit_account_no = 1,
|
||||||
.details.admin_add_incoming.debit_account_no = 2,
|
.details.admin_add_incoming.debit_account_no = 2,
|
||||||
.details.admin_add_incoming.amount = "PUDOS:5.01" },
|
.details.admin_add_incoming.amount = "PUDOS:5.01" },
|
||||||
|
{ .oc = TBI_OC_ADMIN_ADD_INCOMING,
|
||||||
|
.label = "deposit-2",
|
||||||
|
.details.admin_add_incoming.expected_response_code = MHD_HTTP_OK,
|
||||||
|
.details.admin_add_incoming.credit_account_no = 1,
|
||||||
|
.details.admin_add_incoming.debit_account_no = 2,
|
||||||
|
.details.admin_add_incoming.amount = "PUDOS:5.01" },
|
||||||
|
{ .oc = TBI_OC_HISTORY,
|
||||||
|
.label = "history-1c",
|
||||||
|
.details.history.account_number = 1,
|
||||||
|
.details.history.direction = TALER_BANK_DIRECTION_CREDIT,
|
||||||
|
.details.history.start_row = 0,
|
||||||
|
.details.history.num_results = 5 },
|
||||||
|
{ .oc = TBI_OC_HISTORY,
|
||||||
|
.label = "history-2d",
|
||||||
|
.details.history.account_number = 2,
|
||||||
|
.details.history.direction = TALER_BANK_DIRECTION_DEBIT,
|
||||||
|
.details.history.start_row = 0,
|
||||||
|
.details.history.num_results = 5 },
|
||||||
|
{ .oc = TBI_OC_HISTORY,
|
||||||
|
.label = "history-2dr",
|
||||||
|
.details.history.account_number = 2,
|
||||||
|
.details.history.direction = TALER_BANK_DIRECTION_DEBIT,
|
||||||
|
.details.history.start_row = UINT64_MAX,
|
||||||
|
.details.history.num_results = -5 },
|
||||||
|
{ .oc = TBI_OC_HISTORY,
|
||||||
|
.label = "history-2fwd",
|
||||||
|
.details.history.account_number = 2,
|
||||||
|
.details.history.direction = TALER_BANK_DIRECTION_DEBIT,
|
||||||
|
.details.history.start_row = 1,
|
||||||
|
.details.history.num_results = 5 },
|
||||||
{ .oc = TBI_OC_END }
|
{ .oc = TBI_OC_END }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -92,7 +127,7 @@ main (int argc,
|
|||||||
"serve-http",
|
"serve-http",
|
||||||
"--port", "8081",
|
"--port", "8081",
|
||||||
NULL);
|
NULL);
|
||||||
if (NULL == bankd_admin)
|
if (NULL == bankd_admin)
|
||||||
{
|
{
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
"Failed to launch `taler-bank-manage' for admin, skipping test\n");
|
"Failed to launch `taler-bank-manage' for admin, skipping test\n");
|
||||||
|
@ -39,29 +39,69 @@ run (void *cls)
|
|||||||
int *resultp = cls;
|
int *resultp = cls;
|
||||||
static struct TBI_Command commands[] =
|
static struct TBI_Command commands[] =
|
||||||
{
|
{
|
||||||
|
{ .oc = TBI_OC_HISTORY,
|
||||||
|
.label = "history-0",
|
||||||
|
.details.history.account_number = 1,
|
||||||
|
.details.history.direction = TALER_BANK_DIRECTION_BOTH,
|
||||||
|
.details.history.start_row = 0,
|
||||||
|
.details.history.num_results = 1 },
|
||||||
/* Add EUR:5.01 to account 1 */
|
/* Add EUR:5.01 to account 1 */
|
||||||
{ .oc = TBI_OC_ADMIN_ADD_INCOMING,
|
{ .oc = TBI_OC_ADMIN_ADD_INCOMING,
|
||||||
.label = "deposit-1",
|
.label = "debit-1",
|
||||||
.details.admin_add_incoming.expected_response_code = MHD_HTTP_OK,
|
.details.admin_add_incoming.expected_response_code = MHD_HTTP_OK,
|
||||||
.details.admin_add_incoming.credit_account_no = 1,
|
.details.admin_add_incoming.credit_account_no = 1,
|
||||||
.details.admin_add_incoming.debit_account_no = 2,
|
.details.admin_add_incoming.debit_account_no = 2,
|
||||||
.details.admin_add_incoming.exchange_base_url = "https://exchange.net/",
|
.details.admin_add_incoming.exchange_base_url = "https://exchange.net/",
|
||||||
.details.admin_add_incoming.amount = "PUDOS:5.01" },
|
.details.admin_add_incoming.amount = "PUDOS:5.01" },
|
||||||
/* Add EUR:3.21 to account 3 */
|
/* Add EUR:3.21 to account 3 */
|
||||||
|
{ .oc = TBI_OC_HISTORY,
|
||||||
|
.label = "history-1c",
|
||||||
|
.details.history.account_number = 1,
|
||||||
|
.details.history.direction = TALER_BANK_DIRECTION_CREDIT,
|
||||||
|
.details.history.start_row = 0,
|
||||||
|
.details.history.num_results = 5 },
|
||||||
|
{ .oc = TBI_OC_HISTORY,
|
||||||
|
.label = "history-1d",
|
||||||
|
.details.history.account_number = 1,
|
||||||
|
.details.history.direction = TALER_BANK_DIRECTION_DEBIT,
|
||||||
|
.details.history.start_row = 0,
|
||||||
|
.details.history.num_results = 5 },
|
||||||
{ .oc = TBI_OC_ADMIN_ADD_INCOMING,
|
{ .oc = TBI_OC_ADMIN_ADD_INCOMING,
|
||||||
.label = "deposit-2",
|
.label = "debit-2",
|
||||||
.details.admin_add_incoming.expected_response_code = MHD_HTTP_OK,
|
.details.admin_add_incoming.expected_response_code = MHD_HTTP_OK,
|
||||||
.details.admin_add_incoming.credit_account_no = 3,
|
.details.admin_add_incoming.credit_account_no = 3,
|
||||||
.details.admin_add_incoming.debit_account_no = 2,
|
.details.admin_add_incoming.debit_account_no = 2,
|
||||||
.details.admin_add_incoming.exchange_base_url = "https://exchange.org/",
|
.details.admin_add_incoming.exchange_base_url = "https://exchange.org/",
|
||||||
.details.admin_add_incoming.amount = "PUDOS:3.21" },
|
.details.admin_add_incoming.amount = "PUDOS:3.21" },
|
||||||
|
{ .oc = TBI_OC_ADMIN_ADD_INCOMING,
|
||||||
|
.label = "credit-2",
|
||||||
|
.details.admin_add_incoming.expected_response_code = MHD_HTTP_OK,
|
||||||
|
.details.admin_add_incoming.credit_account_no = 2,
|
||||||
|
.details.admin_add_incoming.debit_account_no = 3,
|
||||||
|
.details.admin_add_incoming.exchange_base_url = "https://exchange.org/",
|
||||||
|
.details.admin_add_incoming.amount = "PUDOS:3.21" },
|
||||||
|
{ .oc = TBI_OC_HISTORY,
|
||||||
|
.label = "history-2b",
|
||||||
|
.details.history.account_number = 2,
|
||||||
|
.details.history.direction = TALER_BANK_DIRECTION_BOTH,
|
||||||
|
.details.history.start_row = 0,
|
||||||
|
.details.history.num_results = 5 },
|
||||||
|
{ .oc = TBI_OC_HISTORY,
|
||||||
|
.label = "history-2bi",
|
||||||
|
.details.history.account_number = 2,
|
||||||
|
.details.history.direction = TALER_BANK_DIRECTION_BOTH,
|
||||||
|
.details.history.start_row = 1,
|
||||||
|
.details.history.num_results = 5 },
|
||||||
/* check transfers arrived at fakebank */
|
/* check transfers arrived at fakebank */
|
||||||
{ .oc = TBI_OC_EXPECT_TRANSFER,
|
{ .oc = TBI_OC_EXPECT_TRANSFER,
|
||||||
.label = "expect-2",
|
.label = "expect-2d",
|
||||||
.details.expect_transfer.cmd_ref = "deposit-2" },
|
.details.expect_transfer.cmd_ref = "credit-2" },
|
||||||
|
{ .oc = TBI_OC_EXPECT_TRANSFER,
|
||||||
|
.label = "expect-2c",
|
||||||
|
.details.expect_transfer.cmd_ref = "debit-2" },
|
||||||
{ .oc = TBI_OC_EXPECT_TRANSFER,
|
{ .oc = TBI_OC_EXPECT_TRANSFER,
|
||||||
.label = "expect-1",
|
.label = "expect-1",
|
||||||
.details.expect_transfer.cmd_ref = "deposit-1" },
|
.details.expect_transfer.cmd_ref = "debit-1" },
|
||||||
/* check transfer list is now empty */
|
/* check transfer list is now empty */
|
||||||
{ .oc = TBI_OC_EXPECT_TRANSFERS_EMPTY,
|
{ .oc = TBI_OC_EXPECT_TRANSFERS_EMPTY,
|
||||||
.label = "expect-empty" },
|
.label = "expect-empty" },
|
||||||
|
@ -174,6 +174,44 @@ add_incoming_cb (void *cls,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callbacks of this type are used to serve the result of asking
|
||||||
|
* the bank for the transaction history.
|
||||||
|
*
|
||||||
|
* @param cls closure
|
||||||
|
* @param http_status HTTP response code, #MHD_HTTP_OK (200) for successful status request
|
||||||
|
* 0 if the bank's reply is bogus (fails to follow the protocol),
|
||||||
|
* #MHD_HTTP_NO_CONTENT if there are no more results; on success the
|
||||||
|
* last callback is always of this status (even if `abs(num_results)` were
|
||||||
|
* already returned).
|
||||||
|
* @param dir direction of the transfer
|
||||||
|
* @param serial_id monotonically increasing counter corresponding to the transaction
|
||||||
|
* @param details details about the wire transfer
|
||||||
|
* @param json detailed response from the HTTPD, or NULL if reply was not in JSON
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
history_cb (void *cls,
|
||||||
|
unsigned int http_status,
|
||||||
|
enum TALER_BANK_Direction dir,
|
||||||
|
uint64_t serial_id,
|
||||||
|
const struct TALER_BANK_TransferDetails *details,
|
||||||
|
const json_t *json)
|
||||||
|
{
|
||||||
|
struct InterpreterState *is = cls;
|
||||||
|
struct TBI_Command *cmd = &is->commands[is->ip];
|
||||||
|
|
||||||
|
if (MHD_HTTP_OK != http_status)
|
||||||
|
{
|
||||||
|
cmd->details.history.hh = NULL;
|
||||||
|
is->ip++;
|
||||||
|
is->task = GNUNET_SCHEDULER_add_now (&interpreter_run,
|
||||||
|
is);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
/* FIXME: check history data is OK! */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the main interpreter loop that performs bank operations.
|
* Run the main interpreter loop that performs bank operations.
|
||||||
*
|
*
|
||||||
@ -199,6 +237,9 @@ interpreter_run (void *cls)
|
|||||||
fail (is);
|
fail (is);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
auth.method = TALER_BANK_AUTH_BASIC; /* or "NONE"? */
|
||||||
|
auth.details.basic.username = "user";
|
||||||
|
auth.details.basic.password = "pass";
|
||||||
switch (cmd->oc)
|
switch (cmd->oc)
|
||||||
{
|
{
|
||||||
case TBI_OC_END:
|
case TBI_OC_END:
|
||||||
@ -220,9 +261,6 @@ interpreter_run (void *cls)
|
|||||||
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
|
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
|
||||||
&cmd->details.admin_add_incoming.wtid,
|
&cmd->details.admin_add_incoming.wtid,
|
||||||
sizeof (cmd->details.admin_add_incoming.wtid));
|
sizeof (cmd->details.admin_add_incoming.wtid));
|
||||||
auth.method = TALER_BANK_AUTH_BASIC; /* or "NONE"? */
|
|
||||||
auth.details.basic.username = "user";
|
|
||||||
auth.details.basic.password = "pass";
|
|
||||||
cmd->details.admin_add_incoming.aih
|
cmd->details.admin_add_incoming.aih
|
||||||
= TALER_BANK_admin_add_incoming (is->ctx,
|
= TALER_BANK_admin_add_incoming (is->ctx,
|
||||||
"http://localhost:8081",
|
"http://localhost:8081",
|
||||||
@ -241,6 +279,24 @@ interpreter_run (void *cls)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
case TBI_OC_HISTORY:
|
||||||
|
cmd->details.history.hh
|
||||||
|
= TALER_BANK_history (is->ctx,
|
||||||
|
"http://localhost:8081",
|
||||||
|
&auth,
|
||||||
|
cmd->details.history.account_number,
|
||||||
|
cmd->details.history.direction,
|
||||||
|
cmd->details.history.start_row,
|
||||||
|
cmd->details.history.num_results,
|
||||||
|
&history_cb,
|
||||||
|
is);
|
||||||
|
if (NULL == cmd->details.history.hh)
|
||||||
|
{
|
||||||
|
GNUNET_break (0);
|
||||||
|
fail (is);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return;
|
||||||
case TBI_OC_EXPECT_TRANSFER:
|
case TBI_OC_EXPECT_TRANSFER:
|
||||||
ref = find_command (is,
|
ref = find_command (is,
|
||||||
cmd->details.expect_transfer.cmd_ref);
|
cmd->details.expect_transfer.cmd_ref);
|
||||||
@ -346,6 +402,21 @@ do_shutdown (void *cls)
|
|||||||
cmd->details.admin_add_incoming.aih = NULL;
|
cmd->details.admin_add_incoming.aih = NULL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case TBI_OC_HISTORY:
|
||||||
|
if (NULL != cmd->details.history.hh)
|
||||||
|
{
|
||||||
|
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
|
||||||
|
"Command %u (%s) did not complete\n",
|
||||||
|
i,
|
||||||
|
cmd->label);
|
||||||
|
TALER_BANK_history_cancel (cmd->details.history.hh);
|
||||||
|
cmd->details.history.hh = NULL;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TBI_OC_EXPECT_TRANSFER:
|
||||||
|
break;
|
||||||
|
case TBI_OC_EXPECT_TRANSFERS_EMPTY:
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||||
"Unknown instruction %d at %u (%s)\n",
|
"Unknown instruction %d at %u (%s)\n",
|
||||||
|
@ -44,6 +44,11 @@ enum TBI_OpCode
|
|||||||
*/
|
*/
|
||||||
TBI_OC_ADMIN_ADD_INCOMING,
|
TBI_OC_ADMIN_ADD_INCOMING,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request wire transfer history.
|
||||||
|
*/
|
||||||
|
TBI_OC_HISTORY,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Expect that we have received the specified transfer at fakebank.
|
* Expect that we have received the specified transfer at fakebank.
|
||||||
*/
|
*/
|
||||||
@ -122,6 +127,36 @@ struct TBI_Command
|
|||||||
|
|
||||||
} admin_add_incoming;
|
} admin_add_incoming;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For which account do we query the history.
|
||||||
|
*/
|
||||||
|
uint64_t account_number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Which types of transactions should be listed?
|
||||||
|
*/
|
||||||
|
enum TALER_BANK_Direction direction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* At which offset do we start?
|
||||||
|
* Use UINT64_MAX or 0 for the extremes.
|
||||||
|
*/
|
||||||
|
uint64_t start_row;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How many results should be returned (if available)?
|
||||||
|
*/
|
||||||
|
int64_t num_results;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set to the API's handle during the operation.
|
||||||
|
*/
|
||||||
|
struct TALER_BANK_HistoryHandle *hh;
|
||||||
|
|
||||||
|
} history;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If @e opcode is #TBI_OC_EXPECT_TRANSFER, this
|
* If @e opcode is #TBI_OC_EXPECT_TRANSFER, this
|
||||||
* specifies which transfer we expected.
|
* specifies which transfer we expected.
|
||||||
|
Loading…
Reference in New Issue
Block a user