Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove slice() length documentation caveats #3152

Merged
merged 1 commit into from Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/built-in-functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ Data Manipulation

* ``b``: value being sliced
* ``start``: start position of the slice
* ``length``: length of the slice, must be constant. Immutables and variables are not supported.
* ``length``: length of the slice

If the value being sliced is a ``Bytes`` or ``bytes32``, the return type is ``Bytes``. If it is a ``String``, the return type is ``String``.

Expand Down
17 changes: 17 additions & 0 deletions tests/parser/functions/test_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,23 @@ def dice() -> Bytes[1]:
assert c.dice() == b"A"


def test_slice_immutable_length_arg(get_contract_with_gas_estimation):
code = """
LENGTH: immutable(uint256)

@external
def __init__():
LENGTH = 5

@external
def do_slice(inp: Bytes[50]) -> Bytes[50]:
return slice(inp, 0, LENGTH)
"""
c = get_contract_with_gas_estimation(code)
x = c.do_slice(b"abcdefghijklmnopqrstuvwxyz1234")
assert x == b"abcde", x


def test_slice_at_end(get_contract):
code = """
@external
Expand Down