@@ -427,6 +427,156 @@ def test_get_transactions_object(self):
427
427
428
428
eval_stat (time_cost , "get transactions object" )
429
429
430
+ def test_find_transactions_obj_by_tag (self ):
431
+ logging .debug (
432
+ "\n ================================find transactions object by tag================================"
433
+ )
434
+
435
+ # cmd
436
+ # 0. 27 trytes tag
437
+ # 1. 20 trytes tag
438
+ # 2. multiple transactions share the same 27 trytes tag
439
+ # 3. 30 trytes tag
440
+ # 4. unicode trytes tag
441
+ # 5. Null trytes tag
442
+ rand_tag_27 = gen_rand_trytes (27 )
443
+ rand_tag_27_multi = gen_rand_trytes (27 )
444
+ rand_tag_20 = gen_rand_trytes (20 )
445
+ rand_tag_30 = gen_rand_trytes (30 )
446
+ test_cases = [
447
+ rand_tag_27 , rand_tag_27_multi , rand_tag_20 , rand_tag_30 , "半導體絆倒你" ,
448
+ ""
449
+ ]
450
+
451
+ rand_msg = gen_rand_trytes (30 )
452
+ rand_addr = gen_rand_trytes (81 )
453
+ transaction_response = []
454
+ for i in range (3 ):
455
+ post_data = {
456
+ "value" : 0 ,
457
+ "message" : rand_msg ,
458
+ "tag" : test_cases [i ],
459
+ "address" : rand_addr
460
+ }
461
+ post_data_json = json .dumps (post_data )
462
+
463
+ if i == 2 :
464
+ transaction_response .append ([
465
+ API ("/transaction/" , post_data = post_data_json ),
466
+ API ("/transaction/" , post_data = post_data_json )
467
+ ])
468
+ else :
469
+ transaction_response .append (
470
+ API ("/transaction/" , post_data = post_data_json ))
471
+
472
+ for i in range (len (transaction_response )):
473
+ logging .debug ("find transactions obj by tag i = " + str (i ) +
474
+ ", tx_res = " + repr (transaction_response [i ][0 ]))
475
+
476
+ response = []
477
+ for t_case in test_cases :
478
+ logging .debug ("testing case = " + repr (t_case ))
479
+ response .append (API ("/tag/" , get_data = t_case ))
480
+
481
+ for i in range (len (response )):
482
+ logging .debug ("find transactions obj by tag i = " + str (i ) +
483
+ ", res = " + repr (response [i ]))
484
+
485
+ for i in range (len (response )):
486
+ if i == 0 or i == 1 :
487
+ tx_res_json = json .loads (transaction_response [i ][0 ])
488
+ res_tx_json = json .loads (response [i ][0 ])
489
+ res_json = res_tx_json ["transactions" ][0 ]
490
+
491
+ self .assertEqual (tx_res_json ["hash" ], res_json ["hash" ])
492
+ self .assertEqual (tx_res_json ["signature_and_message_fragment" ],
493
+ res_json ["signature_and_message_fragment" ])
494
+ self .assertEqual (tx_res_json ["address" ], res_json ["address" ])
495
+ self .assertEqual (tx_res_json ["value" ], res_json ["value" ])
496
+ self .assertEqual (tx_res_json ["obsolete_tag" ],
497
+ res_json ["obsolete_tag" ])
498
+ self .assertEqual (tx_res_json ["timestamp" ],
499
+ res_json ["timestamp" ])
500
+ self .assertEqual (tx_res_json ["last_index" ],
501
+ res_json ["last_index" ])
502
+ self .assertEqual (tx_res_json ["bundle_hash" ],
503
+ res_json ["bundle_hash" ])
504
+ self .assertEqual (tx_res_json ["trunk_transaction_hash" ],
505
+ res_json ["trunk_transaction_hash" ])
506
+ self .assertEqual (tx_res_json ["branch_transaction_hash" ],
507
+ res_json ["branch_transaction_hash" ])
508
+ self .assertEqual (tx_res_json ["tag" ], res_json ["tag" ])
509
+ self .assertEqual (tx_res_json ["attachment_timestamp" ],
510
+ res_json ["attachment_timestamp" ])
511
+ self .assertEqual (
512
+ tx_res_json ["attachment_timestamp_lower_bound" ],
513
+ res_json ["attachment_timestamp_lower_bound" ])
514
+ self .assertEqual (
515
+ tx_res_json ["attachment_timestamp_upper_bound" ],
516
+ res_json ["attachment_timestamp_upper_bound" ])
517
+ self .assertEqual (tx_res_json ["nonce" ], res_json ["nonce" ])
518
+ elif i == 2 :
519
+ res_tx_json = json .loads (response [i ][0 ])
520
+ res_json = []
521
+ tx_res_json = []
522
+ for j in range (len (transaction_response [i ])):
523
+ res_json .append (res_tx_json ["transactions" ][j ])
524
+ tx_res_json .append (
525
+ json .loads (transaction_response [i ][j ][0 ]))
526
+
527
+ for j in range (len (tx_res_json )):
528
+ case_examined_equal = False
529
+ for k in range (len (res_json )):
530
+ if tx_res_json [j ]["hash" ] == res_json [k ]["hash" ]:
531
+ self .assertEqual (
532
+ tx_res_json [j ]["signature_and_message_fragment" ],
533
+ res_json [k ]["signature_and_message_fragment" ])
534
+ self .assertEqual (tx_res_json [j ]["address" ],
535
+ res_json [k ]["address" ])
536
+ self .assertEqual (tx_res_json [j ]["value" ],
537
+ res_json [k ]["value" ])
538
+ self .assertEqual (tx_res_json [j ]["obsolete_tag" ],
539
+ res_json [k ]["obsolete_tag" ])
540
+ self .assertEqual (tx_res_json [j ]["timestamp" ],
541
+ res_json [k ]["timestamp" ])
542
+ self .assertEqual (tx_res_json [j ]["last_index" ],
543
+ res_json [k ]["last_index" ])
544
+ self .assertEqual (tx_res_json [j ]["bundle_hash" ],
545
+ res_json [k ]["bundle_hash" ])
546
+ self .assertEqual (
547
+ tx_res_json [j ]["trunk_transaction_hash" ],
548
+ res_json [k ]["trunk_transaction_hash" ])
549
+ self .assertEqual (
550
+ tx_res_json [j ]["branch_transaction_hash" ],
551
+ res_json [k ]["branch_transaction_hash" ])
552
+ self .assertEqual (tx_res_json [j ]["tag" ],
553
+ res_json [k ]["tag" ])
554
+ self .assertEqual (
555
+ tx_res_json [j ]["attachment_timestamp" ],
556
+ res_json [k ]["attachment_timestamp" ])
557
+ self .assertEqual (
558
+ tx_res_json [j ]["attachment_timestamp_lower_bound" ],
559
+ res_json [k ]["attachment_timestamp_lower_bound" ])
560
+ self .assertEqual (
561
+ tx_res_json [j ]["attachment_timestamp_upper_bound" ],
562
+ res_json [k ]["attachment_timestamp_upper_bound" ])
563
+ self .assertEqual (tx_res_json [j ]["nonce" ],
564
+ res_json [k ]["nonce" ])
565
+ case_examined_equal = True
566
+ break
567
+ self .assertTrue (case_examined_equal )
568
+ else :
569
+ self .assertEqual (STATUS_CODE_400 , response [i ][1 ])
570
+
571
+ # Time Statistics
572
+ time_cost = []
573
+ for i in range (TIMES_TOTAL ):
574
+ start_time = time .time ()
575
+ response .append (API ("/tag/" , get_data = rand_tag_27 ))
576
+ time_cost .append (time .time () - start_time )
577
+
578
+ eval_stat (time_cost , "find transactions obj by tag" )
579
+
430
580
431
581
"""
432
582
API List
0 commit comments