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

Commit c7410f0

Browse files
committed
feat(reg): Add test for send_trytes()
Each requesting trytes is made by all_nines string + trunk + branch
1 parent 60bb1ca commit c7410f0

File tree

1 file changed

+70
-2
lines changed

1 file changed

+70
-2
lines changed

tests/regression/runner.py

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ def eval_stat(time_cost, func_name):
4949
"sec, including 95% of API call time consumption")
5050

5151

52+
def fill_nines(trytes, output_len):
53+
out_str = trytes + "9" * (output_len - len(trytes))
54+
55+
return out_str
56+
57+
5258
def gen_rand_trytes(tryte_len):
5359
trytes = ""
5460
for i in range(tryte_len):
@@ -130,7 +136,7 @@ def test_mam_send_msg(self):
130136

131137
response = []
132138
for i in range(len(query_string)):
133-
logging.debug("testing case = " + str(query_string[i]))
139+
logging.debug("testing case = " + repr(query_string[i]))
134140
if i == 5:
135141
post_data_json = query_string[i]
136142
elif i == 6:
@@ -247,7 +253,7 @@ def test_send_transfer(self):
247253

248254
response = []
249255
for i in range(len(query_string)):
250-
logging.debug("testing case = " + str(query_string[i]))
256+
logging.debug("testing case = " + repr(query_string[i]))
251257
post_data = {
252258
"value": query_string[i][0],
253259
"message": query_string[i][1],
@@ -689,6 +695,68 @@ def test_generate_address(self):
689695

690696
eval_stat(time_cost, "generate_address")
691697

698+
def test_send_trytes(self):
699+
logging.debug(
700+
"\n================================send_trytes================================"
701+
)
702+
# cmd
703+
# 0. single 2673 trytes legal transaction object
704+
# 1. multiple 2673 ligal trytes transaction object
705+
# 2. single 200 trytes illegal transaction object
706+
# 3. single single 3000 trytes illegal transaction object
707+
# 4. single unicode illegal transaction object
708+
# 5. empty trytes list
709+
# 6. empty not trytes list object
710+
rand_trytes = []
711+
for i in range(2):
712+
all_9_context = fill_nines("", 2673 - 81 * 3)
713+
tips_response = API("/tips/pair/", get_data="")
714+
res_json = json.loads(tips_response["content"])
715+
tips = res_json["tips"]
716+
717+
rand_trytes.append(all_9_context + tips[0] + tips[1] +
718+
fill_nines("", 81))
719+
720+
query_string = [[rand_trytes[0]], [rand_trytes[0], rand_trytes[1]],
721+
[gen_rand_trytes(200)], [gen_rand_trytes(3000)],
722+
["逼類不司"], [""], ""]
723+
724+
response = []
725+
for i in range(len(query_string)):
726+
logging.debug("testing case = " + repr(query_string[i]))
727+
post_data = {"trytes": query_string[i]}
728+
logging.debug("post_data = " + repr(post_data))
729+
post_data_json = json.dumps(post_data)
730+
response.append(API("/tryte", post_data=post_data_json))
731+
732+
for i in range(len(response)):
733+
logging.debug("send_trytes i = " + str(i) + ", res = " +
734+
response[i]["content"] + ", status code = " +
735+
response[i]["status_code"])
736+
737+
pass_case = [0, 1]
738+
for i in range(len(response)):
739+
logging.debug("send_trytes i = " + str(i) + ", res = " +
740+
response[i]["content"] + ", status code = " +
741+
response[i]["status_code"])
742+
if i in pass_case:
743+
res_json = json.loads(response[i]["content"])
744+
745+
self.assertEqual(query_string[i], res_json["trytes"])
746+
else:
747+
self.assertEqual(STATUS_CODE_500, response[i]["status_code"])
748+
749+
# Time Statistics
750+
time_cost = []
751+
post_data = {"trytes": [rand_trytes[0]]}
752+
post_data_json = json.dumps(post_data)
753+
for i in range(TIMES_TOTAL):
754+
start_time = time.time()
755+
API("/tryte", post_data=post_data_json)
756+
time_cost.append(time.time() - start_time)
757+
758+
eval_stat(time_cost, "send trytes")
759+
692760

693761
"""
694762
API List

0 commit comments

Comments
 (0)