aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2022-03-24 14:33:52 +0100
committerMarcoFalke <falke.marco@gmail.com>2022-03-24 14:33:28 +0100
commitfa450c18db7326b2924db435a753620895b41c53 (patch)
tree05d05f8f7e059ec3d5f49720ce24f0098d61cc4e /test
parent4a0ab355b3e7e7a3fae218fb5d9894fb7f3636a5 (diff)
downloadbitcoin-fa450c18db7326b2924db435a753620895b41c53.tar.xz
test: Rework create_self_transfer_multi
* Add fallback for utxos_to_spend if none are provided * Refactor a for-loop
Diffstat (limited to 'test')
-rw-r--r--test/functional/test_framework/wallet.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/test/functional/test_framework/wallet.py b/test/functional/test_framework/wallet.py
index 37b8a2294d..e86f365f11 100644
--- a/test/functional/test_framework/wallet.py
+++ b/test/functional/test_framework/wallet.py
@@ -207,11 +207,12 @@ class MiniWallet:
return {'new_utxos': [self.get_utxo(txid=txid, vout=vout) for vout in range(len(tx.vout))],
'txid': txid, 'hex': tx.serialize().hex(), 'tx': tx}
- def create_self_transfer_multi(self, *, from_node, utxos_to_spend, num_outputs=1, fee_per_output=1000):
+ def create_self_transfer_multi(self, *, from_node, utxos_to_spend=None, num_outputs=1, fee_per_output=1000):
"""
Create and return a transaction that spends the given UTXOs and creates a
certain number of outputs with equal amounts.
"""
+ utxos_to_spend = utxos_to_spend or [self.get_utxo()]
# create simple tx template (1 input, 1 output)
tx = self.create_self_transfer(fee_rate=0, from_node=from_node, utxo_to_spend=utxos_to_spend[0], mempool_valid=False)['tx']
@@ -227,8 +228,8 @@ class MiniWallet:
# adapt output amounts (use fixed fee per output)
inputs_value_total = sum([int(COIN * utxo['value']) for utxo in utxos_to_spend])
outputs_value_total = inputs_value_total - fee_per_output * num_outputs
- for i in range(num_outputs):
- tx.vout[i].nValue = outputs_value_total // num_outputs
+ for o in tx.vout:
+ o.nValue = outputs_value_total // num_outputs
return tx
def create_self_transfer(self, *, fee_rate=Decimal("0.003"), from_node=None, utxo_to_spend=None, mempool_valid=True, locktime=0, sequence=0):