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

Commit

Permalink
fix(api): Fix send_transfer JSON null value error
Browse files Browse the repository at this point in the history
  • Loading branch information
howjmay committed May 17, 2019
1 parent 22dfaf5 commit 7700939
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
7 changes: 4 additions & 3 deletions serializer/serializer.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ status_t ta_send_transfer_req_deserialize(const char* const obj,
}

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

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

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

json_result = cJSON_GetObjectItemCaseSensitive(json_obj, "address");
if (json_result != NULL && (strnlen(json_result->valuestring, 81) == 81)) {
if (json_result != NULL && json_result->valuestring != NULL &&
(strnlen(json_result->valuestring, 81) == 81)) {
flex_trits_from_trytes(address_trits, NUM_TRITS_HASH,
(const tryte_t*)json_result->valuestring,
NUM_TRYTES_HASH, NUM_TRYTES_HASH);
Expand Down
4 changes: 2 additions & 2 deletions tests/regression/1_close_TA.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env bash

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

trap 'exit 0' SIGTERM

4 changes: 3 additions & 1 deletion tests/regression/1_run_TA.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
make

redis-server &

bazel run //accelerator &
TA_pid=$!
sleep 20
sleep 5

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

19 changes: 11 additions & 8 deletions tests/regression/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
raw_url = sys.argv[1]
elif len(sys.argv) == 3:
raw_url = sys.argv[1]
# if DEBUG_FLAG field == `Y`, then starts debugging mode
# if DEBUG_FLAG field == `Y`, then starts debugging mode with less iteration in statistical tests
if sys.argv[2] == 'y' or sys.argv[2] == 'Y':
DEBUG_FLAG = True
else:
Expand All @@ -27,13 +27,14 @@
MSG_STATUS_CODE_405 = "[405] Method Not Allowed"
MSG_STATUS_CODE_400 = "{\"message\":\"Invalid request header\"}"
MSG_STATUS_CODE_404 = "404 Not Found"
MSG_STATUS_CODE_500 = "500"
EMPTY_REPLY = "000"
LEN_TAG = 27
LEN_ADDR = 81
LEN_MSG_SIGN = 2187
tryte_alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ9"

if DEBUG_FLAG == True:
if sys.argv[2] == 'Y':
TIMES_TOTAL = 2
else:
TIMES_TOTAL = 100
Expand Down Expand Up @@ -97,7 +98,7 @@ def API(get_query, get_data=None, post_data=None, delay=True):
return None
if not response:
response = ""

if delay == True:
time.sleep(2)
return response
Expand All @@ -122,7 +123,7 @@ def test_mam_send_msg(self):
"JSON msg with wrong key"
]

pass_case = [0, 1]
pass_case = [0, 1, 4]
for i in range(len(test_cases)):
if i not in pass_case:
test_cases[i].encode(encoding='utf-8')
Expand Down Expand Up @@ -155,7 +156,8 @@ def test_mam_send_msg(self):
LEN_ADDR))
else:
self.assertTrue(EMPTY_REPLY in response[i]
or MSG_STATUS_CODE_404 in response[i])
or MSG_STATUS_CODE_404 in response[i]
or MSG_STATUS_CODE_500 in response[i])

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

pass_case = [0, 1, 2]
pass_case = [0, 1, 2, 3]
for i in range(len(response)):
logging.debug("send transfer i = " + str(i) + ", response = " +
response[i])
Expand All @@ -291,7 +293,8 @@ def test_send_transfer(self):
LEN_MSG_SIGN))
else:
self.assertTrue(EMPTY_REPLY in response[i]
or MSG_STATUS_CODE_404 in response[i])
or MSG_STATUS_CODE_404 in response[i]
or MSG_STATUS_CODE_500 in response[i])

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

if not unittest.TestResult().errors:
if len(unittest.TestResult().errors) != 0:
exit(1)

0 comments on commit 7700939

Please sign in to comment.