Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tserg committed Mar 21, 2024
1 parent 157adbd commit a5cd9c8
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/functional/codegen/features/test_assert.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def foo():

def test_assert_reason(w3, get_contract_with_gas_estimation, tx_failed, memory_mocker):
code = """
err: String[32]
@external
def test(a: int128) -> int128:
assert a > 1, "larger than one please"
Expand All @@ -43,6 +45,17 @@ def test2(a: int128, b: int128, extra_reason: String[32]) -> int128:
@external
def test3(reason_str: String[32]):
raise reason_str
@external
def test4(a: int128, reason_str: String[32]) -> int128:
self.err = reason_str
assert a > 1, self.err
return 1 + a
@external
def test5(reason_str: String[32]):
self.err = reason_str
raise self.err
"""
c = get_contract_with_gas_estimation(code)

Expand All @@ -66,6 +79,15 @@ def test3(reason_str: String[32]):
c.test3("An exception")
assert _fixup_err_str(e_info.value.args[0]) == "An exception"

assert c.test4(2, "msg") == 3
with pytest.raises(TransactionFailed) as e_info:
c.test4(0, "larger than one again please")
assert _fixup_err_str(e_info.value.args[0]) == "larger than one again please"

with pytest.raises(TransactionFailed) as e_info:
c.test5("A storage exception")
assert _fixup_err_str(e_info.value.args[0]) == "A storage exception"


invalid_code = [
"""
Expand Down

0 comments on commit a5cd9c8

Please sign in to comment.