Skip to content

Commit 1b71c76

Browse files
author
MacroFake
committed
Merge bitcoin/bitcoin#25435: test: Remove from_node from create_self_transfer* MiniWallet helpers
fa8421b test: Remove from_node from create_self_transfer* MiniWallet helpers (MacroFake) Pull request description: MiniWallet is capable to create a transaction without a node, so don't pass it in where not needed. ACKs for top commit: kouloumos: ACK fa8421b theStack: ACK fa8421b Tree-SHA512: d51e2ae6577c1e2bc80386678ff5c7974609e86317850aaec45cdbf0d23076ba1ae76342610c8f90931a6c0971c8e916864442b041a253212e6a9d476d79c541
2 parents a4e066a + fa8421b commit 1b71c76

File tree

8 files changed

+20
-22
lines changed

8 files changed

+20
-22
lines changed

test/functional/feature_fee_estimation.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ def small_txpuzzle_randfee(
5151
if total_in <= amount + fee:
5252
raise RuntimeError(f"Insufficient funds: need {amount + fee}, have {total_in}")
5353
tx = wallet.create_self_transfer_multi(
54-
from_node=from_node,
5554
utxos_to_spend=utxos_to_spend,
5655
fee_per_output=0)
5756
tx.vout[0].nValue = int((total_in - amount - fee) * COIN)

test/functional/feature_rbf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,6 @@ def test_too_many_replacements_with_default_mempool_params(self):
473473
# Now attempt to submit a tx that double-spends all the root tx inputs, which
474474
# would invalidate `num_txs_invalidated` transactions.
475475
double_tx = wallet.create_self_transfer_multi(
476-
from_node=normal_node,
477476
utxos_to_spend=root_utxos,
478477
fee_per_output=10_000_000, # absurdly high feerate
479478
)

test/functional/mempool_unbroadcast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test_broadcast(self):
4040
wallet_tx_hsh = node.sendtoaddress(addr, 0.0001)
4141

4242
# generate a txn using sendrawtransaction
43-
txFS = self.wallet.create_self_transfer(from_node=node)
43+
txFS = self.wallet.create_self_transfer()
4444
rpc_tx_hsh = node.sendrawtransaction(txFS["hex"])
4545

4646
# check transactions are in unbroadcast using rpc

test/functional/mining_prioritisetransaction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def run_test(self):
212212
assert x not in mempool
213213

214214
# Create a free transaction. Should be rejected.
215-
tx_res = self.wallet.create_self_transfer(from_node=self.nodes[0], fee_rate=0)
215+
tx_res = self.wallet.create_self_transfer(fee_rate=0)
216216
tx_hex = tx_res['hex']
217217
tx_id = tx_res['txid']
218218

test/functional/p2p_segwit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1998,7 +1998,7 @@ class msg_bogus_tx(msg_tx):
19981998
def serialize(self):
19991999
return serialize_with_bogus_witness(self.tx)
20002000

2001-
tx = self.wallet.create_self_transfer(from_node=self.nodes[0])['tx']
2001+
tx = self.wallet.create_self_transfer()['tx']
20022002
assert_raises_rpc_error(-22, "TX decode failed", self.nodes[0].decoderawtransaction, hexstring=serialize_with_bogus_witness(tx).hex(), iswitness=True)
20032003
with self.nodes[0].assert_debug_log(['Unknown transaction optional data']):
20042004
self.test_node.send_and_ping(msg_bogus_tx(tx))

test/functional/rpc_rawtransaction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def sendrawtransaction_testmempoolaccept_tests(self):
285285

286286
# Test a transaction with a large fee.
287287
# Fee rate is 0.20000000 BTC/kvB
288-
tx = self.wallet.create_self_transfer(from_node=self.nodes[0], fee_rate=Decimal("0.20000000"))
288+
tx = self.wallet.create_self_transfer(fee_rate=Decimal("0.20000000"))
289289
# Thus, testmempoolaccept should reject
290290
testres = self.nodes[2].testmempoolaccept([tx['hex']])[0]
291291
assert_equal(testres['allowed'], False)

test/functional/test_framework/util.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -527,9 +527,8 @@ def create_lots_of_big_transactions(mini_wallet, node, fee, tx_batch_size, txout
527527
use_internal_utxos = utxos is None
528528
for _ in range(tx_batch_size):
529529
tx = mini_wallet.create_self_transfer(
530-
from_node=node,
531-
utxo_to_spend=None if use_internal_utxos else utxos.pop(),
532-
fee_rate=0,
530+
utxo_to_spend=None if use_internal_utxos else utxos.pop(),
531+
fee_rate=0,
533532
)["tx"]
534533
tx.vout[0].nValue -= fee_sats
535534
tx.vout.extend(txouts)

test/functional/test_framework/wallet.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,10 @@ def get_utxos(self, *, mark_as_spent=True):
180180
self._utxos = []
181181
return utxos
182182

183-
def send_self_transfer(self, **kwargs):
183+
def send_self_transfer(self, *, from_node, **kwargs):
184184
"""Create and send a tx with the specified fee_rate. Fee may be exact or at most one satoshi higher than needed."""
185185
tx = self.create_self_transfer(**kwargs)
186-
self.sendrawtransaction(from_node=kwargs['from_node'], tx_hex=tx['hex'])
186+
self.sendrawtransaction(from_node=from_node, tx_hex=tx['hex'])
187187
return tx
188188

189189
def send_to(self, *, from_node, scriptPubKey, amount, fee=1000):
@@ -198,14 +198,14 @@ def send_to(self, *, from_node, scriptPubKey, amount, fee=1000):
198198
199199
Returns a tuple (txid, n) referring to the created external utxo outpoint.
200200
"""
201-
tx = self.create_self_transfer(from_node=from_node, fee_rate=0)["tx"]
201+
tx = self.create_self_transfer(fee_rate=0)["tx"]
202202
assert_greater_than_or_equal(tx.vout[0].nValue, amount + fee)
203203
tx.vout[0].nValue -= (amount + fee) # change output -> MiniWallet
204204
tx.vout.append(CTxOut(amount, scriptPubKey)) # arbitrary output -> to be returned
205205
txid = self.sendrawtransaction(from_node=from_node, tx_hex=tx.serialize().hex())
206206
return txid, 1
207207

208-
def send_self_transfer_multi(self, **kwargs):
208+
def send_self_transfer_multi(self, *, from_node, **kwargs):
209209
"""
210210
Create and send a transaction that spends the given UTXOs and creates a
211211
certain number of outputs with equal amounts.
@@ -217,24 +217,26 @@ def send_self_transfer_multi(self, **kwargs):
217217
- list of newly created UTXOs, ordered by vout index
218218
"""
219219
tx = self.create_self_transfer_multi(**kwargs)
220-
txid = self.sendrawtransaction(from_node=kwargs['from_node'], tx_hex=tx.serialize().hex())
220+
txid = self.sendrawtransaction(from_node=from_node, tx_hex=tx.serialize().hex())
221221
return {'new_utxos': [self.get_utxo(txid=txid, vout=vout) for vout in range(len(tx.vout))],
222222
'txid': txid, 'hex': tx.serialize().hex(), 'tx': tx}
223223

224224
def create_self_transfer_multi(
225-
self, *, from_node,
226-
utxos_to_spend: Optional[List[dict]] = None,
227-
num_outputs=1,
228-
sequence=0,
229-
fee_per_output=1000):
225+
self,
226+
*,
227+
utxos_to_spend: Optional[List[dict]] = None,
228+
num_outputs=1,
229+
sequence=0,
230+
fee_per_output=1000,
231+
):
230232
"""
231233
Create and return a transaction that spends the given UTXOs and creates a
232234
certain number of outputs with equal amounts.
233235
"""
234236
utxos_to_spend = utxos_to_spend or [self.get_utxo()]
235237
# create simple tx template (1 input, 1 output)
236238
tx = self.create_self_transfer(
237-
fee_rate=0, from_node=from_node,
239+
fee_rate=0,
238240
utxo_to_spend=utxos_to_spend[0], sequence=sequence)["tx"]
239241

240242
# duplicate inputs, witnesses and outputs
@@ -253,9 +255,8 @@ def create_self_transfer_multi(
253255
o.nValue = outputs_value_total // num_outputs
254256
return tx
255257

256-
def create_self_transfer(self, *, fee_rate=Decimal("0.003"), from_node=None, utxo_to_spend=None, locktime=0, sequence=0):
258+
def create_self_transfer(self, *, fee_rate=Decimal("0.003"), utxo_to_spend=None, locktime=0, sequence=0):
257259
"""Create and return a tx with the specified fee_rate. Fee may be exact or at most one satoshi higher than needed."""
258-
from_node = from_node or self._test_node
259260
utxo_to_spend = utxo_to_spend or self.get_utxo()
260261
if self._mode in (MiniWalletMode.RAW_OP_TRUE, MiniWalletMode.ADDRESS_OP_TRUE):
261262
vsize = Decimal(104) # anyone-can-spend

0 commit comments

Comments
 (0)