cmd/devp2p/internal/ethtest: add correct chain files and improve test output (#21782)
This PR replaces the old test genesis.json and chain.rlp files in the testdata directory for the eth protocol test suite, and also adds documentation for running the eth test suite locally. It also improves the test output text and adds more timeouts. Co-authored-by: Felix Lange <fjl@twurst.com>
This commit is contained in:
@ -19,7 +19,9 @@ package ethtest
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/internal/utesting"
|
||||
"github.com/ethereum/go-ethereum/p2p/enode"
|
||||
@ -27,6 +29,13 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
var pretty = spew.ConfigState{
|
||||
Indent: " ",
|
||||
DisableCapacities: true,
|
||||
DisablePointerAddresses: true,
|
||||
SortKeys: true,
|
||||
}
|
||||
|
||||
// Suite represents a structure used to test the eth
|
||||
// protocol of a node(s).
|
||||
type Suite struct {
|
||||
@ -73,9 +82,9 @@ func (s *Suite) TestStatus(t *utesting.T) {
|
||||
// get status
|
||||
switch msg := conn.statusExchange(t, s.chain).(type) {
|
||||
case *Status:
|
||||
t.Logf("%+v\n", msg)
|
||||
t.Logf("got status message: %s", pretty.Sdump(msg))
|
||||
default:
|
||||
t.Fatalf("unexpected: %#v", msg)
|
||||
t.Fatalf("unexpected: %s", pretty.Sdump(msg))
|
||||
}
|
||||
}
|
||||
|
||||
@ -104,16 +113,17 @@ func (s *Suite) TestGetBlockHeaders(t *utesting.T) {
|
||||
t.Fatalf("could not write to connection: %v", err)
|
||||
}
|
||||
|
||||
switch msg := conn.ReadAndServe(s.chain).(type) {
|
||||
timeout := 20 * time.Second
|
||||
switch msg := conn.ReadAndServe(s.chain, timeout).(type) {
|
||||
case *BlockHeaders:
|
||||
headers := msg
|
||||
for _, header := range *headers {
|
||||
num := header.Number.Uint64()
|
||||
t.Logf("received header (%d): %s", num, pretty.Sdump(header))
|
||||
assert.Equal(t, s.chain.blocks[int(num)].Header(), header)
|
||||
t.Logf("\nHEADER FOR BLOCK NUMBER %d: %+v\n", header.Number, header)
|
||||
}
|
||||
default:
|
||||
t.Fatalf("unexpected: %#v", msg)
|
||||
t.Fatalf("unexpected: %s", pretty.Sdump(msg))
|
||||
}
|
||||
}
|
||||
|
||||
@ -133,14 +143,12 @@ func (s *Suite) TestGetBlockBodies(t *utesting.T) {
|
||||
t.Fatalf("could not write to connection: %v", err)
|
||||
}
|
||||
|
||||
switch msg := conn.ReadAndServe(s.chain).(type) {
|
||||
timeout := 20 * time.Second
|
||||
switch msg := conn.ReadAndServe(s.chain, timeout).(type) {
|
||||
case *BlockBodies:
|
||||
bodies := msg
|
||||
for _, body := range *bodies {
|
||||
t.Logf("\nBODY: %+v\n", body)
|
||||
}
|
||||
t.Logf("received %d block bodies", len(*msg))
|
||||
default:
|
||||
t.Fatalf("unexpected: %#v", msg)
|
||||
t.Fatalf("unexpected: %s", pretty.Sdump(msg))
|
||||
}
|
||||
}
|
||||
|
||||
@ -173,18 +181,27 @@ func (s *Suite) TestBroadcast(t *utesting.T) {
|
||||
t.Fatalf("could not write to connection: %v", err)
|
||||
}
|
||||
|
||||
switch msg := receiveConn.ReadAndServe(s.chain).(type) {
|
||||
timeout := 20 * time.Second
|
||||
switch msg := receiveConn.ReadAndServe(s.chain, timeout).(type) {
|
||||
case *NewBlock:
|
||||
assert.Equal(t, blockAnnouncement.Block.Header(), msg.Block.Header(),
|
||||
"wrong block header in announcement")
|
||||
assert.Equal(t, blockAnnouncement.TD, msg.TD,
|
||||
"wrong TD in announcement")
|
||||
t.Logf("received NewBlock message: %s", pretty.Sdump(msg.Block))
|
||||
assert.Equal(t,
|
||||
blockAnnouncement.Block.Header(), msg.Block.Header(),
|
||||
"wrong block header in announcement",
|
||||
)
|
||||
assert.Equal(t,
|
||||
blockAnnouncement.TD, msg.TD,
|
||||
"wrong TD in announcement",
|
||||
)
|
||||
case *NewBlockHashes:
|
||||
hashes := *msg
|
||||
assert.Equal(t, blockAnnouncement.Block.Hash(), hashes[0].Hash,
|
||||
"wrong block hash in announcement")
|
||||
t.Logf("received NewBlockHashes message: %s", pretty.Sdump(hashes))
|
||||
assert.Equal(t,
|
||||
blockAnnouncement.Block.Hash(), hashes[0].Hash,
|
||||
"wrong block hash in announcement",
|
||||
)
|
||||
default:
|
||||
t.Fatalf("unexpected: %#v", msg)
|
||||
t.Fatalf("unexpected: %s", pretty.Sdump(msg))
|
||||
}
|
||||
// update test suite chain
|
||||
s.chain.blocks = append(s.chain.blocks, s.fullChain.blocks[1000])
|
||||
|
Reference in New Issue
Block a user