Skip to content

Commit

Permalink
hotifx except_revert (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperski95 authored Apr 8, 2022
1 parent 61aaa00 commit d814898
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/commands/test/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ class ExpectedError:
name: Optional[str]
message: Optional[str]

def __str__(self) -> str:
return f"(error_type: {self.name}; error_message: {self.message})"


class TestExecutionEnvironment:
def __init__(self, is_test_fail_enabled: bool, include_paths: List[str]):
Expand Down Expand Up @@ -188,19 +191,26 @@ async def invoke_test_function(self, function_name: str):
call_result = await func().invoke()
if self._expected_error is not None:
raise MissingExceptException(
f"Expected an exception matching the following regex: {self._expected_error.name}"
f"Expected an exception matching the following error: {self._expected_error}"
)
if is_failure_expected:
raise TestNotFailedException()
return call_result

except StarkException as ex:
is_ex_unexpected = self._expected_error is None or (
self._expected_error.name == ex.code.name
and self._expected_error.message == ex.message
is_ex_expected = (
self._expected_error is not None
and (
self._expected_error.name is None
or self._expected_error.name == ex.code.name
)
and (
self._expected_error.message is None
or (ex.message or "").startswith(self._expected_error.message)
)
)

if is_ex_unexpected:
if not is_ex_expected:
raise StarkReportedException(ex) from ex

if is_failure_expected:
Expand Down Expand Up @@ -289,7 +299,7 @@ def deploy_contract(
def expect_revert(self, expected_error: ExpectedError) -> Callable[[], None]:
if self._expected_error is not None:
raise MissingExceptException(
f"Protostar is already expecting an exception matching the following regex: {self._expected_error.name}"
f"Protostar is already expecting an exception matching the following error: {self._expected_error}"
)

self._expected_error = expected_error
Expand Down

0 comments on commit d814898

Please sign in to comment.