Пример #1
0
def test_StringTypeSpec_eq():
    assert abi.StringTypeSpec() == abi.StringTypeSpec()

    for otherType in (
            abi.ByteTypeSpec(),
            abi.StaticArrayTypeSpec(abi.ByteTypeSpec(), 1),
            abi.DynamicArrayTypeSpec(abi.Uint8TypeSpec()),
            abi.DynamicArrayTypeSpec(abi.ByteTypeSpec()),
    ):
        assert abi.StringTypeSpec() != otherType
Пример #2
0
def test_DynamicArray_decode():
    encoded = pt.Bytes("encoded")
    stringType = abi.StringTypeSpec()
    for start_index in (None, pt.Int(1)):
        for end_index in (None, pt.Int(2)):
            for length in (None, pt.Int(3)):
                value = stringType.new_instance()

                if end_index is not None and length is not None:
                    with pytest.raises(pt.TealInputError):
                        value.decode(
                            encoded,
                            start_index=start_index,
                            end_index=end_index,
                            length=length,
                        )
                    continue

                expr = value.decode(encoded,
                                    start_index=start_index,
                                    end_index=end_index,
                                    length=length)
                assert expr.type_of() == pt.TealType.none
                assert expr.has_return() is False

                expectedExpr = value.stored_value.store(
                    substring_for_decoding(
                        encoded,
                        start_index=start_index,
                        end_index=end_index,
                        length=length,
                    ))
                expected, _ = expectedExpr.__teal__(options)
                expected.addIncoming()
                expected = pt.TealBlock.NormalizeBlocks(expected)

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

                with pt.TealComponent.Context.ignoreExprEquality():
                    assert actual == expected
Пример #3
0
def test_String_set_computed():
    bv = pt.Bytes("base16", "0x0004DEADBEEF")
    computed_value = ContainerType(abi.StringTypeSpec(), bv)

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

    _, byte_ops = bv.__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)))
Пример #4
0
def test_StringTypeSpec_new_instance():
    assert isinstance(abi.StringTypeSpec().new_instance(), abi.String)
Пример #5
0
def test_StringTypeSpec_is_dynamic():
    assert (abi.StringTypeSpec()).is_dynamic()
Пример #6
0
def test_StringTypeSpec_str():
    assert str(abi.StringTypeSpec()) == "string"