Skip to content

Commit

Permalink
test: fix issues in tests #127 (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored May 9, 2024
1 parent 43429be commit 66699ff
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
25 changes: 24 additions & 1 deletion ape_etherscan/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,30 @@ def attempt_verification(self):
"""

version = str(self.compiler.version)
settings = self.compiler.settings or self._get_new_settings(version)

# TODO: Fix compiler output in ape-solidity
# and/or add more validation to ethpm_types.Compiler
compiler = self.compiler
valid = True
settings = {}
if compiler:
settings = self.compiler.settings or {}
output_contracts = settings.get("outputSelection", {})
for contract_id in self.compiler.contractTypes or []:
parts = contract_id.split(":")
if len(parts) != 2:
# Bad compiler.
valid = False
continue

_, cname = parts
if cname not in output_contracts:
valid = False
break

if not valid:
settings = self._get_new_settings(version)

optimizer = settings.get("optimizer", {})
optimized = optimizer.get("enabled", False)
runs = optimizer.get("runs", DEFAULT_OPTIMIZATION_RUNS)
Expand Down
6 changes: 6 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ def standard_input_json(library):
@pytest.fixture(autouse=True)
def connection(explorer):
with ape.networks.ethereum.mainnet.use_provider("infura") as provider:
# TODO: Figure out why this is still needed sometimes,
# even after https://github.com/ApeWorX/ape/pull/2022
if not provider.is_connected:
provider.connect()

yield provider


Expand Down Expand Up @@ -281,6 +286,7 @@ def get_url_f(testnet: bool = False, tld: str = "io"):
"arbitrum": {
"mainnet": url("arbiscan"),
"goerli": testnet_url("goerli", "arbiscan"),
"sepolia": testnet_url("sepolia", "arbiscan"),
},
"fantom": {
"opera": com_url("ftmscan"),
Expand Down
8 changes: 5 additions & 3 deletions tests/test_etherscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,21 +177,23 @@ def test_get_contract_type_ecosystems_and_networks(
@pytest.mark.parametrize(
"file_name", ("get_proxy_contract_response", ("get_vyper_contract_response"))
)
def test_get_contract_type_additional_types(mock_backend, file_name, explorer):
def test_get_contract_type_additional_types(mock_backend, file_name, explorer, connection):
# This test parametrizes getting edge-case contract types.
# NOTE: Purposely not merged with test above to avoid adding a new dimension
# to the parametrization.
_ = connection # Needed for symbol lookup
mock_backend.set_network("ethereum", "mainnet")
response = mock_backend.setup_mock_get_contract_type_response(file_name)
actual = explorer.get_contract_type(response.expected_address).name
expected = EXPECTED_CONTRACT_NAME_MAP[response.file_name]
assert actual == expected


def test_get_contract_type_with_rate_limiting(mock_backend, explorer):
def test_get_contract_type_with_rate_limiting(mock_backend, explorer, connection):
"""
This test ensures the rate limiting logic in the Etherscan client works.
"""

_ = connection # Needed for calling symbol() on Vyper_contract
file_name = "get_vyper_contract_response"
setter_upper = mock_backend.setup_mock_get_contract_type_response_with_throttling
throttler, response = setter_upper(file_name)
Expand Down

0 comments on commit 66699ff

Please sign in to comment.