From 3610b30bc64b7403bfee5c874ce3ac1eb2b1faf5 Mon Sep 17 00:00:00 2001 From: boqiu <82121246@qq.com> Date: Thu, 5 Sep 2024 11:21:19 +0800 Subject: [PATCH 1/4] Change zg chain block time in python tests --- tests/config/0gchain-init-genesis.sh | 9 +++++++++ tests/test_framework/test_framework.py | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/config/0gchain-init-genesis.sh b/tests/config/0gchain-init-genesis.sh index bda0a7e..a42a9eb 100644 --- a/tests/config/0gchain-init-genesis.sh +++ b/tests/config/0gchain-init-genesis.sh @@ -62,6 +62,15 @@ for ((i=0; i<$NUM_NODES; i++)) do CONFIG_TOML=$ROOT_DIR/node$i/config/config.toml sed -i '/seeds = /c\seeds = ""' $CONFIG_TOML sed -i 's/addr_book_strict = true/addr_book_strict = false/' $CONFIG_TOML + + # Change block time to very small + sed -i '/timeout_propose = "3s"/c\timeout_propose = "300ms"' $CONFIG_TOML + sed -i '/timeout_propose_delta = "500ms"/c\timeout_propose_delta = "50ms"' $CONFIG_TOML + sed -i '/timeout_prevote = "1s"/c\timeout_prevote = "100ms"' $CONFIG_TOML + sed -i '/timeout_prevote_delta = "500ms"/c\timeout_prevote_delta = "50ms"' $CONFIG_TOML + sed -i '/timeout_precommit = "1s"/c\timeout_precommit = "100ms"' $CONFIG_TOML + sed -i '/timeout_precommit_delta = "500ms"/c\timeout_precommit_delta = "50ms"' $CONFIG_TOML + sed -i '/timeout_commit = "5s"/c\timeout_commit = "500ms"' $CONFIG_TOML done # Update persistent_peers in config.toml diff --git a/tests/test_framework/test_framework.py b/tests/test_framework/test_framework.py index b693eea..8448a05 100644 --- a/tests/test_framework/test_framework.py +++ b/tests/test_framework/test_framework.py @@ -167,8 +167,8 @@ class TestFramework: # sync_blocks(self.blockchain_nodes) elif self.blockchain_node_type == BlockChainNodeType.ZG: # wait for the first block - self.log.debug("Wait 3 seconds for 0gchain node to generate first block") - time.sleep(3) + self.log.debug("Wait for 0gchain node to generate first block") + time.sleep(0.5) for node in self.blockchain_nodes: wait_until(lambda: node.net_peerCount() == self.num_blockchain_nodes - 1) wait_until(lambda: node.eth_blockNumber() is not None) From 9028a30e9d4ce193faa40e820775bc38ecbfab9f Mon Sep 17 00:00:00 2001 From: boqiu <82121246@qq.com> Date: Thu, 5 Sep 2024 14:54:00 +0800 Subject: [PATCH 2/4] upload segment in right shard id --- tests/utility/submission.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/utility/submission.py b/tests/utility/submission.py index 1421811..a9fd80f 100644 --- a/tests/utility/submission.py +++ b/tests/utility/submission.py @@ -194,9 +194,14 @@ def generate_merkle_tree_by_batch(data): def submit_data(client, data): + shard_config = client.rpc.zgs_getShardConfig() + shard_id = int(shard_config["shardId"]) + num_shard = int(shard_config["numShard"]) + segments = data_to_segments(data) - for segment in segments: - client.zgs_upload_segment(segment) + for index, segment in enumerate(segments): + if index % num_shard == shard_id: + client.zgs_upload_segment(segment) return segments From 7ef1a73c7c542f2ce8fff2b7456edcdfa983f32e Mon Sep 17 00:00:00 2001 From: boqiu <82121246@qq.com> Date: Thu, 5 Sep 2024 15:25:53 +0800 Subject: [PATCH 3/4] Fix utf-8 encoding err --- tests/utility/run_all.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/utility/run_all.py b/tests/utility/run_all.py index 9e68b73..861f2f3 100644 --- a/tests/utility/run_all.py +++ b/tests/utility/run_all.py @@ -50,7 +50,11 @@ def run_single_test(py, script, test_dir, index, port_min, port_max): ) except subprocess.CalledProcessError as err: print_testcase_result(RED, CROSS, script, start_time) - print("Output of " + script + "\n" + err.output.decode("utf-8"), flush=True) + try: + print("Output of " + script + "\n" + err.output.decode("utf-8"), flush=True) + except UnicodeDecodeError: + print("Output of " + script + "\n", flush=True) + print(err.output) raise err print_testcase_result(BLUE, TICK, script, start_time) From ec21c6fce459afe9d5b2a42d21829151a1f3a1d6 Mon Sep 17 00:00:00 2001 From: boqiu <82121246@qq.com> Date: Thu, 5 Sep 2024 15:42:55 +0800 Subject: [PATCH 4/4] run mine with market test standalone --- tests/test_all.py | 3 ++- tests/utility/run_all.py | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/tests/test_all.py b/tests/test_all.py index 03d9b16..2dfaafd 100755 --- a/tests/test_all.py +++ b/tests/test_all.py @@ -7,6 +7,7 @@ from utility.run_all import run_all if __name__ == "__main__": run_all( test_dir = os.path.dirname(__file__), - slow_tests={"random_test.py", "same_root_test.py"}, + slow_tests={"mine_test.py", "random_test.py", "same_root_test.py"}, long_manual_tests={"fuzz_test.py"}, + single_run_tests={"mine_with_market_test.py"}, ) \ No newline at end of file diff --git a/tests/utility/run_all.py b/tests/utility/run_all.py index 861f2f3..9ce3dee 100644 --- a/tests/utility/run_all.py +++ b/tests/utility/run_all.py @@ -58,7 +58,7 @@ def run_single_test(py, script, test_dir, index, port_min, port_max): raise err print_testcase_result(BLUE, TICK, script, start_time) -def run_all(test_dir: str, test_subdirs: list[str]=[], slow_tests: set[str]={}, long_manual_tests: set[str]={}): +def run_all(test_dir: str, test_subdirs: list[str]=[], slow_tests: set[str]={}, long_manual_tests: set[str]={}, single_run_tests: set[str]={}): tmp_dir = os.path.join(test_dir, "tmp") if not os.path.exists(tmp_dir): os.makedirs(tmp_dir, exist_ok=True) @@ -102,7 +102,7 @@ def run_all(test_dir: str, test_subdirs: list[str]=[], slow_tests: set[str]={}, for file in os.listdir(subdir_path): if file.endswith("_test.py"): rel_path = os.path.join(subdir, file) - if rel_path not in slow_tests and rel_path not in long_manual_tests: + if rel_path not in slow_tests and rel_path not in long_manual_tests and rel_path not in single_run_tests: TEST_SCRIPTS.append(rel_path) executor = ProcessPoolExecutor(max_workers=options.max_workers) @@ -135,6 +135,18 @@ def run_all(test_dir: str, test_subdirs: list[str]=[], slow_tests: set[str]={}, print("CalledProcessError " + repr(err)) failed.add(script) + # Run single tests one by one + for script in single_run_tests: + f = executor.submit( + run_single_test, py, script, test_dir, i, options.port_min, options.port_max + ) + try: + f.result() + except subprocess.CalledProcessError as err: + print("CalledProcessError " + repr(err)) + failed.add(script) + i += 1 + print("Elapsed: " + str(int(time.time() - start_time)) + " seconds", flush=True) if len(failed) > 0: