@@ -41,6 +41,7 @@ func (s *Suite) Is_66(t *utesting.T) {
41
41
// make sure the chain head is correct.
42
42
func (s * Suite ) TestStatus_66 (t * utesting.T ) {
43
43
conn := s .dial66 (t )
44
+ defer conn .Close ()
44
45
// get protoHandshake
45
46
conn .handshake (t )
46
47
// get status
@@ -60,6 +61,7 @@ func (s *Suite) TestStatus_66(t *utesting.T) {
60
61
// an eth66 `GetBlockHeaders` request and that the response is accurate.
61
62
func (s * Suite ) TestGetBlockHeaders_66 (t * utesting.T ) {
62
63
conn := s .setupConnection66 (t )
64
+ defer conn .Close ()
63
65
// get block headers
64
66
req := & eth.GetBlockHeadersPacket66 {
65
67
RequestId : 3 ,
@@ -84,6 +86,8 @@ func (s *Suite) TestGetBlockHeaders_66(t *utesting.T) {
84
86
func (s * Suite ) TestSimultaneousRequests_66 (t * utesting.T ) {
85
87
// create two connections
86
88
conn1 , conn2 := s .setupConnection66 (t ), s .setupConnection66 (t )
89
+ defer conn1 .Close ()
90
+ defer conn2 .Close ()
87
91
// create two requests
88
92
req1 := & eth.GetBlockHeadersPacket66 {
89
93
RequestId : 111 ,
@@ -122,6 +126,9 @@ func (s *Suite) TestSimultaneousRequests_66(t *utesting.T) {
122
126
// propagated to the given node's peer(s) on the eth66 protocol.
123
127
func (s * Suite ) TestBroadcast_66 (t * utesting.T ) {
124
128
sendConn , receiveConn := s .setupConnection66 (t ), s .setupConnection66 (t )
129
+ defer sendConn .Close ()
130
+ defer receiveConn .Close ()
131
+
125
132
nextBlock := len (s .chain .blocks )
126
133
blockAnnouncement := & NewBlock {
127
134
Block : s .fullChain .blocks [nextBlock ],
@@ -141,6 +148,7 @@ func (s *Suite) TestBroadcast_66(t *utesting.T) {
141
148
// the eth66 protocol.
142
149
func (s * Suite ) TestGetBlockBodies_66 (t * utesting.T ) {
143
150
conn := s .setupConnection66 (t )
151
+ defer conn .Close ()
144
152
// create block bodies request
145
153
id := uint64 (55 )
146
154
req := & eth.GetBlockBodiesPacket66 {
@@ -195,17 +203,20 @@ func (s *Suite) TestLargeAnnounce_66(t *utesting.T) {
195
203
t .Fatalf ("could not write to connection: %v" , err )
196
204
}
197
205
// Invalid announcement, check that peer disconnected
198
- switch msg := sendConn .ReadAndServe (s .chain , timeout ).(type ) {
206
+ switch msg := sendConn .ReadAndServe (s .chain , time . Second * 8 ).(type ) {
199
207
case * Disconnect :
200
208
case * Error :
201
209
break
202
210
default :
203
211
t .Fatalf ("unexpected: %s wanted disconnect" , pretty .Sdump (msg ))
204
212
}
213
+ sendConn .Close ()
205
214
}
206
215
// Test the last block as a valid block
207
- sendConn := s .setupConnection66 (t )
208
- receiveConn := s .setupConnection66 (t )
216
+ sendConn , receiveConn := s .setupConnection66 (t ), s .setupConnection66 (t )
217
+ defer sendConn .Close ()
218
+ defer receiveConn .Close ()
219
+
209
220
s .testAnnounce66 (t , sendConn , receiveConn , blocks [3 ])
210
221
// update test suite chain
211
222
s .chain .blocks = append (s .chain .blocks , s .fullChain .blocks [nextBlock ])
@@ -216,12 +227,17 @@ func (s *Suite) TestLargeAnnounce_66(t *utesting.T) {
216
227
}
217
228
218
229
func (s * Suite ) TestOldAnnounce_66 (t * utesting.T ) {
219
- s .oldAnnounce (t , s .setupConnection66 (t ), s .setupConnection66 (t ))
230
+ sendConn , recvConn := s .setupConnection66 (t ), s .setupConnection66 (t )
231
+ defer sendConn .Close ()
232
+ defer recvConn .Close ()
233
+
234
+ s .oldAnnounce (t , sendConn , recvConn )
220
235
}
221
236
222
237
// TestMaliciousHandshake_66 tries to send malicious data during the handshake.
223
238
func (s * Suite ) TestMaliciousHandshake_66 (t * utesting.T ) {
224
239
conn := s .dial66 (t )
240
+ defer conn .Close ()
225
241
// write hello to client
226
242
pub0 := crypto .FromECDSAPub (& conn .ourKey .PublicKey )[1 :]
227
243
handshakes := []* Hello {
@@ -295,6 +311,7 @@ func (s *Suite) TestMaliciousHandshake_66(t *utesting.T) {
295
311
// TestMaliciousStatus_66 sends a status package with a large total difficulty.
296
312
func (s * Suite ) TestMaliciousStatus_66 (t * utesting.T ) {
297
313
conn := s .dial66 (t )
314
+ defer conn .Close ()
298
315
// get protoHandshake
299
316
conn .handshake (t )
300
317
status := & Status {
@@ -334,23 +351,37 @@ func (s *Suite) TestTransaction_66(t *utesting.T) {
334
351
}
335
352
336
353
func (s * Suite ) TestMaliciousTx_66 (t * utesting.T ) {
337
- tests := []* types.Transaction {
354
+ badTxs := []* types.Transaction {
338
355
getOldTxFromChain (t , s ),
339
356
invalidNonceTx (t , s ),
340
357
hugeAmount (t , s ),
341
358
hugeGasPrice (t , s ),
342
359
hugeData (t , s ),
343
360
}
344
- for i , tx := range tests {
361
+ sendConn := s .setupConnection66 (t )
362
+ defer sendConn .Close ()
363
+ // set up receiving connection before sending txs to make sure
364
+ // no announcements are missed
365
+ recvConn := s .setupConnection66 (t )
366
+ defer recvConn .Close ()
367
+
368
+ for i , tx := range badTxs {
345
369
t .Logf ("Testing malicious tx propagation: %v\n " , i )
346
- sendFailingTx66 (t , s , tx )
370
+ if err := sendConn .Write (& Transactions {tx }); err != nil {
371
+ t .Fatalf ("could not write to connection: %v" , err )
372
+ }
373
+
347
374
}
375
+ // check to make sure bad txs aren't propagated
376
+ waitForTxPropagation (t , s , badTxs , recvConn )
348
377
}
349
378
350
379
// TestZeroRequestID_66 checks that a request ID of zero is still handled
351
380
// by the node.
352
381
func (s * Suite ) TestZeroRequestID_66 (t * utesting.T ) {
353
382
conn := s .setupConnection66 (t )
383
+ defer conn .Close ()
384
+
354
385
req := & eth.GetBlockHeadersPacket66 {
355
386
RequestId : 0 ,
356
387
GetBlockHeadersPacket : & eth.GetBlockHeadersPacket {
@@ -367,6 +398,7 @@ func (s *Suite) TestZeroRequestID_66(t *utesting.T) {
367
398
// concurrently to a single node.
368
399
func (s * Suite ) TestSameRequestID_66 (t * utesting.T ) {
369
400
conn := s .setupConnection66 (t )
401
+ defer conn .Close ()
370
402
// create two separate requests with same ID
371
403
reqID := uint64 (1234 )
372
404
req1 := & eth.GetBlockHeadersPacket66 {
0 commit comments