Skip to content

Commit

Permalink
fix: issues with manifest-dependencies, evm-version in foundry projec…
Browse files Browse the repository at this point in the history
…ts, and unpacking (#2114)
  • Loading branch information
antazoey committed Jun 4, 2024
1 parent 5830c40 commit f308f9a
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 9 deletions.
19 changes: 13 additions & 6 deletions src/ape/managers/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,12 +774,19 @@ def _unpack(self, path: Path, tracked: set[str]) -> Iterator["Dependency"]:

if not folder.is_dir():
# Not yet unpacked.
contracts_folder_id = get_relative_path(
self.project.contracts_folder, self.project.path
)
destination = folder / contracts_folder_id
destination.parent.mkdir(parents=True, exist_ok=True)
shutil.copytree(self.project.contracts_folder, destination)
if isinstance(self.project, LocalProject):
contracts_folder_id = get_relative_path(
self.project.contracts_folder, self.project.path
)
destination = folder / contracts_folder_id
destination.parent.mkdir(parents=True, exist_ok=True)
if self.project.contracts_folder.is_dir():
shutil.copytree(self.project.contracts_folder, destination)

else:
# Will create contracts folder from source IDs.
folder.parent.mkdir(parents=True, exist_ok=True)
self.project.manifest.unpack_sources(folder)

# self is done!
yield self
Expand Down
5 changes: 4 additions & 1 deletion src/ape_pm/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def extract_config(self, **overrides) -> "ApeConfig":
# Handle root project configuration.
# NOTE: The default contracts folder name is `src` in foundry
# instead of `contracts`, hence the default.
ape_cfg["contracts_folder"] = root_data.get("src", "src")
ape_cfg["contracts_folder"] = root_data.get("src")

# Used for seeing which remappings are comings from dependencies.
lib_paths = root_data.get("libs", ("lib",))
Expand All @@ -173,6 +173,9 @@ def extract_config(self, **overrides) -> "ApeConfig":
solidity_data["optimize"] = root_data["optimizer"]
if runs := solidity_data.get("optimizer_runs"):
solidity_data["optimization_runs"] = runs
if evm_version := root_data.get("evm_version"):
solidity_data["evm_version"] = evm_version

if soldata := solidity_data:
ape_cfg["solidity"] = soldata

Expand Down
12 changes: 10 additions & 2 deletions tests/functional/test_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,17 @@ def test_unpack(project_with_downloaded_dependencies):
def test_unpack_dependencies_of_dependencies(project, with_dependencies_project_path):
dep = project.dependencies.install(local=with_dependencies_project_path, name="wdep")
with create_tempdir() as tempdir:
dep.unpack(tempdir)
list(dep.unpack(tempdir))
subdirs = [x.name for x in tempdir.iterdir() if x.is_dir()]
assert "sub-dependency" in subdirs

# TODO: Check for dependency of dependency!

def test_unpack_no_contracts_folder(project, with_dependencies_project_path):
dep = project.dependencies.install(local=with_dependencies_project_path, name="wdep")
with create_tempdir() as tempdir:
list(dep.unpack(tempdir))
subdirs = [x.name for x in tempdir.iterdir() if x.is_dir()]
assert "empty-dependency" in subdirs


class TestPackagesCache:
Expand Down
2 changes: 2 additions & 0 deletions tests/functional/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ def toml(self):
out = 'out'
libs = ['lib']
solc = "0.8.18"
evm_version = 'cancun'
remappings = [
'forge-std/=lib/forge-std/src/',
Expand Down Expand Up @@ -630,6 +631,7 @@ def test_extract_config(self, toml, gitmodules, mock_github):
"@openzeppelin/=openzeppelin-contracts/",
]
assert actual_sol["version"] == "0.8.18"
assert actual_sol["evm_version"] == "cancun"

# Ensure dependencies migrated from .gitmodules.
assert "dependencies" in actual, "Dependencies failed to migrate"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ dependencies:

- name: manifest-dependency
local: ./manifest_dependency.json

- name: empty-dependency
local: ./empty_dependency
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# For testing anything with a dependency with no contracts.

0 comments on commit f308f9a

Please sign in to comment.