예제 #1
0
def test_err():
    expr = pt.Err()
    assert expr.type_of() == pt.TealType.none
    assert expr.has_return()
    expected = pt.TealSimpleBlock([pt.TealOp(expr, pt.Op.err)])
    actual, _ = expr.__teal__(pt.CompileOptions())
    assert actual == expected
예제 #2
0
def test_cond_two_pred():
    expr = pt.Cond([pt.Int(1), pt.Bytes("one")], [pt.Int(0), pt.Bytes("zero")])
    assert expr.type_of() == pt.TealType.bytes

    cond1, _ = pt.Int(1).__teal__(options)
    pred1, _ = pt.Bytes("one").__teal__(options)
    cond1Branch = pt.TealConditionalBlock([])
    cond2, _ = pt.Int(0).__teal__(options)
    pred2, _ = pt.Bytes("zero").__teal__(options)
    cond2Branch = pt.TealConditionalBlock([])
    end = pt.TealSimpleBlock([])

    cond1.setNextBlock(cond1Branch)
    cond1Branch.setTrueBlock(pred1)
    cond1Branch.setFalseBlock(cond2)
    pred1.setNextBlock(end)

    cond2.setNextBlock(cond2Branch)
    cond2Branch.setTrueBlock(pred2)
    cond2Branch.setFalseBlock(pt.Err().__teal__(options)[0])
    pred2.setNextBlock(end)

    expected = cond1

    actual, _ = expr.__teal__(options)

    with pt.TealComponent.Context.ignoreExprEquality():
        assert actual == expected
예제 #3
0
def test_teal_2_assert():
    arg = pt.Int(1)
    expr = pt.Assert(arg)
    assert expr.type_of() == pt.TealType.none

    expected, _ = arg.__teal__(avm2Options)
    expectedBranch = pt.TealConditionalBlock([])
    expectedBranch.setTrueBlock(pt.TealSimpleBlock([]))
    expectedBranch.setFalseBlock(pt.Err().__teal__(avm2Options)[0])
    expected.setNextBlock(expectedBranch)

    actual, _ = expr.__teal__(avm2Options)

    with pt.TealComponent.Context.ignoreExprEquality():
        assert actual == expected
예제 #4
0
def test_cond_one_pred():
    expr = pt.Cond([pt.Int(1), pt.Int(2)])
    assert expr.type_of() == pt.TealType.uint64

    cond1, _ = pt.Int(1).__teal__(options)
    pred1, _ = pt.Int(2).__teal__(options)
    cond1Branch = pt.TealConditionalBlock([])
    cond1.setNextBlock(cond1Branch)
    cond1Branch.setTrueBlock(pred1)
    cond1Branch.setFalseBlock(pt.Err().__teal__(options)[0])
    pred1.setNextBlock(pt.TealSimpleBlock([]))
    expected = cond1

    actual, _ = expr.__teal__(options)

    with pt.TealComponent.Context.ignoreExprEquality():
        assert actual == expected
예제 #5
0
def test_cond_two_pred_multi():
    args = [
        pt.Int(1),
        [pt.Pop(pt.Int(1)), pt.Bytes("one")],
        pt.Int(0),
        [pt.Pop(pt.Int(2)), pt.Bytes("zero")],
    ]
    expr = pt.Cond(
        [args[0]] + args[1],
        [args[2]] + args[3],
    )
    assert expr.type_of() == pt.TealType.bytes

    cond1, _ = args[0].__teal__(options)
    pred1, pred1End = pt.Seq(args[1]).__teal__(options)
    cond1Branch = pt.TealConditionalBlock([])
    cond2, _ = args[2].__teal__(options)
    pred2, pred2End = pt.Seq(args[3]).__teal__(options)
    cond2Branch = pt.TealConditionalBlock([])
    end = pt.TealSimpleBlock([])

    cond1.setNextBlock(cond1Branch)
    cond1Branch.setTrueBlock(pred1)
    cond1Branch.setFalseBlock(cond2)
    pred1End.setNextBlock(end)

    cond2.setNextBlock(cond2Branch)
    cond2Branch.setTrueBlock(pred2)
    cond2Branch.setFalseBlock(pt.Err().__teal__(options)[0])
    pred2End.setNextBlock(end)

    expected = cond1

    actual, _ = expr.__teal__(options)

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