Skip to content

Commit

Permalink
cli, test: update -getinfo to use rpc getbalances#total
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatack committed Nov 22, 2024
1 parent fa331ae commit e986efe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/bitcoin-cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ class GetinfoRequestHandler: public BaseRequestHandler
result.pushKV("paytxfee", batch[ID_WALLETINFO]["result"]["paytxfee"]);
}
if (!batch[ID_BALANCES]["result"].isNull()) {
result.pushKV("balance", batch[ID_BALANCES]["result"]["mine"]["trusted"]);
result.pushKV("balance", batch[ID_BALANCES]["result"]["total"]);
}
result.pushKV("relayfee", batch[ID_NETWORKINFO]["result"]["relayfee"]);
result.pushKV("warnings", batch[ID_NETWORKINFO]["result"]["warnings"]);
Expand Down Expand Up @@ -1007,7 +1007,7 @@ static void ParseError(const UniValue& error, std::string& strPrint, int& nRet)

/**
* GetWalletBalances calls listwallets; if more than one wallet is loaded, it then
* fetches mine.trusted balances for each loaded wallet and pushes them to `result`.
* fetches the total balance for each loaded wallet and pushes it to `result`.
*
* @param result Reference to UniValue object the wallet names and balances are pushed to.
*/
Expand All @@ -1023,7 +1023,7 @@ static void GetWalletBalances(UniValue& result)
for (const UniValue& wallet : wallets.getValues()) {
const std::string& wallet_name = wallet.get_str();
const UniValue getbalances = ConnectAndCallRPC(&rh, "getbalances", /* args=*/{}, wallet_name);
const UniValue& balance = getbalances.find_value("result")["mine"]["trusted"];
const UniValue& balance = getbalances.find_value("result")["total"];
balances.pushKV(wallet_name, balance);
}
result.pushKV("balances", std::move(balances));
Expand Down
9 changes: 5 additions & 4 deletions test/functional/interface_bitcoin_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@
import time

# The block reward of coinbaseoutput.nValue (50) BTC/block matures after
# COINBASE_MATURITY (100) blocks. Therefore, after mining 101 blocks we expect
# node 0 to have a balance of (BLOCKS - COINBASE_MATURITY) * 50 BTC/block.
# COINBASE_MATURITY (100) blocks.
BLOCKS = COINBASE_MATURITY + 1
BALANCE = (BLOCKS - 100) * 50
BALANCE = BLOCKS * 50

JSON_PARSING_ERROR = 'error: Error parsing JSON: foo'
BLOCKS_VALUE_OF_ZERO = 'error: the first argument (number of blocks to generate, default: 1) must be an integer value greater than zero'
Expand Down Expand Up @@ -219,7 +218,7 @@ def run_test(self):

# Setup to test -getinfo, -generate, and -rpcwallet= with multiple wallets.
wallets = [self.default_wallet_name, 'Encrypted', 'secret']
amounts = [BALANCE + Decimal('9.999928'), Decimal(9), Decimal(31)]
amounts = [BALANCE, 9, 31]
self.nodes[0].createwallet(wallet_name=wallets[1])
self.nodes[0].createwallet(wallet_name=wallets[2])
w1 = self.nodes[0].get_wallet_rpc(wallets[0])
Expand All @@ -231,9 +230,11 @@ def run_test(self):
w2.encryptwallet(password)
w1.sendtoaddress(w2.getnewaddress(), amounts[1])
w1.sendtoaddress(w3.getnewaddress(), amounts[2])
amounts[0] -= (amounts[1] + amounts[2])

# Mine a block to confirm; adds a block reward (50 BTC) to the default wallet.
self.generate(self.nodes[0], 1)
amounts[0] += 50

self.log.info("Test -getinfo with multiple wallets and -rpcwallet returns specified wallet balance")
for i in range(len(wallets)):
Expand Down

0 comments on commit e986efe

Please sign in to comment.