Skip to content

Commit ccc431d

Browse files
committed
Merge bitcoin/bitcoin#27640: test: Return dict in MiniWallet::send_to
faf4315 test: Return dict in MiniWallet::send_to (MarcoFalke) Pull request description: Returning a tuple has many issues: * If only one value is needed, it can not be indexed by name * If another value is added to the return value, all call sites need to be updated Bite the bullet now and update all call sites to fix the above issues. ACKs for top commit: brunoerg: crACK faf4315 theStack: Code-review ACK faf4315 stickies-v: Code review ACK faf4315 Tree-SHA512: 8ce1aca237df21f04b3990d0e5fcb49cc408fe6404399d3769a64eae1b5218941157d9785fce1bd9e45140cf70e06c3aa42646ee8f7b57855beb784fc3ef0261
2 parents 5f70cd3 + faf4315 commit ccc431d

File tree

8 files changed

+20
-16
lines changed

8 files changed

+20
-16
lines changed

test/functional/feature_coinstatsindex.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,14 @@ def _test_coin_stats_index(self):
149149
self.block_sanity_check(res5['block_info'])
150150

151151
# Generate and send a normal tx with two outputs
152-
tx1_txid, tx1_vout = self.wallet.send_to(
152+
tx1 = self.wallet.send_to(
153153
from_node=node,
154154
scriptPubKey=self.wallet.get_scriptPubKey(),
155155
amount=21 * COIN,
156156
)
157157

158158
# Find the right position of the 21 BTC output
159-
tx1_out_21 = self.wallet.get_utxo(txid=tx1_txid, vout=tx1_vout)
159+
tx1_out_21 = self.wallet.get_utxo(txid=tx1["txid"], vout=tx1["sent_vout"])
160160

161161
# Generate and send another tx with an OP_RETURN output (which is unspendable)
162162
tx2 = self.wallet.create_self_transfer(utxo_to_spend=tx1_out_21)['tx']

test/functional/feature_rbf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def make_utxo(self, node, amount, *, confirmed=True, scriptPubKey=None):
9393
confirmed - txout created will be confirmed in the blockchain;
9494
unconfirmed otherwise.
9595
"""
96-
txid, n = self.wallet.send_to(from_node=node, scriptPubKey=scriptPubKey or self.wallet.get_scriptPubKey(), amount=amount)
96+
tx = self.wallet.send_to(from_node=node, scriptPubKey=scriptPubKey or self.wallet.get_scriptPubKey(), amount=amount)
9797

9898
if confirmed:
9999
mempool_size = len(node.getrawmempool())
@@ -105,7 +105,7 @@ def make_utxo(self, node, amount, *, confirmed=True, scriptPubKey=None):
105105
assert new_size < mempool_size
106106
mempool_size = new_size
107107

108-
return self.wallet.get_utxo(txid=txid, vout=n)
108+
return self.wallet.get_utxo(txid=tx["txid"], vout=tx["sent_vout"])
109109

110110
def test_simple_doublespend(self):
111111
"""Simple doublespend"""

test/functional/interface_rest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def run_test(self):
9696
self.wallet = MiniWallet(self.nodes[0])
9797

9898
self.log.info("Broadcast test transaction and sync nodes")
99-
txid, _ = self.wallet.send_to(from_node=self.nodes[0], scriptPubKey=getnewdestination()[1], amount=int(0.1 * COIN))
99+
txid = self.wallet.send_to(from_node=self.nodes[0], scriptPubKey=getnewdestination()[1], amount=int(0.1 * COIN))["txid"]
100100
self.sync_all()
101101

102102
self.log.info("Test the /tx URI")
@@ -173,7 +173,7 @@ def run_test(self):
173173
# found with or without /checkmempool.
174174

175175
# do a tx and don't sync
176-
txid, _ = self.wallet.send_to(from_node=self.nodes[0], scriptPubKey=getnewdestination()[1], amount=int(0.1 * COIN))
176+
txid = self.wallet.send_to(from_node=self.nodes[0], scriptPubKey=getnewdestination()[1], amount=int(0.1 * COIN))["txid"]
177177
json_obj = self.test_rest_request(f"/tx/{txid}")
178178
# get the spent output to later check for utxo (should be spent by then)
179179
spent = (json_obj['vin'][0]['txid'], json_obj['vin'][0]['vout'])

test/functional/mempool_accept.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ def run_test(self):
350350

351351
self.log.info('A tiny transaction(in non-witness bytes) that is disallowed')
352352
tx = CTransaction()
353-
tx.vin.append(CTxIn(COutPoint(int(seed_tx[0], 16), seed_tx[1]), b"", SEQUENCE_FINAL))
353+
tx.vin.append(CTxIn(COutPoint(int(seed_tx["txid"], 16), seed_tx["sent_vout"]), b"", SEQUENCE_FINAL))
354354
tx.wit.vtxinwit = [CTxInWitness()]
355355
tx.wit.vtxinwit[0].scriptWitness.stack = [CScript([OP_TRUE])]
356356
tx.vout.append(CTxOut(0, CScript([OP_RETURN] + ([OP_0] * (MIN_PADDING - 2)))))

test/functional/mempool_sigoplimit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ def create_p2wsh_spending_tx(self, witness_script, output_script):
4949
"""Create a 1-input-1-output P2WSH spending transaction with only the
5050
witness script in the witness stack and the given output script."""
5151
# create P2WSH address and fund it via MiniWallet first
52-
txid, vout = self.wallet.send_to(
52+
fund = self.wallet.send_to(
5353
from_node=self.nodes[0],
5454
scriptPubKey=script_to_p2wsh_script(witness_script),
5555
amount=1000000,
5656
)
5757

5858
# create spending transaction
5959
tx = CTransaction()
60-
tx.vin = [CTxIn(COutPoint(int(txid, 16), vout))]
60+
tx.vin = [CTxIn(COutPoint(int(fund["txid"], 16), fund["sent_vout"]))]
6161
tx.wit.vtxinwit = [CTxInWitness()]
6262
tx.wit.vtxinwit[0].scriptWitness.stack = [bytes(witness_script)]
6363
tx.vout = [CTxOut(500000, output_script)]

test/functional/p2p_filter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def test_msg_mempool(self):
136136
filter_peer = P2PBloomFilter()
137137

138138
self.log.debug("Create a tx relevant to the peer before connecting")
139-
txid, _ = self.wallet.send_to(from_node=self.nodes[0], scriptPubKey=filter_peer.watch_script_pubkey, amount=9 * COIN)
139+
txid = self.wallet.send_to(from_node=self.nodes[0], scriptPubKey=filter_peer.watch_script_pubkey, amount=9 * COIN)["txid"]
140140

141141
self.log.debug("Send a mempool msg after connecting and check that the tx is received")
142142
self.nodes[0].add_p2p_connection(filter_peer)
@@ -183,14 +183,14 @@ def test_filter(self, filter_peer):
183183

184184
self.log.info('Check that we receive a tx if the filter matches a mempool tx')
185185
filter_peer.merkleblock_received = False
186-
txid, _ = self.wallet.send_to(from_node=self.nodes[0], scriptPubKey=filter_peer.watch_script_pubkey, amount=9 * COIN)
186+
txid = self.wallet.send_to(from_node=self.nodes[0], scriptPubKey=filter_peer.watch_script_pubkey, amount=9 * COIN)["txid"]
187187
filter_peer.wait_for_tx(txid)
188188
assert not filter_peer.merkleblock_received
189189

190190
self.log.info('Check that after deleting filter all txs get relayed again')
191191
filter_peer.send_and_ping(msg_filterclear())
192192
for _ in range(5):
193-
txid, _ = self.wallet.send_to(from_node=self.nodes[0], scriptPubKey=getnewdestination()[1], amount=7 * COIN)
193+
txid = self.wallet.send_to(from_node=self.nodes[0], scriptPubKey=getnewdestination()[1], amount=7 * COIN)["txid"]
194194
filter_peer.wait_for_tx(txid)
195195

196196
self.log.info('Check that request for filtered blocks is ignored if no filter is set')

test/functional/rpc_createmultisig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def do_multisig(self):
195195
wmulti.unloadwallet()
196196

197197
spk = address_to_scriptpubkey(madd)
198-
txid, _ = self.wallet.send_to(from_node=self.nodes[0], scriptPubKey=spk, amount=1300)
198+
txid = self.wallet.send_to(from_node=self.nodes[0], scriptPubKey=spk, amount=1300)["txid"]
199199
tx = node0.getrawtransaction(txid, True)
200200
vout = [v["n"] for v in tx["vout"] if madd == v["scriptPubKey"]["address"]]
201201
assert len(vout) == 1

test/functional/test_framework/wallet.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,15 +256,19 @@ def send_to(self, *, from_node, scriptPubKey, amount, fee=1000):
256256
Note that this method fails if there is no single internal utxo
257257
available that can cover the cost for the amount and the fixed fee
258258
(the utxo with the largest value is taken).
259-
260-
Returns a tuple (txid, n) referring to the created external utxo outpoint.
261259
"""
262260
tx = self.create_self_transfer(fee_rate=0)["tx"]
263261
assert_greater_than_or_equal(tx.vout[0].nValue, amount + fee)
264262
tx.vout[0].nValue -= (amount + fee) # change output -> MiniWallet
265263
tx.vout.append(CTxOut(amount, scriptPubKey)) # arbitrary output -> to be returned
266264
txid = self.sendrawtransaction(from_node=from_node, tx_hex=tx.serialize().hex())
267-
return txid, 1
265+
return {
266+
"sent_vout": 1,
267+
"txid": txid,
268+
"wtxid": tx.getwtxid(),
269+
"hex": tx.serialize().hex(),
270+
"tx": tx,
271+
}
268272

269273
def send_self_transfer_multi(self, *, from_node, **kwargs):
270274
"""Call create_self_transfer_multi and send the transaction."""

0 commit comments

Comments
 (0)