Spaces:
Runtime error
Runtime error
| import requests | |
| import yaml | |
| import os | |
| import sys | |
| def validate_environment(space_url, repo_url): | |
| print(f"Starting Validation for: {space_url}\n") | |
| results = {} | |
| # 1. Ping Check (Must return 200) | |
| try: | |
| r = requests.get(space_url, timeout=10) | |
| results["HF Space Ping (200)"] = r.status_code == 200 | |
| except Exception as e: | |
| results[f"HF Space Ping (200) - Error: {str(e)}"] = False | |
| # 2. Reset Check (Must return AuditObservation) | |
| try: | |
| r = requests.post(f"{space_url}/reset", json={"task_id": "easy_reentrancy"}, timeout=10) | |
| data = r.json() | |
| results["reset() returns AuditObservation"] = "contract_code" in data and "task_id" in data | |
| except Exception as e: | |
| results[f"reset() returns AuditObservation - Error: {str(e)}"] = False | |
| # 3. Step Check (Must return scored result) | |
| try: | |
| # Note: We send a "buggy" action even though the contract is "fixed" | |
| # to ensure the grader runs and returns a score (even if 0.0) | |
| action = { | |
| "analysis": "Testing validation", | |
| "vulnerabilities": [{"type": "reentrancy", "line": 14, "severity": "high", "description": "test"}], | |
| "suggested_fixes": ["test"] | |
| } | |
| r = requests.post(f"{space_url}/step", json=action, timeout=10) | |
| data = r.json() | |
| reward = data.get("reward", -1) | |
| results["step() returns scored result (0.0-1.0)"] = 0.0 <= reward <= 1.0 | |
| except Exception as e: | |
| results[f"step() returns scored result - Error: {str(e)}"] = False | |
| # 4. State Check (Must return AuditState) | |
| try: | |
| r = requests.get(f"{space_url}/state", timeout=10) | |
| data = r.json() | |
| results["state() returns AuditState"] = "current_task" in data | |
| except Exception as e: | |
| results[f"state() returns AuditState - Error: {str(e)}"] = False | |
| # 5. Local File Checks | |
| results["openenv.yaml exists"] = os.path.exists("openenv.yaml") | |
| results["Dockerfile exists"] = os.path.exists("Dockerfile") | |
| results["inference.py exists"] = os.path.exists("inference.py") | |
| results["README.md exists"] = os.path.exists("README.md") | |
| # 6. Task Count Check | |
| try: | |
| with open("openenv.yaml", "r") as f: | |
| cfg = yaml.safe_load(f) | |
| tasks = cfg.get("tasks", []) | |
| results["openenv.yaml has 3+ tasks"] = len(tasks) >= 3 | |
| except: | |
| results["openenv.yaml has 3+ tasks"] = False | |
| print("--- Final Checklist ---") | |
| all_passed = True | |
| for task, passed in results.items(): | |
| status = "[PASS]" if passed else "[FAIL]" | |
| if not passed: all_passed = False | |
| print(f"{status} | {task}") | |
| print("-" * 25) | |
| if all_passed: | |
| print("\n✨ EVERYTHING IS PERFECT! You are ready to submit.") | |
| print(f"Space URL: {space_url}") | |
| print(f"Repo URL: {repo_url}") | |
| else: | |
| print("\nSOME CHECKS FAILED. Please ensure your Space is 'Running' on Hugging Face before submitting.") | |
| if __name__ == "__main__": | |
| # Detect Space URL from repo name if possible, else use provided | |
| url = "https://ismail131-smart-contract-audit-env.hf.space" | |
| repo = "https://github.com/Sayyed23/ET-hackethon" | |
| validate_environment(url, repo) | |