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

Passing ABI type arguments to Subroutine #263

Merged
merged 8 commits into from
Mar 30, 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
18 changes: 7 additions & 11 deletions examples/application/vote_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,17 +401,13 @@ def main():
max_votes = 0
tzaffi marked this conversation as resolved.
Show resolved Hide resolved
max_votes_choice = None
for key, value in global_state.items():
if (
key
not in (
"RegBegin",
"RegEnd",
"VoteBegin",
"VoteEnd",
"Creator",
)
and isinstance(value, int)
):
if key not in (
"RegBegin",
"RegEnd",
"VoteBegin",
"VoteEnd",
"Creator",
) and isinstance(value, int):
if value > max_votes:
max_votes = value
max_votes_choice = key
Expand Down
2 changes: 1 addition & 1 deletion pyteal/ast/abi/type.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def decode(
*,
startIndex: Expr = None,
endIndex: Expr = None,
length: Expr = None
length: Expr = None,
) -> Expr:
"""Decode a substring of the passed in encoded string and set it as this type's value.

Expand Down
7 changes: 4 additions & 3 deletions pyteal/ast/abi/uint.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def uint_set(size: int, uintVar: ScratchVar, value: Union[int, Expr, "Uint"]) ->

checked = False
if type(value) is int:
if value >= 2 ** size:
if value >= 2**size:
raise TealInputError("Value exceeds uint{} maximum: {}".format(size, value))
value = Int(value)
checked = True
Expand All @@ -54,7 +54,7 @@ def uint_set(size: int, uintVar: ScratchVar, value: Union[int, Expr, "Uint"]) ->

return Seq(
uintVar.store(cast(Expr, value)),
Assert(uintVar.load() < Int(2 ** size)),
Assert(uintVar.load() < Int(2**size)),
)


Expand Down Expand Up @@ -222,7 +222,8 @@ def get(self) -> Expr:
def set(self, value: Union[int, Expr, "Uint"]) -> Expr:
if isinstance(value, BaseType) and not (
isinstance(value.type_spec(), UintTypeSpec)
and self.type_spec().bit_size() == value.type_spec().bit_size()
and self.type_spec().bit_size()
== cast(UintTypeSpec, value.type_spec()).bit_size()
ahangsu marked this conversation as resolved.
Show resolved Hide resolved
):
raise TealInputError(
"Type {} is not assignable to type {}".format(
Expand Down
8 changes: 4 additions & 4 deletions pyteal/ast/abi/uint_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def noneToInt0(value: Union[None, Expr]):
uintType=abi.Uint8TypeSpec(),
instanceType=abi.Uint8,
expectedBits=8,
maxValue=2 ** 8 - 1,
maxValue=2**8 - 1,
checkUpperBound=True,
expectedDecoding=lambda encoded, startIndex, endIndex, length: GetByte(
encoded, noneToInt0(startIndex)
Expand All @@ -44,7 +44,7 @@ def noneToInt0(value: Union[None, Expr]):
uintType=abi.Uint16TypeSpec(),
instanceType=abi.Uint16,
expectedBits=16,
maxValue=2 ** 16 - 1,
maxValue=2**16 - 1,
checkUpperBound=True,
expectedDecoding=lambda encoded, startIndex, endIndex, length: ExtractUint16(
encoded, noneToInt0(startIndex)
Expand All @@ -55,7 +55,7 @@ def noneToInt0(value: Union[None, Expr]):
uintType=abi.Uint32TypeSpec(),
instanceType=abi.Uint32,
expectedBits=32,
maxValue=2 ** 32 - 1,
maxValue=2**32 - 1,
checkUpperBound=True,
expectedDecoding=lambda encoded, startIndex, endIndex, length: ExtractUint32(
encoded, noneToInt0(startIndex)
Expand All @@ -66,7 +66,7 @@ def noneToInt0(value: Union[None, Expr]):
uintType=abi.Uint64TypeSpec(),
instanceType=abi.Uint64,
expectedBits=64,
maxValue=2 ** 64 - 1,
maxValue=2**64 - 1,
checkUpperBound=False,
expectedDecoding=lambda encoded, startIndex, endIndex, length: Btoi(encoded)
if startIndex is None and endIndex is None and length is None
Expand Down
2 changes: 1 addition & 1 deletion pyteal/ast/int.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(self, value: int) -> None:

if type(value) is not int:
raise TealInputError("invalid input type {} to Int".format(type(value)))
elif value >= 0 and value < 2 ** 64:
elif value >= 0 and value < 2**64:
self.value = value
else:
raise TealInputError("Int {} is out of range".format(value))
Expand Down
4 changes: 2 additions & 2 deletions pyteal/ast/int_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


def test_int():
values = [0, 1, 8, 232323, 2 ** 64 - 1]
values = [0, 1, 8, 232323, 2**64 - 1]

for value in values:
expr = Int(value)
Expand All @@ -30,7 +30,7 @@ def test_int_invalid():
Int(-1)

with pytest.raises(TealInputError):
Int(2 ** 64)
Int(2**64)

with pytest.raises(TealInputError):
Int("0")
Expand Down
2 changes: 1 addition & 1 deletion pyteal/ast/return_.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __teal__(self, options: "CompileOptions"):
options.version,
"TEAL version too low to use subroutines",
)
returnType = options.currentSubroutine.returnType
returnType = options.currentSubroutine.return_type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

if returnType == TealType.none:
if self.value is not None:
raise TealCompileError(
Expand Down
Loading