Skip to content

Commit 79e82fa

Browse files
committed
ignore propagated txs from old tests while waiting for block, update test chain only after block is received
1 parent a81cf0d commit 79e82fa

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

cmd/devp2p/internal/ethtest/eth66_suite.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,12 @@ func (s *Suite) TestLargeAnnounce_66(t *utesting.T) {
222222
defer receiveConn.Close()
223223

224224
s.testAnnounce66(t, sendConn, receiveConn, blocks[3])
225-
// update test suite chain
226-
s.chain.blocks = append(s.chain.blocks, s.fullChain.blocks[nextBlock])
227225
// wait for client to update its chain
228226
if err := receiveConn.waitForBlock66(s.fullChain.blocks[nextBlock]); err != nil {
229227
t.Fatal(err)
230228
}
229+
// update test suite chain
230+
s.chain.blocks = append(s.chain.blocks, s.fullChain.blocks[nextBlock])
231231
}
232232

233233
func (s *Suite) TestOldAnnounce_66(t *utesting.T) {

cmd/devp2p/internal/ethtest/eth66_suiteHelpers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,10 @@ func (s *Suite) sendNextBlock66(t *utesting.T) {
319319
}
320320
// send announcement and wait for node to request the header
321321
s.testAnnounce66(t, sendConn, receiveConn, blockAnnouncement)
322-
// update test suite chain
323-
s.chain.blocks = append(s.chain.blocks, s.fullChain.blocks[nextBlock])
324322
// wait for client to update its chain
325323
if err := receiveConn.waitForBlock66(s.chain.Head()); err != nil {
326324
t.Fatal(err)
327325
}
326+
// update test suite chain
327+
s.chain.blocks = append(s.chain.blocks, s.fullChain.blocks[nextBlock])
328328
}

cmd/devp2p/internal/ethtest/suite.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,22 +260,28 @@ func (s *Suite) TestGetBlockBodies(t *utesting.T) {
260260
// TestBroadcast tests whether a block announcement is correctly
261261
// propagated to the given node's peer(s).
262262
func (s *Suite) TestBroadcast(t *utesting.T) {
263+
s.sendNextBlock(t)
264+
}
265+
266+
func (s *Suite) sendNextBlock(t *utesting.T) {
263267
sendConn, receiveConn := s.setupConnection(t), s.setupConnection(t)
264268
defer sendConn.Close()
265269
defer receiveConn.Close()
266270

271+
// create new block announcement
267272
nextBlock := len(s.chain.blocks)
268273
blockAnnouncement := &NewBlock{
269274
Block: s.fullChain.blocks[nextBlock],
270275
TD: s.fullChain.TD(nextBlock + 1),
271276
}
277+
// send announcement and wait for node to request the header
272278
s.testAnnounce(t, sendConn, receiveConn, blockAnnouncement)
273-
// update test suite chain
274-
s.chain.blocks = append(s.chain.blocks, s.fullChain.blocks[nextBlock])
275279
// wait for client to update its chain
276280
if err := receiveConn.waitForBlock(s.chain.Head()); err != nil {
277281
t.Fatal(err)
278282
}
283+
// update test suite chain
284+
s.chain.blocks = append(s.chain.blocks, s.fullChain.blocks[nextBlock])
279285
}
280286

281287
// TestMaliciousHandshake tries to send malicious data during the handshake.
@@ -400,12 +406,12 @@ func (s *Suite) TestLargeAnnounce(t *utesting.T) {
400406
defer receiveConn.Close()
401407

402408
s.testAnnounce(t, sendConn, receiveConn, blocks[3])
403-
// update test suite chain
404-
s.chain.blocks = append(s.chain.blocks, s.fullChain.blocks[nextBlock])
405409
// wait for client to update its chain
406410
if err := receiveConn.waitForBlock(s.fullChain.blocks[nextBlock]); err != nil {
407411
t.Fatal(err)
408412
}
413+
// update test suite chain
414+
s.chain.blocks = append(s.chain.blocks, s.fullChain.blocks[nextBlock])
409415
}
410416

411417
func (s *Suite) TestOldAnnounce(t *utesting.T) {

cmd/devp2p/internal/ethtest/suite_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func TestEthSuite(t *testing.T) {
5252
t.Fatal()
5353
}
5454
})
55+
time.Sleep(100 * time.Millisecond)
5556
}
5657
}
5758

0 commit comments

Comments
 (0)