Skip to content

Commit bb41e63

Browse files
committed
wallet_balance.py: Prevent edge cases
1 parent 12fd4bb commit bb41e63

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

test/functional/wallet_balance.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,17 @@ def create_transactions(node, address, amt, fees):
2828
for utxo in utxos:
2929
inputs.append({"txid": utxo["txid"], "vout": utxo["vout"]})
3030
ins_total += utxo['amount']
31-
if ins_total + max(fees) > amt:
31+
if ins_total >= amt + max(fees):
3232
break
33+
# make sure there was enough utxos
34+
assert ins_total >= amt + max(fees)
3335

3436
txs = []
3537
for fee in fees:
36-
outputs = {address: amt, node.getrawchangeaddress(): ins_total - amt - fee}
38+
outputs = {address: amt}
39+
# prevent 0 change output
40+
if ins_total > amt + fee:
41+
outputs[node.getrawchangeaddress()] = ins_total - amt - fee
3742
raw_tx = node.createrawtransaction(inputs, outputs, 0, True)
3843
raw_tx = node.signrawtransactionwithwallet(raw_tx)
3944
assert_equal(raw_tx['complete'], True)

0 commit comments

Comments
 (0)