@@ -107,7 +107,7 @@ def run_test(self):
107
107
# First argument of getbalance must be set to "*"
108
108
assert_raises_rpc_error (- 32 , "dummy first argument must be excluded or set to \" *\" " , self .nodes [1 ].getbalance , "" )
109
109
110
- self .log .info ("Test getbalance and getunconfirmedbalance with unconfirmed inputs" )
110
+ self .log .info ("Test balances with unconfirmed inputs" )
111
111
112
112
# Before `test_balance()`, we have had two nodes with a balance of 50
113
113
# each and then we:
@@ -148,6 +148,18 @@ def run_test(self):
148
148
149
149
150
150
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 )
151
163
# getbalance without any arguments includes unconfirmed transactions, but not untrusted transactions
152
164
assert_equal (self .nodes [0 ].getbalance (), Decimal ('9.99' )) # change from node 0's send
153
165
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):
160
172
assert_equal (self .nodes [1 ].getbalance (minconf = 1 ), Decimal ('0' ))
161
173
# getunconfirmedbalance
162
174
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
-
166
175
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' ))
168
178
assert_equal (self .nodes [1 ].getwalletinfo ()["unconfirmed_balance" ], Decimal ('30' ) - fee_node_1 )
169
179
170
180
test_balances (fee_node_1 = Decimal ('0.01' ))
@@ -174,15 +184,19 @@ def test_balances(*, fee_node_1=0):
174
184
self .nodes [0 ].sendrawtransaction (txs [1 ]['hex' ]) # sending on both nodes is faster than waiting for propagation
175
185
self .sync_all ()
176
186
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" )
178
188
test_balances (fee_node_1 = Decimal ('0.02' ))
179
189
180
190
self .nodes [1 ].generatetoaddress (1 , ADDRESS_WATCHONLY )
181
191
self .sync_all ()
182
192
183
193
# 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 )
186
200
187
201
# Send total balance away from node 1
188
202
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):
200
214
201
215
# check mempool transactions count for wallet unconfirmed balance after
202
216
# dynamically loading the wallet.
203
- before = self .nodes [1 ].getunconfirmedbalance ()
217
+ before = self .nodes [1 ].getbalances ()[ 'mine' ][ 'untrusted_pending' ]
204
218
dst = self .nodes [1 ].getnewaddress ()
205
219
self .nodes [1 ].unloadwallet ('' )
206
220
self .nodes [0 ].sendtoaddress (dst , 0.1 )
207
221
self .sync_all ()
208
222
self .nodes [1 ].loadwallet ('' )
209
- after = self .nodes [1 ].getunconfirmedbalance ()
223
+ after = self .nodes [1 ].getbalances ()[ 'mine' ][ 'untrusted_pending' ]
210
224
assert_equal (before + Decimal ('0.1' ), after )
211
225
212
226
# Create 3 more wallet txs, where the last is not accepted to the
0 commit comments