aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2018-11-27 13:54:16 -0500
committerMarcoFalke <falke.marco@gmail.com>2018-11-27 13:54:23 -0500
commit8c119b27551f56db72bfbdb9ed632b4deb19e161 (patch)
tree740630916bbe77c4de283d6a1d06d4e60c2ad39a /src/wallet
parentd49103007676b4b857c6c643bad071e1a7305420 (diff)
parentfa739d4bd735c21bc530f97272007e8695cb0ba3 (diff)
Merge #14813: qa: Add wallet_encryption error tests
fa739d4bd7 qa: Add wallet_encryption error tests (MarcoFalke) Pull request description: The errors for empty passphrases are the help text of the RPC call, which is not very specific. Replace that with proper RPC errors and test them. Tree-SHA512: 3137e0f8f2e42a1f8ab1eeb57c99052557725f6f85139ff48c24acc8f3cf4087802de5216f3ce97375b291d21bddb7cd1379a6f280166136a306a0c9663bbd42
Diffstat (limited to 'src/wallet')
-rw-r--r--src/wallet/rpcwallet.cpp43
1 files changed, 12 insertions, 31 deletions
diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp
index ecc8fa2643..d4806b4c6b 100644
--- a/src/wallet/rpcwallet.cpp
+++ b/src/wallet/rpcwallet.cpp
@@ -2009,21 +2009,13 @@ static UniValue walletpassphrase(const JSONRPCRequest& request)
nSleepTime = MAX_SLEEP_TIME;
}
- if (strWalletPass.length() > 0)
- {
- if (!pwallet->Unlock(strWalletPass)) {
- throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect.");
- }
+ if (strWalletPass.empty()) {
+ throw JSONRPCError(RPC_INVALID_PARAMETER, "passphrase can not be empty");
+ }
+
+ if (!pwallet->Unlock(strWalletPass)) {
+ throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect.");
}
- else
- throw std::runtime_error(
- RPCHelpMan{"walletpassphrase",
- "Stores the wallet decryption key in memory for <timeout> seconds.",
- {
- {"passphrase", RPCArg::Type::STR, false},
- {"timeout", RPCArg::Type::NUM, false},
- }}
- .ToString());
pwallet->TopUpKeyPool();
@@ -2089,15 +2081,9 @@ static UniValue walletpassphrasechange(const JSONRPCRequest& request)
strNewWalletPass.reserve(100);
strNewWalletPass = request.params[1].get_str().c_str();
- if (strOldWalletPass.length() < 1 || strNewWalletPass.length() < 1)
- throw std::runtime_error(
- RPCHelpMan{"walletpassphrasechange",
- "Changes the wallet passphrase from <oldpassphrase> to <newpassphrase>.",
- {
- {"oldpassphrase", RPCArg::Type::STR, false},
- {"newpassphrase", RPCArg::Type::STR, false},
- }}
- .ToString());
+ if (strOldWalletPass.empty() || strNewWalletPass.empty()) {
+ throw JSONRPCError(RPC_INVALID_PARAMETER, "passphrase can not be empty");
+ }
if (!pwallet->ChangeWalletPassphrase(strOldWalletPass, strNewWalletPass)) {
throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect.");
@@ -2200,14 +2186,9 @@ static UniValue encryptwallet(const JSONRPCRequest& request)
strWalletPass.reserve(100);
strWalletPass = request.params[0].get_str().c_str();
- if (strWalletPass.length() < 1)
- throw std::runtime_error(
- RPCHelpMan{"encryptwallet",
- "Encrypts the wallet with <passphrase>.",
- {
- {"passphrase", RPCArg::Type::STR, false},
- }}
- .ToString());
+ if (strWalletPass.empty()) {
+ throw JSONRPCError(RPC_INVALID_PARAMETER, "passphrase can not be empty");
+ }
if (!pwallet->EncryptWallet(strWalletPass)) {
throw JSONRPCError(RPC_WALLET_ENCRYPTION_FAILED, "Error: Failed to encrypt the wallet.");