Skip to content

Commit

Permalink
fix: issue where revert infos were the same [APE-1210] (#1550)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Jul 20, 2023
1 parent 41518ad commit bdea511
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/ape/pytest/contextmanagers.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(
self.expected_message = expected_message
self.dev_message = dev_message
self.error_inputs = error_inputs
self.revert_info = RevertInfo()
self.revert_info: Optional[RevertInfo] = None

def _check_dev_message(self, exception: ContractLogicError):
"""
Expand Down Expand Up @@ -142,7 +142,9 @@ def _check_custom_error(self, exception: Union[CustomError]):
raise AssertionError("\n".join(incorrect_values))

def __enter__(self, *args, **kwargs):
return self.revert_info
info = RevertInfo()
self.revert_info = info
return info

def __exit__(self, exc_type: Type, exc_value: Exception, traceback) -> bool:
if exc_type is None:
Expand All @@ -166,7 +168,8 @@ def __exit__(self, exc_type: Type, exc_value: Exception, traceback) -> bool:

# Set the exception on the returned info.
# This allows the user to make further assertions on the exception.
self.revert_info.value = exc_value
if self.revert_info is not None:
self.revert_info.value = exc_value

# Returning True causes the expected exception not to get raised
# and the test to pass
Expand Down
14 changes: 14 additions & 0 deletions tests/functional/test_reverts_context_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@
from tests.conftest import geth_process_test


def test_revert_info_context(owner, reverts_contract_instance):
"""
Shows no two revert info objects are the same instance.
"""

rev = reverts()
with rev as rev0:
reverts_contract_instance.revertStrings(0, sender=owner)
with rev as rev1:
reverts_contract_instance.revertStrings(1, sender=owner)

assert rev0.value.revert_message != rev1.value.revert_message


def test_no_args(owner, reverts_contract_instance):
"""
Test catching transaction reverts without asserting on error messages.
Expand Down

0 comments on commit bdea511

Please sign in to comment.