Skip to content

Commit

Permalink
add test for mload merge overlap
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Oct 2, 2023
1 parent a126502 commit 5580e98
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions tests/parser/features/test_assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,3 +442,63 @@ def bug(p: Point) -> Point:
"""
c = get_contract(code)
assert c.bug((1, 2)) == (2, 1)


mload_merge_codes = [
(
"""
@external
def foo() -> uint256[4]:
# copy "backwards"
xs: uint256[4] = [1, 2, 3, 4]
# dst < src
xs[0] = xs[1]
xs[1] = xs[2]
xs[2] = xs[3]
return xs
""",
[2, 3, 4, 4],
),
(
"""
@external
def foo() -> uint256[4]:
# copy "forwards"
xs: uint256[4] = [1, 2, 3, 4]
# src < dst
xs[1] = xs[0]
xs[2] = xs[1]
xs[3] = xs[2]
return xs
""",
[1, 1, 1, 1],
),
(
"""
@external
def foo() -> uint256[5]:
# partial "forward" copy
xs: uint256[5] = [1, 2, 3, 4, 5]
# src < dst
xs[2] = xs[0]
xs[3] = xs[1]
xs[4] = xs[2]
return xs
""",
[1, 2, 1, 2, 1],
),
]


# functional test that mload merging does not occur when source and dest
# buffers overlap. (note: mload merging only applies after cancun)
@pytest.mark.parametrize("code,expected_result", mload_merge_codes)
def test_mcopy_overlap(get_contract, code, expected_result):
c = get_contract(code)
assert c.foo() == expected_result

0 comments on commit 5580e98

Please sign in to comment.