They would have known immediately. The addictive properties of morphine and opium were well known and documented at the time of the discovery of Heroin. Heroin (Diacetyl-Morphine Hydrochloride) was just a new variation of Morphine. It was synthesized in 1874 and commercialized by Bayer some 25 years later.
Take this quote from the nineteenth edition of the "Squire's companion to the latest edition of the British Pharma-copoeia" (A Phamacist's handbook written in 1906). It is particularly damning.
"Medicinal Properties.— Introduced as a substitute for Morphine, it being stated to possess the advantages of not causing constipation and of being active in much smaller doses. Very useful in acute and chronic bronchitis, bronchial astluna, the cough of phthisis, in acute pneumonia and in pertussis.
Has been recommended in the treatment of the Morphia habit, but its use is deprecated on the ground that the craving following its use is infinitely more unmanageable than is that of Morphine."
People weren't stupid, they knew exactly how addictive ti was.
Standard disclaimer -- not an historian, but I'm a doctor who runs a medical history podcast. I recently did an episode on the first opiate epidemic in the United States (with the pertinent parallels to today), and I highly recommend Dark Paradise by the historian David Courtwright, which is my source for most of this.
Heroin (diacetylmorphine), as u/sociojoe pointed out, was first synthesized in the late nineteenth century, and then marketed by Bayer in the early 1900s as a cough suppressant (as in this remarkable advertisement from ~1903-1904). When heroin hit the scene, the United States and the Europe were in the midst of an epidemic of opiate addiction, with estimated levels of addiction similar to today. Doctors by this time were leading the charge to limit opiate prescription (morphine was most commonly abused) on the state level, and this would be codified into federal law with the Harrison Narcotics Act in 1914. And physician opposition to heroin was strong -- the American Medical Association actually released a statement calling for its ban. Because of this, heroin never really caught on, and was an infrequently used drug until the 1930s, when it became the preferred drug for illicit opiate use because of its ease of transport as well as relative simplicity to "cut" and dilute the substance.
So basically, the addictive properties of heroin were immediately known. The more interesting story, I think, is how doctors discovered that opium and the class of opiates were addictive, how their prescribing got out of hand, and how this was finally curtailed in the early 20th century. I find it especially interesting because it has HUGE parallels to our modern opiate epidemic in North America, and some of the implications for this epidemic are rather unpleasant.
Further reading: