Skip to content

Commit

Permalink
add pop tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tserg committed Dec 30, 2024
1 parent 0a8fdca commit ca9fb7b
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions tests/functional/syntax/test_for_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def bar(t: address):
pass
""",
StateAccessViolation,
"May not call state modifying function within a range expression.",
"May not call state modifying function within a range expression or for loop iterator.",
None,
"extcall I(t).bar()",
),
Expand All @@ -354,7 +354,7 @@ def bar(t: address):
pass
""",
StateAccessViolation,
"May not call state modifying function within a range expression.",
"May not call state modifying function within a range expression or for loop iterator.",
None,
"extcall I(t).bar()",
),
Expand All @@ -369,10 +369,43 @@ def bar(t: address):
pass
""",
StateAccessViolation,
"May not call state modifying function for loop iterator.",
"May not call state modifying function within a range expression or for loop iterator.",
None,
"extcall I(t).bar()",
),
# Cannot call `pop()` in for range because it modifies state
(
"""
arr: DynArray[uint256, 10]
@external
def test()-> (DynArray[uint256, 6], DynArray[uint256, 10]):
b: DynArray[uint256, 6] = []
self.arr = [1,0]
for i: uint256 in range(self.arr.pop(), 20, bound=12):
b.append(i)
return b, self.arr
""",
StateAccessViolation,
"May not call state modifying function within a range expression or for loop iterator.",
None,
"self.arr.pop()",
),
(
"""
arr: DynArray[uint256, 10]
@external
def test()-> (DynArray[uint256, 6], DynArray[uint256, 10]):
b: DynArray[uint256, 6] = []
self.arr = [1,0]
for i: uint256 in range(5, self.arr.pop() + 2, bound=12):
b.append(i)
return b, self.arr
""",
StateAccessViolation,
"May not call state modifying function within a range expression or for loop iterator.",
None,
"self.arr.pop() + 2",
),
]

for_code_regex = re.compile(r"for .+ in (.*):", re.DOTALL)
Expand Down

0 comments on commit ca9fb7b

Please sign in to comment.