Skip to content

Commit 6110ae8

Browse files
author
MarcoFalke
committed
Merge #18451: test: shift coverage from getunconfirmedbalance to getbalances
0306d78 Use getbalances in wallet_address_types tests (Jon Atack) 7eacdc5 Shift coverage from getunconfirmedbalance to getbalances in wallet_abandonconflict tests (Jon Atack) 3e6f737 Improve getbalances coverage in wallet_balance tests (Jon Atack) Pull request description: <strike>This PR updates several tests and then removes the `getunconfirmedbalance` RPC which was deprecated in facfb41 a year ago. Next steps: remove the deprecated `getwalletinfo` fields and the `getbalance` RPC in follow-ups, if there seems to be consensus on those removals.</strike> Update: `getunconfirmedbalance` RPC was deprecated in facfb41 a year ago, but following the review comments below, this PR now only updates the test coverage to use `getbalances` while still leaving basic coverage for `getunconfirmedbalance` in wallet_balance.py. That said, I've seen 3 regular contributors confused in the past 10 days by "DEPRECATED" warnings in the code that are not following the deprecation policy in [JSON-RPC-interface.md#versioning](https://github.com/bitcoin/bitcoin/blob/master/doc/JSON-RPC-interface.md#versioning). ISTM these warnings should either be removed, or the calls deprecated (`-deprecatedrpc`), or the policy updated to describe these warnings as a pre-deprecation practice. ACKs for top commit: jnewbery: utACK 0306d78 Tree-SHA512: 692e43e9bed5afa97d905740666e365f0b64e559e1c75a6a398236d9e943894e3477947fc11324f420a6feaffa0c0c1532aa983c50090ca39d06551399e6ddd1
2 parents 6ef45bc + 0306d78 commit 6110ae8

File tree

3 files changed

+30
-19
lines changed

3 files changed

+30
-19
lines changed

test/functional/wallet_abandonconflict.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ def run_test(self):
110110
assert_equal(newbalance, balance - signed3_change)
111111
# Unconfirmed received funds that are not in mempool, also shouldn't show
112112
# up in unconfirmed balance
113-
unconfbalance = self.nodes[0].getunconfirmedbalance() + self.nodes[0].getbalance()
114-
assert_equal(unconfbalance, newbalance)
113+
balances = self.nodes[0].getbalances()['mine']
114+
assert_equal(balances['untrusted_pending'] + balances['trusted'], newbalance)
115115
# Also shouldn't show up in listunspent
116116
assert not txABC2 in [utxo["txid"] for utxo in self.nodes[0].listunspent(0)]
117117
balance = newbalance

test/functional/wallet_address_types.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,9 @@ def setup_network(self):
9797
connect_nodes(self.nodes[i], j)
9898
self.sync_all()
9999

100-
def get_balances(self, confirmed=True):
101-
"""Return a list of confirmed or unconfirmed balances."""
102-
if confirmed:
103-
return [self.nodes[i].getbalance() for i in range(4)]
104-
else:
105-
return [self.nodes[i].getunconfirmedbalance() for i in range(4)]
100+
def get_balances(self, key='trusted'):
101+
"""Return a list of balances."""
102+
return [self.nodes[i].getbalances()['mine'][key] for i in range(4)]
106103

107104
# Quick test of python bech32 implementation
108105
def test_python_bech32(self, addr):
@@ -307,7 +304,7 @@ def run_test(self):
307304
self.nodes[from_node].sendmany("", sends)
308305
self.sync_mempools()
309306

310-
unconf_balances = self.get_balances(False)
307+
unconf_balances = self.get_balances('untrusted_pending')
311308
self.log.debug("Check unconfirmed balances: {}".format(unconf_balances))
312309
assert_equal(unconf_balances[from_node], 0)
313310
for n, to_node in enumerate(range(from_node + 1, from_node + 4)):

test/functional/wallet_balance.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def run_test(self):
107107
# First argument of getbalance must be set to "*"
108108
assert_raises_rpc_error(-32, "dummy first argument must be excluded or set to \"*\"", self.nodes[1].getbalance, "")
109109

110-
self.log.info("Test getbalance and getunconfirmedbalance with unconfirmed inputs")
110+
self.log.info("Test balances with unconfirmed inputs")
111111

112112
# Before `test_balance()`, we have had two nodes with a balance of 50
113113
# each and then we:
@@ -148,6 +148,18 @@ def run_test(self):
148148

149149

