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 d00e26c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
27 changes: 26 additions & 1 deletion pyteal/ast/box_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
# import pytest
import pytest
import pyteal as pt

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


def test_compile_version_correct():
with pytest.raises(pt.TealInputError):
pt.Box.create(pt.Bytes("box"), pt.Int(10)).__teal__(teal6Options)

with pytest.raises(pt.TealInputError):
pt.Box.delete(pt.Bytes("box")).__teal__(teal6Options)

with pytest.raises(pt.TealInputError):
pt.Box.extract(pt.Bytes("box"), pt.Int(2), pt.Int(4)).__teal__(teal6Options)

with pytest.raises(pt.TealInputError):
pt.Box.replace(pt.Bytes("box"), pt.Int(3), pt.Bytes("replace")).__teal__(
teal6Options
)

with pytest.raises(pt.TealInputError):
pt.Box.length(pt.Bytes("box")).__teal__(teal6Options)

with pytest.raises(pt.TealInputError):
pt.Box.get(pt.Bytes("box")).__teal__(teal6Options)

with pytest.raises(pt.TealInputError):
pt.Box.put(pt.Bytes("box"), pt.Bytes("goonery")).__teal__(teal6Options)
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 d00e26c

Please sign in to comment.