diff --git a/ape_solidity/_models.py b/ape_solidity/_models.py index 74a780c..91f17d3 100644 --- a/ape_solidity/_models.py +++ b/ape_solidity/_models.py @@ -194,6 +194,10 @@ def _resolve_source( self._resolve_path(reference, project) def _resolve_import_remapping(self, project: ProjectManager): + if self.value.startswith("."): + # Relative paths should not use import-remappings. + return + import_remapping = self.solidity._import_remapping_cache[project] # Get all matches. diff --git a/tests/ape-config.yaml b/tests/ape-config.yaml index c6dab25..568c28d 100644 --- a/tests/ape-config.yaml +++ b/tests/ape-config.yaml @@ -21,6 +21,8 @@ dependencies: ref: master # Ensure NPM dependencies work. + # NOTE: Do not change this dependency; it is also + # part of other tests. See `./safe/ThisIsNotGnosisSafe.sol`. - name: safe npm: "@gnosis.pm/safe-contracts" version: 1.3.0 diff --git a/tests/contracts/BuiltinErrorChecker.sol b/tests/contracts/BuiltinErrorChecker.sol index 7f65155..ad627e9 100644 --- a/tests/contracts/BuiltinErrorChecker.sol +++ b/tests/contracts/BuiltinErrorChecker.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity ^0.8.2; contract BuiltinErrorChecker { diff --git a/tests/contracts/Imports.sol b/tests/contracts/Imports.sol index 87514f6..1620adb 100644 --- a/tests/contracts/Imports.sol +++ b/tests/contracts/Imports.sol @@ -22,6 +22,8 @@ import "@noncompilingdependency/CompilingContract.sol"; import "@noncompilingdependency/CompilingContract.sol"; import "@safe/contracts/common/Enum.sol"; +// Show we can import a local contract with the same name (sin-@) as a dependency. +import "./safe/ThisIsNotGnosisSafe.sol"; // Purposely exclude the contracts folder to test older Ape-style project imports. import "@noncompilingdependency/subdir/SubCompilingContract.sol"; diff --git a/tests/contracts/safe/README.md b/tests/contracts/safe/README.md new file mode 100644 index 0000000..f78d9fd --- /dev/null +++ b/tests/contracts/safe/README.md @@ -0,0 +1,5 @@ +# Local folder named 'safe' + +Do not change the name of this folder. +It is part of test where we ensure we can have local imports to folders that have the same name as dependencies. +In this case, we also have a dependency with key `@safe`. diff --git a/tests/contracts/safe/ThisIsNotGnosisSafe.sol b/tests/contracts/safe/ThisIsNotGnosisSafe.sol new file mode 100644 index 0000000..20fd0ae --- /dev/null +++ b/tests/contracts/safe/ThisIsNotGnosisSafe.sol @@ -0,0 +1,10 @@ +// SPDX-License-Identifier: MIT +// The point of this file is show we can have contracts in folders +// where the folder is the same name as a dependency. +pragma solidity ^0.8.0; + +contract ThisIsNotGnosisSafe { + constructor(){ + + } +} diff --git a/tests/test_cli.py b/tests/test_cli.py index 495cbe9..9929adf 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -61,6 +61,15 @@ return true; } } +// File: ./safe/ThisIsNotGnosisSafe.sol +// The point of this file is show we can have contracts in folders +// where the folder is the same name as a dependency. + +contract ThisIsNotGnosisSafe { + constructor(){ + + } +} // File: ./subfolder/Relativecontract.sol contract Relativecontract { @@ -138,6 +147,8 @@ // Purposely repeat an import to test how the plugin handles that. +// Show we can import a local contract with the same name (sin-@) as a dependency. + // Purposely exclude the contracts folder to test older Ape-style project imports. // Showing sources with extra extensions are by default excluded, diff --git a/tests/test_compiler.py b/tests/test_compiler.py index 7ae4713..18ade11 100644 --- a/tests/test_compiler.py +++ b/tests/test_compiler.py @@ -130,6 +130,7 @@ def test_get_imports_complex(project, compiler): "contracts/MissingPragma.sol", "contracts/NumerousDefinitions.sol", "contracts/Source.extra.ext.sol", + "contracts/safe/ThisIsNotGnosisSafe.sol", "contracts/subfolder/Relativecontract.sol", ], "contracts/MissingPragma.sol": [], @@ -413,6 +414,7 @@ def test_get_compiler_settings(project, compiler): "contracts/MissingPragma.sol", "contracts/NumerousDefinitions.sol", "contracts/Source.extra.ext.sol", + "contracts/safe/ThisIsNotGnosisSafe.sol", "contracts/subfolder/Relativecontract.sol", ] assert actual_files == expected_files @@ -653,7 +655,7 @@ def test_compile_outputs_compiler_data_to_manifest(project, compiler): actual = project.manifest.compilers[0] assert actual.name == "solidity" assert "CompilesOnce" in actual.contractTypes - assert actual.version == "0.8.26+commit.8a97fa7a" + assert actual.version == "0.8.27+commit.40a35a09" # Compiling again should not add the same compiler again. _ = [c for c in compiler.compile((path,), project=project)] length_again = len(project.manifest.compilers or [])