support/testing: package: bitcoin: replace deprecated wallet rpc calls

The getunconfirmedbalance rpc call was marked as deprecated
in [1] (included in v0.19.0, released on 2019-11-08) and removed
in [2] (included in v30.0, released on 2025-10-09).

This commit replaces the old getbalance/getunconfirmedbalance rpc
calls with the new call getbalances (plural) returning a json
object containing all the data.

This commit is needed before updating bitcoin to v30.0.

[1] facfb4111d
[2] c3fe85e2d6

Cc: Bernd Kuhls <bernd@kuhls.net>
Signed-off-by: Julien Olivain <ju.o@free.fr>
This commit is contained in:
Julien Olivain
2025-10-26 14:35:51 +01:00
parent 724bed5d4d
commit 632aade2c5

View File

@@ -1,3 +1,4 @@
import json
import os
import time
@@ -47,19 +48,25 @@ class TestBitcoin(infra.basetest.BRTest):
self.create_btc_wallet(wallet_name)
return self.gen_btc_address(wallet_name)
def get_wallet_balances(self, wallet):
"""Return the balances of a wallet."""
cmd = f"{self.cli_cmd} -rpcwallet={wallet} getbalances"
out, ret = self.emulator.run(cmd)
self.assertEqual(ret, 0)
balances = json.loads("".join(out))
return balances
def get_wallet_balance(self, wallet):
"""Return the (confirmed) balance of a wallet."""
cmd = f"{self.cli_cmd} -rpcwallet={wallet} getbalance"
out, ret = self.emulator.run(cmd)
self.assertEqual(ret, 0)
return float(out[0])
balances = self.get_wallet_balances(wallet)
balance = balances["mine"]["trusted"]
return balance
def get_wallet_unconfirmed_balance(self, wallet):
"""Return the unconfirmed balance of a wallet."""
cmd = f"{self.cli_cmd} -rpcwallet={wallet} getunconfirmedbalance"
out, ret = self.emulator.run(cmd)
self.assertEqual(ret, 0)
return float(out[0])
"""Return the untrusted pending (unconfirmed) balance of a wallet."""
balances = self.get_wallet_balances(wallet)
untrusted_balance = balances["mine"]["untrusted_pending"]
return untrusted_balance
def get_block_count(self):
"""Returns the height of the most-work fully-validated chain."""