Skip to content

Commit

Permalink
fix: compiler settings issue inc version
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Feb 1, 2024
1 parent 44d2659 commit c6e28b6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
27 changes: 15 additions & 12 deletions ape_etherscan/dependency.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import tempfile
from pathlib import Path

import yaml
from ape.api.projects import DependencyAPI
from ape.types import AddressType
from ethpm_types import PackageManifest
from ethpm_types import Compiler, PackageManifest
from pydantic import AnyUrl, HttpUrl

from .explorer import Etherscan
Expand Down Expand Up @@ -54,19 +53,23 @@ def extract_manifest(self, use_cache: bool = True) -> PackageManifest:
project_path = Path(temp_dir).resolve()
contracts_folder = project_path / "contracts"
contracts_folder.mkdir()

response = self.explorer._get_source_code(self.address)

# Ensure compiler settings match.
if response.evm_version and response.evm_version != "Default":
data = {"solidity": {"evm_version": response.evm_version}}
config_file = project_path / "ape-config.yaml"
with open(config_file, "w") as file:
yaml.safe_dump(data, file)

compiler = Compiler(
name="Solidity",
version=response.compiler_version,
settings={
"optimizer": {
"enabled": response.optimization_used,
"runs": response.optimization_runs,
},
},
contractTypes=[response.name],
)
new_path = contracts_folder / f"{response.name}.sol"
new_path.write_text(response.source_code)
return self._extract_local_manifest(project_path, use_cache=use_cache)
manifest = self._extract_local_manifest(project_path, use_cache=use_cache)
manifest.compilers = [compiler]
return manifest

finally:
if ctx:
Expand Down
3 changes: 3 additions & 0 deletions tests/test_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ def test_dependency(mock_backend):
)
actual = dependency.extract_manifest()
assert "BoredApeYachtClub.sol" in actual.sources
assert actual.compilers[0].name == "Solidity"
assert not actual.compilers[0].settings["optimizer"]["enabled"]
assert actual.compilers[0].contractTypes == ["BoredApeYachtClub"]

0 comments on commit c6e28b6

Please sign in to comment.