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

Commit 1a91bf7

Browse files
author
Yu Wei Wu
committed
fix(config): Fix all test cases related to configs
1 parent bc2ee0a commit 1a91bf7

File tree

4 files changed

+28
-26
lines changed

4 files changed

+28
-26
lines changed

tests/driver.c

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "accelerator/apis.h"
33
#include "test_define.h"
44

5-
iota_client_service_t service;
5+
static ta_core_t ta_core;
66
struct timespec start_time, end_time;
77

88
#if defined(ENABLE_STAT)
@@ -29,7 +29,8 @@ void test_generate_address(void) {
2929

3030
for (size_t count = 0; count < TEST_COUNT; count++) {
3131
clock_gettime(CLOCK_REALTIME, &start_time);
32-
TEST_ASSERT_FALSE(api_generate_address(&service, &json_result));
32+
TEST_ASSERT_FALSE(
33+
api_generate_address(&ta_core.config, &ta_core.service, &json_result));
3334
clock_gettime(CLOCK_REALTIME, &end_time);
3435
#if defined(ENABLE_STAT)
3536
printf("%lf\n", diff_time(start_time, end_time));
@@ -46,7 +47,8 @@ void test_get_tips_pair(void) {
4647

4748
for (size_t count = 0; count < TEST_COUNT; count++) {
4849
clock_gettime(CLOCK_REALTIME, &start_time);
49-
TEST_ASSERT_FALSE(api_get_tips_pair(&service, &json_result));
50+
TEST_ASSERT_FALSE(
51+
api_get_tips_pair(&ta_core.config, &ta_core.service, &json_result));
5052
clock_gettime(CLOCK_REALTIME, &end_time);
5153
#if defined(ENABLE_STAT)
5254
printf("%lf\n", diff_time(start_time, end_time));
@@ -63,7 +65,7 @@ void test_get_tips(void) {
6365

6466
for (size_t count = 0; count < TEST_COUNT; count++) {
6567
clock_gettime(CLOCK_REALTIME, &start_time);
66-
TEST_ASSERT_FALSE(api_get_tips(&service, &json_result));
68+
TEST_ASSERT_FALSE(api_get_tips(&ta_core.service, &json_result));
6769
clock_gettime(CLOCK_REALTIME, &end_time);
6870
#if defined(ENABLE_STAT)
6971
printf("%lf\n", diff_time(start_time, end_time));
@@ -85,7 +87,8 @@ void test_send_transfer(void) {
8587

8688
for (size_t count = 0; count < TEST_COUNT; count++) {
8789
clock_gettime(CLOCK_REALTIME, &start_time);
88-
TEST_ASSERT_FALSE(api_send_transfer(&service, json, &json_result));
90+
TEST_ASSERT_FALSE(api_send_transfer(&ta_core.config, &ta_core.service, json,
91+
&json_result));
8992
clock_gettime(CLOCK_REALTIME, &end_time);
9093
#if defined(ENABLE_STAT)
9194
printf("%lf\n", diff_time(start_time, end_time));
@@ -103,8 +106,8 @@ void test_get_transaction_object(void) {
103106
clock_gettime(CLOCK_REALTIME, &start_time);
104107
for (size_t count = 0; count < TEST_COUNT; count++) {
105108
clock_gettime(CLOCK_REALTIME, &start_time);
106-
TEST_ASSERT_FALSE(
107-
api_get_transaction_object(&service, TRYTES_81_1, &json_result));
109+
TEST_ASSERT_FALSE(api_get_transaction_object(&ta_core.service, TRYTES_81_1,
110+
&json_result));
108111
clock_gettime(CLOCK_REALTIME, &end_time);
109112
#if defined(ENABLE_STAT)
110113
printf("%lf\n", diff_time(start_time, end_time));
@@ -122,7 +125,7 @@ void test_find_transactions_by_tag(void) {
122125
for (size_t count = 0; count < TEST_COUNT; count++) {
123126
clock_gettime(CLOCK_REALTIME, &start_time);
124127
TEST_ASSERT_FALSE(
125-
api_find_transactions_by_tag(&service, TAG_MSG, &json_result));
128+
api_find_transactions_by_tag(&ta_core.service, TAG_MSG, &json_result));
126129
clock_gettime(CLOCK_REALTIME, &end_time);
127130
#if defined(ENABLE_STAT)
128131
printf("%lf\n", diff_time(start_time, end_time));
@@ -139,8 +142,8 @@ void test_find_transactions_obj_by_tag(void) {
139142

140143
for (size_t count = 0; count < TEST_COUNT; count++) {
141144
clock_gettime(CLOCK_REALTIME, &start_time);
142-
TEST_ASSERT_FALSE(
143-
api_find_transactions_obj_by_tag(&service, TAG_MSG, &json_result));
145+
TEST_ASSERT_FALSE(api_find_transactions_obj_by_tag(&ta_core.service,
146+
TAG_MSG, &json_result));
144147
clock_gettime(CLOCK_REALTIME, &end_time);
145148
#if defined(ENABLE_STAT)
146149
printf("%lf\n", diff_time(start_time, end_time));
@@ -158,7 +161,7 @@ void test_receive_mam_message(void) {
158161
for (size_t count = 0; count < TEST_COUNT; count++) {
159162
clock_gettime(CLOCK_REALTIME, &start_time);
160163
TEST_ASSERT_FALSE(
161-
api_receive_mam_message(&service, BUNDLE_HASH, &json_result));
164+
api_receive_mam_message(&ta_core.service, BUNDLE_HASH, &json_result));
162165
clock_gettime(CLOCK_REALTIME, &end_time);
163166
#if defined(ENABLE_STAT)
164167
printf("%lf\n", diff_time(start_time, end_time));
@@ -171,12 +174,8 @@ void test_receive_mam_message(void) {
171174

172175
int main(void) {
173176
UNITY_BEGIN();
174-
service.http.path = "/";
175-
service.http.host = IRI_HOST;
176-
service.http.port = IRI_PORT;
177-
service.http.api_version = 1;
178-
service.serializer_type = SR_JSON;
179-
iota_client_core_init(&service);
177+
178+
ta_config_init(&ta_core.info, &ta_core.config, &ta_core.service);
180179

181180
printf("Total samples for each API test: %d\n", TEST_COUNT);
182181
RUN_TEST(test_generate_address);
@@ -187,6 +186,6 @@ int main(void) {
187186
RUN_TEST(test_find_transactions_by_tag);
188187
RUN_TEST(test_find_transactions_obj_by_tag);
189188
RUN_TEST(test_receive_mam_message);
190-
iota_client_core_destroy(&service);
189+
ta_config_destroy(&ta_core.service);
191190
return UNITY_END();
192191
}

tests/iota_api_mock.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,6 @@ retcode_t iota_client_get_trytes(const iota_client_service_t* const service,
7878
}
7979

8080
status_t ta_send_trytes(const iota_client_service_t* const service,
81-
hash8019_array_p trytes) {
82-
return APIMockObj.ta_send_trytes(service, trytes);
81+
uint8_t depth, uint8_t mwm, hash8019_array_p trytes) {
82+
return APIMockObj.ta_send_trytes(service, depth, mwm, trytes);
8383
}

tests/iota_api_mock.hh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class IotaAPI {
4343
return RC_OK;
4444
}
4545
virtual status_t ta_send_trytes(const iota_client_service_t* const service,
46+
uint8_t depth, uint8_t mwm,
4647
hash8019_array_p trytes) {
4748
return SC_OK;
4849
}
@@ -79,7 +80,7 @@ class APIMock : public IotaAPI {
7980
MOCK_METHOD3(iota_client_get_trytes,
8081
retcode_t(const iota_client_service_t* const service,
8182
get_trytes_req_t* const req, get_trytes_res_t* res));
82-
MOCK_METHOD2(ta_send_trytes,
83+
MOCK_METHOD4(ta_send_trytes,
8384
status_t(const iota_client_service_t* const service,
84-
hash8019_array_p trytes));
85+
uint8_t depth, uint8_t mwm, hash8019_array_p trytes));
8586
};

tests/test_common.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ using ::testing::AtLeast;
88
using ::testing::ElementsAreArray;
99

1010
APIMock APIMockObj;
11+
iota_config_t config;
1112
iota_client_service_t service;
1213

1314
TEST(GetTxnToApproveTest, TrunkBranchHashTest) {
@@ -24,7 +25,7 @@ TEST(GetTxnToApproveTest, TrunkBranchHashTest) {
2425
EXPECT_CALL(APIMockObj, iota_client_get_transactions_to_approve(_, _, _))
2526
.Times(AtLeast(1));
2627

27-
EXPECT_EQ(cclient_get_txn_to_approve(&service, res), 0);
28+
EXPECT_EQ(cclient_get_txn_to_approve(&service, 3, res), 0);
2829
EXPECT_FALSE(memcmp(res->tips->hash, hash_trits_1,
2930
sizeof(flex_trit_t) * FLEX_TRIT_SIZE_243));
3031
hash243_stack_pop(&res->tips);
@@ -72,6 +73,7 @@ TEST(FindTxnTest, TxnHashTest) {
7273
}
7374

7475
TEST(GenAdressTest, GetNewAddressTest) {
76+
config.seed = SEED;
7577
hash243_queue_entry_t* q_iter = NULL;
7678
ta_generate_address_res_t* res = ta_generate_address_res_new();
7779
flex_trit_t hash_trits_1[FLEX_TRIT_SIZE_243];
@@ -82,7 +84,7 @@ TEST(GenAdressTest, GetNewAddressTest) {
8284
EXPECT_CALL(APIMockObj, iota_client_get_new_address(_, _, _, _))
8385
.Times(AtLeast(1));
8486

85-
EXPECT_EQ(ta_generate_address(&service, res), 0);
87+
EXPECT_EQ(ta_generate_address(&config, &service, res), 0);
8688
CDL_FOREACH(res->addresses, q_iter) {
8789
EXPECT_FALSE(memcmp(q_iter->hash, hash_trits_1,
8890
sizeof(flex_trit_t) * FLEX_TRIT_SIZE_243));
@@ -154,11 +156,11 @@ TEST(SendTransferTest, SendTransferTest) {
154156
flex_trits_slice(req->message, req->msg_len, msg_trits, req->msg_len, 0,
155157
req->msg_len);
156158

157-
EXPECT_CALL(APIMockObj, ta_send_trytes(_, _)).Times(AtLeast(1));
159+
EXPECT_CALL(APIMockObj, ta_send_trytes(_, _, _, _)).Times(AtLeast(1));
158160
EXPECT_CALL(APIMockObj, iota_client_find_transactions(_, _, _))
159161
.Times(AtLeast(1));
160162

161-
EXPECT_EQ(ta_send_transfer(&service, req, res), 0);
163+
EXPECT_EQ(ta_send_transfer(&config, &service, req, res), 0);
162164
txn_hash = hash243_queue_peek(res->hash);
163165
EXPECT_FALSE(
164166
memcmp(txn_hash, hash_trits_1, sizeof(flex_trit_t) * FLEX_TRIT_SIZE_243));

0 commit comments

Comments
 (0)