88
99#include <time.h>
1010#include "accelerator/apis.h"
11+ #include "accelerator/proxy_apis.h"
1112#include "test_define.h"
1213
1314static ta_core_t ta_core ;
@@ -16,6 +17,38 @@ struct timespec start_time, end_time;
1617char driver_tag_msg [NUM_TRYTES_TAG ];
1718ta_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+
220272int 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}
0 commit comments