Skip to content

Commit

Permalink
fix: Change None check to Falsey check for ContractLogicError message…
Browse files Browse the repository at this point in the history
… to be the TB revert type (ApeWorX#2253)
  • Loading branch information
antazoey authored Aug 29, 2024
1 parent b40c1c0 commit b1bbc23
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
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

0 comments on commit b1bbc23

Please sign in to comment.