From 8ce986c4aa3c31fe81b95d5cd0e08b3084f82ba2 Mon Sep 17 00:00:00 2001 From: danijelTxFusion Date: Wed, 10 Jan 2024 10:34:21 +0100 Subject: [PATCH] build: add script that waits for local-setup to be ready --- scripts/wait.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 scripts/wait.py diff --git a/scripts/wait.py b/scripts/wait.py new file mode 100644 index 0000000..561ee56 --- /dev/null +++ b/scripts/wait.py @@ -0,0 +1,38 @@ +import time + +import os +import sys + + +def is_node_ready(w3): + try: + w3.zksync.get_block_number() + return True + except Exception as _: + return False + + +def wait_for_node(): + print("Waiting for node to be ready") + from zksync2.module.module_builder import ZkSyncBuilder + + max_attempts = 30 + w3 = ZkSyncBuilder.build("http://localhost:3050") + + for i in range(max_attempts): + if is_node_ready(w3): + print("Node is ready") + return + time.sleep(20) + raise Exception("Maximum retries exceeded.") + + +if __name__ == '__main__': + current_directory = os.path.dirname(os.path.abspath(__file__)) + parent_directory = os.path.join(current_directory, '..') + sys.path.append(parent_directory) + try: + wait_for_node() + except Exception as e: + print(f"Error: {e}") + sys.path.remove(parent_directory)