@@ -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).
262262func (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
411417func (s * Suite ) TestOldAnnounce (t * utesting.T ) {
0 commit comments