Skip to content

Commit

Permalink
test: Return new_utxos from create_self_transfer_multi in MiniWallet
Browse files Browse the repository at this point in the history
  • Loading branch information
MacroFake committed Jun 27, 2022
1 parent fa34e44 commit fa04ff6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
8 changes: 3 additions & 5 deletions test/functional/feature_dbcrash.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,12 @@ def generate_small_transactions(self, node, count, utxo_list):
# 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):
Expand Down
3 changes: 2 additions & 1 deletion test/functional/feature_fee_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions test/functional/feature_rbf.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,11 +472,10 @@ def test_too_many_replacements_with_default_mempool_params(self):

# 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(
Expand Down
29 changes: 15 additions & 14 deletions test/functional/test_framework/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,20 +209,10 @@ def send_to(self, *, from_node, scriptPubKey, amount, fee=1000):
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,
Expand Down Expand Up @@ -256,7 +246,18 @@ def create_self_transfer_multi(
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."""
Expand Down

0 comments on commit fa04ff6

Please sign in to comment.