10
10
import logging
11
11
12
12
DEBUG_FLAG = False
13
+ TIMES_TOTAL = 100
13
14
if len (sys .argv ) == 2 :
14
15
raw_url = sys .argv [1 ]
15
- elif len (sys .argv ) == 3 :
16
+ elif len (sys .argv ) == 4 :
16
17
raw_url = sys .argv [1 ]
17
18
if sys .argv [2 ] == 'Y' :
18
19
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
19
24
else :
20
25
raw_url = "localhost:8000"
21
26
url = "http://" + raw_url
33
38
LEN_MSG_SIGN = 2187
34
39
tryte_alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ9"
35
40
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
-
42
41
43
42
def eval_stat (time_cost , func_name ):
44
43
avg = statistics .mean (time_cost )
@@ -354,7 +353,6 @@ def test_find_transactions_by_tag(self):
354
353
logging .debug ("find transactions by tag i = " + str (i ) +
355
354
", res = " + response [i ][0 ] + ", status code = " +
356
355
response [i ][1 ])
357
-
358
356
for i in range (len (response )):
359
357
logging .debug ("find transactions by tag i = " + str (i ) +
360
358
", res = " + response [i ][0 ] + ", status code = " +
@@ -376,6 +374,69 @@ def test_find_transactions_by_tag(self):
376
374
377
375
eval_stat (time_cost , "find transactions by tag" )
378
376
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
+
379
440
380
441
"""
381
442
API List
0 commit comments