Skip to content

Commit

Permalink
Merge branch 'master' into abi-return
Browse files Browse the repository at this point in the history
  • Loading branch information
ahangsu committed Feb 10, 2022
2 parents b9e9c2b + 20b2346 commit 013d6f3
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 43 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: "Build workflow"
on:
pull_request:
push:
branches:
- master
jobs:
build-test:
runs-on: ubuntu-20.04
container: python:${{ matrix.python }}-slim
strategy:
matrix:
python: ['3.6', '3.7', '3.8', '3.9']
steps:
- run: python3 --version
- name: Check out code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Install pip dependencies
run: pip install -r requirements.txt
- name: Build and Test
run: |
pytest
mypy pyteal
python3 -c "import pyteal" scripts/generate_init.py --check
black --check .
upload-to-pypi:
runs-on: ubuntu-20.04
needs: ['build-test']
if: ${{ github.event_name == 'push' && contains(github.ref, 'master') && startsWith(github.ref, 'refs/tags') }}
steps:
- name: Check out code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Install dependencies
run: pip install wheel
- name: Build package
run: python setup.py sdist bdist_wheel
- name: Release
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
34 changes: 0 additions & 34 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions pyteal/ast/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def optedIn(cls, account: Expr, app: Expr) -> "App":
Txn.Accounts or is Txn.Sender, must be evaluated to bytes).
app: An index into Txn.ForeignApps that corresponds to the application to read from,
must be evaluated to uint64 (or, since v4, an application id that appears in
Txn.ForeignApps or is the CurrentApplicationID, must be evaluated to bytes).
Txn.ForeignApps or is the CurrentApplicationID, must be evaluated to int).
"""
require_type(account, TealType.anytype)
require_type(app, TealType.uint64)
Expand Down Expand Up @@ -123,7 +123,7 @@ def localGetEx(cls, account: Expr, app: Expr, key: Expr) -> MaybeValue:
Txn.Accounts or is Txn.Sender, must be evaluated to bytes).
app: An index into Txn.ForeignApps that corresponds to the application to read from,
must be evaluated to uint64 (or, since v4, an application id that appears in
Txn.ForeignApps or is the CurrentApplicationID, must be evaluated to bytes).
Txn.ForeignApps or is the CurrentApplicationID, must be evaluated to int).
key: The key to read from the account's local state. Must evaluate to bytes.
"""
require_type(account, TealType.anytype)
Expand Down
10 changes: 10 additions & 0 deletions pyteal/ast/subroutine.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ def __init__(
)
)

for var, var_type in implementation.__annotations__.items():
if var_type is not Expr:
stub = "Return" if var == "return" else ("parameter " + var)

raise TealInputError(
"Function has {} of disallowed type {}. Only type Expr is allowed".format(
stub, var_type
)
)

self.implementation = implementation
self.implementationParams = sig.parameters
self.returnType = returnType
Expand Down
55 changes: 48 additions & 7 deletions pyteal/ast/subroutine_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ def fn10Args(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10):
lam2Args = lambda a1, a2: Return()
lam10Args = lambda a1, a2, a3, a4, a5, a6, a7, a8, a9, a10: Return()

def fnWithExprAnnotations(a: Expr, b: Expr) -> Expr:
return Return()

def fnWithOnlyReturnExprAnnotations(a, b) -> Expr:
return Return()

def fnWithOnlyArgExprAnnotations(a: Expr, b: Expr):
return Return()

def fnWithPartialExprAnnotations(a, b: Expr) -> Expr:
return Return()

cases = (
(fn0Args, 0, "fn0Args"),
(fn1Args, 1, "fn1Args"),
Expand All @@ -37,6 +49,10 @@ def fn10Args(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10):
(lam1Args, 1, "<lambda>"),
(lam2Args, 2, "<lambda>"),
(lam10Args, 10, "<lambda>"),
(fnWithExprAnnotations, 2, "fnWithExprAnnotations"),
(fnWithOnlyReturnExprAnnotations, 2, "fnWithOnlyReturnExprAnnotations"),
(fnWithOnlyArgExprAnnotations, 2, "fnWithOnlyArgExprAnnotations"),
(fnWithPartialExprAnnotations, 2, "fnWithPartialExprAnnotations"),
)

for (fn, numArgs, name) in cases:
Expand Down Expand Up @@ -72,18 +88,43 @@ def fnWithKeywordArgs(a, *, b):
def fnWithVariableArgs(a, *b):
return Return()

def fnWithNonExprReturnAnnotation(a, b) -> TealType.uint64:
return Return()

def fnWithNonExprParamAnnotation(a, b: TealType.uint64):
return Return()

cases = (
1,
None,
fnWithDefaults,
fnWithKeywordArgs,
fnWithVariableArgs,
(1, "TealInputError('Input to SubroutineDefinition is not callable'"),
(None, "TealInputError('Input to SubroutineDefinition is not callable'"),
(
fnWithDefaults,
"TealInputError('Function has a parameter with a default value, which is not allowed in a subroutine: b'",
),
(
fnWithKeywordArgs,
"TealInputError('Function has a parameter type that is not allowed in a subroutine: parameter b with type KEYWORD_ONLY'",
),
(
fnWithVariableArgs,
"TealInputError('Function has a parameter type that is not allowed in a subroutine: parameter b with type VAR_POSITIONAL'",
),
(
fnWithNonExprReturnAnnotation,
"TealInputError('Function has Return of disallowed type TealType.uint64. Only type Expr is allowed'",
),
(
fnWithNonExprParamAnnotation,
"TealInputError('Function has parameter b of disallowed type TealType.uint64. Only type Expr is allowed'",
),
)

for case in cases:
with pytest.raises(TealInputError):
for case, msg in cases:
with pytest.raises(TealInputError) as e:
SubroutineDefinition(case, TealType.none)

assert msg in str(e), "failed for case [{}]".format(case)


def test_subroutine_declaration():
cases = (
Expand Down

0 comments on commit 013d6f3

Please sign in to comment.