Skip to content
This repository was archived by the owner on Dec 26, 2022. It is now read-only.

Commit ca89e2e

Browse files
committed
feat(tests): Append IRI Proxy API test cases
1 parent e900bf5 commit ca89e2e

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

tests/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ cc_test(
3333
deps = [
3434
":test_define",
3535
"//accelerator:apis",
36+
"//accelerator:proxy_apis",
3637
],
3738
)
3839

@@ -45,6 +46,7 @@ cc_binary(
4546
deps = [
4647
":test_define",
4748
"//accelerator:apis",
49+
"//accelerator:proxy_apis",
4850
],
4951
)
5052

tests/driver.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <time.h>
1010
#include "accelerator/apis.h"
11+
#include "accelerator/proxy_apis.h"
1112
#include "test_define.h"
1213

1314
static ta_core_t ta_core;
@@ -16,6 +17,38 @@ struct timespec start_time, end_time;
1617
char driver_tag_msg[NUM_TRYTES_TAG];
1718
ta_send_mam_res_t* res;
1819

20+
/**
21+
* TODO: Since there are two kinds of formats to call IRI Proxy API,
22+
* so here are two formats of function pointer. Once the number of
23+
* parameters of existing APIs is varied, the function pointer must
24+
* be updated as well.
25+
**/
26+
typedef status_t (*Proxy_apis)(const iota_client_service_t* const service, const char* const obj, char** json_result);
27+
typedef status_t (*Proxy_apis_without_args)(const iota_client_service_t* const service, char** json_result);
28+
29+
static struct proxy_apis_s {
30+
Proxy_apis api; // function pointer of IRI Proxy API with args
31+
Proxy_apis_without_args api_without_args; // function pointer of IRI Proxy API without args
32+
const char* name;
33+
const char* json; // args which are passed to IRI API
34+
} proxy_apis_g[] = {{api_check_consistency, NULL, "check_consistency",
35+
"{\"command\":\"checkConsistency\","
36+
"\"tails\":[\"" TRYTES_81_2 "\",\"" TRYTES_81_3 "\"]}"},
37+
{api_get_balances, NULL, "get_balances",
38+
"{\"command\":\"getBalances\","
39+
"\"addresses\":[\"" TRYTES_81_2 "\",\"" TRYTES_81_3 "\"],"
40+
"\"threshold\":" STR(THRESHOLD) "}"},
41+
{api_get_inclusion_states, NULL, "get_inclusion_states",
42+
"{\"command\":\"getInclusionStates\","
43+
"\"transactions\":[\"" TRYTES_81_2 "\",\"" TRYTES_81_3 "\"],"
44+
"\"tips\":[\"" TRYTES_81_2 "\",\"" TRYTES_81_3 "\"]}"},
45+
{NULL, api_get_node_info, "get_node_info", NULL},
46+
{api_get_trytes, NULL, "get_trytes",
47+
"{\"command\":\"getTrytes\","
48+
"\"hashes\":[\"" TRYTES_81_2 "\",\"" TRYTES_81_3 "\"]}"}};
49+
50+
static const int proxy_apis_num = sizeof(proxy_apis_g) / sizeof(struct proxy_apis_s);
51+
1952
#if defined(ENABLE_STAT)
2053
#define TEST_COUNT 100
2154
#else
@@ -217,6 +250,25 @@ void test_receive_mam_message(void) {
217250
printf("Average time of receive_mam_message: %lf\n", sum / TEST_COUNT);
218251
}
219252

253+
void test_proxy_apis() {
254+
for (int i = 0; i < proxy_apis_num; i++) {
255+
char* json_result;
256+
double sum = 0;
257+
258+
for (size_t count = 0; count < TEST_COUNT; count++) {
259+
test_time_start(&start_time);
260+
if (proxy_apis_g[i].json != NULL) {
261+
TEST_ASSERT_EQUAL_INT32(SC_OK, proxy_apis_g[i].api(&ta_core.service, proxy_apis_g[i].json, &json_result));
262+
} else {
263+
TEST_ASSERT_EQUAL_INT32(SC_OK, proxy_apis_g[i].api_without_args(&ta_core.service, &json_result));
264+
}
265+
test_time_end(&start_time, &end_time, &sum);
266+
free(json_result);
267+
}
268+
printf("Average time of %s: %lf\n", proxy_apis_g[i].name, sum / TEST_COUNT);
269+
}
270+
}
271+
220272
int main(void) {
221273
srand(time(NULL));
222274

@@ -242,6 +294,7 @@ int main(void) {
242294
// RUN_TEST(test_receive_mam_message);
243295
RUN_TEST(test_find_transactions_by_tag);
244296
RUN_TEST(test_find_transactions_obj_by_tag);
297+
RUN_TEST(test_proxy_apis);
245298
ta_config_destroy(&ta_core.service);
246299
return UNITY_END();
247300
}

tests/test_define.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ extern "C" {
3939
#define CURRENT_INDEX 1
4040
#define LAST_INDEX 2
4141
#define NONCE "THISTANGLEACCELERATORNONCES"
42+
#define THRESHOLD 100
4243

4344
#define TRYTES_2673_LEN 2673
4445
#define TRYTES_2673_1 \

0 commit comments

Comments
 (0)