This is one of the reasons I hugely support legalized drug testing, and having law enforcement keep out of the way of drug testing orgs, because it's a public health risk.
Reagent testing kits are pretty easy for the individual consumer to buy (legally) and test their substances with before use.
In the UK, the charity The Loop is making great strides with testing and harm-reduction awareness, they've been running stalls at large festivals for a few years now and have a few permanent centers in large cities. When they discover drugs being sold with dangerous adulterants, they make it known on social media, and relay the info to paramedics and welfare. Has definitely saved a few lives!
But you can protect yourself. Whenever you have a new batch of some street drug, you test with a small dose. Maybe 10% of what you'd normally use. If it's too little, test with maybe twice as much. Waiting as appropriate, if tolerance is an issue (as with LSD). And then use what you need, to get the desired effect.
In most cases, bad drugs are either cut way too much, or adulterated with some other drug. But it's pretty rare for someone to be selling outright poison. So maybe an amphetamine in the MDMA or LSD. But nothing that's likely to kill at 10% of a typical dose.
The one key exception is fentanyl. So yes, some idiot may indeed sell you heroin (or even cocaine) containing too much fentanyl. However, you can still protect yourself by initially testing a small dose.
Most open marketplaces on the internet, not just darknet markets, provide reputation systems for this purpose.
Even Amazon has a review and rating system in place, which was integral towards building initial trust with its buyers and sellers.