Skip to content

Commit

Permalink
[wallet] getreceivedbyaddress should return error if address is not mine
Browse files Browse the repository at this point in the history
  • Loading branch information
jnewbery committed Nov 10, 2017
1 parent ea0cd24 commit 5e0ba8f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/wallet/rpcwallet.cpp
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion test/functional/receivedby.py
Expand Up @@ -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):
Expand Down Expand Up @@ -68,6 +71,9 @@ def run_test(self):
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
Expand Down

0 comments on commit 5e0ba8f

Please sign in to comment.