Skip to content

Commit

Permalink
rebased on announce_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusVanDerWijden committed Nov 23, 2020
1 parent 7eb6017 commit 0cffa42
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
6 changes: 2 additions & 4 deletions cmd/devp2p/internal/ethtest/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ var pretty = spew.ConfigState{
SortKeys: true,
}

var timeout = 20 * time.Second

// Suite represents a structure used to test the eth
// protocol of a node(s).
type Suite struct {
Expand Down Expand Up @@ -120,7 +122,6 @@ func (s *Suite) TestMaliciousStatus(t *utesting.T) {
default:
t.Fatalf("expected status, got: %#v ", msg)
}
timeout := 20 * time.Second
// wait for disconnect
switch msg := conn.ReadAndServe(s.chain, timeout).(type) {
case *Disconnect:
Expand Down Expand Up @@ -156,7 +157,6 @@ func (s *Suite) TestGetBlockHeaders(t *utesting.T) {
t.Fatalf("could not write to connection: %v", err)
}

timeout := 20 * time.Second
switch msg := conn.ReadAndServe(s.chain, timeout).(type) {
case *BlockHeaders:
headers := msg
Expand Down Expand Up @@ -186,7 +186,6 @@ func (s *Suite) TestGetBlockBodies(t *utesting.T) {
t.Fatalf("could not write to connection: %v", err)
}

timeout := 20 * time.Second
switch msg := conn.ReadAndServe(s.chain, timeout).(type) {
case *BlockBodies:
t.Logf("received %d block bodies", len(*msg))
Expand Down Expand Up @@ -318,7 +317,6 @@ func (s *Suite) TestLargeAnnounce(t *utesting.T) {
t.Fatalf("could not write to connection: %v", err)
}
// Invalid announcement, check that peer disconnected
timeout := 20 * time.Second
switch msg := sendConn.ReadAndServe(s.chain, timeout).(type) {
case *Disconnect:
case *Error:
Expand Down
29 changes: 16 additions & 13 deletions cmd/devp2p/internal/ethtest/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,17 @@ func sendSuccessfulTx(t *utesting.T, s *Suite, tx *types.Transaction) {
t.Fatal(err)
}
// Wait for the transaction announcement
rawTxMsg, err := recvConn.waitForMessage(Transactions{})
if err != nil {
t.Fatalf("waiting for transaction propagation failed: %v", err)
}
recTxs := *rawTxMsg.(*Transactions)
if len(recTxs) != 1 {
t.Fatalf("received transactions do not match send: %v", recTxs)
}
if tx.Hash() != recTxs[0].Hash() {
t.Fatalf("received transactions do not match send: got %v want %v", tx, recTxs)
switch msg := recvConn.ReadAndServe(s.chain, timeout).(type) {
case *Transactions:
recTxs := *msg
if len(recTxs) != 1 {
t.Fatalf("received transactions do not match send: %v", recTxs)
}
if tx.Hash() != recTxs[0].Hash() {
t.Fatalf("received transactions do not match send: got %v want %v", tx, recTxs)
}
default:
t.Fatalf("unexpected: %s", pretty.Sdump(msg))
}
}

Expand All @@ -56,9 +57,11 @@ func sendFailingTx(t *utesting.T, s *Suite, tx *types.Transaction) {
t.Fatal(err)
}
// Wait for the transaction announcement
_, err := recvConn.waitForMessage(Transactions{})
if err == nil {
t.Fatalf("received a transaction, but wanted none", err)
switch msg := recvConn.ReadAndServe(s.chain, timeout).(type) {
case *Transactions:
t.Fatalf("Received unexpected transaction announcement: %v", msg)
default:
t.Fatalf("unexpected: %s", pretty.Sdump(msg))
}
}

Expand Down

0 comments on commit 0cffa42

Please sign in to comment.