diff options
Diffstat (limited to 'src/backenddb/test_merchantdb.c')
-rw-r--r-- | src/backenddb/test_merchantdb.c | 152 |
1 files changed, 137 insertions, 15 deletions
diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c index 818172d9..9fd159d8 100644 --- a/src/backenddb/test_merchantdb.c +++ b/src/backenddb/test_merchantdb.c @@ -37,8 +37,11 @@ static int result; */ static struct TALER_MERCHANTDB_Plugin *plugin; +/** + * @param test 0 on success, non-zero on failure + */ #define TEST_WITH_FAIL_CLAUSE(test, on_fail) \ - if (0 != (test)) \ + if ((test)) \ { \ GNUNET_break (0); \ on_fail \ @@ -53,6 +56,9 @@ static struct TALER_MERCHANTDB_Plugin *plugin; return 1; \ } +/** + * @param __test 0 on success, non-zero on failure + */ #define TEST_RET_ON_FAIL(__test) \ TEST_WITH_FAIL_CLAUSE (__test, \ return 1; \ @@ -145,8 +151,9 @@ make_account (struct TALER_MERCHANTDB_AccountDetails *account) { GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG, &account->h_wire); - GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG, - &account->salt); + GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG, + &account->salt, + sizeof (account->salt)); account->payto_uri = "payto://x-taler-bank/bank.demo.taler.net/4"; account->active = true; } @@ -249,10 +256,10 @@ static int check_accounts_equal (const struct TALER_MERCHANTDB_AccountDetails *a, const struct TALER_MERCHANTDB_AccountDetails *b) { - if ((0 != GNUNET_CRYPTO_hash_cmp (&a->h_wire, - &b->h_wire)) || - (0 != GNUNET_CRYPTO_hash_cmp (&a->salt, - &b->salt)) || + if ((0 != GNUNET_memcmp (&a->h_wire, + &b->h_wire)) || + (0 != GNUNET_memcmp (&a->salt, + &b->salt)) || (0 != strcmp (a->payto_uri, b->payto_uri)) || (a->active != b->active)) @@ -6647,6 +6654,119 @@ test_lookup_orders_all_filters (void) } +static void +kyc_status_ok (void *cls, + const struct GNUNET_HashCode *h_wire, + uint64_t exchange_kyc_serial, + const char *payto_uri, + const char *exchange_url, + struct GNUNET_TIME_Absolute last_check, + bool kyc_ok) +{ + bool *fail = cls; + + if (kyc_ok) + *fail = false; +} + + +static void +kyc_status_fail (void *cls, + const struct GNUNET_HashCode *h_wire, + uint64_t exchange_kyc_serial, + const char *payto_uri, + const char *exchange_url, + struct GNUNET_TIME_Absolute last_check, + bool kyc_ok) +{ + bool *fail = cls; + + if (! kyc_ok) + *fail = false; +} + + +/** + * Function that tests the KYC table. + * + * @return 0 on success, 1 otherwise. + */ +static int +test_kyc (void) +{ + struct InstanceData instance; + struct TALER_MERCHANTDB_AccountDetails account; + bool fail; + + make_instance ("test_kyc", + &instance); + make_account (&account); + TEST_RET_ON_FAIL (test_insert_instance (&instance, + GNUNET_DB_STATUS_SUCCESS_ONE_RESULT)); + TEST_RET_ON_FAIL (test_insert_account (&instance, + &account, + GNUNET_DB_STATUS_SUCCESS_ONE_RESULT)); + TEST_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != + plugin->account_kyc_set_status (plugin->cls, + instance.instance.id, + &account.h_wire, + "https://exchange.net/", + 1LLU, + false)); + TEST_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != + plugin->account_kyc_set_status (plugin->cls, + instance.instance.id, + &account.h_wire, + "https://exchange2.com/", + 1LLU, + false)); + TEST_RET_ON_FAIL (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != + plugin->account_kyc_set_status (plugin->cls, + instance.instance.id, + &account.h_wire, + "https://exchange.net/", + 1LLU, + true)); + fail = true; + TEST_RET_ON_FAIL (1 != + plugin->account_kyc_get_status (plugin->cls, + instance.instance.id, + &account.h_wire, + "https://exchange.net/", + &kyc_status_ok, + &fail)); + TEST_RET_ON_FAIL (fail); + fail = true; + TEST_RET_ON_FAIL (1 != + plugin->account_kyc_get_status (plugin->cls, + instance.instance.id, + NULL, + "https://exchange2.com/", + &kyc_status_fail, + &fail)); + TEST_RET_ON_FAIL (fail); + fail = true; + TEST_RET_ON_FAIL (2 != + plugin->account_kyc_get_status (plugin->cls, + instance.instance.id, + NULL, + NULL, + &kyc_status_fail, + &fail)); + TEST_RET_ON_FAIL (fail); + fail = true; + TEST_RET_ON_FAIL (2 != + plugin->account_kyc_get_status (plugin->cls, + instance.instance.id, + NULL, + NULL, + &kyc_status_ok, + &fail)); + TEST_RET_ON_FAIL (fail); + return 0; +} + + /** * Function that runs all tests. * @@ -6663,7 +6783,7 @@ run_tests (void) TEST_RET_ON_FAIL (test_tips ()); TEST_RET_ON_FAIL (test_refunds ()); TEST_RET_ON_FAIL (test_lookup_orders_all_filters ()); - + TEST_RET_ON_FAIL (test_kyc ()); return 0; } @@ -6703,14 +6823,16 @@ run (void *cls) plugin->preflight (plugin->cls); result = run_tests (); - - /* Test dropping tables */ - if (GNUNET_OK != plugin->drop_tables (plugin->cls)) + if (0 == result) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Dropping tables failed\n"); - result = 77; - return; + /* Test dropping tables */ + if (GNUNET_OK != plugin->drop_tables (plugin->cls)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Dropping tables failed\n"); + result = 77; + return; + } } TALER_MERCHANTDB_plugin_unload (plugin); |