Skip to content

Commit

Permalink
automatic layouts tester
Browse files Browse the repository at this point in the history
  • Loading branch information
Okm165 committed Mar 19, 2024
1 parent a8dd2d4 commit 3e2efe4
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions test_layouts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import subprocess
import argparse
from colorama import Fore, Style


# Function to execute commands and log the process
def log_and_run(commands, description, cwd=None):
full_command = " && ".join(commands)

try:
print(f"{Fore.YELLOW}Starting: {description}...{Style.RESET_ALL}")
print(f"{Fore.CYAN}Command: {full_command}{Style.RESET_ALL}")

# Execute the command
result = subprocess.run(
full_command, shell=True, check=True, cwd=cwd, text=True
)

print(f"{Fore.GREEN}Success: {description} completed!\n{Style.RESET_ALL}")
except subprocess.CalledProcessError as e:
print(
f"{Fore.RED}Error running command '{full_command}': {e}\n{Style.RESET_ALL}"
)


# List of layouts to test
LAYOUTS = ["DEX", "RECURSIVE", "RECURSIVE_WITH_POSEIDON", "SMALL"]


# Main function to run the tests and optionally restore the src folder
def main(restore_src=None):
for layout in LAYOUTS:
log_and_run(
[
f"python configure.py -l {layout} -s KECCAK",
"scarb build",
f"cargo run --release --bin runner -- target/dev/cairo_verifier.sierra.json < examples/proofs/{layout.lower()}/example_proof.json",
],
f"Testing {layout.lower()} layout",
cwd=".",
)

# Check if src folder restoration is required
if restore_src is None:
response = input("Do you want to restore the src folder? (y/n): ")
restore_src = response.lower() == "y"

# Restore the src folder if requested
if restore_src:
log_and_run(["git restore src/"], "Restoring src folder", cwd=".")


# Entry point of the script
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Test cairo1-verifier layouts on example proofs"
)

# Define command-line arguments
parser.add_argument(
"-r", "--restore-src", action="store_true", help="Restore src folder after run"
)

# Parse the arguments
args = parser.parse_args()

# Run main function with the specified arguments
main(args.restore_src)

0 comments on commit 3e2efe4

Please sign in to comment.