Skip to content

Commit

Permalink
Merge pull request #230 from DanielSchiavini/fix/revert
Browse files Browse the repository at this point in the history
fix: nested reverts error strings
  • Loading branch information
charles-cooper authored May 20, 2024
2 parents 69c68d6 + e7bab37 commit 4430c0d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
5 changes: 4 additions & 1 deletion boa/contracts/base_evm_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ def __str__(self):
frame = self.stack_trace.last_frame
if hasattr(frame, "vm_error"):
err = frame.vm_error
err.args = (frame.pretty_vm_reason, *err.args[1:])
if not hasattr(err, "_boa_patched__"):
# avoid double patching when str() is called more than once
setattr(err, "_boa_patched__", True)
err.args = (frame.pretty_vm_reason, *err.args[1:])
else:
err = frame
return f"{err}\n\n{self.stack_trace}"
4 changes: 2 additions & 2 deletions boa/interpret.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def func():
return _disk_cache.caching_lookup(str((kwargs, source_code)), func)


def load(filename: str, *args, **kwargs) -> _Contract: # type: ignore
def load(filename: str | Path, *args, **kwargs) -> _Contract: # type: ignore
name = filename
# TODO: investigate if we can just put name in the signature
if "name" in kwargs:
Expand Down Expand Up @@ -138,7 +138,7 @@ def loads_abi(json_str: str, *args, name: str = None, **kwargs) -> ABIContractFa
def loads_partial(
source_code: str,
name: str = None,
filename: str = None,
filename: str | Path | None = None,
dedent: bool = True,
compiler_args: dict = None,
) -> VyperDeployer:
Expand Down
9 changes: 5 additions & 4 deletions tests/unitary/test_reverts.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,11 @@ def add():
assert self.counter == 0
"""
)
try:
assert c.add()
except BoaError as e:
assert "<storage: counter=1>" in str(e)
with pytest.raises(BoaError) as context:
c.add()

assert "<storage: counter=1>" in str(context.value)
assert str(context.value).startswith("Revert(b'')")

assert 0 == c._storage.counter.get()
assert 0 == c.counter()
Expand Down

0 comments on commit 4430c0d

Please sign in to comment.