From 5e0ba8f8cd55a5c2cea4e4e2343d7dcd52aa8fad Mon Sep 17 00:00:00 2001 From: John Newbery Date: Tue, 15 Aug 2017 11:33:39 -0400 Subject: [PATCH] [wallet] getreceivedbyaddress should return error if address is not mine --- src/wallet/rpcwallet.cpp | 2 +- test/functional/receivedby.py | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index d4015f6c8..8abb4c9a2 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -654,7 +654,7 @@ UniValue getreceivedbyaddress(const JSONRPCRequest& request) } CScript scriptPubKey = GetScriptForDestination(dest); if (!IsMine(*pwallet, scriptPubKey)) { - return ValueFromAmount(0); + throw JSONRPCError(RPC_WALLET_ERROR, "Address not found in wallet"); } // Minimum confirmations diff --git a/test/functional/receivedby.py b/test/functional/receivedby.py index c40572f57..97da19546 100755 --- a/test/functional/receivedby.py +++ b/test/functional/receivedby.py @@ -6,7 +6,10 @@ from decimal import Decimal from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import assert_array_result, assert_equal +from test_framework.util import (assert_array_result, + assert_equal, + assert_raises_rpc_error, + ) class ReceivedByTest(BitcoinTestFramework): def set_test_params(self): @@ -68,6 +71,9 @@ class ReceivedByTest(BitcoinTestFramework): balance = self.nodes[1].getreceivedbyaddress(addr) assert_equal(balance, Decimal("0.1")) + # Trying to getreceivedby for an address the wallet doesn't own should return an error + assert_raises_rpc_error(-4, "Address not found in wallet", self.nodes[0].getreceivedbyaddress, addr) + self.log.info("listreceivedbyaccount + getreceivedbyaccount Test") # set pre-state -- 2.11.4.GIT