5
5
"""
6
6
Test transaction download behavior
7
7
"""
8
+ import time
8
9
9
10
from test_framework .messages import (
10
11
CInv ,
13
14
MSG_WTX ,
14
15
msg_inv ,
15
16
msg_notfound ,
16
- tx_from_hex ,
17
17
)
18
18
from test_framework .p2p import (
19
19
P2PInterface ,
23
23
from test_framework .util import (
24
24
assert_equal ,
25
25
)
26
- from test_framework .address import ADDRESS_BCRT1_UNSPENDABLE
27
-
28
- import time
26
+ from test_framework .wallet import MiniWallet
29
27
30
28
31
29
class TestP2PConn (P2PInterface ):
@@ -88,19 +86,8 @@ def getdata_found(peer_index):
88
86
89
87
def test_inv_block (self ):
90
88
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 )
104
91
105
92
self .log .info (
106
93
"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):
109
96
p .send_and_ping (msg )
110
97
111
98
self .log .info ("Put the tx in node 0's mempool" )
112
- self .nodes [0 ].sendrawtransaction (tx )
99
+ self .nodes [0 ].sendrawtransaction (tx [ 'hex' ] )
113
100
114
101
# Since node 1 is connected outbound to an honest peer (node 0), it
115
102
# should get the tx within a timeout. (Assuming that node 0
@@ -255,6 +242,8 @@ def test_spurious_notfound(self):
255
242
self .nodes [0 ].p2ps [0 ].send_message (msg_notfound (vec = [CInv (MSG_TX , 1 )]))
256
243
257
244
def run_test (self ):
245
+ self .wallet = MiniWallet (self .nodes [0 ])
246
+
258
247
# Run tests without mocktime that only need one peer-connection first, to avoid restarting the nodes
259
248
self .test_expiry_fallback ()
260
249
self .test_disconnect_fallback ()
0 commit comments