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

test: fix issues in tests #127 #128

Merged
merged 11 commits into from
May 9, 2024
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
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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# 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
Loading