Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/vyperlang/vyper into tool…
Browse files Browse the repository at this point in the history
…/storage_layout_json
  • Loading branch information
tserg committed Dec 10, 2024
2 parents 49986e5 + 12ab491 commit 42eb3e9
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 5 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ jobs:
# modes across all python versions - one is enough
- python-version: ["3.10", "310"]
- python-version: ["3.12", "312"]
- python-version: ["3.13", "313"]

# os-specific rules
- os: windows
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def _global_version(version):
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
],
package_data={"vyper.ast": ["grammar.lark"]},
data_files=[("", [hash_file_rel_path])],
Expand Down
14 changes: 14 additions & 0 deletions tests/functional/codegen/types/numbers/test_exponents.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,17 @@ def foo(b: int128) -> int128:
c.foo(max_power)
with tx_failed():
c.foo(max_power + 1)


valid_list = [
"""
@external
def foo() -> uint256:
return (10**18)**2
"""
]


@pytest.mark.parametrize("good_code", valid_list)
def test_exponent_success(good_code):
assert compile_code(good_code) is not None
33 changes: 32 additions & 1 deletion tests/functional/syntax/test_abi_encode.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from vyper import compiler
from vyper.exceptions import TypeMismatch
from vyper.exceptions import InvalidLiteral, TypeMismatch

fail_list = [
(
Expand Down Expand Up @@ -41,11 +41,37 @@ def foo(x: uint256) -> Bytes[36]:
(
"""
@external
def foo(x: uint256) -> Bytes[36]:
return _abi_encode(x, method_id=b"abc")
""",
InvalidLiteral, # len(method_id) must be greater than 3
),
(
"""
@external
def foo(x: uint256) -> Bytes[36]:
return _abi_encode(x, method_id=0x1234567890)
""",
TypeMismatch, # len(method_id) must be less than 4
),
(
"""
@external
def foo(x: uint256) -> Bytes[36]:
return _abi_encode(x, method_id=0x123456)
""",
TypeMismatch, # len(method_id) must be greater than 3
),
(
"""
@external
def foo() -> Bytes[132]:
x: uint256 = 1
y: Bytes[32] = b"234"
return abi_encode(x, y, method_id=b"")
""",
InvalidLiteral, # len(method_id) must be 4
),
]


Expand Down Expand Up @@ -82,6 +108,11 @@ def foo(x: Bytes[1]) -> Bytes[68]:
return _abi_encode(x, ensure_tuple=False, method_id=0x12345678)
""",
"""
@external
def foo(x: Bytes[1]) -> Bytes[68]:
return _abi_encode(x, ensure_tuple=False, method_id=b"1234")
""",
"""
BAR: constant(DynArray[uint256, 5]) = [1, 2, 3, 4, 5]
@external
Expand Down
8 changes: 7 additions & 1 deletion vyper/builtins/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2363,7 +2363,13 @@ def infer_kwarg_types(self, node):
for kwarg in node.keywords:
kwarg_name = kwarg.arg
validate_expected_type(kwarg.value, self._kwargs[kwarg_name].typ)
ret[kwarg_name] = get_exact_type_from_node(kwarg.value)

typ = get_exact_type_from_node(kwarg.value)
if kwarg_name == "method_id" and isinstance(typ, BytesT):
if typ.length != 4:
raise InvalidLiteral("method_id must be exactly 4 bytes!", kwarg.value)

ret[kwarg_name] = typ
return ret

def fetch_call_return(self, node):
Expand Down
2 changes: 1 addition & 1 deletion vyper/semantics/analysis/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def _validate_op(node, types_list, validation_fn_name):
try:
_validate_fn(node)
ret.append(type_)
except InvalidOperation as e:
except (InvalidOperation, OverflowException) as e:
err_list.append(e)

if ret:
Expand Down
4 changes: 2 additions & 2 deletions vyper/semantics/types/primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ def _get_lr():
if isinstance(left, vy_ast.Int):
if left.value >= 2**value_bits:
raise OverflowException(
"Base is too large, calculation will always overflow", left
f"Base is too large for {self}, calculation will always overflow", left
)
elif left.value < -(2**value_bits):
raise OverflowException(
"Base is too small, calculation will always underflow", left
f"Base is too small for {self}, calculation will always underflow", left
)
elif isinstance(right, vy_ast.Int):
if right.value < 0:
Expand Down

0 comments on commit 42eb3e9

Please sign in to comment.