Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bug where couldn't put contracts_folder in dependency config_override config #1819

Merged
merged 3 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/ape/api/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,11 @@ def compile(self, use_cache: bool = True) -> PackageManifest:
with tempfile.TemporaryDirectory() as temp_dir:
path = Path(temp_dir)
contracts_folder = path / config_data.get("contracts_folder", "contracts")
with self.config_manager.using_project(
path, contracts_folder=contracts_folder, **config_data
) as project:

if "contracts_folder" not in config_data:
config_data["contracts_folder"] = contracts_folder

with self.config_manager.using_project(path, **config_data) as project:
manifest.unpack_sources(contracts_folder)
compiled_manifest = project.local_project.create_manifest()

Expand Down
31 changes: 23 additions & 8 deletions tests/functional/test_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,19 @@ def test_npm_dependency(mock_home_directory):
shutil.rmtree(package_folder)


def test_decode_with_config_override(dependency_manager, project):
settings = {".json": {"evm_version": "paris"}}
path = "__test_path__"
base_path = project.path / path
contracts_path = base_path / "contracts"
contracts_path.mkdir(parents=True)
(contracts_path / "contract.json").write_text('{"abi": []}')

data = {"name": "FooBar", "local": path, "config_override": settings}
dependency = dependency_manager.decode_dependency(data)
assert dependency.config_override == settings


def test_compile(project_with_downloaded_dependencies):
name = "OpenZeppelin"
oz_442 = project_with_downloaded_dependencies.dependencies[name]["4.4.2"]
Expand All @@ -131,17 +144,19 @@ def test_compile(project_with_downloaded_dependencies):
assert len(actual.contract_types) > 0


def test_compile_with_extra_settings(dependency_manager, project):
settings = {".json": {"evm_version": "paris"}}
def test_compile_with_config_override(dependency_manager, project):
# NOTE: It is important that `contracts_folder` is present in settings
# for this test to test against a previous bug where we got multiple values.
override = {"contracts_folder": "src"}
path = "__test_path__"
base_path = project.path / path
contracts_path = base_path / "contracts"
contracts_path.mkdir(parents=True)
contracts_path = project.path / path / "contracts"
contracts_path.mkdir(exist_ok=True, parents=True)
(contracts_path / "contract.json").write_text('{"abi": []}')

data = {"name": "FooBar", "local": path, "config_override": settings}
data = {"name": "FooBar", "local": path, "config_override": override}
dependency = dependency_manager.decode_dependency(data)
assert dependency.config_override == settings

actual = dependency.compile()
assert len(actual.contract_types) > 0


def test_github_dependency_ref_or_version_is_required():
Expand Down
Loading