コード例 #1
0
def test_for_compiles():
    i = pt.ScratchVar()

    expr = pt.For(i.store(pt.Int(0)), pt.Int(1), i.store(i.load() + pt.Int(1))).Do(
        pt.App.globalPut(pt.Itob(pt.Int(0)), pt.Itob(pt.Int(2)))
    )
    assert expr.type_of() == pt.TealType.none
    assert not expr.has_return()
    expr.__teal__(options)
コード例 #2
0
ファイル: pre_v6_test.py プロジェクト: algorand/pyteal
def logcat(some_bytes, an_int):
    catted = pt.ScratchVar(pt.TealType.bytes)
    return pt.Seq(
        catted.store(pt.Concat(some_bytes, pt.Itob(an_int))),
        pt.Log(catted.load()),
        catted.load(),
    )
コード例 #3
0
def test_for():
    i = pt.ScratchVar()
    items = [
        (i.store(pt.Int(0))),
        i.load() < pt.Int(10),
        i.store(i.load() + pt.Int(1)),
        pt.App.globalPut(pt.Itob(i.load()), i.load() * pt.Int(2)),
    ]
    expr = pt.For(items[0], items[1], items[2]).Do(pt.Seq([items[3]]))

    assert expr.type_of() == pt.TealType.none
    assert not expr.has_return()

    expected, varEnd = items[0].__teal__(options)
    condStart, condEnd = items[1].__teal__(options)
    stepStart, stepEnd = items[2].__teal__(options)
    do, doEnd = pt.Seq([items[3]]).__teal__(options)
    expectedBranch = pt.TealConditionalBlock([])
    end = pt.TealSimpleBlock([])

    varEnd.setNextBlock(condStart)
    doEnd.setNextBlock(stepStart)

    expectedBranch.setTrueBlock(do)
    expectedBranch.setFalseBlock(end)
    condEnd.setNextBlock(expectedBranch)
    stepEnd.setNextBlock(condStart)

    actual, _ = expr.__teal__(options)

    assert actual == expected
コード例 #4
0
ファイル: unaryexpr_test.py プロジェクト: algorand/pyteal
def test_itob():
    arg = pt.Int(1)
    expr = pt.Itob(arg)
    assert expr.type_of() == pt.TealType.bytes

    expected = pt.TealSimpleBlock(
        [pt.TealOp(arg, pt.Op.int, 1), pt.TealOp(expr, pt.Op.itob)]
    )

    actual, _ = expr.__teal__(avm2Options)
    actual.addIncoming()
    actual = pt.TealBlock.NormalizeBlocks(actual)

    assert actual == expected
コード例 #5
0
ファイル: unaryexpr_test.py プロジェクト: algorand/pyteal
def test_itob_invalid():
    with pytest.raises(pt.TealTypeError):
        pt.Itob(pt.Arg(1))
コード例 #6
0
ファイル: subroutine_test.py プロジェクト: algorand/pyteal
 def fn_log_add(a: pt.abi.Uint64, b: pt.abi.Uint32) -> pt.Expr:
     return pt.Seq(pt.Log(pt.Itob(a.get() + b.get())), pt.Return())
コード例 #7
0
ファイル: router_test.py プロジェクト: algorand/pyteal
def mult_over_u64_and_log(a: pt.Expr, b: pt.Expr):
    return pt.Log(pt.Itob(a * b))
