Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #48 from antazoey/fix/cairo1-fixes
Browse files Browse the repository at this point in the history
fix: swp bytecodes [APE-848]
  • Loading branch information
antazoey authored Apr 18, 2023
2 parents 7ceefc6 + 90f49a0 commit de19547
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: 3.9

- name: Install dependencies
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: 3.9

- name: Install Dependencies
run: |
Expand Down Expand Up @@ -63,7 +63,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest] # eventually add `windows-latest`
python-version: [3.8, 3.9]
python-version: [3.9, "3.10"]

env:
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repos:
- id: isort

- repo: https://github.com/psf/black
rev: 22.12.0
rev: 23.3.0
hooks:
- id: black
name: black
Expand Down
23 changes: 17 additions & 6 deletions ape_cairo/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def starknet_compile(
logger.warning(
"Cairo stuck in locked state. Clearing debug target and retrying."
)
shutil.rmtree(self.manifest_path.parent / "target", ignore_errors=True)
shutil.rmtree(target_path, ignore_errors=True)
return _compile(*arguments)

raise # Original error
Expand All @@ -131,7 +131,7 @@ def starknet_sierra_compile(
self, in_path: Path, out_path: Path, allow_libfuncs_list_name: Optional[str] = None
) -> Tuple[str, str]:
_bin = self._which(STARKNET_SIERRA_COMPILE)
arguments = [*_bin, str(in_path), str(out_path)]
arguments = [*_bin, str(in_path), str(out_path), "--add-pythonic-hints"]
if allow_libfuncs_list_name is not None:
arguments.extend(("--allowed-libfuncs-list-name", allow_libfuncs_list_name))

Expand Down Expand Up @@ -227,7 +227,7 @@ def get_versions(self, all_paths: List[Path]) -> Set[str]:
if not all_paths:
return set()

return {"v1.0.0-alpha.6"}
return {"v1.0.0-alpha.7"}

def compile(
self, contract_filepaths: List[Path], base_path: Optional[Path] = None
Expand Down Expand Up @@ -300,12 +300,23 @@ def compile(
)

output_dict = json.loads(program_path.read_text())

# Migrate ABIs to EthPM spec.
abis = []
for abi in output_dict["abi"]:
if abi["name"] == "constructor":
# Constructor look like a normal method ABI in Cairo 1.
abi["type"] = "constructor"
del abi["name"]

abis.append(abi)

contract_type = ContractType(
abi=output_dict["abi"],
abi=abis,
contractName=contract_name,
sourceId=source_id,
runtimeBytecode={"bytecode": to_hex(text=program_path.read_text())},
deploymentBytecode={"bytecode": to_hex(text=str(casm_path.read_text()))},
runtimeBytecode={"bytecode": to_hex(text=str(casm_path.read_text()))},
deploymentBytecode={"bytecode": to_hex(text=program_path.read_text())},
)
contract_types.append(contract_type)

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"hypothesis>=6.70,<7.0", # Strategy-based fuzzer
],
"lint": [
"black>=22.12.0", # auto-formatter and linter
"black>=23.3.0", # auto-formatter and linter
"mypy>=0.991,<1", # Static type analyzer
"types-setuptools", # Needed due to mypy typeshed
"flake8>=6.0.0,<7", # Style linter
Expand Down Expand Up @@ -57,7 +57,7 @@
url="https://github.com/ApeWorX/ape-cairo",
include_package_data=True,
install_requires=[
"eth-ape>=0.6.6,<0.7",
"eth-ape>=0.6.8,<0.7",
"ethpm-types", # Use same version as eth-ape
],
python_requires=">=3.8,<3.11",
Expand Down
9 changes: 9 additions & 0 deletions tests/contracts/storage.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ mod importme;

#[contract]
mod Storage {
struct Storage {
store_id: felt252
}

#[constructor]
fn constructor(sid: felt252) {
store_id::write(sid);
}

#[view]
fn supports_interface(interface_id: felt252) -> bool {
true
Expand Down
9 changes: 8 additions & 1 deletion tests/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ def test_event_abi_migration(compiler, project):
assert not event_abi.inputs[0].indexed


def test_constructor(compiler, project):
contract_with_event = project.contracts_folder / "storage.cairo"
contract_type = compiler.compile([contract_with_event])[0]
constructor = contract_type.constructor
assert len(constructor.inputs) == 1


def get_expected_contract_type_name(contract_path: Path, base_path: Path) -> str:
"""
Converts paths like Path("path/to/base_dir/namespace/storage.cairo") -> "namespace.storage".
Expand All @@ -57,4 +64,4 @@ def get_expected_contract_type_name(contract_path: Path, base_path: Path) -> str
def test_get_versions(compiler, project):
path = project.contracts_folder / "storage.cairo"
versions = compiler.get_versions([path])
assert versions == {"v1.0.0-alpha.6"}
assert versions == {"v1.0.0-alpha.7"}

0 comments on commit de19547

Please sign in to comment.