Skip to content

Commit

Permalink
add tests for variable revert reasons
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Oct 24, 2021
1 parent f81d581 commit 2a4972f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
18 changes: 9 additions & 9 deletions tests/parser/features/test_assert.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ def test(a: int128) -> int128:
return 1 + a
@external
def test2(a: int128, b: int128) -> int128:
def test2(a: int128, b: int128, extra_reason: String[32]) -> int128:
c: int128 = 11
assert a > 1, "a is not large enough"
assert b == 1, "b may only be 1"
assert b == 1, concat("b may only be 1", extra_reason)
return a + b + c
@external
def test3() :
raise "An exception"
def test3(reason_str: String[32]):
raise reason_str
"""
c = get_contract_with_gas_estimation(code)

Expand All @@ -48,17 +48,17 @@ def test3() :
assert e_info.value.args[0] == "larger than one please"
# a = 0, b = 1
with pytest.raises(TransactionFailed) as e_info:
c.test2(0, 1)
c.test2(0, 1, "")
assert e_info.value.args[0] == "a is not large enough"
# a = 1, b = 0
with pytest.raises(TransactionFailed) as e_info:
c.test2(2, 2)
assert e_info.value.args[0] == "b may only be 1"
c.test2(2, 2, " because I said so")
assert e_info.value.args[0] == "b may only be 1" + " because I said so"
# return correct value
assert c.test2(5, 1) == 17
assert c.test2(5, 1, "") == 17

with pytest.raises(TransactionFailed) as e_info:
c.test3()
c.test3("An exception")
assert e_info.value.args[0] == "An exception"


Expand Down
5 changes: 2 additions & 3 deletions vyper/old_codegen/stmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
make_byte_array_copier,
make_setter,
unwrap_location,
mzero,
zero_pad,
)
from vyper.old_codegen.return_ import make_return_stmt
from vyper.old_codegen.types import BaseType, ByteArrayType, ListType, parse_type
Expand Down Expand Up @@ -182,9 +182,8 @@ def _get_last(lll):
_runtime_length = ["mload", buf]
revert_seq = [
"seq",
# abi_encode uses zero pad, this uses less space.
mzero(buf, msg_lll.typ.maxlen),
instantiate_msg,
zero_pad(buf),
["mstore", buf - 64, method_id],
["mstore", buf - 32, 0x20],
["revert", buf - 36, ["add", 4 + 32 + 32, ["ceil32", _runtime_length]]],
Expand Down

0 comments on commit 2a4972f

Please sign in to comment.