From e986efe55f4308a055a31e8bb9983d292ea18929 Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Fri, 22 Nov 2024 08:23:54 -0600 Subject: [PATCH] cli, test: update -getinfo to use rpc getbalances#total --- src/bitcoin-cli.cpp | 6 +++--- test/functional/interface_bitcoin_cli.py | 9 +++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index dd7b21e567137d..e5ef6428d3216c 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -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"]); @@ -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. */ @@ -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)); diff --git a/test/functional/interface_bitcoin_cli.py b/test/functional/interface_bitcoin_cli.py index 3fe6570dd16c37..968b9b7039567b 100755 --- a/test/functional/interface_bitcoin_cli.py +++ b/test/functional/interface_bitcoin_cli.py @@ -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' @@ -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]) @@ -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)):