Skip to content

Commit

Permalink
Fix broken imports when launching CLI from package (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
feltroidprime authored Aug 25, 2024
1 parent e7eacaa commit 0b381b5
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 74 deletions.
2 changes: 1 addition & 1 deletion hydra/garaga/starknet/cli/smart_contract_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
from starknet_py.hash.sierra_class_hash import compute_sierra_class_hash
from starknet_py.net.account.account import Account

from garaga.starknet.cli.utils import get_sierra_casm_artifacts
from garaga.starknet.groth16_contract_generator.calldata import (
groth16_calldata_from_vk_and_proof,
)
from garaga.starknet.groth16_contract_generator.parsing_utils import (
Groth16Proof,
Groth16VerifyingKey,
)
from tests.contracts_e2e.contracts_test_utils import get_sierra_casm_artifacts


class EmptyContract(Exception):
Expand Down
71 changes: 71 additions & 0 deletions hydra/garaga/starknet/cli/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import asyncio
import glob
import json
import os
import shutil
import subprocess
from enum import Enum

import rich
Expand Down Expand Up @@ -94,3 +98,70 @@ def voyager_link_tx(network: Network, tx_hash: int) -> str:
def voyager_link_class(network: Network, class_hash: int) -> str:
voyager_prefix = get_voyager_network_prefix(network)
return f"https://{voyager_prefix}voyager.online/class/{hex(class_hash)}"


def scarb_build_contract_folder(contract_folder_path: str):
cmd = "scarb build"
print(f"Running command: {cmd} in directory: {contract_folder_path}")
try:
subprocess.run(
cmd,
cwd=contract_folder_path,
check=True,
shell=True,
capture_output=True,
text=True,
)
except subprocess.CalledProcessError as e:
print(f"Error building contract: {e}")
print(f"Command output:\n{e.output}")
raise
except FileNotFoundError as e:
print(f"Error: {e}")
raise
except Exception as e:
print(f"An unexpected error occurred: {e}")
raise


def get_sierra_casm_artifacts(
contract_folder_path: str,
) -> tuple[None, None] | tuple[str, str]:
"""
Get the Sierra and CASM artifacts for a contract.
"""
target_dir = os.path.join(contract_folder_path, "target/dev/")

# Clean the target/dev/ folder if it already exists
if os.path.exists(target_dir):
shutil.rmtree(target_dir)
os.makedirs(target_dir)

scarb_build_contract_folder(contract_folder_path)

artifacts_file = glob.glob(os.path.join(target_dir, "*.starknet_artifacts.json"))
assert (
len(artifacts_file) == 1
), "Artifacts JSON file not found or multiple files found."

with open(artifacts_file[0], "r") as f:
artifacts = json.load(f)

contracts = artifacts["contracts"]
if len(contracts) == 0:
return None, None

sierra_file = contracts[0]["artifacts"]["sierra"]
casm_file = contracts[0]["artifacts"]["casm"]

sierra_path = os.path.join(target_dir, sierra_file)
casm_path = os.path.join(target_dir, casm_file)

assert os.path.exists(sierra_path), f"Sierra file not found: {sierra_path}"
assert os.path.exists(casm_path), f"CASM file not found: {casm_path}"

with open(sierra_path, "r") as f:
sierra = f.read()
with open(casm_path, "r") as f:
casm = f.read()
return sierra, casm
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "maturin"

[project]
name = "garaga"
version = "0.13.2.1"
version = "0.13.2.2"
requires-python = ">=3.10,<3.11"
dependencies = [
"fastecdsa",
Expand Down
72 changes: 0 additions & 72 deletions tests/contracts_e2e/contracts_test_utils.py

This file was deleted.

0 comments on commit 0b381b5

Please sign in to comment.