Add inverse modulo test. Includes some test code from the wallet2.0 branch to make future merges easier.