Implementing unit tests from bitcoind key_tests.cpp