150150
def test_balances(*, fee_node_1=0):
151+
# getbalances
152+
expected_balances_0 = {'mine': {'immature': Decimal('0E-8'),
153+
'trusted': Decimal('9.99'), # change from node 0's send
154+
'untrusted_pending': Decimal('60.0')},
155+
'watchonly': {'immature': Decimal('5000'),
156+
'trusted': Decimal('50.0'),
157+
'untrusted_pending': Decimal('0E-8')}}
158+
expected_balances_1 = {'mine': {'immature': Decimal('0E-8'),
159+
'trusted': Decimal('0E-8'), # node 1's send had an unsafe input
160+
'untrusted_pending': Decimal('30.0') - fee_node_1}} # Doesn't include output of node 0's send since it was spent
161+
assert_equal(self.nodes[0].getbalances(), expected_balances_0)
162+
assert_equal(self.nodes[1].getbalances(), expected_balances_1)
151163
# getbalance without any arguments includes unconfirmed transactions, but not untrusted transactions
152164
assert_equal(self.nodes[0].getbalance(), Decimal('9.99')) # change from node 0's send
153165
assert_equal(self.nodes[1].getbalance(), Decimal('0')) # node 1's send had an unsafe input
@@ -160,11 +172,9 @@ def test_balances(*, fee_node_1=0):
160172
assert_equal(self.nodes[1].getbalance(minconf=1), Decimal('0'))
161173
# getunconfirmedbalance
162174
assert_equal(self.nodes[0].getunconfirmedbalance(), Decimal('60')) # output of node 1's spend
163-
assert_equal(self.nodes[0].getbalances()['mine']['untrusted_pending'], Decimal('60'))
164-
assert_equal(self.nodes[0].getwalletinfo()["unconfirmed_balance"], Decimal('60'))
165-
166175
assert_equal(self.nodes[1].getunconfirmedbalance(), Decimal('30') - fee_node_1) # Doesn't include output of node 0's send since it was spent
167-
assert_equal(self.nodes[1].getbalances()['mine']['untrusted_pending'], Decimal('30') - fee_node_1)
176+
# getwalletinfo.unconfirmed_balance
177+
assert_equal(self.nodes[0].getwalletinfo()["unconfirmed_balance"], Decimal('60'))
168178
assert_equal(self.nodes[1].getwalletinfo()["unconfirmed_balance"], Decimal('30') - fee_node_1)
169179

170180
test_balances(fee_node_1=Decimal('0.01'))
@@ -174,15 +184,19 @@ def test_balances(*, fee_node_1=0):
174184
self.nodes[0].sendrawtransaction(txs[1]['hex']) # sending on both nodes is faster than waiting for propagation
175185
self.sync_all()
176186

177-
self.log.info("Test getbalance and getunconfirmedbalance with conflicted unconfirmed inputs")
187+
self.log.info("Test getbalance and getbalances.mine.untrusted_pending with conflicted unconfirmed inputs")
178188
test_balances(fee_node_1=Decimal('0.02'))
179189

180190
self.nodes[1].generatetoaddress(1, ADDRESS_WATCHONLY)
181191
self.sync_all()
182192

183193
# balances are correct after the transactions are confirmed
184-
assert_equal(self.nodes[0].getbalance(), Decimal('69.99')) # node 1's send plus change from node 0's send
185-
assert_equal(self.nodes[1].getbalance(), Decimal('29.98')) # change from node 0's send
194+
balance_node0 = Decimal('69.99') # node 1's send plus change from node 0's send
195+
balance_node1 = Decimal('29.98') # change from node 0's send
196+
assert_equal(self.nodes[0].getbalances()['mine']['trusted'], balance_node0)
197+
assert_equal(self.nodes[1].getbalances()['mine']['trusted'], balance_node1)
198+
assert_equal(self.nodes[0].getbalance(), balance_node0)
199+
assert_equal(self.nodes[1].getbalance(), balance_node1)
186200

187201
# Send total balance away from node 1
188202
txs = create_transactions(self.nodes[1], self.nodes[0].getnewaddress(), Decimal('29.97'), [Decimal('0.01')])
@@ -200,13 +214,13 @@ def test_balances(*, fee_node_1=0):
200214

201215
# check mempool transactions count for wallet unconfirmed balance after
202216
# dynamically loading the wallet.
203-
before = self.nodes[1].getunconfirmedbalance()
217+
before = self.nodes[1].getbalances()['mine']['untrusted_pending']
204218
dst = self.nodes[1].getnewaddress()
205219
self.nodes[1].unloadwallet('')
206220
self.nodes[0].sendtoaddress(dst, 0.1)
207221
self.sync_all()
208222
self.nodes[1].loadwallet('')
209-
after = self.nodes[1].getunconfirmedbalance()
223+
after = self.nodes[1].getbalances()['mine']['untrusted_pending']
210224
assert_equal(before + Decimal('0.1'), after)
211225

212226
# Create 3 more wallet txs, where the last is not accepted to the

0 commit comments

Comments
 (0)