Пример #1
0
def string_mult():
    s = pt.ScratchVar(pt.TealType.bytes)
    return pt.Seq(
        s.store(pt.Txn.application_args[0]),
        subr_string_mult(s, pt.Btoi(pt.Txn.application_args[1])),
        pt.Log(s.load()),
        pt.Int(100),
    )
Пример #2
0
def tallygo():
    result = pt.ScratchVar(pt.TealType.bytes)
    # pt.If-Then is a hook for creating + opting in without providing any args
    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(
                          result.store(pt.Bytes("dummy")),
                          tally(pt.Int(4), result),
                          pt.Btoi(result.load()),
                      )))
Пример #3
0
def fac_by_ref_args():
    n = pt.ScratchVar(pt.TealType.uint64)
    return pt.Seq(
        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(
                    n.store(pt.Btoi(pt.Txn.application_args[0])),
                    factorial(n),
                    n.load(),
                )))
Пример #4
0
def test_btoi():
    arg = pt.Arg(1)
    expr = pt.Btoi(arg)
    assert expr.type_of() == pt.TealType.uint64

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

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

    assert actual == expected
Пример #5
0
def test_btoi_invalid():
    with pytest.raises(pt.TealTypeError):
        pt.Btoi(pt.Int(1))
Пример #6
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,
                      )))