Skip to content

Commit b24f6c6

Browse files
committed
test: MiniWallet: support default from_node for creating txs
If no `from_node` parameter is passed explicitely to the `create_self_transfer` method, the test node passed in the course of creating the MiniWallet instance is used. This seems to be the main use-case in most of the current functional tests, i.e. in many instances the calls can be shortened.
1 parent f30041c commit b24f6c6

File tree

9 files changed

+16
-18
lines changed

9 files changed

+16
-18
lines changed

test/functional/feature_cltv.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def run_test(self):
115115
# create one invalid tx per CLTV failure reason (5 in total) and collect them
116116
invalid_cltv_txs = []
117117
for i in range(5):
118-
spendtx = wallet.create_self_transfer(from_node=self.nodes[0])['tx']
118+
spendtx = wallet.create_self_transfer()['tx']
119119
cltv_invalidate(spendtx, i)
120120
invalid_cltv_txs.append(spendtx)
121121

@@ -146,7 +146,7 @@ def run_test(self):
146146

147147
# create and test one invalid tx per CLTV failure reason (5 in total)
148148
for i in range(5):
149-
spendtx = wallet.create_self_transfer(from_node=self.nodes[0])['tx']
149+
spendtx = wallet.create_self_transfer()['tx']
150150
cltv_invalidate(spendtx, i)
151151

