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

Commit b65e818

Browse files
committed
feat(reg): Add test for get_transaction_object
Fix statistical test error, too.
1 parent 8b1c13f commit b65e818

File tree

1 file changed

+69
-8
lines changed

1 file changed

+69
-8
lines changed

tests/regression/runner.py

Lines changed: 69 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,17 @@
1010
import logging
1111

1212
DEBUG_FLAG = False
13+
TIMES_TOTAL = 100
1314
if len(sys.argv) == 2:
1415
raw_url = sys.argv[1]
15-
elif len(sys.argv) == 3:
16+
elif len(sys.argv) == 4:
1617
raw_url = sys.argv[1]
1718
if sys.argv[2] == 'Y':
1819
DEBUG_FLAG = True
20+
21+
# the 3rd arg is the option which determine if use the debugging mode of statistical tests
22+
if sys.argv[3] == 'Y':
23+
TIMES_TOTAL = 2
1924
else:
2025
raw_url = "localhost:8000"
2126
url = "http://" + raw_url
@@ -33,12 +38,6 @@
3338
LEN_MSG_SIGN = 2187
3439
tryte_alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ9"
3540

36-
# the 3rd arg is the option which determine if use the debugging mode of statistical tests
37-
if sys.argv[3] == 'Y':
38-
TIMES_TOTAL = 2
39-
else:
40-
TIMES_TOTAL = 100
41-
4241

4342
def eval_stat(time_cost, func_name):
4443
avg = statistics.mean(time_cost)
@@ -354,7 +353,6 @@ def test_find_transactions_by_tag(self):
354353
logging.debug("find transactions by tag i = " + str(i) +
355354
", res = " + response[i][0] + ", status code = " +
356355
response[i][1])
357-
358356
for i in range(len(response)):
359357
logging.debug("find transactions by tag i = " + str(i) +
360358
", res = " + response[i][0] + ", status code = " +
@@ -376,6 +374,69 @@ def test_find_transactions_by_tag(self):
376374

377375
eval_stat(time_cost, "find transactions by tag")
378376

377+
def test_get_transactions_object(self):
378+
logging.debug(
379+
"\n================================get transactions object================================"
380+
)
381+
# cmd
382+
# 0. 81 trytes transaction hash
383+
# 1. 20 trytes transaction hash
384+
# 2. 100 trytes transaction hash
385+
# 3. unicode transaction hash
386+
# 4. Null transaction hash
387+
rand_tag = gen_rand_trytes(27)
388+
rand_msg = gen_rand_trytes(30)
389+
rand_addr = gen_rand_trytes(81)
390+
post_data = {
391+
"value": 0,
392+
"message": rand_msg,
393+
"tag": rand_tag,
394+
"address": rand_addr
395+
}
396+
post_data_json = json.dumps(post_data)
397+
sent_transaction_obj = API("/transaction/", post_data=post_data_json)
398+
399+
logging.debug("sent_transaction_obj = " +
400+
", sent_transaction_obj[0] = " +
401+
sent_transaction_obj[0] +
402+
", sent_transaction_obj[1] = " + sent_transaction_obj[1])
403+
sent_transaction_obj_json = json.loads(sent_transaction_obj[0])
404+
sent_transaction_hash = sent_transaction_obj_json["hash"]
405+
test_cases = [
406+
sent_transaction_hash, sent_transaction_hash[0:19],
407+
sent_transaction_hash + gen_rand_trytes(19), "工程師批哩趴啦的生活", ""
408+
]
409+
410+
response = []
411+
for t_case in test_cases:
412+
logging.debug("testing case = " + repr(t_case))
413+
response.append(API("/transaction/", get_data=t_case))
414+
415+
for i in range(len(response)):
416+
logging.debug("get transactions object i = " + str(i) +
417+
", res = " + repr(response[i][0]) +
418+
", status code = " + repr(response[i][1]))
419+
420+
for i in range(len(response)):
421+
logging.debug("get transactions object i = " + str(i) +
422+
", res = " + repr(response[i][0]) +
423+
", status code = " + repr(response[i][1]))
424+
if i == 0:
425+
res_json = json.loads(response[i][0])
426+
self.assertEqual(sent_transaction_hash, res_json["hash"])
427+
else:
428+
self.assertEqual(STATUS_CODE_405, response[i][1])
429+
430+
# Time Statistics
431+
time_cost = []
432+
for i in range(TIMES_TOTAL):
433+
start_time = time.time()
434+
response.append(
435+
API("/transaction/", get_data=sent_transaction_hash))
436+
time_cost.append(time.time() - start_time)
437+
438+
eval_stat(time_cost, "get transactions object")
439+
379440

380441
"""
381442
API List

0 commit comments

Comments
 (0)