diff --git a/e2e/tests/sync/juno_from_juno.star b/e2e/tests/sync/juno_from_juno.star index 1f29f3ac..3379afbc 100644 --- a/e2e/tests/sync/juno_from_juno.star +++ b/e2e/tests/sync/juno_from_juno.star @@ -1,7 +1,8 @@ participants = import_module("../../clients/participants.star") +sync_utils = import_module("./sync_test_utils.star") # Test configuration -SYNC_TIMEOUT_SECONDS = 1200 +SYNC_TIMEOUT_SECONDS = 1800 TARGET_BLOCK_NUMBER = 1000 def run(plan): @@ -24,20 +25,5 @@ def run(plan): "network": "sepolia", }) - tester_image = plan.add_service( - "sync-tester", - config=ServiceConfig( - image=ImageBuildSpec( - image_name="sync-test", - build_context_dir="./../../tester", - ), - ) - ) - - # Run the tester - plan.print("Starting the sync tester...") - plan.exec(tester_image.name, ExecRecipe( - ["node", "index.mjs", "http://" + peer_node.ip_address + ":6061", str(SYNC_TIMEOUT_SECONDS), str(TARGET_BLOCK_NUMBER)] - )) - - plan.print("Juno to Juno sync test completed") + sync_utils.run_sync_test(plan, feeder_node, peer_node, SYNC_TIMEOUT_SECONDS, TARGET_BLOCK_NUMBER) + plan.print("Juno to Juno sync test completed") \ No newline at end of file diff --git a/e2e/tests/sync/juno_from_pathfinder.star b/e2e/tests/sync/juno_from_pathfinder.star index 5d63434a..4d1217f5 100644 --- a/e2e/tests/sync/juno_from_pathfinder.star +++ b/e2e/tests/sync/juno_from_pathfinder.star @@ -1,11 +1,12 @@ participants = import_module("../../clients/participants.star") +sync_utils = import_module("./sync_test_utils.star") # Test configuration -SYNC_TIMEOUT_SECONDS = 1200 +SYNC_TIMEOUT_SECONDS = 1800 TARGET_BLOCK_NUMBER = 1000 def run(plan): - # Run the Pathfinder feeder node + # Run the Pathfinder as feeder node feeder_node = participants.run_participant(plan, "pathfinder-feeder", { "type": "pathfinder", "is_feeder": True, @@ -22,20 +23,5 @@ def run(plan): "network": "sepolia", }) - tester_image = plan.add_service( - "sync-tester", - config=ServiceConfig( - image=ImageBuildSpec( - image_name="sync-test", - build_context_dir="./../../tester", - ), - ) - ) - - # Run the tester - plan.print("Starting the sync tester...") - plan.exec(tester_image.name, ExecRecipe( - ["node", "index.mjs", "http://" + peer_node.ip_address + ":6061", str(SYNC_TIMEOUT_SECONDS), str(TARGET_BLOCK_NUMBER)] - )) - - plan.print("Juno from Pathfinder sync test completed") \ No newline at end of file + sync_utils.run_sync_test(plan, feeder_node, peer_node, SYNC_TIMEOUT_SECONDS, TARGET_BLOCK_NUMBER) + plan.print("Juno from Pathfinder sync test completed") diff --git a/e2e/tests/sync/sync_test_utils.star b/e2e/tests/sync/sync_test_utils.star new file mode 100644 index 00000000..9342a111 --- /dev/null +++ b/e2e/tests/sync/sync_test_utils.star @@ -0,0 +1,43 @@ +def execute_sync_test(plan, peer_node, sync_timeout_seconds, target_block_number): + """ + Executes the sync test against a peer node: + 1. Creates a tester service + 2. Runs the sync test + 3. Returns the test results + """ + # Create and run tester service + tester_service = plan.add_service( + "sync-tester", + config=ServiceConfig( + image=ImageBuildSpec( + image_name="sync-test", + build_context_dir="./../../tester", + ), + ) + ) + + plan.print("Starting the sync tester...") + plan.exec(tester_service.name, ExecRecipe( + ["node", "index.mjs", "http://" + peer_node.ip_address + ":6061", str(sync_timeout_seconds), str(target_block_number)] + )) + +def cleanup_services(plan): + """ + Cleans up all services after the test is complete + """ + services = plan.get_services(description="Fetching running services") + for service in services: + plan.print("Found service: " + service.name + " at " + service.ip_address) + plan.remove_service( + name=service.name, + description="Removing service " + service.name + ) + +def run_sync_test(plan, feeder_node, peer_node, sync_timeout_seconds, target_block_number): + """ + Orchestrates the complete sync test process: + 1. Executes the sync test + 2. Cleans up all services + """ + execute_sync_test(plan, peer_node, sync_timeout_seconds, target_block_number) + cleanup_services(plan) \ No newline at end of file