152152
expected_cltv_reject_reason = [

test/functional/feature_csv_activation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def set_test_params(self):
104104

105105
def create_self_transfer_from_utxo(self, input_tx):
106106
utxo = self.miniwallet.get_utxo(txid=input_tx.rehash(), mark_as_spent=False)
107-
tx = self.miniwallet.create_self_transfer(from_node=self.nodes[0], utxo_to_spend=utxo)['tx']
107+
tx = self.miniwallet.create_self_transfer(utxo_to_spend=utxo)['tx']
108108
return tx
109109

110110
def create_bip112special(self, input, txversion):

test/functional/feature_dersig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def set_test_params(self):
5757

5858
def create_tx(self, input_txid):
5959
utxo_to_spend = self.miniwallet.get_utxo(txid=input_txid, mark_as_spent=False)
60-
return self.miniwallet.create_self_transfer(from_node=self.nodes[0], utxo_to_spend=utxo_to_spend)['tx']
60+
return self.miniwallet.create_self_transfer(utxo_to_spend=utxo_to_spend)['tx']
6161

6262
def test_dersig_info(self, *, is_active):
6363
assert_equal(self.nodes[0].getblockchaininfo()['softforks']['bip66'],

test/functional/feature_rbf.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def test_simple_doublespend(self):
115115
"""Simple doublespend"""
116116
# we use MiniWallet to create a transaction template with inputs correctly set,
117117
# and modify the output (amount, scriptPubKey) according to our needs
118-
tx_template = self.wallet.create_self_transfer(from_node=self.nodes[0])['tx']
118+
tx_template = self.wallet.create_self_transfer()['tx']
119119

120120
tx1a = deepcopy(tx_template)
121121
tx1a.vout = [CTxOut(1 * COIN, DUMMY_P2WPKH_SCRIPT)]
@@ -563,7 +563,6 @@ def test_no_inherited_signaling(self):
563563
assert_equal(True, self.nodes[0].getmempoolentry(optin_parent_tx['txid'])['bip125-replaceable'])
564564

565565
replacement_parent_tx = self.wallet.create_self_transfer(
566-
from_node=self.nodes[0],
567566
utxo_to_spend=confirmed_utxo,
568567
sequence=BIP125_SEQUENCE_NUMBER,
569568
fee_rate=Decimal('0.02'),
@@ -588,7 +587,6 @@ def test_no_inherited_signaling(self):
588587
assert_equal(True, self.nodes[0].getmempoolentry(optout_child_tx['txid'])['bip125-replaceable'])
589588

590589
replacement_child_tx = self.wallet.create_self_transfer(
591-
from_node=self.nodes[0],
592590
utxo_to_spend=parent_utxo,
593591
sequence=SEQUENCE_FINAL,
594592
fee_rate=Decimal('0.02'),

test/functional/mempool_reorg.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,13 @@ def run_test(self):
4545
utxo_2 = wallet.get_utxo(txid=coinbase_txids[2])
4646
utxo_3 = wallet.get_utxo(txid=coinbase_txids[3])
4747
self.log.info("Create three transactions spending from coinbase utxos: spend_1, spend_2, spend_3")
48-
spend_1 = wallet.create_self_transfer(from_node=self.nodes[0], utxo_to_spend=utxo_1)
49-
spend_2 = wallet.create_self_transfer(from_node=self.nodes[0], utxo_to_spend=utxo_2)
50-
spend_3 = wallet.create_self_transfer(from_node=self.nodes[0], utxo_to_spend=utxo_3)
48+
spend_1 = wallet.create_self_transfer(utxo_to_spend=utxo_1)
49+
spend_2 = wallet.create_self_transfer(utxo_to_spend=utxo_2)
50+
spend_3 = wallet.create_self_transfer(utxo_to_spend=utxo_3)
5151

5252
self.log.info("Create another transaction which is time-locked to two blocks in the future")
5353
utxo = wallet.get_utxo(txid=coinbase_txids[0])
5454
timelock_tx = wallet.create_self_transfer(
55-
from_node=self.nodes[0],
5655
utxo_to_spend=utxo,
5756
mempool_valid=False,
5857
locktime=self.nodes[0].getblockcount() + 2
@@ -71,9 +70,9 @@ def run_test(self):
7170

7271
self.log.info("Create spend_2_1 and spend_3_1")
7372
spend_2_utxo = wallet.get_utxo(txid=spend_2['txid'])
74-
spend_2_1 = wallet.create_self_transfer(from_node=self.nodes[0], utxo_to_spend=spend_2_utxo)
73+
spend_2_1 = wallet.create_self_transfer(utxo_to_spend=spend_2_utxo)
7574
spend_3_utxo = wallet.get_utxo(txid=spend_3['txid'])
76-
spend_3_1 = wallet.create_self_transfer(from_node=self.nodes[0], utxo_to_spend=spend_3_utxo)
75+
spend_3_1 = wallet.create_self_transfer(utxo_to_spend=spend_3_utxo)
7776

7877
self.log.info("Broadcast and mine spend_3_1")
7978
spend_3_1_id = self.nodes[0].sendrawtransaction(spend_3_1['hex'])

test/functional/mempool_spend_coinbase.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def run_test(self):
4040
spend_mature_id = wallet.send_self_transfer(from_node=self.nodes[0], utxo_to_spend=utxo_mature)["txid"]
4141

4242
# other coinbase should be too immature to spend
43-
immature_tx = wallet.create_self_transfer(from_node=self.nodes[0], utxo_to_spend=utxo_immature, mempool_valid=False)
43+
immature_tx = wallet.create_self_transfer(utxo_to_spend=utxo_immature, mempool_valid=False)
4444
assert_raises_rpc_error(-26,
4545
"bad-txns-premature-spend-of-coinbase",
4646
lambda: self.nodes[0].sendrawtransaction(immature_tx['hex']))

test/functional/p2p_blocksonly.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def blocks_relay_conn_tests(self):
102102

103103
def check_p2p_tx_violation(self):
104104
self.log.info('Check that txs from P2P are rejected and result in disconnect')
105-
spendtx = self.miniwallet.create_self_transfer(from_node=self.nodes[0])
105+
spendtx = self.miniwallet.create_self_transfer()
106106

107107
with self.nodes[0].assert_debug_log(['transaction sent in violation of protocol peer=0']):
108108
self.nodes[0].p2ps[0].send_message(msg_tx(spendtx['tx']))

test/functional/rpc_generateblock.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def run_test(self):
6363
assert_equal(block['tx'][1], txid)
6464

6565
self.log.info('Generate block with raw tx')
66-
rawtx = miniwallet.create_self_transfer(from_node=node)['hex']
66+
rawtx = miniwallet.create_self_transfer()['hex']
6767
hash = self.generateblock(node, address, [rawtx])['hash']
6868

6969
block = node.getblock(hash, 1)
@@ -74,7 +74,7 @@ def run_test(self):
7474
self.log.info('Fail to generate block with out of order txs')
7575
txid1 = miniwallet.send_self_transfer(from_node=node)['txid']
7676
utxo1 = miniwallet.get_utxo(txid=txid1)
77-
rawtx2 = miniwallet.create_self_transfer(from_node=node, utxo_to_spend=utxo1)['hex']
77+
rawtx2 = miniwallet.create_self_transfer(utxo_to_spend=utxo1)['hex']
7878
assert_raises_rpc_error(-25, 'TestBlockValidity failed: bad-txns-inputs-missingorspent', self.generateblock, node, address, [rawtx2, txid1])
7979

8080
self.log.info('Fail to generate block with txid not in mempool')

test/functional/test_framework/wallet.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,9 @@ def send_to(self, *, from_node, scriptPubKey, amount, fee=1000):
179179
txid = self.sendrawtransaction(from_node=from_node, tx_hex=tx.serialize().hex())
180180
return txid, 1
181181

182-
def create_self_transfer(self, *, fee_rate=Decimal("0.003"), from_node, utxo_to_spend=None, mempool_valid=True, locktime=0, sequence=0):
182+
def create_self_transfer(self, *, fee_rate=Decimal("0.003"), from_node=None, utxo_to_spend=None, mempool_valid=True, locktime=0, sequence=0):
183183
"""Create and return a tx with the specified fee_rate. Fee may be exact or at most one satoshi higher than needed."""
184+
from_node = from_node or self._test_node
184185
utxo_to_spend = utxo_to_spend or self.get_utxo()
185186
if self._priv_key is None:
186187
vsize = Decimal(104) # anyone-can-spend

0 commit comments

Comments
 (0)