8
8
9
9
#include <time.h>
10
10
#include "accelerator/apis.h"
11
+ #include "accelerator/proxy_apis.h"
11
12
#include "test_define.h"
12
13
13
14
static ta_core_t ta_core ;
@@ -16,6 +17,38 @@ struct timespec start_time, end_time;
16
17
char driver_tag_msg [NUM_TRYTES_TAG ];
17
18
ta_send_mam_res_t * res ;
18
19
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
+
19
52
#if defined(ENABLE_STAT )
20
53
#define TEST_COUNT 100
21
54
#else
@@ -217,6 +250,25 @@ void test_receive_mam_message(void) {
217
250
printf ("Average time of receive_mam_message: %lf\n" , sum / TEST_COUNT );
218
251
}
219
252
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
+
220
272
int main (void ) {
221
273
srand (time (NULL ));
222
274
@@ -242,6 +294,7 @@ int main(void) {
242
294
// RUN_TEST(test_receive_mam_message);
243
295
RUN_TEST (test_find_transactions_by_tag );
244
296
RUN_TEST (test_find_transactions_obj_by_tag );
297
+ RUN_TEST (test_proxy_apis );
245
298
ta_config_destroy (& ta_core .service );
246
299
return UNITY_END ();
247
300
}
0 commit comments