def test_ReferenceType_decode(): encoded = pt.Bytes("encoded") for value in (abi.Account(), abi.Asset(), abi.Application()): for start_index in (None, pt.Int(1)): for end_index in (None, pt.Int(2)): for length in (None, pt.Int(3)): 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 expected_decoding = value.stored_value.store( pt.GetByte( encoded, start_index if start_index is not None else pt.Int(0), )) expected, _ = expected_decoding.__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_Application_params(): value = abi.Application() params = value.params() assert type(params) is pt.AppParamObject expected = value.referenced_index() actual = params._app with pt.TealComponent.Context.ignoreExprEquality(): assert actual.__teal__(options) == expected.__teal__(options)
def test_ReferenceType_referenced_index(): for value in (abi.Account(), abi.Asset(), abi.Application()): expr = value.referenced_index() assert expr.type_of() == pt.TealType.uint64 assert expr.has_return() is False expected = pt.TealSimpleBlock([ pt.TealOp(expr, pt.Op.load, value.stored_value.slot), ]) actual, _ = expr.__teal__(options) actual.addIncoming() actual = pt.TealBlock.NormalizeBlocks(actual) with pt.TealComponent.Context.ignoreExprEquality(): assert actual == expected
def test_Application_application_id(): value = abi.Application() expr = value.application_id() assert expr.type_of() == pt.TealType.uint64 assert expr.has_return() is False expected = pt.TealSimpleBlock([ pt.TealOp(None, pt.Op.load, value.stored_value.slot), pt.TealOp(None, pt.Op.txnas, "Applications"), ]) actual, _ = expr.__teal__(options) actual.addIncoming() actual = pt.TealBlock.NormalizeBlocks(actual) with pt.TealComponent.Context.ignoreExprEquality(): assert actual == expected
def test_ReferenceType_encode(): for value in (abi.Account(), abi.Asset(), abi.Application()): with pytest.raises(pt.TealInputError, match=r"A ReferenceType cannot be encoded$"): value.encode()
def test_Application_typespec(): assert abi.Application().type_spec() == abi.ApplicationTypeSpec()