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: Change None check to Falsey check for ContractLogicError message to be the TB revert type #2253

Merged
merged 1 commit into from
Aug 29, 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
4 changes: 1 addition & 3 deletions src/ape/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ def __init__(
):
self.txn = txn
self.contract_address = contract_address

super().__init__(
base_err=base_err,
contract_address=contract_address,
Expand All @@ -316,8 +315,7 @@ def __init__(
trace=trace,
txn=txn,
)

if revert_message is None and source_traceback is not None and (dev := self.dev_message):
if not revert_message and source_traceback is not None and (dev := self.dev_message):
try:
# Attempt to use dev message as main exception message.
self.message = dev
Expand Down
17 changes: 17 additions & 0 deletions tests/functional/test_exceptions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import re
from pathlib import Path
from typing import Optional

import pytest

Expand All @@ -11,6 +12,7 @@
TransactionError,
handle_ape_exception,
)
from ape.types import SourceTraceback
from ape_ethereum.transactions import DynamicFeeTransaction, Receipt


Expand Down Expand Up @@ -207,3 +209,18 @@ def test_handle_ape_exception_hides_home_dir(mocker):
# We expect the same only the home dir has been hidden.
expected = "\n" + tb_str.replace(str(Path.home()), "$HOME")
assert actual == expected


class TestContractLogicError:
@pytest.mark.parametrize("revert_message", (None, ""))
def test_message_uses_revert_type_when_no_revert_message(self, mocker, revert_message):
class TB(SourceTraceback):
@property
def revert_type(self) -> Optional[str]:
return "CUSTOM_ERROR"

tb = TB([{"statements": [], "closure": {"name": "fn"}, "depth": 0}]) # type: ignore
error = ContractLogicError(revert_message=revert_message, source_traceback=tb)
actual = error.message
expected = "CUSTOM_ERROR"
assert actual == expected
Loading