18
18
from websockets .sync .client import connect
19
19
from websockets .extensions import permessage_deflate
20
20
21
- SILK = "silk"
22
- RPCDAEMON = "rpcdaemon"
21
+ DAEMON_ON_OTHER_PORT = "silk"
22
+ DAEMON_ON_DEFAULT_PORT = "rpcdaemon"
23
+ NONE = "none"
23
24
EXTERNAL_PROVIDER = "external-provider"
24
25
TIME = 0.1
25
26
MAX_TIME = 200 # times of TIME secs
@@ -111,45 +112,47 @@ def usage(argv):
111
112
print ("-o,--dump-response: dump JSON RPC response" )
112
113
print ("-H,--host: host where the RpcDaemon is located (e.g.: 10.10.2.3)" )
113
114
print ("-p,--port: port where the RpcDaemon is located (e.g.: 8545)" )
114
- print ("-r ,--erigon-rpcdaemon: connect to Erigon RpcDaemon [default: connect to Silkrpc] " )
115
+ print ("-I ,--silk-port: Use 51515/51516 ports to server " )
115
116
print ("-e,--verify-external-provider: <provider_url> send any request also to external API endpoint as reference" )
116
117
print ("-i,--without-compare-results: send request without compare results" )
117
118
print ("-w,--waiting_time: waiting after test execution (millisec)" )
118
119
print ("-S,--serial: all tests are runned in serial way" )
119
120
120
121
121
- def get_target_name (target_type : str ):
122
- """ Return name server """
123
- if target_type == SILK :
124
- return "Silk"
125
- if target_type == RPCDAEMON :
126
- return "RpcDaemon"
122
+ def get_target (target_type : str , method : str , config ):
123
+ """ determine target
124
+ """
125
+
127
126
if target_type == EXTERNAL_PROVIDER :
128
- return "Infura"
129
- return "Undef"
127
+ return config .external_provider_url
130
128
129
+ if config .verify_with_daemon and target_type == DAEMON_ON_OTHER_PORT and "engine_" in method :
130
+ return config .daemon_on_host + ":" + str (51516 )
131
131
132
- def get_target (target_type : str , method : str , external_provider_url : str , host : str , port : int = 0 ):
133
- """ determine target
134
- """
132
+ if config .verify_with_daemon and target_type == DAEMON_ON_OTHER_PORT :
133
+ return config .daemon_on_host + ":" + str (51515 )
135
134
136
- if "engine_" in method and target_type == RPCDAEMON :
137
- return host + ":" + str (port if port > 0 else 8551 )
135
+ if target_type == DAEMON_ON_OTHER_PORT and "engine_" in method :
136
+ return config . daemon_on_host + ":" + str (51516 )
138
137
139
- if target_type == EXTERNAL_PROVIDER :
140
- return external_provider_url
138
+ if target_type == DAEMON_ON_OTHER_PORT :
139
+ return config . daemon_on_host + ":" + str ( 51515 )
141
140
142
- return host + ":" + str (port if port > 0 else 8545 )
141
+ if "engine_" in method :
142
+ return config .daemon_on_host + ":" + str (config .engine_port if config .engine_port > 0 else 8551 )
143
143
144
+ return config .daemon_on_host + ":" + str (config .server_port if config .server_port > 0 else 8545 )
144
145
145
- def get_json_filename_ext (target_type : str ):
146
+
147
+ def get_json_filename_ext (target_type : str , target ):
146
148
""" determine json file name
147
149
"""
148
- if target_type == SILK :
149
- return "-silk.json"
150
+ port = target .split (":" )
151
+ if target_type == DAEMON_ON_OTHER_PORT :
152
+ return "_" + port [1 ] + "-silk.json"
150
153
if target_type == EXTERNAL_PROVIDER :
151
154
return "-external_provider_url.json"
152
- return "-rpcdaemon.json"
155
+ return "_" + port [ 1 ] + " -rpcdaemon.json"
153
156
154
157
155
158
def get_jwt_secret (name ):
@@ -284,15 +287,16 @@ class Config:
284
287
def __init__ (self ):
285
288
""" init the configuration params """
286
289
self .exit_on_fail = True
287
- self .daemon_under_test = SILK
288
- self .daemon_as_reference = RPCDAEMON
290
+ self .daemon_under_test = DAEMON_ON_DEFAULT_PORT
291
+ self .daemon_as_reference = NONE
289
292
self .loop_number = 1
290
293
self .verbose_level = 0
291
294
self .req_test_number = - 1
292
295
self .force_dump_jsons = False
293
296
self .external_provider_url = ""
294
297
self .daemon_on_host = "localhost"
295
- self .daemon_on_port = 0
298
+ self .server_port = 0
299
+ self .engine_port = 0
296
300
self .testing_apis_with = ""
297
301
self .testing_apis = ""
298
302
self .verify_with_daemon = False
@@ -314,8 +318,8 @@ def __init__(self):
314
318
def select_user_options (self , argv ):
315
319
""" process user command """
316
320
try :
317
- opts , _ = getopt .getopt (argv [1 :], "iw:hfrcv :t:l:a:de:b:ox:X:H:k:s:p:T:A:jS" ,
318
- ['help' , 'continue' , 'erigon-rpcdaemon ' , 'verify-external-provider' , 'host=' ,
321
+ opts , _ = getopt .getopt (argv [1 :], "iw:hfIcv :t:l:a:de:b:ox:X:H:k:s:p:P :T:A:jS" ,
322
+ ['help' , 'continue' , 'silk-port ' , 'verify-external-provider' , 'host=' , 'engine-port =' ,
319
323
'port=' , 'display-only-fail' , 'verbose=' , 'run-single-test=' , 'start-from-test=' ,
320
324
'api-list-with=' , 'api-list=' ,'loops=' , 'compare-erigon-rpcdaemon' , 'jwt=' , 'blockchain=' ,
321
325
'transport_type=' , 'exclude-api-list=' , 'exclude-test-list=' , 'json-diff' , 'waiting_time=' ,
@@ -333,13 +337,13 @@ def select_user_options(self, argv):
333
337
self .waiting_time = int (optarg )
334
338
elif option in ("-c" , "--continue" ):
335
339
self .exit_on_fail = 0
336
- elif option in ("-r " , "--erigon-rpcdaemon " ):
337
- if self .verify_with_daemon == 1 :
340
+ elif option in ("-I " , "--silk-port " ):
341
+ if self .verify_with_daemon is True :
338
342
print ("Error on options: "
339
- "-r /--erigon-rpcdaemon is not compatible with -d/--compare-erigon-rpcdaemon" )
343
+ "-I /--silk-port is not compatible with -d/--compare-erigon-rpcdaemon" )
340
344
usage (argv )
341
345
sys .exit (1 )
342
- self .daemon_under_test = RPCDAEMON
346
+ self .daemon_under_test = DAEMON_ON_OTHER_PORT
343
347
elif option in ("-e" , "--verify-external-provider" ):
344
348
self .daemon_as_reference = EXTERNAL_PROVIDER
345
349
self .external_provider_url = optarg
@@ -348,7 +352,9 @@ def select_user_options(self, argv):
348
352
elif option in ("-H" , "--host" ):
349
353
self .daemon_on_host = optarg
350
354
elif option in ("-p" , "--port" ):
351
- self .daemon_on_port = int (optarg )
355
+ self .server_port = int (optarg )
356
+ elif option in ("-P" , "--engine-port" ):
357
+ self .engine_port = int (optarg )
352
358
elif option in ("-f" , "--display-only-fail" ):
353
359
self .display_only_fail = 1
354
360
elif option in ("-v" , "--verbose" ):
@@ -375,17 +381,18 @@ def select_user_options(self, argv):
375
381
elif option in ("-l" , "--loops" ):
376
382
self .loop_number = int (optarg )
377
383
elif option in ("-d" , "--compare-erigon-rpcdaemon" ):
378
- if self .daemon_under_test != SILK :
384
+ if self .daemon_under_test != DAEMON_ON_DEFAULT_PORT :
379
385
print ("Error in options: "
380
- "-d/--compare-erigon-rpcdaemon is not compatible with -r /--erigon-rpcdaemon " )
386
+ "-d/--compare-erigon-rpcdaemon is not compatible with -I /--silk-port " )
381
387
usage (argv )
382
388
sys .exit (1 )
383
389
if self .without_compare_results is True :
384
390
print ("Error in options: "
385
391
"-d/--compare-erigon-rpcdaemon is not compatible with -i/--without_compare_results" )
386
392
usage (argv )
387
393
sys .exit (1 )
388
- self .verify_with_daemon = 1
394
+ self .verify_with_daemon = True
395
+ self .daemon_as_reference = DAEMON_ON_DEFAULT_PORT
389
396
self .use_jsondiff = True
390
397
elif option in ("-o" , "--dump-response" ):
391
398
self .force_dump_jsons = 1
@@ -424,7 +431,7 @@ def select_user_options(self, argv):
424
431
elif option in ("-j" , "--json-diff" ):
425
432
self .use_jsondiff = True
426
433
elif option in ("-i" , "--without-compare-results" ):
427
- if self .verify_with_daemon == 1 :
434
+ if self .verify_with_daemon is True :
428
435
print ("Error on options: "
429
436
"-i/--without-compare-results is not compatible with -d/--compare-erigon-rpcdaemon" )
430
437
usage (argv )
@@ -445,18 +452,18 @@ def select_user_options(self, argv):
445
452
shutil .rmtree (self .output_dir )
446
453
447
454
448
- def get_json_from_response (msg , verbose_level : int , json_file , result : str ):
455
+ def get_json_from_response (target , msg , verbose_level : int , json_file , result : str ):
449
456
""" Retrieve JSON from response """
450
457
if verbose_level > 2 :
451
458
print (msg + " :[" + result + "]" )
452
459
453
460
if len (result ) == 0 :
454
- error_msg = "Failed (json response is zero length, maybe server is down)"
461
+ error_msg = "Failed (json response is zero length, maybe server is down) on " + target
455
462
return None , error_msg
456
463
try :
457
464
return result , ""
458
465
except json .decoder .JSONDecodeError :
459
- error_msg = "Failed (bad json format)"
466
+ error_msg = "Failed (bad json format) + target "
460
467
if verbose_level :
461
468
print (msg )
462
469
print ("Failed (bad json format)" )
@@ -500,7 +507,7 @@ def execute_request(transport_type: str, jwt_auth, encoded, request_dumps, targe
500
507
result = rsp .json ()
501
508
except :
502
509
if verbose_level :
503
- print ("\n http connection fail" )
510
+ print ("\n http connection failç: " , target_url )
504
511
return ""
505
512
else :
506
513
ws_target = "ws://" + target # use websocket
@@ -619,16 +626,16 @@ def compare_json(config, response, json_file, silk_file, exp_rsp_file, diff_file
619
626
os .remove (temp_file2 )
620
627
return return_code , error_msg
621
628
622
- def process_response (result , result1 , response_in_file : str , config ,
629
+ def process_response (target , target1 , result , result1 , response_in_file : str , config ,
623
630
output_dir : str , silk_file : str , exp_rsp_file : str , diff_file : str , json_file : str , test_number : int ):
624
631
""" Process the response If exact result or error don't care, they are null but present in expected_response. """
625
632
626
- response , error_msg = get_json_from_response (config .daemon_under_test , config .verbose_level , json_file , result )
633
+ response , error_msg = get_json_from_response (target , config .daemon_under_test , config .verbose_level , json_file , result )
627
634
if response is None :
628
635
return 0 , error_msg
629
636
630
637
if result1 != "" :
631
- expected_response , error_msg = get_json_from_response (config .daemon_as_reference , config .verbose_level , json_file , result1 )
638
+ expected_response , error_msg = get_json_from_response (target1 , config .daemon_as_reference , config .verbose_level , json_file , result1 )
632
639
if expected_response is None :
633
640
return 0 , error_msg
634
641
else :
@@ -708,15 +715,16 @@ def run_test(json_file: str, test_number, transport_type, config):
708
715
except KeyError :
709
716
method = ""
710
717
request_dumps = json .dumps (request )
711
- target = get_target (config .daemon_under_test , method , config .external_provider_url , config .daemon_on_host , config .daemon_on_port )
718
+ target = get_target (config .daemon_under_test , method , config )
719
+ target1 = ""
712
720
if config .jwt_secret == "" :
713
721
jwt_auth = ""
714
722
encoded = ""
715
723
else :
716
724
byte_array_secret = bytes .fromhex (config .jwt_secret )
717
725
encoded = jwt .encode ({"iat" : datetime .now (pytz .utc )}, byte_array_secret , algorithm = "HS256" )
718
726
jwt_auth = "Bearer " + str (encoded )
719
- if config .verify_with_daemon == 0 : # compare daemon result with file
727
+ if config .verify_with_daemon is False : # compare daemon result with file
720
728
result = execute_request (transport_type , jwt_auth , encoded , request_dumps , target , config .verbose_level )
721
729
result1 = ""
722
730
response_in_file = json_rpc ["response" ]
@@ -727,21 +735,23 @@ def run_test(json_file: str, test_number, transport_type, config):
727
735
728
736
silk_file = output_api_filename + "response.json"
729
737
exp_rsp_file = output_api_filename + "expResponse.json"
730
- else : # run tests with both servers
731
- target = get_target (SILK , method , config . external_provider_url , config . daemon_on_host , config . daemon_on_port )
738
+ else : # run tests with two servers
739
+ target = get_target (DAEMON_ON_OTHER_PORT , method , config )
732
740
result = execute_request (transport_type , jwt_auth , encoded , request_dumps , target , config .verbose_level )
733
- target1 = get_target (config .daemon_as_reference , method , config . external_provider_url , config . daemon_on_host , config . daemon_on_port )
741
+ target1 = get_target (config .daemon_as_reference , method , config )
734
742
result1 = execute_request (transport_type , jwt_auth , encoded , request_dumps , target1 , config .verbose_level )
735
743
response_in_file = None
736
744
737
745
output_api_filename = config .output_dir + json_file [:- 4 ]
738
746
output_dir_name = output_api_filename [:output_api_filename .rfind ("/" )]
739
747
diff_file = output_api_filename + "-diff.json"
740
748
741
- silk_file = output_api_filename + get_json_filename_ext (SILK )
742
- exp_rsp_file = output_api_filename + get_json_filename_ext (config .daemon_as_reference )
749
+ silk_file = output_api_filename + get_json_filename_ext (DAEMON_ON_OTHER_PORT , target )
750
+ exp_rsp_file = output_api_filename + get_json_filename_ext (config .daemon_as_reference , target1 )
743
751
744
752
return process_response (
753
+ target ,
754
+ target1 ,
745
755
result ,
746
756
result1 ,
747
757
response_in_file ,
@@ -772,13 +782,18 @@ def main(argv) -> int:
772
782
failed_tests = 0
773
783
success_tests = 0
774
784
tests_not_executed = 0
775
- global_test_number = 1
776
785
786
+ if config .verify_with_daemon is True :
787
+ server_endpoints = "both servers"
788
+ else :
789
+ target = get_target (config .daemon_under_test , "eth_call" , config )
790
+ target1 = get_target (config .daemon_under_test , "engine_" , config )
791
+ server_endpoints = target + "/" + target1
777
792
if config .parallel is True :
778
- print ("Runs tests in parallel" )
793
+ print ("Runs tests in parallel on" , server_endpoints )
779
794
exe = ProcessPoolExecutor ()
780
795
else :
781
- print ("Runs tests in serial way" )
796
+ print ("Runs tests in serial way on" , server_endpoints )
782
797
exe = ProcessPoolExecutor (max_workers = 1 )
783
798
784
799
@@ -791,13 +806,16 @@ def main(argv) -> int:
791
806
test_number_in_any_loop = 1
792
807
tests_descr_list = []
793
808
dirs = sorted (os .listdir (config .json_dir ))
809
+ global_test_number = 0
810
+ available_tested_apis = 0
794
811
for curr_api in dirs : # scans all api present in dir
795
812
# jump results folder or any hidden OS-specific folder
796
813
if curr_api == config .results_dir or curr_api .startswith ("." ):
797
814
continue
798
815
test_dir = config .json_dir + curr_api
799
816
if not os .path .isdir (test_dir ): # jump if not dir
800
817
continue
818
+ available_tested_apis = available_tested_apis + 1
801
819
test_lists = sorted (os .listdir (test_dir ), key = extract_number )
802
820
test_number = 1
803
821
for test_name in test_lists : # scan all json test present in the dir
@@ -831,8 +849,7 @@ def main(argv) -> int:
831
849
time .sleep (config .waiting_time / 1000 )
832
850
executed_tests = executed_tests + 1
833
851
834
- if test_rep == 0 :
835
- global_test_number = global_test_number + 1
852
+ global_test_number = global_test_number + 1
836
853
test_number_in_any_loop = test_number_in_any_loop + 1
837
854
test_number = test_number + 1
838
855
@@ -874,7 +891,8 @@ def main(argv) -> int:
874
891
elapsed = datetime .now () - start_time
875
892
print (" \r " )
876
893
print (f"Test time-elapsed: { str (elapsed )} " )
877
- print (f"Avalable_tests: { global_test_number - 1 } " )
894
+ print (f"Avalable tests: { global_test_number - 1 } " )
895
+ print (f"Avalable tested api: { available_tested_apis } " )
878
896
print (f"Number of loop: { test_rep + 1 } " )
879
897
print (f"Number of executed tests: { executed_tests } " )
880
898
print (f"Number of NOT executed tests: { tests_not_executed } " )
0 commit comments