diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -757,7 +757,7 @@ } CScript scriptPubKey = GetScriptForDestination(dest); if (!IsMine(*pwallet, scriptPubKey)) { - return ValueFromAmount(Amount::zero()); + throw JSONRPCError(RPC_WALLET_ERROR, "Address not found in wallet"); } // Minimum confirmations diff --git a/test/functional/receivedby.py b/test/functional/receivedby.py --- a/test/functional/receivedby.py +++ b/test/functional/receivedby.py @@ -7,7 +7,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): @@ -72,6 +75,10 @@ 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