コード例 #8
0
def lots_o_vars():
    z = pt.Int(0)
    one = pt.ScratchVar()
    two = pt.ScratchVar()
    three = pt.ScratchVar()
    four = pt.ScratchVar()
    five = pt.Bytes("five")
    six = pt.Bytes("six")
    seven = pt.Bytes("seven")
    eight = pt.Bytes("eight")
    nine = pt.Bytes("nine")
    ten = pt.Bytes("ten")
    eleven = pt.Bytes("eleven")
    twelve = pt.Bytes("twelve")
    int_cursor = pt.DynamicScratchVar(pt.TealType.uint64)
    bytes_cursor = pt.DynamicScratchVar(pt.TealType.bytes)
    thirteen = pt.ScratchVar(pt.TealType.uint64, 13)
    fourteen = pt.ScratchVar(pt.TealType.bytes, 14)
    fifteen = pt.ScratchVar(pt.TealType.uint64)
    sixteen = pt.ScratchVar(pt.TealType.bytes)
    leet = pt.Int(1337)
    ngl = pt.Bytes("NGL: ")
    return (pt.If(
        pt.Or(pt.App.id() == pt.Int(0),
              pt.Txn.application_args.length() == pt.Int(0))).Then(
                  pt.Int(1)).Else(
                      pt.Seq(
                          one.store(pt.Int(1)),
                          two.store(pt.Bytes("two")),
                          three.store(pt.Int(3)),
                          four.store(pt.Bytes("four")),
                          pt.App.localPut(z, five, pt.Int(5)),
                          pt.App.localPut(z, six, six),
                          pt.App.localPut(z, seven, pt.Int(7)),
                          pt.App.localPut(z, eight, eight),
                          pt.App.globalPut(nine, pt.Int(9)),
                          pt.App.globalPut(ten, ten),
                          pt.App.globalPut(eleven, pt.Int(11)),
                          pt.App.globalPut(twelve, twelve),
                          one.store(one.load() + leet),
                          two.store(pt.Concat(ngl, two.load())),
                          three.store(three.load() + leet),
                          four.store(pt.Concat(ngl, four.load())),
                          pt.App.localPut(z, five,
                                          leet + pt.App.localGet(z, five)),
                          pt.App.localPut(
                              z, six, pt.Concat(ngl, pt.App.localGet(z, six))),
                          pt.App.localPut(z, seven, pt.App.localGet(z, seven)),
                          pt.App.localPut(
                              z, eight,
                              pt.Concat(ngl, pt.App.localGet(z, eight))),
                          pt.App.globalPut(nine,
                                           leet + pt.App.globalGet(nine)),
                          pt.App.globalPut(
                              ten, pt.Concat(ngl, pt.App.globalGet(ten))),
                          pt.App.globalPut(eleven,
                                           leet + pt.App.globalGet(eleven)),
                          pt.App.globalPut(
                              twelve, pt.Concat(ngl,
                                                pt.App.globalGet(twelve))),
                          thirteen.store(pt.Btoi(pt.Txn.application_args[0])),
                          fourteen.store(pt.Txn.application_args[1]),
                          fifteen.store(pt.Btoi(pt.Txn.application_args[2])),
                          sixteen.store(pt.Txn.application_args[3]),
                          pt.Pop(one.load()),
                          pt.Pop(two.load()),
                          pt.Pop(three.load()),
                          pt.Pop(four.load()),
                          pt.Pop(pt.App.localGet(z, five)),
                          pt.Pop(pt.App.localGet(z, six)),
                          pt.Pop(pt.App.localGet(z, seven)),
                          pt.Pop(pt.App.localGet(z, eight)),
                          pt.Pop(pt.App.globalGet(nine)),
                          pt.Pop(pt.App.globalGet(ten)),
                          pt.Pop(pt.App.globalGet(eleven)),
                          pt.Pop(pt.App.globalGet(twelve)),
                          int_cursor.set_index(thirteen),
                          pt.Log(pt.Itob(int_cursor.load())),
                          bytes_cursor.set_index(fourteen),
                          pt.Log(bytes_cursor.load()),
                          int_cursor.set_index(fifteen),
                          pt.Log(pt.Itob(int_cursor.load())),
                          bytes_cursor.set_index(sixteen),
                          pt.Log(bytes_cursor.load()),
                          leet,
                      )))
コード例 #9
0
def mixed_annotations(x: pt.Expr, y: pt.Expr, z: pt.ScratchVar) -> pt.Expr:
    return pt.Seq(
        z.store(x),
        pt.Log(pt.Concat(y, pt.Bytes("="), pt.Itob(x))),
        x,
    )
コード例 #10
0
def logcat_dynamic(first: pt.ScratchVar, an_int):
    return pt.Seq(
        first.store(pt.Concat(first.load(), pt.Itob(an_int))),
        pt.Log(first.load()),
    )
コード例 #11
0
     maxValue=2**8 - 1,
     checkUpperBound=True,
     expectedDecoding=lambda encoded, start_index, end_index, length: pt.
     GetByte(encoded, noneToInt0(start_index)),
     expectedEncoding=lambda uintType: pt.SetByte(pt.Bytes(
         b"\x00"), pt.Int(0), uintType.get()),
 ),
 UintTestData(
     uintType=abi.Uint16TypeSpec(),
     instanceType=abi.Uint16,
     expectedBits=16,
     maxValue=2**16 - 1,
     checkUpperBound=True,
     expectedDecoding=lambda encoded, start_index, end_index, length: pt.
     ExtractUint16(encoded, noneToInt0(start_index)),
     expectedEncoding=lambda uintType: pt.Suffix(pt.Itob(uintType.get()),
                                                 pt.Int(6)),
 ),
 UintTestData(
     uintType=abi.Uint32TypeSpec(),
     instanceType=abi.Uint32,
     expectedBits=32,
     maxValue=2**32 - 1,
     checkUpperBound=True,
     expectedDecoding=lambda encoded, start_index, end_index, length: pt.
     ExtractUint32(encoded, noneToInt0(start_index)),
     expectedEncoding=lambda uintType: pt.Suffix(pt.Itob(uintType.get()),
                                                 pt.Int(4)),
 ),
 UintTestData(
     uintType=abi.Uint64TypeSpec(),