Пример #1
0
def test_replace_stack_not_int():
    my_string = "*" * 257
    add = pt.Add(pt.Int(254), pt.Int(2))
    args = [pt.Bytes(my_string), add, pt.Bytes("ab")]
    expr = pt.Replace(args[0], args[1], args[2])
    assert expr.type_of() == pt.TealType.bytes

    expected = pt.TealSimpleBlock([
        pt.TealOp(args[0], pt.Op.byte,
                  '"{my_string}"'.format(my_string=my_string)),
        pt.TealOp(pt.Int(254), pt.Op.int, 254),
        pt.TealOp(pt.Int(2), pt.Op.int, 2),
        pt.TealOp(add, pt.Op.add),
        pt.TealOp(args[2], pt.Op.byte, '"ab"'),
        pt.TealOp(expr, pt.Op.replace3),
    ])

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

    with pt.TealComponent.Context.ignoreExprEquality():
        assert actual == expected

    with pytest.raises(pt.TealInputError):
        expr.__teal__(avm6Options)
Пример #2
0
def test_pragma_expr_does_not_change():
    without_pragma = pt.Seq(pt.Pop(pt.Add(pt.Int(1), pt.Int(2))),
                            pt.Return(pt.Int(1)))
    pragma = pt.Pragma(without_pragma, compiler_version=">=0.0.0")

    compiled_with_pragma = pt.compileTeal(pragma,
                                          mode=pt.Mode.Application,
                                          version=6)
    compiled_without_pragma = pt.compileTeal(without_pragma,
                                             mode=pt.Mode.Application,
                                             version=6)

    assert compiled_with_pragma == compiled_without_pragma
Пример #3
0
def test_add():
    args = [pt.Int(2), pt.Int(3)]
    expr = pt.Add(args[0], args[1])
    assert expr.type_of() == pt.TealType.uint64

    expected = pt.TealSimpleBlock([
        pt.TealOp(args[0], pt.Op.int, 2),
        pt.TealOp(args[1], pt.Op.int, 3),
        pt.TealOp(expr, pt.Op.add),
    ])

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

    assert actual == expected
Пример #4
0
def test_endArg_not_int(op: pt.Op):
    my_string = "*" * 257
    add = pt.Add(pt.Int(254), pt.Int(3))
    args = [pt.Bytes(my_string), pt.Int(256), add]

    def generate_expr() -> pt.Expr:
        match op:
            case pt.Op.extract3:
                return pt.Extract(args[0], args[1], args[2])
            case pt.Op.substring3:
                return pt.Substring(args[0], args[1], args[2])
            case _:
                raise Exception(f"Unsupported {op=}")

    expr = generate_expr()
    assert expr.type_of() == pt.TealType.bytes

    expected = pt.TealSimpleBlock(
        [
            pt.TealOp(args[0], pt.Op.byte, '"{my_string}"'.format(my_string=my_string)),
            pt.TealOp(args[1], pt.Op.int, 256),
            pt.TealOp(pt.Int(254), pt.Op.int, 254),
            pt.TealOp(pt.Int(3), pt.Op.int, 3),
            pt.TealOp(add, pt.Op.add),
            pt.TealOp(None, op),
        ]
    )

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

    with pt.TealComponent.Context.ignoreExprEquality():
        assert actual == expected

    if op == pt.Op.extract3:
        with pytest.raises(pt.TealInputError):
            expr.__teal__(avm4Options)
Пример #5
0
def test_add_invalid():
    with pytest.raises(pt.TealTypeError):
        pt.Add(pt.Int(2), pt.Txn.receiver())

    with pytest.raises(pt.TealTypeError):
        pt.Add(pt.Txn.sender(), pt.Int(2))