Most of this code in the test can be removed:
0diff --git a/test/functional/p2p_tx_privacy.py b/test/functional/p2p_tx_privacy.py
1index 7944095abc..d7139f5ab7 100755
2--- a/test/functional/p2p_tx_privacy.py
3+++ b/test/functional/p2p_tx_privacy.py
4@@ -17,54 +17,29 @@ from test_framework.p2p import (
5 p2p_lock,
6 )
7 from test_framework.test_framework import BitcoinTestFramework
8+from test_framework.wallet import MiniWallet
9
10 class P2PTxSpy(P2PInterface):
11- def __init__(self, wtxidrelay=True):
12- super().__init__(wtxidrelay=wtxidrelay)
13-
14 def on_version(self, message):
15 # Avoid sending verack in response to version.
16 # When calling add_p2p_connection, wait_for_verack=False must be set (see
17 # comment in add_p2p_connection).
18- if message.nVersion >= 70016 and self.wtxidrelay:
19- self.send_message(msg_wtxidrelay())
20+ self.send_message(msg_wtxidrelay())
21
22 class TxPrivacyTest(BitcoinTestFramework):
23 def set_test_params(self):
24- self.setup_clean_chain = True
25 self.num_nodes = 1
26
27 def run_test(self):
28- self.generate(self.nodes[0], 200)
29+ self.wallet = MiniWallet(self.nodes[0])
30+ self.wallet.rescan_utxos()
31
32 tx_originator = self.nodes[0].add_p2p_connection(P2PInterface())
33- spy = self.nodes[0].add_p2p_connection(P2PTxSpy(), send_version=False, wait_for_verack=False)
34-
35- # Spy sends version message to enable tx relay but doesn't send a verack
36- txrelay_version_msg = msg_version()
37- txrelay_version_msg.nVersion = P2P_VERSION
38- txrelay_version_msg.strSubVer = "😈😈😈"
39- txrelay_version_msg.nServices = P2P_SERVICES
40- txrelay_version_msg.relay = 1
41- spy.send_message(txrelay_version_msg)
42+ spy = self.nodes[0].add_p2p_connection(P2PTxSpy(), wait_for_verack=False)
43 spy.wait_for_verack()
44
45 # Create a tx to send
46- prevtx = self.nodes[0].getblock(self.nodes[0].getblockhash(5), 2)['tx'][0]
47- rawtx = self.nodes[0].createrawtransaction(
48- inputs=[{'txid': prevtx['txid'], 'vout': 0}],
49- outputs=[{self.nodes[0].get_deterministic_priv_key().address: 50 - 0.00125}],
50- )
51- sigtx = self.nodes[0].signrawtransactionwithkey(
52- hexstring=rawtx,
53- privkeys=[self.nodes[0].get_deterministic_priv_key().key],
54- prevtxs=[{
55- 'txid': prevtx['txid'],
56- 'vout': 0,
57- 'scriptPubKey': prevtx['vout'][0]['scriptPubKey']['hex'],
58- }],
59- )['hex']
60- tx = tx_from_hex(sigtx)
61+ tx = self.wallet.create_self_transfer()["tx"]
62
63 # tx_originator sends a tx
64 tx_originator.send_and_ping(msg_tx(tx))