aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Newbery <john@johnnewbery.com>2017-02-09 16:27:28 -0500
committerJohn Newbery <john@johnnewbery.com>2017-03-07 16:45:09 -0500
commit960bc7f778d8dd618e65f1e37ec734e2d4734051 (patch)
tree016914cfdb765f2fbaf5a2dabed94235c897854b
parentc1190963b388590dc0a346bf625c7e84f69cee8d (diff)
downloadbitcoin-960bc7f778d8dd618e65f1e37ec734e2d4734051.tar.xz
Return correct error codes in removeprunedfunds().
The removeprunedfunds() RPC was returning misleading or incorrect error codes (for example RPC_INTERNAL_ERROR when the transaction was not found in the wallet). This commit fixes those error codes: - RPC_INTERNAL_ERROR should not be returned for application-level errors, only for genuine internal errors such as corrupted data. This error code has been replaced with RPC_WALLET_ERROR. This commit also updates the test cases to explicitly test the error code.
-rwxr-xr-xqa/rpc-tests/importprunedfunds.py14
-rw-r--r--src/wallet/rpcdump.cpp4
2 files changed, 4 insertions, 14 deletions
diff --git a/qa/rpc-tests/importprunedfunds.py b/qa/rpc-tests/importprunedfunds.py
index a941124656..4e529951ed 100755
--- a/qa/rpc-tests/importprunedfunds.py
+++ b/qa/rpc-tests/importprunedfunds.py
@@ -76,12 +76,7 @@ class ImportPrunedFundsTest(BitcoinTestFramework):
self.sync_all()
#Import with no affiliated address
- try:
- self.nodes[1].importprunedfunds(rawtxn1, proof1)
- except JSONRPCException as e:
- assert('No addresses' in e.error['message'])
- else:
- assert(False)
+ assert_raises_jsonrpc(-5, "No addresses", self.nodes[1].importprunedfunds, rawtxn1, proof1)
balance1 = self.nodes[1].getbalance("", 0, True)
assert_equal(balance1, Decimal(0))
@@ -112,12 +107,7 @@ class ImportPrunedFundsTest(BitcoinTestFramework):
assert_equal(address_info['ismine'], True)
#Remove transactions
- try:
- self.nodes[1].removeprunedfunds(txnid1)
- except JSONRPCException as e:
- assert('does not exist' in e.error['message'])
- else:
- assert(False)
+ assert_raises_jsonrpc(-8, "Transaction does not exist in wallet.", self.nodes[1].removeprunedfunds, txnid1)
balance1 = self.nodes[1].getbalance("*", 0, True)
assert_equal(balance1, Decimal('0.075'))
diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp
index e02c6513e4..ad5ecf4976 100644
--- a/src/wallet/rpcdump.cpp
+++ b/src/wallet/rpcdump.cpp
@@ -350,11 +350,11 @@ UniValue removeprunedfunds(const JSONRPCRequest& request)
vector<uint256> vHashOut;
if (pwallet->ZapSelectTx(vHash, vHashOut) != DB_LOAD_OK) {
- throw JSONRPCError(RPC_INTERNAL_ERROR, "Could not properly delete the transaction.");
+ throw JSONRPCError(RPC_WALLET_ERROR, "Could not properly delete the transaction.");
}
if(vHashOut.empty()) {
- throw JSONRPCError(RPC_INTERNAL_ERROR, "Transaction does not exist in wallet.");
+ throw JSONRPCError(RPC_INVALID_PARAMETER, "Transaction does not exist in wallet.");
}
return NullUniValue;