Skip to content

Commit

Permalink
first set of test, add versioning in multi
Browse files Browse the repository at this point in the history
  • Loading branch information
ahangsu committed Jul 12, 2022
1 parent ff16945 commit c6b4b91
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
20 changes: 19 additions & 1 deletion pyteal/ast/box_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# import pytest
import pytest
import pyteal as pt

teal6Options = pt.CompileOptions(version=6)
teal7Options = pt.CompileOptions(version=7)


def test_compile_version_correct():
TEST_CASES: list[pt.Expr] = [
pt.Box.create(pt.Bytes("box"), pt.Int(10)),
pt.Box.delete(pt.Bytes("box")),
pt.Box.extract(pt.Bytes("box"), pt.Int(2), pt.Int(4)),
pt.Box.replace(pt.Bytes("box"), pt.Int(3), pt.Bytes("replace")),
pt.Box.length(pt.Bytes("box")),
pt.Box.get(pt.Bytes("box")),
pt.Box.put(pt.Bytes("box"), pt.Bytes("goonery")),
]

for test_case in TEST_CASES:
with pytest.raises(pt.TealInputError):
test_case.__teal__(teal6Options)

test_case.__teal__(teal7Options)
9 changes: 8 additions & 1 deletion pyteal/ast/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from pyteal.ast.scratch import ScratchSlot
from pyteal.ast.seq import Seq

from pyteal.errors import TealInputError

if TYPE_CHECKING:
from pyteal.compiler import CompileOptions

Expand All @@ -20,7 +22,7 @@ def __init__(
types: List[TealType],
*,
immediate_args: List[Union[int, str]] = None,
args: List[Expr] = None
args: List[Expr] = None,
):
"""Create a new MultiValue.
Expand Down Expand Up @@ -57,6 +59,11 @@ def __str__(self):
return ret_str

def __teal__(self, options: "CompileOptions"):
if options.version < self.op.min_version:
raise TealInputError(
f"{self.op} not available on teal version {options.version} (first available {self.op.min_version})"
)

tealOp = TealOp(self, self.op, *self.immediate_args)
callStart, callEnd = TealBlock.FromOp(options, tealOp, *self.args)

Expand Down

0 comments on commit c6b4b91

Please sign in to comment.