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

Commit 7700939

Browse files
committed
fix(api): Fix send_transfer JSON null value error
1 parent 22dfaf5 commit 7700939

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed

serializer/serializer.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ status_t ta_send_transfer_req_deserialize(const char* const obj,
260260
}
261261

262262
json_result = cJSON_GetObjectItemCaseSensitive(json_obj, "tag");
263-
if (json_result != NULL) {
263+
if (json_result != NULL && json_result->valuestring != NULL) {
264264
tag_len = strnlen(json_result->valuestring, NUM_TRYTES_TAG);
265265

266266
// If 'tag' is less than 27 trytes (NUM_TRYTES_TAG), expands it
@@ -297,7 +297,7 @@ status_t ta_send_transfer_req_deserialize(const char* const obj,
297297
}
298298

299299
json_result = cJSON_GetObjectItemCaseSensitive(json_obj, "message");
300-
if (json_result != NULL) {
300+
if (json_result != NULL && json_result->valuestring != NULL) {
301301
if (raw_message) {
302302
msg_len = strlen(json_result->valuestring) * 2;
303303
req->msg_len = msg_len * 3;
@@ -322,7 +322,8 @@ status_t ta_send_transfer_req_deserialize(const char* const obj,
322322
}
323323

324324
json_result = cJSON_GetObjectItemCaseSensitive(json_obj, "address");
325-
if (json_result != NULL && (strnlen(json_result->valuestring, 81) == 81)) {
325+
if (json_result != NULL && json_result->valuestring != NULL &&
326+
(strnlen(json_result->valuestring, 81) == 81)) {
326327
flex_trits_from_trytes(address_trits, NUM_TRITS_HASH,
327328
(const tryte_t*)json_result->valuestring,
328329
NUM_TRYTES_HASH, NUM_TRYTES_HASH);

tests/regression/1_close_TA.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env bash
22

33
wait $(ps aux | grep '[r]unner.py' | awk '{print $2}')
4-
kill $(ps aux | grep '[.]/accelerator' | awk '{print $2}')
5-
wait $!
4+
wait $(kill $(ps aux | grep '[r]edis' | awk '{print $2}'))
5+
wait $(kill $(ps aux | grep '[.]/accelerator' | awk '{print $2}'))
66

77
trap 'exit 0' SIGTERM
88

tests/regression/1_run_TA.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
make
22

3+
redis-server &
4+
35
bazel run //accelerator &
46
TA_pid=$!
5-
sleep 20
7+
sleep 5
68

79
pip install --user -r tests/regression/requirements.txt
810

tests/regression/runner.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
raw_url = sys.argv[1]
1515
elif len(sys.argv) == 3:
1616
raw_url = sys.argv[1]
17-
# if DEBUG_FLAG field == `Y`, then starts debugging mode
17+
# if DEBUG_FLAG field == `Y`, then starts debugging mode with less iteration in statistical tests
1818
if sys.argv[2] == 'y' or sys.argv[2] == 'Y':
1919
DEBUG_FLAG = True
2020
else:
@@ -27,13 +27,14 @@
2727
MSG_STATUS_CODE_405 = "[405] Method Not Allowed"
2828
MSG_STATUS_CODE_400 = "{\"message\":\"Invalid request header\"}"
2929
MSG_STATUS_CODE_404 = "404 Not Found"
30+
MSG_STATUS_CODE_500 = "500"
3031
EMPTY_REPLY = "000"
3132
LEN_TAG = 27
3233
LEN_ADDR = 81
3334
LEN_MSG_SIGN = 2187
3435
tryte_alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ9"
3536

36-
if DEBUG_FLAG == True:
37+
if sys.argv[2] == 'Y':
3738
TIMES_TOTAL = 2
3839
else:
3940
TIMES_TOTAL = 100
@@ -97,7 +98,7 @@ def API(get_query, get_data=None, post_data=None, delay=True):
9798
return None
9899
if not response:
99100
response = ""
100-
101+
101102
if delay == True:
102103
time.sleep(2)
103104
return response
@@ -122,7 +123,7 @@ def test_mam_send_msg(self):
122123
"JSON msg with wrong key"
123124
]
124125

125-
pass_case = [0, 1]
126+
pass_case = [0, 1, 4]
126127
for i in range(len(test_cases)):
127128
if i not in pass_case:
128129
test_cases[i].encode(encoding='utf-8')
@@ -155,7 +156,8 @@ def test_mam_send_msg(self):
155156
LEN_ADDR))
156157
else:
157158
self.assertTrue(EMPTY_REPLY in response[i]
158-
or MSG_STATUS_CODE_404 in response[i])
159+
or MSG_STATUS_CODE_404 in response[i]
160+
or MSG_STATUS_CODE_500 in response[i])
159161

160162
# Time Statistics
161163
payload = "Who are we? Just a speck of dust within the galaxy?"
@@ -266,7 +268,7 @@ def test_send_transfer(self):
266268
logging.debug("send transfer i = " + str(i) + ", response = " +
267269
response[i])
268270

269-
pass_case = [0, 1, 2]
271+
pass_case = [0, 1, 2, 3]
270272
for i in range(len(response)):
271273
logging.debug("send transfer i = " + str(i) + ", response = " +
272274
response[i])
@@ -291,7 +293,8 @@ def test_send_transfer(self):
291293
LEN_MSG_SIGN))
292294
else:
293295
self.assertTrue(EMPTY_REPLY in response[i]
294-
or MSG_STATUS_CODE_404 in response[i])
296+
or MSG_STATUS_CODE_404 in response[i]
297+
or MSG_STATUS_CODE_500 in response[i])
295298

296299
# Time Statistics
297300
time_cost = []
@@ -333,5 +336,5 @@ def test_send_transfer(self):
333336
logging.basicConfig(level=logging.INFO)
334337
unittest.main(argv=['first-arg-is-ignored'], exit=False)
335338

336-
if not unittest.TestResult().errors:
339+
if len(unittest.TestResult().errors) != 0:
337340
exit(1)

0 commit comments

Comments
 (0)