Skip to content

Commit

Permalink
add tests for assertions inside for loops
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdefinitelyahuman committed Sep 22, 2019
1 parent d20c927 commit d0d076c
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/parser/features/test_assert.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,37 @@ def test():
c2 = get_contract(code, *[c1.address])
# static call prohibits state change
assert_tx_failed(lambda: c2.test())


def test_assert_in_for_loop(get_contract, assert_tx_failed):
code = """
@public
def test(x: uint256[3]) -> bool:
for i in range(3):
assert x[i] < 5
return True
"""

c = get_contract(code)

c.test([1, 2, 3])
assert_tx_failed(lambda: c.test([5, 1, 3]))
assert_tx_failed(lambda: c.test([1, 5, 3]))
assert_tx_failed(lambda: c.test([1, 3, 5]))


def test_assert_with_reason_in_for_loop(get_contract, assert_tx_failed):
code = """
@public
def test(x: uint256[3]) -> bool:
for i in range(3):
assert x[i] < 5, "because reasons"
return True
"""

c = get_contract(code)

c.test([1, 2, 3])
assert_tx_failed(lambda: c.test([5, 1, 3]))
assert_tx_failed(lambda: c.test([1, 5, 3]))
assert_tx_failed(lambda: c.test([1, 3, 5]))

0 comments on commit d0d076c

Please sign in to comment.