Skip to content

Commit 36b51b8

Browse files
authored
cmd/devp2p: add old block announcement test to eth test suite (ethereum#22474)
Add old block announcement test to eth test suite, checks to make sure old block announcement isn't propagated
1 parent 5bf6612 commit 36b51b8

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

cmd/devp2p/internal/ethtest/eth66_suite.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@ func (s *Suite) TestLargeAnnounce_66(t *utesting.T) {
215215
}
216216
}
217217

218+
func (s *Suite) TestOldAnnounce_66(t *utesting.T) {
219+
s.oldAnnounce(t, s.setupConnection66(t), s.setupConnection66(t))
220+
}
221+
218222
// TestMaliciousHandshake_66 tries to send malicious data during the handshake.
219223
func (s *Suite) TestMaliciousHandshake_66(t *utesting.T) {
220224
conn := s.dial66(t)

cmd/devp2p/internal/ethtest/suite.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package ethtest
1919
import (
2020
"fmt"
2121
"net"
22+
"strings"
2223
"time"
2324

2425
"github.com/davecgh/go-spew/spew"
@@ -84,6 +85,8 @@ func (s *Suite) AllEthTests() []utesting.Test {
8485
{Name: "Broadcast_66", Fn: s.TestBroadcast_66},
8586
{Name: "TestLargeAnnounce", Fn: s.TestLargeAnnounce},
8687
{Name: "TestLargeAnnounce_66", Fn: s.TestLargeAnnounce_66},
88+
{Name: "TestOldAnnounce", Fn: s.TestOldAnnounce},
89+
{Name: "TestOldAnnounce_66", Fn: s.TestOldAnnounce_66},
8790
// malicious handshakes + status
8891
{Name: "TestMaliciousHandshake", Fn: s.TestMaliciousHandshake},
8992
{Name: "TestMaliciousStatus", Fn: s.TestMaliciousStatus},
@@ -389,6 +392,36 @@ func (s *Suite) TestLargeAnnounce(t *utesting.T) {
389392
}
390393
}
391394

395+
func (s *Suite) TestOldAnnounce(t *utesting.T) {
396+
s.oldAnnounce(t, s.setupConnection(t), s.setupConnection(t))
397+
}
398+
399+
func (s *Suite) oldAnnounce(t *utesting.T, sendConn, receiveConn *Conn) {
400+
oldBlockAnnounce := &NewBlock{
401+
Block: s.chain.blocks[len(s.chain.blocks)/2],
402+
TD: s.chain.blocks[len(s.chain.blocks)/2].Difficulty(),
403+
}
404+
405+
if err := sendConn.Write(oldBlockAnnounce); err != nil {
406+
t.Fatalf("could not write to connection: %v", err)
407+
}
408+
409+
switch msg := receiveConn.ReadAndServe(s.chain, timeout*2).(type) {
410+
case *NewBlock:
411+
t.Fatalf("unexpected: block propagated: %s", pretty.Sdump(msg))
412+
case *NewBlockHashes:
413+
t.Fatalf("unexpected: block announced: %s", pretty.Sdump(msg))
414+
case *Error:
415+
errMsg := *msg
416+
// check to make sure error is timeout (propagation didn't come through == test successful)
417+
if !strings.Contains(errMsg.String(), "timeout") {
418+
t.Fatalf("unexpected error: %v", pretty.Sdump(msg))
419+
}
420+
default:
421+
t.Fatalf("unexpected: %s", pretty.Sdump(msg))
422+
}
423+
}
424+
392425
func (s *Suite) testAnnounce(t *utesting.T, sendConn, receiveConn *Conn, blockAnnouncement *NewBlock) {
393426
// Announce the block.
394427
if err := sendConn.Write(blockAnnouncement); err != nil {

0 commit comments

Comments
 (0)