Skip to content

Commit

Permalink
fix: issue with reference-based dependencies (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Apr 25, 2023
1 parent 6b1add1 commit c263156
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 11 deletions.
20 changes: 13 additions & 7 deletions ape_solidity/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,19 @@ def _add_dependencies(
version = "local"
else:
# Check for GitHub-style dependency
version_match = re.match(r".*/releases/tag/(v?[\d|.]+)", str(uri_str))
if version_match:
version = version_match.groups()[0]
if not version.startswith("v"):
version = f"v{version}"
else:
raise CompilerError(f"Unable to discern dependency type '{uri_str}'.")
match_checks = (r".*/releases/tag/(v?[\d|.]+)", r".*/tree/(v?[\w|.|\d]+)")
version = None
for check in match_checks:
version_match = re.match(check, str(uri_str))
if version_match:
version = version_match.groups()[0]
if not version.startswith("v") and version[0].isnumeric():
version = f"v{version}"

break

if version is None:
raise CompilerError(f"Unable to discern dependency type '{uri_str}'.")

# Find matching package
for package in packages_dir.iterdir():
Expand Down
6 changes: 6 additions & 0 deletions tests/ape-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ dependencies:
github: yearn/yearn-vaults
version: 0.4.5

# Ensure dependencies using GitHub references work.
- name: vault
github: yearn/yearn-vaults
ref: master

solidity:
import_remapping:
- "@remapping/contracts=TestDependency"
Expand All @@ -29,6 +34,7 @@ solidity:

# Ensure yearn-vaults works as a remapping
- "@vault=vault/v0.4.5"
- "@vaultmain=vault/master"


# Using evm_version compatible with older and newer solidity versions.
Expand Down
18 changes: 14 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
from ape_solidity.compiler import Extension

# NOTE: Ensure that we don't use local paths for these
ape.config.DATA_FOLDER = Path(mkdtemp()).resolve()
ape.config.PROJECT_FOLDER = Path(mkdtemp()).resolve()
DATA_FOLDER = Path(mkdtemp()).resolve()
PROJECT_FOLDER = Path(mkdtemp()).resolve()
ape.config.DATA_FOLDER = DATA_FOLDER
ape.config.PROJECT_FOLDER = PROJECT_FOLDER


@contextmanager
Expand Down Expand Up @@ -62,15 +64,23 @@ def temp_solcx_path(monkeypatch):
yield path


@pytest.fixture(autouse=True)
def data_folder():
base_path = Path(__file__).parent / "data"
copy_tree(base_path.as_posix(), DATA_FOLDER.as_posix())
return DATA_FOLDER


@pytest.fixture
def config():
return ape.config


@pytest.fixture(autouse=True)
def project(config):
def project(data_folder, config):
_ = data_folder # Ensure happens first.
project_source_dir = Path(__file__).parent
project_dest_dir = config.PROJECT_FOLDER / project_source_dir.name
project_dest_dir = PROJECT_FOLDER / project_source_dir.name

# Delete build / .cache that may exist pre-copy
project_path = Path(__file__).parent
Expand Down
1 change: 1 addition & 0 deletions tests/contracts/UseYearn.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity >=0.8.17;

import {VaultAPI} from "@vault/BaseStrategy.sol";
import {VaultAPI as VaultMain} from "@vaultmain/BaseStrategy.sol";


interface UseYearn is VaultAPI {
Expand Down
1 change: 1 addition & 0 deletions tests/data/packages/OpenZeppelin/v4.5.0/OpenZeppelin.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions tests/data/packages/OpenZeppelin/v4.7.1/OpenZeppelin.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions tests/data/packages/vault/master/vault_main.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions tests/data/packages/vault/v0.4.5/vault.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions tests/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def test_get_import_remapping(compiler, project, config):
"@openzeppelin/contracts": ".cache/OpenZeppelin/v4.7.1",
"@oz/contracts": ".cache/OpenZeppelin/v4.5.0",
"@vault": ".cache/vault/v0.4.5",
"@vaultmain": ".cache/vault/master",
}

with config.using_project(project.path / "ProjectWithinProject") as proj:
Expand Down Expand Up @@ -253,6 +254,7 @@ def test_compiler_data_in_manifest(project):
in compiler_latest.settings["remappings"]
)
assert "@vault=.cache/vault/v0.4.5" in compiler_latest.settings["remappings"]
assert "@vaultmain=.cache/vault/master" in compiler_latest.settings["remappings"]
common_suffix = ".cache/TestDependency/local"
expected_remappings = (
"@remapping_2_brownie=.cache/BrownieDependency/local",
Expand Down

0 comments on commit c263156

Please sign in to comment.