Your explanation (that “the drugs bind to the opiod receptors in the brain and block the pain signals,”) is approximately correct as far as it goes. Opioids are a class of neuroactive chemicals which couple with G protein–coupled receptors (GPCR), creating a sense of well-being in the patient and dulling the perception of pain. They don’t literally block the nerve signals that cause pain but rather overwhelm the neural response to pain in the parietal lobe and in the autonomous nervous system. Under the influence of opioids or opiates you will still sense pain, but it is dulled to the degree that it can be endured. Unfortunately, there are similar receptors in other parts of the brain involved in perception and processing, the parasympathetic nervous system, and even the enteric nervous system (the interconnected set of neurons in the intestinal lining that control the autonomous response of the intestine to digestive action); hence, the consumption of opioids and opiates results in altered or dulled perception, difficulties with coordination, and constipation due to poor digestive action. There is considerable work going into targeted analgesics which can operate only on specific parts of the brain but the lack of distinction between brain cells and other cells in the nervous systems makes this very challenging, and perhaps even impossible with conventional pharmaceutical approaches.
How do scientists know how these drugs work? There are a variety of methods that can be used to measure the action and response of neuroactive chemicals but the primary mechanisms in human subjects use radioisotope trackers (radioactive isotopes that are bound into proteins, usually replacing some chemically similar element). This allows scientists to track the movement and uptake of these chemicals to the specific part of the brain which can be correlated to behavioral response; however, to “directly” observe the action, they actually need to isolate specific receptor sites. Fortunately, these receptors are similar across all neural tissue in vertebrates (and for some, even in invertebrate brains) and the response can be studied in situ using animal subjects. The change in potentiation of the individual neuron is measured with the introduction of a specific agonist which lets neurologists evaluate the action and effect of the chemical.
By the way, this is very complex, laborious, and error-generating work that has requirs enormous effort and time to perform, notwithstanding the essentially difficulty in working with live subjects which have to be fed and cared for even as they are being vivisectioned and implanted with sensors. However you feel about the ethics of medical experimentation on animals, without this practical application what we currently understand about neural behavior and operation would be manifestly reduced, and our ability to develop and synthesize many pharmaceuticals (and especially those involved in regulation or modification of brain function) would be essentially none without it. That being said, the scientists who do this work would welcome computational models which could substitute for animal experimentation en masse if that capability existed for both practical and emotional reasons. Unfortunately, our understanding of even how single neurons and receptors function, much less the complex interconnections of how even localized parts of the brain function, is still well beyond the state of the art in computational neurochemistry to predict.