aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bank-lib/test_bank_api.c2
-rw-r--r--src/bank-lib/test_bank_api_with_fakebank.c22
-rw-r--r--src/bank-lib/test_bank_interpreter.c47
-rw-r--r--src/bank-lib/test_bank_interpreter.h36
4 files changed, 93 insertions, 14 deletions
diff --git a/src/bank-lib/test_bank_api.c b/src/bank-lib/test_bank_api.c
index deba9fd53..3503e47b1 100644
--- a/src/bank-lib/test_bank_api.c
+++ b/src/bank-lib/test_bank_api.c
@@ -42,7 +42,7 @@ run (void *cls)
/* Add EUR:5.01 to account 42 */
{ .oc = TBI_OC_ADMIN_ADD_INCOMING,
.label = "deposit-1",
- .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.debit_account_no = 2,
.details.admin_add_incoming.amount = "PUDOS:5.01" },
diff --git a/src/bank-lib/test_bank_api_with_fakebank.c b/src/bank-lib/test_bank_api_with_fakebank.c
index fccdf6645..d0f730655 100644
--- a/src/bank-lib/test_bank_api_with_fakebank.c
+++ b/src/bank-lib/test_bank_api_with_fakebank.c
@@ -39,14 +39,30 @@ run (void *cls)
int *resultp = cls;
static struct TBI_Command commands[] =
{
- /* Add EUR:5.01 to account 42 */
+ /* Add EUR:5.01 to account 1 */
{ .oc = TBI_OC_ADMIN_ADD_INCOMING,
.label = "deposit-1",
- .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.debit_account_no = 2,
.details.admin_add_incoming.amount = "PUDOS:5.01" },
-
+ /* Add EUR:3.21 to account 3 */
+ { .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 = 3,
+ .details.admin_add_incoming.debit_account_no = 2,
+ .details.admin_add_incoming.amount = "PUDOS:3.21" },
+ /* check transactions arrived at fakebank */
+ { .oc = TBI_OC_EXPECT_TRANSACTION,
+ .label = "expect-2",
+ .details.expect_transaction.cmd_ref = "deposit-2" },
+ { .oc = TBI_OC_EXPECT_TRANSACTION,
+ .label = "expect-1",
+ .details.expect_transaction.cmd_ref = "deposit-1" },
+ /* check transaction list is now empty */
+ { .oc = TBI_OC_EXPECT_TRANSACTIONS_EMPTY,
+ .label = "expect-empty" },
{ .oc = TBI_OC_END }
};
diff --git a/src/bank-lib/test_bank_interpreter.c b/src/bank-lib/test_bank_interpreter.c
index 7fff8be2f..39129a549 100644
--- a/src/bank-lib/test_bank_interpreter.c
+++ b/src/bank-lib/test_bank_interpreter.c
@@ -96,7 +96,6 @@ fail (struct InterpreterState *is)
}
-#if 0
/**
* Find a command by label.
*
@@ -127,7 +126,6 @@ find_command (const struct InterpreterState *is,
label);
return NULL;
}
-#endif
/**
@@ -156,7 +154,7 @@ add_incoming_cb (void *cls,
struct TBI_Command *cmd = &is->commands[is->ip];
cmd->details.admin_add_incoming.aih = NULL;
- if (cmd->expected_response_code != http_status)
+ if (cmd->details.admin_add_incoming.expected_response_code != http_status)
{
GNUNET_break (0);
fprintf (stderr,
@@ -186,6 +184,8 @@ interpreter_run (void *cls)
{
struct InterpreterState *is = cls;
struct TBI_Command *cmd = &is->commands[is->ip];
+ const struct TBI_Command *ref;
+ struct TALER_WireTransferIdentifierRawP wtid;
struct TALER_Amount amount;
const struct GNUNET_SCHEDULER_TaskContext *tc;
@@ -205,7 +205,6 @@ interpreter_run (void *cls)
GNUNET_SCHEDULER_shutdown ();
return;
case TBI_OC_ADMIN_ADD_INCOMING:
-
if (GNUNET_OK !=
TALER_string_to_amount (cmd->details.admin_add_incoming.amount,
&amount))
@@ -236,6 +235,46 @@ interpreter_run (void *cls)
return;
}
return;
+ case TBI_OC_EXPECT_TRANSACTION:
+ ref = find_command (is,
+ cmd->details.expect_transaction.cmd_ref);
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (ref->details.admin_add_incoming.amount,
+ &amount));
+ if (GNUNET_OK !=
+ FAKEBANK_check (is->fakebank,
+ &amount,
+ ref->details.admin_add_incoming.debit_account_no,
+ ref->details.admin_add_incoming.credit_account_no,
+ &wtid))
+ {
+ GNUNET_break (0);
+ fail (is);
+ return;
+ }
+ if (0 != memcmp (&wtid,
+ &ref->details.admin_add_incoming.wtid,
+ sizeof (wtid)))
+ {
+ GNUNET_break (0);
+ fail (is);
+ return;
+ }
+ is->ip++;
+ is->task = GNUNET_SCHEDULER_add_now (&interpreter_run,
+ is);
+ return;
+ case TBI_OC_EXPECT_TRANSACTIONS_EMPTY:
+ if (GNUNET_OK != FAKEBANK_check_empty (is->fakebank))
+ {
+ GNUNET_break (0);
+ fail (is);
+ return;
+ }
+ is->ip++;
+ is->task = GNUNET_SCHEDULER_add_now (&interpreter_run,
+ is);
+ return;
default:
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unknown instruction %d at %u (%s)\n",
diff --git a/src/bank-lib/test_bank_interpreter.h b/src/bank-lib/test_bank_interpreter.h
index f54986973..329b51461 100644
--- a/src/bank-lib/test_bank_interpreter.h
+++ b/src/bank-lib/test_bank_interpreter.h
@@ -42,7 +42,17 @@ enum TBI_OpCode
/**
* Add funds to a reserve by (faking) incoming wire transfer.
*/
- TBI_OC_ADMIN_ADD_INCOMING
+ TBI_OC_ADMIN_ADD_INCOMING,
+
+ /**
+ * Expect that we have received the specified transaction at fakebank.
+ */
+ TBI_OC_EXPECT_TRANSACTION,
+
+ /**
+ * Expect that we have exhaustively gone over all transactions at fakebank.
+ */
+ TBI_OC_EXPECT_TRANSACTIONS_EMPTY
};
@@ -63,11 +73,6 @@ struct TBI_Command
const char *label;
/**
- * Which response code do we expect for this command?
- */
- unsigned int expected_response_code;
-
- /**
* Details about the command.
*/
union
@@ -101,12 +106,31 @@ struct TBI_Command
struct TALER_WireTransferIdentifierRawP wtid;
/**
+ * Which response code do we expect for this command?
+ */
+ unsigned int expected_response_code;
+
+ /**
* Set to the API's handle during the operation.
*/
struct TALER_BANK_AdminAddIncomingHandle *aih;
} admin_add_incoming;
+ /**
+ * If @e opcode is #TBI_OC_EXPECT_TRANSACTION, this
+ * specifies which transaction we expected.
+ */
+ struct {
+
+ /**
+ * Label of the command of an /admin/add/incoming
+ * request that we should check was executed.
+ */
+ const char *cmd_ref;
+
+ } expect_transaction;
+
} details;
};