diff options
author | fanquake <fanquake@gmail.com> | 2023-05-18 14:14:17 +0100 |
---|---|---|
committer | fanquake <fanquake@gmail.com> | 2023-05-18 14:26:13 +0100 |
commit | ccc431d53ea05081e8f827d6165221129f362ebb (patch) | |
tree | 2f0b8fc05cc7e41bafcc35cf934485d5de46968a /test/functional | |
parent | 5f70cd39974dcb966f2a7913dda216258c2d24c1 (diff) | |
parent | faf4315c88d8c81c2ff84870bc81aef3cf719816 (diff) | |
download | bitcoin-ccc431d53ea05081e8f827d6165221129f362ebb.tar.xz |
Merge bitcoin/bitcoin#27640: test: Return dict in MiniWallet::send_to
faf4315c88d8c81c2ff84870bc81aef3cf719816 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 faf4315c88d8c81c2ff84870bc81aef3cf719816
theStack:
Code-review ACK faf4315c88d8c81c2ff84870bc81aef3cf719816
stickies-v:
Code review ACK faf4315c88d8c81c2ff84870bc81aef3cf719816
Tree-SHA512: 8ce1aca237df21f04b3990d0e5fcb49cc408fe6404399d3769a64eae1b5218941157d9785fce1bd9e45140cf70e06c3aa42646ee8f7b57855beb784fc3ef0261
Diffstat (limited to 'test/functional')
-rwxr-xr-x | test/functional/feature_coinstatsindex.py | 4 | ||||
-rwxr-xr-x | test/functional/feature_rbf.py | 4 | ||||
-rwxr-xr-x | test/functional/interface_rest.py | 4 | ||||
-rwxr-xr-x | test/functional/mempool_accept.py | 2 | ||||
-rwxr-xr-x | test/functional/mempool_sigoplimit.py | 4 | ||||
-rwxr-xr-x | test/functional/p2p_filter.py | 6 | ||||
-rwxr-xr-x | test/functional/rpc_createmultisig.py | 2 | ||||
-rw-r--r-- | test/functional/test_framework/wallet.py | 10 |
8 files changed, 20 insertions, 16 deletions
diff --git a/test/functional/feature_coinstatsindex.py b/test/functional/feature_coinstatsindex.py index eacdeb43eb..2ffb182946 100755 --- a/test/functional/feature_coinstatsindex.py +++ b/test/functional/feature_coinstatsindex.py @@ -149,14 +149,14 @@ class CoinStatsIndexTest(BitcoinTestFramework): self.block_sanity_check(res5['block_info']) # Generate and send a normal tx with two outputs - tx1_txid, tx1_vout = self.wallet.send_to( + tx1 = self.wallet.send_to( from_node=node, scriptPubKey=self.wallet.get_scriptPubKey(), amount=21 * COIN, ) # Find the right position of the 21 BTC output - tx1_out_21 = self.wallet.get_utxo(txid=tx1_txid, vout=tx1_vout) + tx1_out_21 = self.wallet.get_utxo(txid=tx1["txid"], vout=tx1["sent_vout"]) # Generate and send another tx with an OP_RETURN output (which is unspendable) tx2 = self.wallet.create_self_transfer(utxo_to_spend=tx1_out_21)['tx'] diff --git a/test/functional/feature_rbf.py b/test/functional/feature_rbf.py index 947d2e8273..c5eeaf66e0 100755 --- a/test/functional/feature_rbf.py +++ b/test/functional/feature_rbf.py @@ -93,7 +93,7 @@ class ReplaceByFeeTest(BitcoinTestFramework): confirmed - txout created will be confirmed in the blockchain; unconfirmed otherwise. """ - txid, n = self.wallet.send_to(from_node=node, scriptPubKey=scriptPubKey or self.wallet.get_scriptPubKey(), amount=amount) + tx = self.wallet.send_to(from_node=node, scriptPubKey=scriptPubKey or self.wallet.get_scriptPubKey(), amount=amount) if confirmed: mempool_size = len(node.getrawmempool()) @@ -105,7 +105,7 @@ class ReplaceByFeeTest(BitcoinTestFramework): assert new_size < mempool_size mempool_size = new_size - return self.wallet.get_utxo(txid=txid, vout=n) + return self.wallet.get_utxo(txid=tx["txid"], vout=tx["sent_vout"]) def test_simple_doublespend(self): """Simple doublespend""" diff --git a/test/functional/interface_rest.py b/test/functional/interface_rest.py index 5017f77d18..315d717986 100755 --- a/test/functional/interface_rest.py +++ b/test/functional/interface_rest.py @@ -96,7 +96,7 @@ class RESTTest (BitcoinTestFramework): self.wallet = MiniWallet(self.nodes[0]) self.log.info("Broadcast test transaction and sync nodes") - txid, _ = self.wallet.send_to(from_node=self.nodes[0], scriptPubKey=getnewdestination()[1], amount=int(0.1 * COIN)) + txid = self.wallet.send_to(from_node=self.nodes[0], scriptPubKey=getnewdestination()[1], amount=int(0.1 * COIN))["txid"] self.sync_all() self.log.info("Test the /tx URI") @@ -173,7 +173,7 @@ class RESTTest (BitcoinTestFramework): # found with or without /checkmempool. # do a tx and don't sync - txid, _ = self.wallet.send_to(from_node=self.nodes[0], scriptPubKey=getnewdestination()[1], amount=int(0.1 * COIN)) + txid = self.wallet.send_to(from_node=self.nodes[0], scriptPubKey=getnewdestination()[1], amount=int(0.1 * COIN))["txid"] json_obj = self.test_rest_request(f"/tx/{txid}") # get the spent output to later check for utxo (should be spent by then) spent = (json_obj['vin'][0]['txid'], json_obj['vin'][0]['vout']) diff --git a/test/functional/mempool_accept.py b/test/functional/mempool_accept.py index 362b407062..737a8d0a2e 100755 --- a/test/functional/mempool_accept.py +++ b/test/functional/mempool_accept.py @@ -350,7 +350,7 @@ class MempoolAcceptanceTest(BitcoinTestFramework): self.log.info('A tiny transaction(in non-witness bytes) that is disallowed') tx = CTransaction() - tx.vin.append(CTxIn(COutPoint(int(seed_tx[0], 16), seed_tx[1]), b"", SEQUENCE_FINAL)) + tx.vin.append(CTxIn(COutPoint(int(seed_tx["txid"], 16), seed_tx["sent_vout"]), b"", SEQUENCE_FINAL)) tx.wit.vtxinwit = [CTxInWitness()] tx.wit.vtxinwit[0].scriptWitness.stack = [CScript([OP_TRUE])] tx.vout.append(CTxOut(0, CScript([OP_RETURN] + ([OP_0] * (MIN_PADDING - 2))))) diff --git a/test/functional/mempool_sigoplimit.py b/test/functional/mempool_sigoplimit.py index b178b9feda..962b2b19bd 100755 --- a/test/functional/mempool_sigoplimit.py +++ b/test/functional/mempool_sigoplimit.py @@ -49,7 +49,7 @@ class BytesPerSigOpTest(BitcoinTestFramework): """Create a 1-input-1-output P2WSH spending transaction with only the witness script in the witness stack and the given output script.""" # create P2WSH address and fund it via MiniWallet first - txid, vout = self.wallet.send_to( + fund = self.wallet.send_to( from_node=self.nodes[0], scriptPubKey=script_to_p2wsh_script(witness_script), amount=1000000, @@ -57,7 +57,7 @@ class BytesPerSigOpTest(BitcoinTestFramework): # create spending transaction tx = CTransaction() - tx.vin = [CTxIn(COutPoint(int(txid, 16), vout))] + tx.vin = [CTxIn(COutPoint(int(fund["txid"], 16), fund["sent_vout"]))] tx.wit.vtxinwit = [CTxInWitness()] tx.wit.vtxinwit[0].scriptWitness.stack = [bytes(witness_script)] tx.vout = [CTxOut(500000, output_script)] diff --git a/test/functional/p2p_filter.py b/test/functional/p2p_filter.py index b3e68ca536..6699cc3528 100755 --- a/test/functional/p2p_filter.py +++ b/test/functional/p2p_filter.py @@ -136,7 +136,7 @@ class FilterTest(BitcoinTestFramework): filter_peer = P2PBloomFilter() self.log.debug("Create a tx relevant to the peer before connecting") - txid, _ = self.wallet.send_to(from_node=self.nodes[0], scriptPubKey=filter_peer.watch_script_pubkey, amount=9 * COIN) + txid = self.wallet.send_to(from_node=self.nodes[0], scriptPubKey=filter_peer.watch_script_pubkey, amount=9 * COIN)["txid"] self.log.debug("Send a mempool msg after connecting and check that the tx is received") self.nodes[0].add_p2p_connection(filter_peer) @@ -183,14 +183,14 @@ class FilterTest(BitcoinTestFramework): self.log.info('Check that we receive a tx if the filter matches a mempool tx') filter_peer.merkleblock_received = False - txid, _ = self.wallet.send_to(from_node=self.nodes[0], scriptPubKey=filter_peer.watch_script_pubkey, amount=9 * COIN) + txid = self.wallet.send_to(from_node=self.nodes[0], scriptPubKey=filter_peer.watch_script_pubkey, amount=9 * COIN)["txid"] filter_peer.wait_for_tx(txid) assert not filter_peer.merkleblock_received self.log.info('Check that after deleting filter all txs get relayed again') filter_peer.send_and_ping(msg_filterclear()) for _ in range(5): - txid, _ = self.wallet.send_to(from_node=self.nodes[0], scriptPubKey=getnewdestination()[1], amount=7 * COIN) + txid = self.wallet.send_to(from_node=self.nodes[0], scriptPubKey=getnewdestination()[1], amount=7 * COIN)["txid"] filter_peer.wait_for_tx(txid) self.log.info('Check that request for filtered blocks is ignored if no filter is set') diff --git a/test/functional/rpc_createmultisig.py b/test/functional/rpc_createmultisig.py index bec499107f..279fb01a57 100755 --- a/test/functional/rpc_createmultisig.py +++ b/test/functional/rpc_createmultisig.py @@ -195,7 +195,7 @@ class RpcCreateMultiSigTest(BitcoinTestFramework): wmulti.unloadwallet() spk = address_to_scriptpubkey(madd) - txid, _ = self.wallet.send_to(from_node=self.nodes[0], scriptPubKey=spk, amount=1300) + txid = self.wallet.send_to(from_node=self.nodes[0], scriptPubKey=spk, amount=1300)["txid"] tx = node0.getrawtransaction(txid, True) vout = [v["n"] for v in tx["vout"] if madd == v["scriptPubKey"]["address"]] assert len(vout) == 1 diff --git a/test/functional/test_framework/wallet.py b/test/functional/test_framework/wallet.py index fcd396c700..64606b818b 100644 --- a/test/functional/test_framework/wallet.py +++ b/test/functional/test_framework/wallet.py @@ -256,15 +256,19 @@ class MiniWallet: Note that this method fails if there is no single internal utxo available that can cover the cost for the amount and the fixed fee (the utxo with the largest value is taken). - - Returns a tuple (txid, n) referring to the created external utxo outpoint. """ tx = self.create_self_transfer(fee_rate=0)["tx"] assert_greater_than_or_equal(tx.vout[0].nValue, amount + fee) tx.vout[0].nValue -= (amount + fee) # change output -> MiniWallet tx.vout.append(CTxOut(amount, scriptPubKey)) # arbitrary output -> to be returned txid = self.sendrawtransaction(from_node=from_node, tx_hex=tx.serialize().hex()) - return txid, 1 + return { + "sent_vout": 1, + "txid": txid, + "wtxid": tx.getwtxid(), + "hex": tx.serialize().hex(), + "tx": tx, + } def send_self_transfer_multi(self, *, from_node, **kwargs): """Call create_self_transfer_multi and send the transaction.""" |