Skip to content

Commit 7aa4b32

Browse files
committed
test: refactor: simplify p2p_tx_download.py by using MiniWallet
1 parent 2343886 commit 7aa4b32

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

test/functional/p2p_tx_download.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""
66
Test transaction download behavior
77
"""
8+
import time
89

910
from test_framework.messages import (
1011
CInv,
@@ -13,7 +14,6 @@
1314
MSG_WTX,
1415
msg_inv,
1516
msg_notfound,
16-
tx_from_hex,
1717
)
1818
from test_framework.p2p import (
1919
P2PInterface,
@@ -23,9 +23,7 @@
2323
from test_framework.util import (
2424
assert_equal,
2525
)
26-
from test_framework.address import ADDRESS_BCRT1_UNSPENDABLE
27-
28-
import time
26+
from test_framework.wallet import MiniWallet
2927

3028

3129
class TestP2PConn(P2PInterface):
@@ -88,19 +86,8 @@ def getdata_found(peer_index):
8886

8987
def test_inv_block(self):
9088
self.log.info("Generate a transaction on node 0")
91-
tx = self.nodes[0].createrawtransaction(
92-
inputs=[{ # coinbase
93-
"txid": self.nodes[0].getblock(self.nodes[0].getblockhash(1))['tx'][0],
94-
"vout": 0
95-
}],
96-
outputs={ADDRESS_BCRT1_UNSPENDABLE: 50 - 0.00025},
97-
)
98-
tx = self.nodes[0].signrawtransactionwithkey(
99-
hexstring=tx,
100-
privkeys=[self.nodes[0].get_deterministic_priv_key().key],
101-
)['hex']
102-
ctx = tx_from_hex(tx)
103-
txid = int(ctx.rehash(), 16)
89+
tx = self.wallet.create_self_transfer()
90+
txid = int(tx['txid'], 16)
10491

10592
self.log.info(
10693
"Announce the transaction to all nodes from all {} incoming peers, but never send it".format(NUM_INBOUND))
@@ -109,7 +96,7 @@ def test_inv_block(self):
10996
p.send_and_ping(msg)
11097

11198
self.log.info("Put the tx in node 0's mempool")
112-
self.nodes[0].sendrawtransaction(tx)
99+
self.nodes[0].sendrawtransaction(tx['hex'])
113100

114101
# Since node 1 is connected outbound to an honest peer (node 0), it
115102
# should get the tx within a timeout. (Assuming that node 0
@@ -255,6 +242,8 @@ def test_spurious_notfound(self):
255242
self.nodes[0].p2ps[0].send_message(msg_notfound(vec=[CInv(MSG_TX, 1)]))
256243

257244
def run_test(self):
245+
self.wallet = MiniWallet(self.nodes[0])
246+
258247
# Run tests without mocktime that only need one peer-connection first, to avoid restarting the nodes
259248
self.test_expiry_fallback()
260249
self.test_disconnect_fallback()

0 commit comments

Comments
 (0)