test: Return new_utxos from create_self_transfer_multi in MiniWallet

This commit is contained in:
MacroFake 2022-06-23 10:50:29 +02:00
parent fa34e44e98
commit fa04ff61b6
No known key found for this signature in database
GPG key ID: CE2B75697E69A548
4 changed files with 22 additions and 23 deletions

View file

@ -192,14 +192,12 @@ class ChainstateWriteCrashTest(BitcoinTestFramework):
# Sanity check -- if we chose inputs that are too small, skip
continue
tx = self.wallet.create_self_transfer_multi(
self.wallet.send_self_transfer_multi(
from_node=node,
utxos_to_spend=utxos_to_spend,
num_outputs=3,
fee_per_output=FEE // 3)
# Send the transaction to get into the mempool (skip fee-checks to run faster)
node.sendrawtransaction(hexstring=tx.serialize().hex(), maxfeerate=0)
fee_per_output=FEE // 3,
)
num_transactions += 1
def run_test(self):

View file

@ -52,7 +52,8 @@ def small_txpuzzle_randfee(
raise RuntimeError(f"Insufficient funds: need {amount + fee}, have {total_in}")
tx = wallet.create_self_transfer_multi(
utxos_to_spend=utxos_to_spend,
fee_per_output=0)
fee_per_output=0,
)["tx"]
tx.vout[0].nValue = int((total_in - amount - fee) * COIN)
tx.vout.append(deepcopy(tx.vout[0]))
tx.vout[1].nValue = int(amount * COIN)

View file

@ -472,11 +472,10 @@ class ReplaceByFeeTest(BitcoinTestFramework):
# Now attempt to submit a tx that double-spends all the root tx inputs, which
# would invalidate `num_txs_invalidated` transactions.
double_tx = wallet.create_self_transfer_multi(
tx_hex = wallet.create_self_transfer_multi(
utxos_to_spend=root_utxos,
fee_per_output=10_000_000, # absurdly high feerate
)
tx_hex = double_tx.serialize().hex()
)["hex"]
if failure_expected:
assert_raises_rpc_error(

View file

@ -209,20 +209,10 @@ class MiniWallet:
return txid, 1
def send_self_transfer_multi(self, *, from_node, **kwargs):
"""
Create and send a transaction that spends the given UTXOs and creates a
certain number of outputs with equal amounts.
Returns a dictionary with
- txid
- serialized transaction in hex format
- transaction as CTransaction instance
- list of newly created UTXOs, ordered by vout index
"""
"""Call create_self_transfer_multi and send the transaction."""
tx = self.create_self_transfer_multi(**kwargs)
txid = self.sendrawtransaction(from_node=from_node, tx_hex=tx.serialize().hex())
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}
self.sendrawtransaction(from_node=from_node, tx_hex=tx["hex"])
return tx
def create_self_transfer_multi(
self,
@ -256,7 +246,18 @@ class MiniWallet:
outputs_value_total = inputs_value_total - fee_per_output * num_outputs
for o in tx.vout:
o.nValue = outputs_value_total // num_outputs
return tx
txid = tx.rehash()
return {
"new_utxos": [self._create_utxo(
txid=txid,
vout=i,
value=Decimal(tx.vout[i].nValue) / COIN,
height=0,
) for i in range(len(tx.vout))],
"txid": txid,
"hex": tx.serialize().hex(),
"tx": tx,
}
def create_self_transfer(self, *, fee_rate=Decimal("0.003"), utxo_to_spend=None, locktime=0, sequence=0):
"""Create and return a tx with the specified fee_rate. Fee may be exact or at most one satoshi higher than needed."""