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

Commit

Permalink
feat(reg): Add test for send_trytes()
Browse files Browse the repository at this point in the history
Each requesting trytes is made by all_nines string + trunk + branch
  • Loading branch information
howjmay committed Jun 3, 2019
1 parent 60bb1ca commit c7410f0
Showing 1 changed file with 70 additions and 2 deletions.
72 changes: 70 additions & 2 deletions tests/regression/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ def eval_stat(time_cost, func_name):
"sec, including 95% of API call time consumption")


def fill_nines(trytes, output_len):
out_str = trytes + "9" * (output_len - len(trytes))

return out_str


def gen_rand_trytes(tryte_len):
trytes = ""
for i in range(tryte_len):
Expand Down Expand Up @@ -130,7 +136,7 @@ def test_mam_send_msg(self):

response = []
for i in range(len(query_string)):
logging.debug("testing case = " + str(query_string[i]))
logging.debug("testing case = " + repr(query_string[i]))
if i == 5:
post_data_json = query_string[i]
elif i == 6:
Expand Down Expand Up @@ -247,7 +253,7 @@ def test_send_transfer(self):

response = []
for i in range(len(query_string)):
logging.debug("testing case = " + str(query_string[i]))
logging.debug("testing case = " + repr(query_string[i]))
post_data = {
"value": query_string[i][0],
"message": query_string[i][1],
Expand Down Expand Up @@ -689,6 +695,68 @@ def test_generate_address(self):

eval_stat(time_cost, "generate_address")

def test_send_trytes(self):
logging.debug(
"\n================================send_trytes================================"
)
# cmd
# 0. single 2673 trytes legal transaction object
# 1. multiple 2673 ligal trytes transaction object
# 2. single 200 trytes illegal transaction object
# 3. single single 3000 trytes illegal transaction object
# 4. single unicode illegal transaction object
# 5. empty trytes list
# 6. empty not trytes list object
rand_trytes = []
for i in range(2):
all_9_context = fill_nines("", 2673 - 81 * 3)
tips_response = API("/tips/pair/", get_data="")
res_json = json.loads(tips_response["content"])
tips = res_json["tips"]

rand_trytes.append(all_9_context + tips[0] + tips[1] +
fill_nines("", 81))

query_string = [[rand_trytes[0]], [rand_trytes[0], rand_trytes[1]],
[gen_rand_trytes(200)], [gen_rand_trytes(3000)],
["逼類不司"], [""], ""]

response = []
for i in range(len(query_string)):
logging.debug("testing case = " + repr(query_string[i]))
post_data = {"trytes": query_string[i]}
logging.debug("post_data = " + repr(post_data))
post_data_json = json.dumps(post_data)
response.append(API("/tryte", post_data=post_data_json))

for i in range(len(response)):
logging.debug("send_trytes i = " + str(i) + ", res = " +
response[i]["content"] + ", status code = " +
response[i]["status_code"])

pass_case = [0, 1]
for i in range(len(response)):
logging.debug("send_trytes i = " + str(i) + ", res = " +
response[i]["content"] + ", status code = " +
response[i]["status_code"])
if i in pass_case:
res_json = json.loads(response[i]["content"])

self.assertEqual(query_string[i], res_json["trytes"])
else:
self.assertEqual(STATUS_CODE_500, response[i]["status_code"])

# Time Statistics
time_cost = []
post_data = {"trytes": [rand_trytes[0]]}
post_data_json = json.dumps(post_data)
for i in range(TIMES_TOTAL):
start_time = time.time()
API("/tryte", post_data=post_data_json)
time_cost.append(time.time() - start_time)

eval_stat(time_cost, "send trytes")


"""
API List
Expand Down

0 comments on commit c7410f0

Please sign in to comment.