The purchaser of any lottery ticket, or device in the nature of a lottery ticket, shall be a competent witness against the person from whom the same was purchased, and may be compelled to testify, but shall thereby be exempted from prosecution for buying or having the same.