No person shall be excused from attending and testifying before a grand jury, or before any court, or in any cause or proceeding, criminal or otherwise based upon or growing out of any alleged violation of the provisions of law as to gambling or gaming, or as to operating a bucket-shop, or the dealing in contracts commonly called “futures,” of which he shall have knowledge, on the ground or for the reason that the testimony or evidence, documentary or otherwise, required of him may tend to criminate him or subject him to a penalty or forfeiture. But no person shall be prosecuted or subject to any penalty or forfeiture for or on account of any transaction, matter or thing, concerning which he may testify or produce evidence, documentary or otherwise, before the grand jury or any court; provided, that no person so testifying shall be exempt from prosecution or punishment for perjury in so testifying. Any person who shall neglect or refuse to so attend or testify, or to answer any lawful inquiry, or to produce books or other documentary evidence, if in his power to do so, shall be guilty of a misdemeanor, and, upon conviction thereof, shall be punished by a fine of not less than one hundred dollars or more than five hundred dollars, or by imprisonment for not more than ninety days, or by both such fine and imprisonment.