mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-18 12:51:39 +00:00
test: support ETH69 in suite test
This commit is contained in:
parent
e0e7e00d3b
commit
abf7f7366e
3 changed files with 57 additions and 24 deletions
|
|
@ -67,6 +67,7 @@ func (s *Suite) dialAs(key *ecdsa.PrivateKey) (*Conn, error) {
|
||||||
}
|
}
|
||||||
conn.caps = []p2p.Cap{
|
conn.caps = []p2p.Cap{
|
||||||
{Name: "eth", Version: 70},
|
{Name: "eth", Version: 70},
|
||||||
|
{Name: "eth", Version: 69},
|
||||||
}
|
}
|
||||||
conn.ourHighestProtoVersion = 70
|
conn.ourHighestProtoVersion = 70
|
||||||
return &conn, nil
|
return &conn, nil
|
||||||
|
|
@ -339,10 +340,12 @@ loop:
|
||||||
if have, want := msg.ForkID, chain.ForkID(); !reflect.DeepEqual(have, want) {
|
if have, want := msg.ForkID, chain.ForkID(); !reflect.DeepEqual(have, want) {
|
||||||
return fmt.Errorf("wrong fork ID in status: have %v, want %v", have, want)
|
return fmt.Errorf("wrong fork ID in status: have %v, want %v", have, want)
|
||||||
}
|
}
|
||||||
if have, want := msg.ProtocolVersion, c.ourHighestProtoVersion; have != uint32(want) {
|
for _, cap := range c.caps {
|
||||||
return fmt.Errorf("wrong protocol version: have %v, want %v", have, want)
|
if cap.Name == "eth" && cap.Version == uint(msg.ProtocolVersion) {
|
||||||
|
break loop
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break loop
|
return fmt.Errorf("wrong protocol version: have %v, want %v", msg.ProtocolVersion, c.caps)
|
||||||
case discMsg:
|
case discMsg:
|
||||||
var msg []p2p.DiscReason
|
var msg []p2p.DiscReason
|
||||||
if rlp.DecodeBytes(data, &msg); len(msg) == 0 {
|
if rlp.DecodeBytes(data, &msg); len(msg) == 0 {
|
||||||
|
|
|
||||||
|
|
@ -426,6 +426,9 @@ func (s *Suite) TestGetReceipts(t *utesting.T) {
|
||||||
// Find some blocks containing receipts.
|
// Find some blocks containing receipts.
|
||||||
var hashes = make([]common.Hash, 0, 3)
|
var hashes = make([]common.Hash, 0, 3)
|
||||||
for i := range s.chain.Len() {
|
for i := range s.chain.Len() {
|
||||||
|
if uint64(i) == s.chain.txInfo.LargeReceiptBlock && conn.negotiatedProtoVersion < eth.ETH70 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
block := s.chain.GetBlock(i)
|
block := s.chain.GetBlock(i)
|
||||||
if len(block.Transactions()) > 0 {
|
if len(block.Transactions()) > 0 {
|
||||||
hashes = append(hashes, block.Hash())
|
hashes = append(hashes, block.Hash())
|
||||||
|
|
@ -435,36 +438,63 @@ func (s *Suite) TestGetReceipts(t *utesting.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create block bodies request.
|
if conn.negotiatedProtoVersion < eth.ETH70 {
|
||||||
req := ð.GetReceiptsPacket70{
|
// Create block bodies request.
|
||||||
RequestId: 66,
|
req := ð.GetReceiptsPacket69{
|
||||||
GetReceiptsRequest: (eth.GetReceiptsRequest)(hashes),
|
RequestId: 66,
|
||||||
FirstBlockReceiptIndex: 0,
|
GetReceiptsRequest: (eth.GetReceiptsRequest)(hashes),
|
||||||
}
|
}
|
||||||
if err := conn.Write(ethProto, eth.GetReceiptsMsg, req); err != nil {
|
if err := conn.Write(ethProto, eth.GetReceiptsMsg, req); err != nil {
|
||||||
t.Fatalf("could not write to connection: %v", err)
|
t.Fatalf("could not write to connection: %v", err)
|
||||||
}
|
}
|
||||||
// Wait for response.
|
// Wait for response.
|
||||||
resp := new(eth.ReceiptsPacket70)
|
resp := new(eth.ReceiptsPacket[*eth.ReceiptList69])
|
||||||
if err := conn.ReadMsg(ethProto, eth.ReceiptsMsg, &resp); err != nil {
|
if err := conn.ReadMsg(ethProto, eth.ReceiptsMsg, &resp); err != nil {
|
||||||
t.Fatalf("error reading block bodies msg: %v", err)
|
t.Fatalf("error reading block receipts msg: %v", err)
|
||||||
}
|
}
|
||||||
if got, want := resp.RequestId, req.RequestId; got != want {
|
if got, want := resp.RequestId, req.RequestId; got != want {
|
||||||
t.Fatalf("unexpected request id in respond", got, want)
|
t.Fatalf("unexpected request id in respond", got, want)
|
||||||
}
|
}
|
||||||
if len(resp.List) != len(req.GetReceiptsRequest) {
|
if len(resp.List) != len(req.GetReceiptsRequest) {
|
||||||
t.Fatalf("wrong bodies in response: expected %d bodies, got %d", len(req.GetReceiptsRequest), len(resp.List))
|
t.Fatalf("wrong receipts in response: expected %d receipts, got %d", len(req.GetReceiptsRequest), len(resp.List))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Create block bodies request.
|
||||||
|
req := ð.GetReceiptsPacket70{
|
||||||
|
RequestId: 66,
|
||||||
|
GetReceiptsRequest: (eth.GetReceiptsRequest)(hashes),
|
||||||
|
FirstBlockReceiptIndex: 0,
|
||||||
|
}
|
||||||
|
if err := conn.Write(ethProto, eth.GetReceiptsMsg, req); err != nil {
|
||||||
|
t.Fatalf("could not write to connection: %v", err)
|
||||||
|
}
|
||||||
|
// Wait for response.
|
||||||
|
resp := new(eth.ReceiptsPacket70)
|
||||||
|
if err := conn.ReadMsg(ethProto, eth.ReceiptsMsg, &resp); err != nil {
|
||||||
|
t.Fatalf("error reading block receipts msg: %v", err)
|
||||||
|
}
|
||||||
|
if got, want := resp.RequestId, req.RequestId; got != want {
|
||||||
|
t.Fatalf("unexpected request id in respond", got, want)
|
||||||
|
}
|
||||||
|
if len(resp.List) != len(req.GetReceiptsRequest) {
|
||||||
|
t.Fatalf("wrong receipts in response: expected %d receipts, got %d", len(req.GetReceiptsRequest), len(resp.List))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Suite) TestGetLargeReceipts(t *utesting.T) {
|
func (s *Suite) TestGetLargeReceipts(t *utesting.T) {
|
||||||
t.Log(`This test sends GetReceipts requests to the node for large receipt (>10MiB) in the test chain.`)
|
t.Log(`This test sends GetReceipts requests to the node for large receipt (>10MiB) in the test chain.
|
||||||
|
This test is meaningful only if the client supports protocol version greater than or equal to ETH70.`)
|
||||||
conn, err := s.dialAndPeer(nil)
|
conn, err := s.dialAndPeer(nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("peering failed: %v", err)
|
t.Fatalf("peering failed: %v", err)
|
||||||
}
|
}
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
|
if conn.negotiatedProtoVersion < eth.ETH70 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Find block with large receipt.
|
// Find block with large receipt.
|
||||||
// Place the large receipt block hash in the middle of the query
|
// Place the large receipt block hash in the middle of the query
|
||||||
start := max(s.chain.txInfo.LargeReceiptBlock-2, 0)
|
start := max(s.chain.txInfo.LargeReceiptBlock-2, 0)
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ const ProtocolName = "eth"
|
||||||
|
|
||||||
// ProtocolVersions are the supported versions of the `eth` protocol (first
|
// ProtocolVersions are the supported versions of the `eth` protocol (first
|
||||||
// is primary).
|
// is primary).
|
||||||
var ProtocolVersions = []uint{ETH69, ETH68, ETH70}
|
var ProtocolVersions = []uint{ETH70, ETH69, ETH68}
|
||||||
|
|
||||||
// protocolLengths are the number of implemented message corresponding to
|
// protocolLengths are the number of implemented message corresponding to
|
||||||
// different protocol versions.
|
// different protocol versions.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue