Skip to content

Commit

Permalink
test: fix issues with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Feb 20, 2025
1 parent 25ea540 commit 73f8260
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
3 changes: 3 additions & 0 deletions tests/functional/test_contract_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
ProjectError,
)
from ape_ethereum.ecosystem import ProxyType
from tests.conftest import explorer_test


def test_deploy(
Expand Down Expand Up @@ -55,13 +56,15 @@ def test_deploy_and_publish_live_network_no_explorer(owner, contract_container,
contract_container.deploy(0, sender=owner, publish=True, required_confirmations=0)


@explorer_test
def test_deploy_and_publish(
owner, contract_container, dummy_live_network_with_explorer, mock_explorer
):
contract = contract_container.deploy(0, sender=owner, publish=True, required_confirmations=0)
mock_explorer.publish_contract.assert_called_once_with(contract.address)


@explorer_test
def test_deploy_and_not_publish(
owner, contract_container, dummy_live_network_with_explorer, mock_explorer
):
Expand Down
28 changes: 14 additions & 14 deletions tests/functional/test_contracts_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from ape import Contract
from ape.contracts import ContractInstance
from ape.exceptions import ContractNotFoundError, ConversionError
from ape.logging import LogLevel
from ape_ethereum.proxies import _make_minimal_proxy
from ape.logging import LogLevel, logger
from ape_ethereum.proxies import ProxyInfo, ProxyType, _make_minimal_proxy
from tests.conftest import explorer_test, skip_if_plugin_installed


Expand Down Expand Up @@ -161,10 +161,10 @@ def test_instance_at_skip_proxy(mocker, chain, vyper_contract_instance, owner):

def test_cache_deployment_live_network(
chain,
dummy_live_network,
clean_contract_caches,
vyper_contract_instance,
vyper_contract_container,
clean_contract_caches,
dummy_live_network,
):
# Arrange - Ensure the contract is not cached anywhere
address = vyper_contract_instance.address
Expand Down Expand Up @@ -435,9 +435,6 @@ def test_get_attempts_explorer_logs_rate_limit_error_from_explorer(
):
contract = owner.deploy(vyper_fallback_container)

# Ensure is not cached locally.
del chain.contracts[contract.address]

# For rate limit errors, we don't show anything else,
# as it may be confusing.
check_error_str = "you have been rate limited"
Expand All @@ -449,10 +446,14 @@ def get_contract_type(addr):
raise ValueError("nope")

with create_mock_sepolia() as network:
# Ensure is not cached locally.
del chain.contracts[contract.address]

mock_explorer.get_contract_type.side_effect = get_contract_type
network.__dict__["explorer"] = mock_explorer
try:
actual = chain.contracts.get(contract.address)
with logger.at_level(LogLevel.INFO):
actual = chain.contracts.get(contract.address)
finally:
network.__dict__["explorer"] = None

Expand Down Expand Up @@ -528,8 +529,9 @@ def test_get_proxy_pass_proxy_info(chain, owner, minimal_proxy_container, ethere
assert minimal_proxy.address not in chain.contracts.contract_types


@explorer_test
def test_get_proxy_pass_proxy_info_and_no_explorer(
chain, owner, minimal_proxy_container, ethereum, dummy_live_network_with_explorer
chain, owner, proxy_contract_container, ethereum, dummy_live_network_with_explorer
):
"""
Tests the condition of both passing `proxy_info=` and setting `use_explorer=False`
Expand All @@ -540,12 +542,10 @@ def test_get_proxy_pass_proxy_info_and_no_explorer(
if placeholder in chain.contracts:
del chain.contracts[placeholder]

minimal_proxy = owner.deploy(minimal_proxy_container, sender=owner, required_confirmations=0)
info = ethereum.get_proxy_info(minimal_proxy.address)
assert info is not None

proxy = proxy_contract_container.deploy(placeholder, sender=owner, required_confirmations=0)
info = ProxyInfo(type=ProxyType.Minimal, target=placeholder)
explorer.get_contract_type.reset_mock()
chain.contracts.get(minimal_proxy.address, proxy_info=info, fetch_from_explorer=False)
chain.contracts.get(proxy.address, proxy_info=info, fetch_from_explorer=False)

# Ensure explorer was not used.
assert explorer.get_contract_type.call_count == 0
Expand Down

0 comments on commit 73f8260

Please sign in to comment.