First off - as I've said before - I'm not a lawyer nor do I play one on the internet. If you're really concerned about a legal matter you should consult a real lawyer.
That said, if someone was arrested and charged with selling drugs to an undercover officer it would be up to the person...