예제 #1
0
def test_addr_invalid():
    with pytest.raises(pt.TealInputError):
        pt.Addr("NJUWK3DJNZTWU2LFNRUW4Z3KNFSWY2LOM5VGSZLMNFXGO2TJMVWGS3TH")

    with pytest.raises(pt.TealInputError):
        pt.Addr("000000000000000000000000000000000000000000000000000000000")

    with pytest.raises(pt.TealInputError):
        pt.Addr(2)
예제 #2
0
def test_Asset_holding():
    value = abi.Asset()

    accounts = (
        (pt.Int(6), pt.Int(6)),
        (
            pt.Addr(
                "QSA6K5MNJPEGO5SDSWXBM3K4UEI3Q2NCPS2OUXVJI5QPCHMVI27MFRSHKI"),
            pt.Addr(
                "QSA6K5MNJPEGO5SDSWXBM3K4UEI3Q2NCPS2OUXVJI5QPCHMVI27MFRSHKI"),
        ),
        (a := abi.Account(), a.referenced_index()),
    )
예제 #3
0
def test_addr():
    expr = pt.Addr("NJUWK3DJNZTWU2LFNRUW4Z3KNFSWY2LOM5VGSZLMNFXGO2TJMVWGS3THMF")
    assert expr.type_of() == pt.TealType.bytes
    expected = pt.TealSimpleBlock(
        [
            pt.TealOp(
                expr,
                pt.Op.addr,
                "NJUWK3DJNZTWU2LFNRUW4Z3KNFSWY2LOM5VGSZLMNFXGO2TJMVWGS3THMF",
            )
        ]
    )
    actual, _ = expr.__teal__(pt.CompileOptions())
    assert actual == expected
예제 #4
0
def test_AssetHoldingObject():
    for asset in (pt.Int(1), pt.Int(100)):
        for account in (
                pt.Int(7),
                pt.Addr(
                    "QSA6K5MNJPEGO5SDSWXBM3K4UEI3Q2NCPS2OUXVJI5QPCHMVI27MFRSHKI"
                ),
        ):
            obj = pt.AssetHoldingObject(asset, account)

            assert obj._asset is asset
            assert obj._account is account

            assert_MaybeValue_equality(obj.balance(),
                                       pt.AssetHolding.balance(account, asset),
                                       avm5Options)
            assert_MaybeValue_equality(obj.frozen(),
                                       pt.AssetHolding.frozen(account, asset),
                                       avm5Options)
예제 #5
0
def test_AccountParamObject():
    for account in (
            pt.Int(7),
            pt.Addr(
                "QSA6K5MNJPEGO5SDSWXBM3K4UEI3Q2NCPS2OUXVJI5QPCHMVI27MFRSHKI"),
    ):
        obj = pt.AccountParamObject(account)

        assert obj._account is account

        assert_MaybeValue_equality(obj.balance(),
                                   pt.AccountParam.balance(account),
                                   avm6Options)
        assert_MaybeValue_equality(obj.min_balance(),
                                   pt.AccountParam.minBalance(account),
                                   avm6Options)
        assert_MaybeValue_equality(obj.auth_address(),
                                   pt.AccountParam.authAddr(account),
                                   avm6Options)
예제 #6
0
def test_Address_set_computed():
    av = pt.Addr("MDDKJUCTY57KA2PBFI44CLTJ5YHY5YVS4SVQUPZAWSRV2ZAVFKI33O6YPE")
    computed_value = ContainerType(abi.AddressTypeSpec(), av)

    value = abi.Address()
    expr = value.set(computed_value)
    assert expr.type_of() == pt.TealType.none
    assert not expr.has_return()

    _, byte_ops = av.__teal__(options)
    expected = pt.TealSimpleBlock([
        byte_ops.ops[0],
        pt.TealOp(None, pt.Op.store, value.stored_value.slot),
    ])

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

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

    with pytest.raises(pt.TealInputError):
        value.set(ContainerType(abi.ByteTypeSpec(), pt.Int(0x01)))