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

Testing ABI Functionality via Graviton / Dry-runs + Txn Friendly Graviton Logic Sig Example #322

Merged
merged 203 commits into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from 199 commits
Commits
Show all changes
203 commits
Select commit Hold shift + click to select a range
dd9abff
wtf
ahangsu Mar 30, 2022
d33e26c
update
ahangsu Mar 30, 2022
cd7632e
update to f-str
ahangsu Mar 31, 2022
a21ce2c
define void type
ahangsu Mar 31, 2022
480ece7
update instantiated computed type returnedType for ABI return in subr…
ahangsu Mar 31, 2022
ff0d275
minor
ahangsu Mar 31, 2022
6929922
update stuffs to help infer type annotation of return ABI
ahangsu Mar 31, 2022
c24e0bd
minor
ahangsu Mar 31, 2022
9e3989b
minor
ahangsu Mar 31, 2022
a1e138e
minor
ahangsu Mar 31, 2022
0d617ff
minor
ahangsu Mar 31, 2022
081bfb6
minor
ahangsu Mar 31, 2022
e8e481e
try my best to save stuffs
ahangsu Mar 31, 2022
bd29b95
Merge branch 'abi-subroutine' of github.com:algorand/pyteal into abi-…
ahangsu Mar 31, 2022
616968d
simplify decorator to single function
ahangsu Mar 31, 2022
12e3ee4
tear it down
ahangsu Mar 31, 2022
f6af8fa
minor
ahangsu Mar 31, 2022
fee70a6
sheeeesh emacs
ahangsu Mar 31, 2022
92b4db4
Merge branch 'feature/abi' into abi-subroutine
ahangsu Apr 1, 2022
41ba233
Merge branch 'feature/abi' into abi-subroutine
ahangsu Apr 12, 2022
f0101d0
updates
ahangsu Apr 12, 2022
1b5cd6a
Merge branch 'feature/abi' into abi-subroutine
ahangsu Apr 14, 2022
a2d9ea2
minor, renaming something
ahangsu Apr 14, 2022
91c87b7
new design, start over
ahangsu Apr 14, 2022
3fb7374
updates
ahangsu Apr 15, 2022
2e27f82
Merge branch 'feature/abi' into abi-subroutine
ahangsu Apr 21, 2022
cf3106d
abi fn wrapper for now
ahangsu Apr 23, 2022
6969622
Merge branch 'feature/abi' into abi-subroutine
ahangsu Apr 23, 2022
dec018f
minor
ahangsu Apr 23, 2022
54fe3bc
minor update on subroutine def
ahangsu Apr 24, 2022
4e5e1e5
minor fixes
ahangsu Apr 24, 2022
287ba71
minor fixes
ahangsu Apr 24, 2022
fa33095
changes
ahangsu Apr 25, 2022
43212b7
more constraint on void ret
ahangsu Apr 25, 2022
31cf527
update comment examples
ahangsu Apr 25, 2022
87c34d8
import from abi
ahangsu Apr 25, 2022
b0baea5
update some error msg and comments
ahangsu Apr 25, 2022
1c48d0c
testcases partial
ahangsu Apr 26, 2022
319b953
upgrade testscripts
ahangsu Apr 27, 2022
96f7ede
Bundle optional refactorings to subroutine.py (#308)
michaeldiamant Apr 29, 2022
79d787b
storing local changes
ahangsu May 2, 2022
ae7b552
Merge branch 'abi-subroutine' of github.com:algorand/pyteal into abi-…
ahangsu May 2, 2022
9422ea3
pr review partly
ahangsu May 2, 2022
02f442a
pr review partly
ahangsu May 2, 2022
c9ed2b2
update test script
ahangsu May 2, 2022
21447bb
Abi subroutine feature merge (#315)
tzaffi May 3, 2022
d43905e
Merge branch 'feature/abi' into abi-subroutine
ahangsu May 3, 2022
d0737ef
resolve conflicts
May 3, 2022
0e776a4
Merge branch 'abi-subroutine' of github.com:algorand/pyteal into abi-…
May 3, 2022
73b595f
lint
May 3, 2022
6557649
Merge branch 'feature/abi' into abi-subroutine
ahangsu May 3, 2022
7ace3fc
minor reconstruct
ahangsu May 3, 2022
1479959
Merge branch 'abi-subroutine' of github.com:algorand/pyteal into abi-…
May 3, 2022
386d57b
missing imports
May 3, 2022
939dea4
missing requirements from bad merge
May 3, 2022
6eacf07
initial commit - failing
May 3, 2022
c685f1b
user_guide_snippet_ABIReturnSubroutine()
May 4, 2022
87eafdd
Merge branch 'feature/abi' into abi-subroutine
ahangsu May 4, 2022
3904b21
comments
May 4, 2022
4512c96
Merge branch 'feature/abi' into abi-subroutine
ahangsu May 4, 2022
69d389b
cooperate with typespec n var def change
ahangsu May 4, 2022
8329a43
Merge remote-tracking branch 'origin/abi-subroutine' into blackbox-abi
May 4, 2022
363865b
wip
May 4, 2022
fc67147
wip
May 4, 2022
5378983
Merge branch 'feature/abi' into abi-subroutine
ahangsu May 4, 2022
10f910a
wip
May 4, 2022
f42339d
update comments
ahangsu May 4, 2022
9127d7c
Merge remote-tracking branch 'origin/abi-subroutine' into blackbox-abi
May 4, 2022
a3bc83e
Merge remote-tracking branch 'origin/abi-subroutine' into blackbox-abi
May 4, 2022
68694cd
mostly there
May 5, 2022
b94b286
pass thet test before pinning to new graviton
May 5, 2022
11f86d2
change expected error message
May 5, 2022
59226b2
some comments resolving?
ahangsu May 5, 2022
44003d6
trim
ahangsu May 5, 2022
0d38806
Merge branch 'abi-subroutine' into blackbox-abi
tzaffi May 5, 2022
9f13409
update some comments
ahangsu May 5, 2022
2c1ccb3
pin gravition to commit with working abi functionality
May 5, 2022
5941108
bring testcase back
ahangsu May 5, 2022
c161e22
restriction on output kwarg name
ahangsu May 5, 2022
d2caed3
stop ci! i am reformatting
ahangsu May 5, 2022
d62a124
wip
May 6, 2022
fce3c5c
utility function abi.algosdk_from_type_spec()
May 6, 2022
56f01d2
abi pyteal blackbox - first good example
May 6, 2022
cfe64af
Merge remote-tracking branch 'origin/abi-subroutine' into blackbox-abi
May 6, 2022
d4c7371
abi outputs must be named "output"
May 6, 2022
02bcdc7
pass existing tests
May 6, 2022
ed8678f
skip broken program
May 6, 2022
e89d347
lint
May 6, 2022
5910445
experiment
May 6, 2022
795182b
minus passes graviton
May 6, 2022
ae5d121
lint + warning commentary
May 6, 2022
e0e1c5d
better wording
May 6, 2022
f0ff459
use Case() instead
May 6, 2022
299e523
add "slick" minus version
May 6, 2022
39426a4
integer multiplication
May 6, 2022
edbd2c1
negation
May 6, 2022
f7af766
vscode is too smart
May 6, 2022
3905d2d
integer addition
May 6, 2022
a61f672
complex addition works
May 6, 2022
0440587
lint
May 6, 2022
4469c11
pass first unary complex function test
May 6, 2022
df13773
complex multiplication
May 6, 2022
da163d6
complex conjugate
May 6, 2022
ee4e4bb
norm_squared
May 6, 2022
78282d7
remove comment
May 8, 2022
cdddc20
oops - wait for future PR to remove this
May 8, 2022
5d7dc9d
pin to new graviton commit
May 8, 2022
92dcf03
Update pyteal/ast/abi/util_test.py
tzaffi May 8, 2022
bc8e7ce
black
May 8, 2022
dfd4687
add coverage and pass ci
May 9, 2022
5d9335b
Update tests/blackbox.py
tzaffi May 9, 2022
bba1709
simplify name constrain
ahangsu May 9, 2022
4c0858f
resolving comments
ahangsu May 9, 2022
d13bc84
Update tests/blackbox.py
tzaffi May 9, 2022
95a9842
Update tests/blackbox.py
tzaffi May 9, 2022
c2bb940
Merge branch 'abi-subroutine' into blackbox-abi
tzaffi May 9, 2022
dc2e060
Merge branch 'feature/abi' into abi-subroutine
ahangsu May 9, 2022
f4e4e9b
pass unit tests of _validate()
May 9, 2022
390a679
skip broken abirouter user guide test that should be fixed soon
May 9, 2022
95caac5
Use deferred subroutine expression for ABI returns (#328)
jasonpaulos May 9, 2022
1beeeb4
wip
May 9, 2022
ab5c630
Merge remote-tracking branch 'origin/abi-subroutine' into blackbox-abi
May 9, 2022
d21e281
Merge branch 'abi-subroutine' of github.com:algorand/pyteal into abi-…
ahangsu May 9, 2022
4e39bc4
Merge remote-tracking branch 'origin/abi-subroutine' into blackbox-abi
May 9, 2022
fad77c6
hack return from abi var
ahangsu May 9, 2022
aa6f858
a hack
ahangsu May 9, 2022
b1cdb85
Merge remote-tracking branch 'origin/abi-subroutine' into blackbox-abi
May 9, 2022
9a71adf
Update pyteal/ast/subroutine.py
tzaffi May 9, 2022
48fd8be
Update pyteal/ast/subroutine.py
tzaffi May 9, 2022
a556e28
Update pyteal/ast/subroutine.py
tzaffi May 9, 2022
e33a9d6
Update pyteal/ast/subroutine.py
tzaffi May 9, 2022
4c148f7
better returned type
ahangsu May 9, 2022
b35ce21
simplify
ahangsu May 9, 2022
6c28188
remove comment
May 10, 2022
bdd78a6
Merge remote-tracking branch 'origin/abi-subroutine' into blackbox-abi
May 10, 2022
6cc721a
Merge branches 'blackbox-abi' and 'blackbox-abi' of github.com:algora…
May 10, 2022
9df640e
add abi examples to unit/blackbox_test but don't yet run them
May 10, 2022
63b0432
add abi examples to unit/blackbox_test but don't yet run them
May 10, 2022
062680f
simplify Blackbox API: program is just an Expr now
May 10, 2022
c3960e6
really we should hook mypy into tests/
May 10, 2022
4401a41
but should still lazy-eval the program
May 10, 2022
a05de2f
Update tests/blackbox.py
tzaffi May 10, 2022
5ae1fe6
Merge branch 'feature/abi' into abi-subroutine
ahangsu May 10, 2022
a0c6a42
add some compiler test
ahangsu May 10, 2022
a14f271
flake break no way
ahangsu May 10, 2022
96e11f4
bugfix for case of no abi params + add abi unit test fixtures and pas…
May 10, 2022
07ecac2
Merge branch 'blackbox-abi' of github.com:algorand/pyteal into blackb…
May 10, 2022
c8bce31
Merge remote-tracking branch 'origin/abi-subroutine' into blackbox-abi
May 10, 2022
8e186be
comment
May 10, 2022
eb4989a
pass and clean up abi unit tests
May 11, 2022
072989e
closer to the 1 -liner
May 11, 2022
1b93347
Update .gitignore
tzaffi May 11, 2022
ebb6d30
Merge remote-tracking branch 'origin/feature/abi' into blackbox-abi
May 11, 2022
5a17d0d
Update tests/integration/graviton_abi_test.py
tzaffi May 11, 2022
3e7b3ff
Update tests/integration/graviton_abi_test.py
tzaffi May 11, 2022
3553065
Update tests/integration/graviton_test.py
tzaffi May 11, 2022
c3b3a58
Update tests/integration/graviton_test.py
tzaffi May 11, 2022
70c5a34
build-and-test is really lint-and-test + separate unit tests from int…
May 11, 2022
4a10413
util.algosdk_from_annotation + begin round-trip tests
May 12, 2022
6e60dd2
mypy
May 12, 2022
055bf67
round trip unit test without arrays
May 12, 2022
afdd2cc
round trip is broken b/c not handling arrays properly
May 12, 2022
f9d341f
comments
May 12, 2022
914fe7e
git revert'able commit - experimental map()-like functionality
May 12, 2022
b824237
Revert "git revert'able commit - experimental map()-like functionality"
May 12, 2022
95782a1
wip
May 12, 2022
47db977
Expand BlackboxPyTealer in an attempt to simplify dryrun request gene…
michaeldiamant May 12, 2022
b8d41d2
wip
May 13, 2022
3c9fdce
Replace blackbox_pyteal with PyTealDryRunExecutor (#338)
michaeldiamant May 13, 2022
4d59b5c
wip
May 13, 2022
f6637f9
Merge branch 'blackbox-abi' of github.com:algorand/pyteal into blackb…
May 13, 2022
0df1cd5
temporary revertable commit
May 13, 2022
0654598
wip
May 13, 2022
aa14bbe
test against head of graviton
May 14, 2022
322c88e
make tuple generic just as array alread is
May 14, 2022
bb43bfe
abi-round-trip test
May 15, 2022
34824e1
abi.address lengths need converting to int's
May 15, 2022
733c0da
Update Makefile
tzaffi May 15, 2022
63e46a4
created reports_dir if needed
May 15, 2022
d2af819
slimmer logic sig integration test
May 15, 2022
4665c99
add annotation_type() to TypeSpec hierarchy + roundtrip unit tests pa…
May 16, 2022
f48a329
mypy 🤞
May 16, 2022
344232e
comments
May 16, 2022
014143a
pass real integration tests that mirror the graviton roundtripts
May 17, 2022
ee8a69d
mypy
May 17, 2022
71f3285
ignore literal of non-literal
May 17, 2022
d3d6863
un-comment out
May 17, 2022
6653de8
no contravariance needed
May 17, 2022
836ab30
Update pyteal/ast/abi/address_test.py
tzaffi May 17, 2022
15a938c
don't genericize tuples with a single typevar
May 17, 2022
a8294ad
vs code is too damn smart
May 17, 2022
d21678e
still need the origin generic type, but rename to disambiguate
May 17, 2022
3625176
update _validate() doc-comment
May 17, 2022
7404ee1
add to program() doc-comment - abi variant
May 17, 2022
1ee6151
remove unused type
May 17, 2022
00971c4
Optionally refactor handling of array_length int subclasses in Static…
michaeldiamant May 17, 2022
c8dfc17
monster abi type for greater confidence in PR #345
May 18, 2022
d2729a4
Merge branch 'blackbox-abi' of github.com:algorand/pyteal into blackb…
May 18, 2022
5074899
better comments
May 18, 2022
7d2022f
Optional refactorings to #322 (#346)
michaeldiamant May 18, 2022
c721c06
Refactor ABIRoundtrip to always use annotation_type (#349)
michaeldiamant May 18, 2022
c9c01d7
Update tests/integration/graviton_abi_test.py
tzaffi May 18, 2022
dd415b9
pin to v0.3.0
May 18, 2022
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
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Install python dependencies
run: make setup-development
- name: Build and Test
run: make build-and-test
run: make lint-and-test

run-integration-tests:
runs-on: ubuntu-20.04
Expand Down Expand Up @@ -63,8 +63,8 @@ jobs:
run: make sandbox-dev-up
- name: Install python dependencies
run: make setup-development
- name: Build, Unit Tests and Integration Tests
run: make all-tests
- name: Integration Tests Only
run: make test-integration
- name: Stop running images
run: make sandbox-dev-stop

Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ celerybeat-schedule
*.sage.py

# Environments
_env
.env
.venv
env/
Expand Down Expand Up @@ -138,3 +139,6 @@ dmypy.json

# mac OS
.DS_Store

# asdf
.tool-versions
9 changes: 4 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ black:
flake8:
flake8 $(ALLPY)

# TODO: add `tests` to $MYPY when graviton respects mypy (version 🐗)
MYPY = pyteal scripts
MYPY = pyteal scripts tests
mypy:
mypy $(MYPY)

Expand All @@ -55,9 +54,9 @@ test-unit:
pytest -n $(NUM_PROCS) --durations=10 -sv pyteal tests/unit --ignore tests/unit/blackbox_test.py --ignore tests/unit/user_guide_test.py
pytest -n 1 -sv tests/unit/blackbox_test.py tests/unit/user_guide_test.py

build-and-test: check-generate-init lint test-unit
lint-and-test: check-generate-init lint test-unit

# ---- Integration Test (algod required) ---- #
# ---- Integration Tests (algod required) ---- #

sandbox-dev-up:
docker-compose up -d algod
Expand All @@ -70,7 +69,7 @@ integration-run:

test-integration: integration-run

all-tests: build-and-test test-integration
all-tests: lint-and-test test-integration

# ---- Local Github Actions Simulation via `act` ---- #
# assumes act is installed, e.g. via `brew install act`
Expand Down
9 changes: 8 additions & 1 deletion pyteal/ast/abi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@
from pyteal.ast.abi.array_dynamic import DynamicArrayTypeSpec, DynamicArray

from pyteal.ast.abi.method_return import MethodReturn
from pyteal.ast.abi.util import type_spec_from_annotation, make
from pyteal.ast.abi.util import (
algosdk_from_annotation,
algosdk_from_type_spec,
make,
type_spec_from_annotation,
)

__all__ = [
"String",
Expand Down Expand Up @@ -81,4 +86,6 @@
"MethodReturn",
"type_spec_from_annotation",
"make",
"algosdk_from_annotation",
"algosdk_from_type_spec",
]
3 changes: 3 additions & 0 deletions pyteal/ast/abi/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ def __init__(self) -> None:
def new_instance(self) -> "Address":
return Address()

def annotation_type(self) -> "type[Address]":
return Address

def __str__(self) -> str:
return "address"

Expand Down
4 changes: 4 additions & 0 deletions pyteal/ast/abi/address_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def test_AddressTypeSpec_byte_length_static():
assert (abi.AddressTypeSpec()).byte_length_static() == abi.AddressLength.Bytes


def test_AddressTypeSpec_length_static():
assert (abi.AddressTypeSpec()).length_static() == abi.AddressLength.Bytes


def test_AddressTypeSpec_new_instance():
assert isinstance(abi.AddressTypeSpec().new_instance(), abi.Address)

Expand Down
3 changes: 3 additions & 0 deletions pyteal/ast/abi/array_dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class DynamicArrayTypeSpec(ArrayTypeSpec[T]):
def new_instance(self) -> "DynamicArray[T]":
return DynamicArray(self)

def annotation_type(self) -> "type[DynamicArray[T]]":
return DynamicArray[self.value_type_spec().annotation_type()] # type: ignore[misc]

def is_length_dynamic(self) -> bool:
return True

Expand Down
18 changes: 9 additions & 9 deletions pyteal/ast/abi/array_static.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
from typing import (
Union,
Sequence,
TypeVar,
Generic,
Final,
cast,
)
from typing import Final, Generic, Literal, Sequence, TypeVar, Union, cast

from pyteal.errors import TealInputError
from pyteal.ast.expr import Expr
Expand All @@ -25,11 +18,18 @@ def __init__(self, value_type_spec: TypeSpec, array_length: int) -> None:
super().__init__(value_type_spec)
if not isinstance(array_length, int) or array_length < 0:
raise TypeError(f"Unsupported StaticArray length: {array_length}")
self.array_length: Final = array_length

# Casts to `int` to handle downstream usage where value is a subclass of int like `IntEnum`.
self.array_length: Final = int(array_length)

def new_instance(self) -> "StaticArray[T, N]":
return StaticArray(self)

def annotation_type(self) -> "type[StaticArray[T, N]]":
return StaticArray[ # type: ignore[misc]
self.value_spec.annotation_type(), Literal[self.array_length] # type: ignore
]

def length_static(self) -> int:
"""Get the size of this static array type.

Expand Down
3 changes: 3 additions & 0 deletions pyteal/ast/abi/bool.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class BoolTypeSpec(TypeSpec):
def new_instance(self) -> "Bool":
return Bool()

def annotation_type(self) -> "type[Bool]":
return Bool

def is_dynamic(self) -> bool:
# Only accurate if this value is alone, since up to 8 consecutive bools will fit into a single byte
return False
Expand Down
3 changes: 3 additions & 0 deletions pyteal/ast/abi/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ def __init__(self) -> None:
def new_instance(self) -> "String":
return String()

def annotation_type(self) -> "type[String]":
return String

def __str__(self) -> str:
return "string"

Expand Down
38 changes: 33 additions & 5 deletions pyteal/ast/abi/tuple.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,33 @@ def length_static(self) -> int:
def new_instance(self) -> "Tuple":
return Tuple(self)

def annotation_type(self) -> "type[Tuple]":
vtses = self.value_type_specs()

def annotater():
return [x.annotation_type() for x in vtses]

match len(vtses):
case 0:
return Tuple0
case 1:
v0 = annotater()[0]
return Tuple1[v0] # type: ignore[valid-type]
case 2:
v0, v1 = annotater()
return Tuple2[v0, v1] # type: ignore[valid-type]
case 3:
v0, v1, v2 = annotater()
return Tuple3[v0, v1, v2] # type: ignore[valid-type]
case 4:
v0, v1, v2, v3 = annotater()
return Tuple4[v0, v1, v2, v3] # type: ignore[valid-type]
case 5:
v0, v1, v2, v3, v4 = annotater()
return Tuple5[v0, v1, v2, v3, v4] # type: ignore[valid-type]

raise TypeError(f"Cannot annotate tuple of length {len(vtses)}")

def is_dynamic(self) -> bool:
return any(type_spec.is_dynamic() for type_spec in self.value_type_specs())

Expand All @@ -243,8 +270,7 @@ def __str__(self) -> str:

TupleTypeSpec.__module__ = "pyteal"


T = TypeVar("T", bound="Tuple")
T_tuple = TypeVar("T_tuple", bound="Tuple")


class Tuple(BaseType):
Expand Down Expand Up @@ -272,7 +298,7 @@ def set(self, *values: BaseType) -> Expr:
...

@overload
def set(self: T, value: ComputedValue[T]) -> Expr:
def set(self: T_tuple, value: ComputedValue[T_tuple]) -> Expr:
...

def set(self, *values):
Expand Down Expand Up @@ -307,8 +333,10 @@ def __getitem__(self, index: int) -> "TupleElement":

Tuple.__module__ = "pyteal"

T = TypeVar("T", bound=BaseType)


class TupleElement(ComputedValue[BaseType]):
class TupleElement(ComputedValue[T]):
"""Represents the extraction of a specific element from a Tuple."""

def __init__(self, tuple: Tuple, index: int) -> None:
Expand All @@ -319,7 +347,7 @@ def __init__(self, tuple: Tuple, index: int) -> None:
def produced_type_spec(self) -> TypeSpec:
return self.tuple.type_spec().value_type_specs()[self.index]

def store_into(self, output: BaseType) -> Expr:
def store_into(self, output: T) -> Expr:
return indexTuple(
self.tuple.type_spec().value_type_specs(),
self.tuple.encode(),
Expand Down
5 changes: 5 additions & 0 deletions pyteal/ast/abi/type.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ def new_instance(self) -> "BaseType":
"""Create a new instance of the specified type."""
pass

@abstractmethod
def annotation_type(self) -> "type[BaseType]":
"""Get the annotation type associated with this spec"""
pass

@abstractmethod
def is_dynamic(self) -> bool:
"""Check if this ABI type is dynamic.
Expand Down
19 changes: 19 additions & 0 deletions pyteal/ast/abi/uint.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ def __init__(self, bit_size: int) -> None:
def new_instance(self) -> "Uint":
pass

@abstractmethod
def annotation_type(self) -> "type[Uint]":
pass

def bit_size(self) -> int:
"""Get the bit size of this uint type"""
return self.size
Expand Down Expand Up @@ -157,6 +161,9 @@ def __init__(self) -> None:
def new_instance(self) -> "Byte":
return Byte()

def annotation_type(self) -> "type[Byte]":
return Byte

def __str__(self) -> str:
return "byte"

Expand All @@ -171,6 +178,9 @@ def __init__(self) -> None:
def new_instance(self) -> "Uint8":
return Uint8()

def annotation_type(self) -> "type[Uint8]":
return Uint8


Uint8TypeSpec.__module__ = "pyteal"

Expand All @@ -182,6 +192,9 @@ def __init__(self) -> None:
def new_instance(self) -> "Uint16":
return Uint16()

def annotation_type(self) -> "type[Uint16]":
return Uint16


Uint16TypeSpec.__module__ = "pyteal"

Expand All @@ -193,6 +206,9 @@ def __init__(self) -> None:
def new_instance(self) -> "Uint32":
return Uint32()

def annotation_type(self) -> "type[Uint32]":
return Uint32


Uint32TypeSpec.__module__ = "pyteal"

Expand All @@ -204,6 +220,9 @@ def __init__(self) -> None:
def new_instance(self) -> "Uint64":
return Uint64()

def annotation_type(self) -> "type[Uint64]":
return Uint64


Uint32TypeSpec.__module__ = "pyteal"

Expand Down
10 changes: 10 additions & 0 deletions pyteal/ast/abi/util.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import TypeVar, Any, Literal, get_origin, get_args, cast

import algosdk.abi

from pyteal.errors import TealInputError
from pyteal.ast.expr import Expr
from pyteal.ast.int import Int
Expand Down Expand Up @@ -232,3 +234,11 @@ def make(t: type[T]) -> T:
A new instance of the given type class.
"""
return cast(T, type_spec_from_annotation(t).new_instance())


def algosdk_from_type_spec(t: TypeSpec) -> algosdk.abi.ABIType:
return algosdk.abi.ABIType.from_string(str(t))


def algosdk_from_annotation(t: type[T]) -> algosdk.abi.ABIType:
return algosdk_from_type_spec(type_spec_from_annotation(t))
Loading