Skip to content

Commit fa04ff6

Browse files
author
MacroFake
committed
test: Return new_utxos from create_self_transfer_multi in MiniWallet
1 parent fa34e44 commit fa04ff6

File tree

4 files changed

+22
-23
lines changed

4 files changed

+22
-23
lines changed

test/functional/feature_dbcrash.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,12 @@ def generate_small_transactions(self, node, count, utxo_list):
192192
# Sanity check -- if we chose inputs that are too small, skip
193193
continue
194194

195-
tx = self.wallet.create_self_transfer_multi(
195+
self.wallet.send_self_transfer_multi(
196196
from_node=node,
197197
utxos_to_spend=utxos_to_spend,
198198
num_outputs=3,
199-
fee_per_output=FEE // 3)
200-
201-
# Send the transaction to get into the mempool (skip fee-checks to run faster)
202-
node.sendrawtransaction(hexstring=tx.serialize().hex(), maxfeerate=0)
199+
fee_per_output=FEE // 3,
200+
)
203201
num_transactions += 1
204202

205203
def run_test(self):

test/functional/feature_fee_estimation.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ def small_txpuzzle_randfee(
5252
raise RuntimeError(f"Insufficient funds: need {amount + fee}, have {total_in}")
5353
tx = wallet.create_self_transfer_multi(
5454
utxos_to_spend=utxos_to_spend,
55-
fee_per_output=0)
55+
fee_per_output=0,
56+
)["tx"]
5657
tx.vout[0].nValue = int((total_in - amount - fee) * COIN)
5758
tx.vout.append(deepcopy(tx.vout[0]))
5859
tx.vout[1].nValue = int(amount * COIN)

test/functional/feature_rbf.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -472,11 +472,10 @@ def test_too_many_replacements_with_default_mempool_params(self):
472472

473473
# Now attempt to submit a tx that double-spends all the root tx inputs, which
474474
# would invalidate `num_txs_invalidated` transactions.
475-
double_tx = wallet.create_self_transfer_multi(
475+
tx_hex = wallet.create_self_transfer_multi(
476476
utxos_to_spend=root_utxos,
477477
fee_per_output=10_000_000, # absurdly high feerate
478-
)
479-
tx_hex = double_tx.serialize().hex()
478+
)["hex"]
480479

481480
if failure_expected:
482481
assert_raises_rpc_error(

test/functional/test_framework/wallet.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -209,20 +209,10 @@ def send_to(self, *, from_node, scriptPubKey, amount, fee=1000):
209209
return txid, 1
210210

211211
def send_self_transfer_multi(self, *, from_node, **kwargs):
212-
"""
213-
Create and send a transaction that spends the given UTXOs and creates a
214-
certain number of outputs with equal amounts.
215-
216-
Returns a dictionary with
217-
- txid
218-
- serialized transaction in hex format
219-
- transaction as CTransaction instance
220-
- list of newly created UTXOs, ordered by vout index
221-
"""
212+
"""Call create_self_transfer_multi and send the transaction."""
222213
tx = self.create_self_transfer_multi(**kwargs)
223-
txid = self.sendrawtransaction(from_node=from_node, tx_hex=tx.serialize().hex())
224-
return {'new_utxos': [self.get_utxo(txid=txid, vout=vout) for vout in range(len(tx.vout))],
225-
'txid': txid, 'hex': tx.serialize().hex(), 'tx': tx}
214+
self.sendrawtransaction(from_node=from_node, tx_hex=tx["hex"])
215+
return tx
226216

227217
def create_self_transfer_multi(
228218
self,
@@ -256,7 +246,18 @@ def create_self_transfer_multi(
256246
outputs_value_total = inputs_value_total - fee_per_output * num_outputs
257247
for o in tx.vout:
258248
o.nValue = outputs_value_total // num_outputs
259-
return tx
249+
txid = tx.rehash()
250+
return {
251+
"new_utxos": [self._create_utxo(
252+
txid=txid,
253+
vout=i,
254+
value=Decimal(tx.vout[i].nValue) / COIN,
255+
height=0,
256+
) for i in range(len(tx.vout))],
257+
"txid": txid,
258+
"hex": tx.serialize().hex(),
259+
"tx": tx,
260+
}
260261

261262
def create_self_transfer(self, *, fee_rate=Decimal("0.003"), utxo_to_spend=None, locktime=0, sequence=0):
262263
"""Create and return a tx with the specified fee_rate. Fee may be exact or at most one satoshi higher than needed."""

0 commit comments

Comments
 (0)