Merge bitcoin/bitcoin#27640: test: Return dict in MiniWallet::send_to

faf4315c88 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 faf4315c88
  theStack:
    Code-review ACK faf4315c88
  stickies-v:
    Code review ACK faf4315c88

Tree-SHA512: 8ce1aca237df21f04b3990d0e5fcb49cc408fe6404399d3769a64eae1b5218941157d9785fce1bd9e45140cf70e06c3aa42646ee8f7b57855beb784fc3ef0261
This commit is contained in:
fanquake 2023-05-18 14:14:17 +01:00
commit ccc431d53e
No known key found for this signature in database
GPG key ID: 2EEB9F5CC09526C1
8 changed files with 20 additions and 16 deletions

View file

@ -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']

View file

@ -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"""

View file

@ -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'])

View file

@ -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)))))

View file

@ -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)]

View file

@ -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')

View file

@ -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

View file

@ -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."""