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
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
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)))
def test_StringTypeSpec_new_instance(): assert isinstance(abi.StringTypeSpec().new_instance(), abi.String)
def test_StringTypeSpec_is_dynamic(): assert (abi.StringTypeSpec()).is_dynamic()
def test_StringTypeSpec_str(): assert str(abi.StringTypeSpec()) == "string"