Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/devp2p/internal/ethtest/eth66_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ func (s *Suite) TestLargeAnnounce_66(t *utesting.T) {
}
}

func (s *Suite) TestOldAnnounce_66(t *utesting.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the code here identical to TestOldAnnounce, with the exception of s.setupConnection66 instead of s.setupConnection ?
I'm thinking you could maybe reduce it so there's one implementation which takes either a setupConn function or a boolean to distinguish which to use?

s.oldAnnounce(t, s.setupConnection66(t), s.setupConnection66(t))
}

// TestMaliciousHandshake_66 tries to send malicious data during the handshake.
func (s *Suite) TestMaliciousHandshake_66(t *utesting.T) {
conn := s.dial66(t)
Expand Down
33 changes: 33 additions & 0 deletions cmd/devp2p/internal/ethtest/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package ethtest
import (
"fmt"
"net"
"strings"
"time"

"github.com/davecgh/go-spew/spew"
Expand Down Expand Up @@ -84,6 +85,8 @@ func (s *Suite) EthTests() []utesting.Test {
{Name: "Broadcast_66", Fn: s.TestBroadcast_66},
{Name: "TestLargeAnnounce", Fn: s.TestLargeAnnounce},
{Name: "TestLargeAnnounce_66", Fn: s.TestLargeAnnounce_66},
{Name: "TestOldAnnounce", Fn: s.TestOldAnnounce},
{Name: "TestOldAnnounce_66", Fn: s.TestOldAnnounce_66},
// malicious handshakes + status
{Name: "TestMaliciousHandshake", Fn: s.TestMaliciousHandshake},
{Name: "TestMaliciousStatus", Fn: s.TestMaliciousStatus},
Expand Down Expand Up @@ -357,6 +360,36 @@ func (s *Suite) TestLargeAnnounce(t *utesting.T) {
}
}

func (s *Suite) TestOldAnnounce(t *utesting.T) {
s.oldAnnounce(t, s.setupConnection(t), s.setupConnection(t))
}

func (s *Suite) oldAnnounce(t *utesting.T, sendConn, receiveConn *Conn) {
oldBlockAnnounce := &NewBlock{
Block: s.chain.blocks[len(s.chain.blocks)/2],
TD: s.chain.blocks[len(s.chain.blocks)/2].Difficulty(),
}

if err := sendConn.Write(oldBlockAnnounce); err != nil {
t.Fatalf("could not write to connection: %v", err)
}

switch msg := receiveConn.ReadAndServe(s.chain, timeout*2).(type) {
case *NewBlock:
t.Fatalf("unexpected: block propagated: %s", pretty.Sdump(msg))
case *NewBlockHashes:
t.Fatalf("unexpected: block announced: %s", pretty.Sdump(msg))
case *Error:
errMsg := *msg
// check to make sure error is timeout (propagation didn't come through == test successful)
if !strings.Contains(errMsg.String(), "timeout") {
t.Fatalf("unexpected error: %v", pretty.Sdump(msg))
}
default:
t.Fatalf("unexpected: %s", pretty.Sdump(msg))
}
}

func (s *Suite) testAnnounce(t *utesting.T, sendConn, receiveConn *Conn, blockAnnouncement *NewBlock) {
// Announce the block.
if err := sendConn.Write(blockAnnouncement); err != nil {
Expand Down