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 get_transaction_object
Browse files Browse the repository at this point in the history
Fix statistical test error, too.
  • Loading branch information
howjmay committed May 23, 2019
1 parent 8b1c13f commit b65e818
Showing 1 changed file with 69 additions and 8 deletions.
77 changes: 69 additions & 8 deletions tests/regression/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@
import logging

DEBUG_FLAG = False
TIMES_TOTAL = 100
if len(sys.argv) == 2:
raw_url = sys.argv[1]
elif len(sys.argv) == 3:
elif len(sys.argv) == 4:
raw_url = sys.argv[1]
if sys.argv[2] == 'Y':
DEBUG_FLAG = True

# the 3rd arg is the option which determine if use the debugging mode of statistical tests
if sys.argv[3] == 'Y':
TIMES_TOTAL = 2
else:
raw_url = "localhost:8000"
url = "http://" + raw_url
Expand All @@ -33,12 +38,6 @@
LEN_MSG_SIGN = 2187
tryte_alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ9"

# the 3rd arg is the option which determine if use the debugging mode of statistical tests
if sys.argv[3] == 'Y':
TIMES_TOTAL = 2
else:
TIMES_TOTAL = 100


def eval_stat(time_cost, func_name):
avg = statistics.mean(time_cost)
Expand Down Expand Up @@ -354,7 +353,6 @@ def test_find_transactions_by_tag(self):
logging.debug("find transactions by tag i = " + str(i) +
", res = " + response[i][0] + ", status code = " +
response[i][1])

for i in range(len(response)):
logging.debug("find transactions by tag i = " + str(i) +
", res = " + response[i][0] + ", status code = " +
Expand All @@ -376,6 +374,69 @@ def test_find_transactions_by_tag(self):

eval_stat(time_cost, "find transactions by tag")

def test_get_transactions_object(self):
logging.debug(
"\n================================get transactions object================================"
)
# cmd
# 0. 81 trytes transaction hash
# 1. 20 trytes transaction hash
# 2. 100 trytes transaction hash
# 3. unicode transaction hash
# 4. Null transaction hash
rand_tag = gen_rand_trytes(27)
rand_msg = gen_rand_trytes(30)
rand_addr = gen_rand_trytes(81)
post_data = {
"value": 0,
"message": rand_msg,
"tag": rand_tag,
"address": rand_addr
}
post_data_json = json.dumps(post_data)
sent_transaction_obj = API("/transaction/", post_data=post_data_json)

logging.debug("sent_transaction_obj = " +
", sent_transaction_obj[0] = " +
sent_transaction_obj[0] +
", sent_transaction_obj[1] = " + sent_transaction_obj[1])
sent_transaction_obj_json = json.loads(sent_transaction_obj[0])
sent_transaction_hash = sent_transaction_obj_json["hash"]
test_cases = [
sent_transaction_hash, sent_transaction_hash[0:19],
sent_transaction_hash + gen_rand_trytes(19), "工程師批哩趴啦的生活", ""
]

response = []
for t_case in test_cases:
logging.debug("testing case = " + repr(t_case))
response.append(API("/transaction/", get_data=t_case))

for i in range(len(response)):
logging.debug("get transactions object i = " + str(i) +
", res = " + repr(response[i][0]) +
", status code = " + repr(response[i][1]))

for i in range(len(response)):
logging.debug("get transactions object i = " + str(i) +
", res = " + repr(response[i][0]) +
", status code = " + repr(response[i][1]))
if i == 0:
res_json = json.loads(response[i][0])
self.assertEqual(sent_transaction_hash, res_json["hash"])
else:
self.assertEqual(STATUS_CODE_405, response[i][1])

# Time Statistics
time_cost = []
for i in range(TIMES_TOTAL):
start_time = time.time()
response.append(
API("/transaction/", get_data=sent_transaction_hash))
time_cost.append(time.time() - start_time)

eval_stat(time_cost, "get transactions object")


"""
API List
Expand Down

0 comments on commit b65e818

Please sign in to comment.