Skip to content

Commit

Permalink
Added test for dumpprivkey and fix bug with dumpprivkey #48
Browse files Browse the repository at this point in the history
  • Loading branch information
meyer9 committed Jul 4, 2018
1 parent ecb377c commit aa4a67c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
16 changes: 10 additions & 6 deletions src/rpcdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,20 +402,24 @@ UniValue dumpprivkey(const UniValue& params, bool fHelp)
"1. \"phoreaddress\" (string, required) The phore address for the private key\n"
"\nResult:\n"
"\"key\" (string) The private key\n"
"\nExamples:\n" +
HelpExampleCli("dumpprivkey", "\"myaddress\"") + HelpExampleCli("importprivkey", "\"mykey\"") + HelpExampleRpc("dumpprivkey", "\"myaddress\""));
"\nExamples:\n"
+ HelpExampleCli("dumpprivkey", "\"myaddress\"")
+ HelpExampleCli("importprivkey", "\"mykey\"")
+ HelpExampleRpc("dumpprivkey", "\"myaddress\"")
);

LOCK2(cs_main, pwalletMain->cs_wallet);

EnsureWalletIsUnlocked();

string strAddress = params[0].get_str();
if (!IsValidDestinationString(strAddress))
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Phore address");
CTxDestination address = DecodeDestination(strAddress);
CKeyID keyid = GetKeyForDestination(*pwalletMain, address);
if (!keyid.IsNull())
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");
const CTxDestination dest = DecodeDestination(strAddress);
auto keyid = GetKeyForDestination(*pwalletMain, dest);
if (keyid.IsNull()) {
throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to a key");
}
CKey vchSecret;
if (!pwalletMain->GetKey(keyid, vchSecret))
throw JSONRPCError(RPC_WALLET_ERROR, "Private key for address " + strAddress + " is not known");
Expand Down
6 changes: 3 additions & 3 deletions test/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ def test_wallet_tutorial(self):
self.sync_all()

assert_equal(self.nodes[0].getbalance(), 0)
#print(self.nodes[2].getbalance("from1"))
#assert_equal(self.nodes[2].getbalance(), 5701)
#assert_equal(self.nodes[2].getbalance("from1"), 17501798)

# Test basic functionality of dumpprivkey
self.nodes[0].dumpprivkey(self.nodes[0].getnewaddress())


if __name__ == '__main__':
Expand Down

0 comments on commit aa4a67c

Please sign in to comment.