Skip to content

Commit

Permalink
fix: all updates
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Dec 14, 2023
1 parent bcf9a65 commit cc2e47a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 23 deletions.
1 change: 0 additions & 1 deletion .mdformat.toml

This file was deleted.

41 changes: 25 additions & 16 deletions ape_etherscan/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from ape.types import AddressType
from ape.utils import ManagerAccessMixin, cached_property
from ethpm_types import ContractType
from semantic_version import Version # type: ignore
from packaging.version import Version

from ape_etherscan.client import AccountClient, ClientFactory, ContractClient
from ape_etherscan.exceptions import ContractVerificationError, EtherscanResponseError
Expand Down Expand Up @@ -231,29 +231,38 @@ def attempt_verification(self):
if not compilers_used:
raise ContractVerificationError("Compiler data missing from project manifest.")

versions = [Version(c.version) for c in compilers_used]
if not versions:
compilers = {c.version: (Version(c.version), c) for c in compilers_used}
if not compilers:
# Might be impossible to get here.
raise ContractVerificationError("Unable to find compiler version used.")

elif len(versions) > 1:
elif len(compilers) > 1:
# Might be impossible to get here.
logger.warning("Source was compiled by multiple versions. Using max.")
version = max(versions)
version = max([x[0] for x in compilers.values()])
compiler = compilers_used[str(version)][1]
else:
version, compiler = next(iter(compilers.values()))

if compiler.settings:
settings = compiler.settings
breakpoint()
else:
version = versions[0]
logger.warning(
"Settings missing from cached manifest. "
"Attempting to re-calculate find settings."
)
# Attempt to re-calculate settings.

compiler_plugin = self.compiler_manager.registered_compilers[self._ext]
all_settings = compiler_plugin.get_compiler_settings(
[self._source_path], base_path=self._base_path
)
compiler_plugin = self.compiler_manager.registered_compilers[self._ext]
all_settings = compiler_plugin.get_compiler_settings(
[self._source_path], base_path=self._base_path
)

# Hack to allow any Version object work.
# TODO: Replace with all_settings[version] on 0.7 upgrade
settings = {str(v): s for v, s in all_settings.items() if str(v) == str(version)}[
str(version)
]
# Hack to allow any Version object work.
settings = {str(v): s for v, s in all_settings.items() if str(v) == str(version)}[
str(version)
]

optimizer = settings.get("optimizer", {})
optimized = optimizer.get("enabled", False)
Expand Down Expand Up @@ -426,7 +435,7 @@ def extract_constructor_arguments(deployment_bytecode: str, runtime_bytecode: st
# If the runtime bytecode is not found within the deployment bytecode,
# return an error message.
if start_index == -1:
raise ContractVerificationError("Runtime bytecode not found within deployment bytecode")
raise ContractVerificationError("Runtime bytecode not found within deployment bytecode.")

# Cut the deployment bytecode at the start of the runtime bytecode
# The remaining part is the constructor arguments
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ force_grid_wrap = 0
include_trailing_comma = true
multi_line_output = 3
use_parentheses = true

[tool.mdformat]
number = true
13 changes: 8 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"ape-infura", # Needed for live network tests
"ape-solidity", # Needed for contract verification tests
"pytest>=6.0", # Core testing package
"pytest-xdist", # multi-process runner
"pytest-xdist", # Multi-process runner
"pytest-cov", # Coverage analyzer plugin
"hypothesis>=6.2.0,<7", # Strategy-based fuzzer
"pytest-mock", # Test mocker
Expand All @@ -25,15 +25,17 @@
"types-requests>=2.28.7", # Needed due to mypy typeshed
"types-setuptools", # Needed due to mypy typeshed
"flake8>=6.1.0,<7", # Style linter
"flake8-breakpoint>=1.1.0,<2", # Detect breakpoints left in code
"flake8-print>=5.0.0,<6", # Detect print statements left in code
"isort>=5.10.1,<6", # Import sorting linter
"mdformat>=0.7.17", # Auto-formatter for markdown
"mdformat-gfm>=0.3.5", # Needed for formatting GitHub-flavored markdown
"mdformat-frontmatter>=0.4.1", # Needed for frontmatters-style headers in issue templates
"pydantic<2", # Needed for successful type check.
"mdformat-pyproject>=0.0.1", # Allows configuring in pyproject.toml
],
"doc": [
"Sphinx>=3.4.3,<4", # Documentation generator
"sphinx_rtd_theme>=0.1.9,<1", # Readthedocs.org theme
"Sphinx>=6.1.3,<7", # Documentation generator
"sphinx_rtd_theme>=1.2.0,<2", # Readthedocs.org theme
"towncrier>=19.2.0,<20", # Generate release notes
],
"release": [ # `release` GitHub Action job uses this
Expand Down Expand Up @@ -76,7 +78,8 @@
url="https://github.com/ApeWorX/ape-etherscan",
include_package_data=True,
install_requires=[
"eth-ape>=0.6.16,<0.7",
"eth-ape>=0.7.0,<0.8",
"ethpm_types", # Use same version as eth-ape
"requests", # Use same version as eth-ape
"yarl", # Use same version as eth-ape
],
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def fn(
network.name = network_name
network.ecosystem = ecosystem
etherscan = ape.networks.get_ecosystem("ethereum").get_network("mainnet")
explorer = Etherscan.construct(name=etherscan.name, network=network)
explorer = Etherscan.model_construct(name=etherscan.name, network=network)
network.explorer = explorer
explorer.network = network
else:
Expand Down

0 comments on commit cc2e47a

Please sign in to comment.