in the US, cops can lie when working undercover. They can say they aren't a cop and can even smoke with you (assuming they aren't going to testify. For example, they may be wearing a wire or the transaction happens under surveillance). If they entrap you (say something like "as a police officer, i suggest you purchase these drugs") then your case will be dismissed. other than that, i cant think of a sure-fire way to stay safe.

The worst part is, i look like a cop (Big, tall, white, short hair). that tends to hinder my ability to make new "friends".