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: allow getting contract types for non-checksummed addresses #58

Merged
merged 3 commits into from
Nov 17, 2022
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
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repos:
- id: black
name: black

- repo: https://gitlab.com/pycqa/flake8
- repo: https://github.com/pycqa/flake8
rev: 5.0.4
hooks:
- id: flake8
Expand All @@ -24,7 +24,7 @@ repos:
rev: v0.982
hooks:
- id: mypy
additional_dependencies: [types-PyYAML, types-requests]
additional_dependencies: [types-PyYAML, types-requests, types-setuptools]


default_language_version:
Expand Down
6 changes: 5 additions & 1 deletion ape_etherscan/explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ def get_transaction_url(self, transaction_hash: str) -> str:
def _client_factory(self) -> ClientFactory:
return ClientFactory(self.network.ecosystem.name, self.network.name.replace("-fork", ""))

def get_contract_type(self, address: str) -> Optional[ContractType]:
def get_contract_type(self, address: AddressType) -> Optional[ContractType]:
if not self.conversion_manager.is_type(address, AddressType):
# Handle non-checksummed addresses
address = self.conversion_manager.convert(str(address), AddressType)

client = self._client_factory.get_contract_client(address)
source_code = client.get_source_code()
abi_string = source_code.abi
Expand Down
9 changes: 5 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from setuptools import find_packages, setup # type: ignore
from setuptools import find_packages, setup

extras_require = {
"test": [ # `test` GitHub Action jobs uses this
Expand All @@ -18,8 +18,9 @@
],
"lint": [
"black>=22.10.0", # auto-formatter and linter
"mypy>=0.982", # Static type analyzer
"types-requests>=2.28.7", # NOTE: Needed due to mypy typeshed
"mypy==0.982", # Static type analyzer
"types-requests>=2.28.7", # Needed due to mypy typeshed
"types-setuptools", # Needed due to mypy typeshed
"flake8>=5.0.4", # Style linter
"isort>=5.10.1", # Import sorting linter
],
Expand Down Expand Up @@ -68,7 +69,7 @@
url="https://github.com/ApeWorX/ape-etherscan",
include_package_data=True,
install_requires=[
"eth-ape>=0.5.2,<0.6",
"eth-ape>=0.5.4,<0.6",
"requests", # Use same version as eth-ape
],
python_requires=">=3.8,<3.11",
Expand Down
4 changes: 4 additions & 0 deletions tests/test_etherscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,11 @@ def test_get_contract_type_ecosystems_and_networks(
response = mock_backend.setup_mock_get_contract_type_response("get_contract_response")
explorer = get_explorer(ecosystem, network)
actual = explorer.get_contract_type(response.expected_address)
contract_type_from_lowered_address = explorer.get_contract_type(
response.expected_address.lower()
)
assert actual is not None
assert actual == contract_type_from_lowered_address

actual = actual.name
expected = EXPECTED_CONTRACT_NAME_MAP[response.file_name]
Expand Down