Skip to content
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
5 changes: 4 additions & 1 deletion src/ape/api/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,10 @@ def deploy(

if publish:
self.local_project.deployments.track(instance)
self.provider.network.publish_contract(address)
try:
self.provider.network.publish_contract(address)
except Exception as err:
logger.error(f"Contract was deployed but explorer verification failed: {err}")

instance.base_path = contract.base_path or self.local_project.path
return instance
Expand Down
5 changes: 4 additions & 1 deletion src/ape/contracts/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1701,7 +1701,10 @@ def deploy(self, *args, publish: bool = False, **kwargs) -> ContractInstance:

if publish:
self.local_project.deployments.track(instance)
self.provider.network.publish_contract(address)
try:
self.provider.network.publish_contract(address)
except Exception as err:
logger.error(f"Contract was deployed but explorer verification failed: {err}")

instance.base_path = self.base_path or self.local_project.contracts_folder
return instance
Expand Down
25 changes: 21 additions & 4 deletions tests/functional/test_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
AliasAlreadyInUseError,
MethodNonPayableError,
MissingDeploymentBytecodeError,
NetworkError,
ProjectError,
SignatureError,
)
Expand Down Expand Up @@ -337,12 +336,13 @@ def test_deploy_and_publish_local_network(owner, minimal_proxy_container):

@explorer_test
def test_deploy_and_publish_live_network_no_explorer(
owner, minimal_proxy_container, dummy_live_network
owner, minimal_proxy_container, dummy_live_network, ape_caplog
):
dummy_live_network.__dict__["explorer"] = None
expected_message = "Unable to publish contract - no explorer plugin installed."
with pytest.raises(NetworkError, match=expected_message):
owner.deploy(minimal_proxy_container, publish=True, required_confirmations=0)
contract = owner.deploy(minimal_proxy_container, publish=True, required_confirmations=0)
assert contract.address
assert expected_message in ape_caplog.head


@explorer_test
Expand All @@ -353,6 +353,23 @@ def test_deploy_and_publish(
mock_explorer.publish_contract.assert_called_once_with(contract.address)


@explorer_test
def test_deploy_and_publish_explorer_failure(
owner,
minimal_proxy_container,
dummy_live_network_with_explorer,
mock_explorer,
ape_caplog,
):
mock_explorer.publish_contract.side_effect = RuntimeError("Verification failed.")
contract = owner.deploy(minimal_proxy_container, publish=True, required_confirmations=0)
assert contract.address
assert (
"Contract was deployed but explorer verification failed: Verification failed."
in ape_caplog.head
)


@explorer_test
def test_deploy_and_not_publish(
owner, minimal_proxy_container, dummy_live_network_with_explorer, mock_explorer
Expand Down
25 changes: 21 additions & 4 deletions tests/functional/test_contract_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
ArgumentsLengthError,
MethodNonPayableError,
MissingDeploymentBytecodeError,
NetworkError,
ProjectError,
)
from ape_ethereum.ecosystem import ProxyType
Expand Down Expand Up @@ -51,12 +50,13 @@ def test_deploy_and_publish_local_network(owner, minimal_proxy_container):


def test_deploy_and_publish_live_network_no_explorer(
owner, minimal_proxy_container, dummy_live_network
owner, minimal_proxy_container, dummy_live_network, ape_caplog
):
dummy_live_network.__dict__["explorer"] = None
expected_message = "Unable to publish contract - no explorer plugin installed."
with pytest.raises(NetworkError, match=expected_message):
minimal_proxy_container.deploy(sender=owner, publish=True, required_confirmations=0)
contract = minimal_proxy_container.deploy(sender=owner, publish=True, required_confirmations=0)
assert contract.address
assert expected_message in ape_caplog.head


@explorer_test
Expand All @@ -67,6 +67,23 @@ def test_deploy_and_publish(
mock_explorer.publish_contract.assert_called_once_with(contract.address)


@explorer_test
def test_deploy_and_publish_explorer_failure(
owner,
minimal_proxy_container,
dummy_live_network_with_explorer,
mock_explorer,
ape_caplog,
):
mock_explorer.publish_contract.side_effect = RuntimeError("Verification failed.")
contract = minimal_proxy_container.deploy(sender=owner, publish=True, required_confirmations=0)
assert contract.address
assert (
"Contract was deployed but explorer verification failed: Verification failed."
in ape_caplog.head
)


@explorer_test
def test_deploy_and_not_publish(
owner, minimal_proxy_container, dummy_live_network_with_explorer, mock_explorer
Expand Down
Loading