7
7
import struct
8
8
import sys
9
9
10
- from test_framework import messages
10
+ from test_framework .messages import (
11
+ CBlockHeader ,
12
+ CInv ,
13
+ msg_getdata ,
14
+ msg_headers ,
15
+ msg_inv ,
16
+ msg_ping ,
17
+ MSG_TX ,
18
+ ser_string ,
19
+ )
11
20
from test_framework .mininode import (
12
21
NetworkThread ,
13
22
P2PDataStore ,
@@ -25,7 +34,7 @@ def __init__(self, *, str_data):
25
34
self .str_data = str_data .encode () if not isinstance (str_data , bytes ) else str_data
26
35
27
36
def serialize (self ):
28
- return messages . ser_string (self .str_data )
37
+ return ser_string (self .str_data )
29
38
30
39
def __repr__ (self ):
31
40
return "{}(data={})" .format (self .msgtype , self .str_data )
@@ -135,7 +144,7 @@ def run_test(self):
135
144
# For some reason unknown to me, we sometimes have to push additional data to the
136
145
# peer in order for it to realize a disconnect.
137
146
try :
138
- node .p2p .send_message (messages . msg_ping (nonce = 123123 ))
147
+ node .p2p .send_message (msg_ping (nonce = 123123 ))
139
148
except IOError :
140
149
pass
141
150
@@ -158,7 +167,7 @@ async def swap_magic_bytes():
158
167
asyncio .run_coroutine_threadsafe (swap_magic_bytes (), NetworkThread .network_event_loop ).result ()
159
168
160
169
with self .nodes [0 ].assert_debug_log (['PROCESSMESSAGE: INVALID MESSAGESTART ping' ]):
161
- conn .send_message (messages . msg_ping (nonce = 0xff ))
170
+ conn .send_message (msg_ping (nonce = 0xff ))
162
171
conn .wait_for_disconnect (timeout = 1 )
163
172
self .nodes [0 ].disconnect_p2ps ()
164
173
@@ -206,13 +215,13 @@ def test_msgtype(self):
206
215
def test_large_inv (self ):
207
216
conn = self .nodes [0 ].add_p2p_connection (P2PInterface ())
208
217
with self .nodes [0 ].assert_debug_log (['Misbehaving' , 'peer=4 (0 -> 20): message inv size() = 50001' ]):
209
- msg = messages . msg_inv ([messages . CInv (messages . MSG_TX , 1 )] * 50001 )
218
+ msg = msg_inv ([CInv (MSG_TX , 1 )] * 50001 )
210
219
conn .send_and_ping (msg )
211
220
with self .nodes [0 ].assert_debug_log (['Misbehaving' , 'peer=4 (20 -> 40): message getdata size() = 50001' ]):
212
- msg = messages . msg_getdata ([messages . CInv (messages . MSG_TX , 1 )] * 50001 )
221
+ msg = msg_getdata ([CInv (MSG_TX , 1 )] * 50001 )
213
222
conn .send_and_ping (msg )
214
223
with self .nodes [0 ].assert_debug_log (['Misbehaving' , 'peer=4 (40 -> 60): headers message size = 2001' ]):
215
- msg = messages . msg_headers ([messages . CBlockHeader ()] * 2001 )
224
+ msg = msg_headers ([CBlockHeader ()] * 2001 )
216
225
conn .send_and_ping (msg )
217
226
self .nodes [0 ].disconnect_p2ps ()
218
227
0 commit comments