cmd/devp2p/internal/v4test: add test for ENRRequest (#32303)
Some checks are pending
/ Linux Build (push) Waiting to run
/ Linux Build (arm) (push) Waiting to run
/ Windows Build (push) Waiting to run
/ Docker Image (push) Waiting to run

This adds a cross-client protocol test for a recently discovered bug in Nethermind.
This commit is contained in:
Felix Lange 2025-07-31 12:13:36 +02:00 committed by GitHub
parent 4d9d72806c
commit d4a3bf1b23
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -27,6 +27,7 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/internal/utesting"
"github.com/ethereum/go-ethereum/p2p/discover/v4wire"
"github.com/ethereum/go-ethereum/p2p/enode"
)
const (
@ -501,6 +502,36 @@ func FindnodeAmplificationWrongIP(t *utesting.T) {
}
}
func ENRRequest(t *utesting.T) {
t.Log(`This test sends an ENRRequest packet and expects a response containing a valid ENR.`)
te := newTestEnv(Remote, Listen1, Listen2)
defer te.close()
bond(t, te)
req := &v4wire.ENRRequest{Expiration: futureExpiration()}
hash := te.send(te.l1, req)
response, _, err := te.read(te.l1)
if err != nil {
t.Fatal("read error:", err)
}
enrResp, ok := response.(*v4wire.ENRResponse)
if !ok {
t.Fatalf("expected ENRResponse packet, got %T", response)
}
if !bytes.Equal(enrResp.ReplyTok, hash) {
t.Errorf("wrong hash in response packet: got %x, want %x", enrResp.ReplyTok, hash)
}
node, err := enode.New(enode.ValidSchemes, &enrResp.Record)
if err != nil {
t.Errorf("invalid record in response: %v", err)
}
if node.ID() != te.remote.ID() {
t.Errorf("wrong node ID in response: got %v, want %v", node.ID(), te.remote.ID())
}
}
var AllTests = []utesting.Test{
{Name: "Ping/Basic", Fn: BasicPing},
{Name: "Ping/WrongTo", Fn: PingWrongTo},
@ -510,6 +541,7 @@ var AllTests = []utesting.Test{
{Name: "Ping/PastExpiration", Fn: PingPastExpiration},
{Name: "Ping/WrongPacketType", Fn: WrongPacketType},
{Name: "Ping/BondThenPingWithWrongFrom", Fn: BondThenPingWithWrongFrom},
{Name: "ENRRequest", Fn: ENRRequest},
{Name: "Findnode/WithoutEndpointProof", Fn: FindnodeWithoutEndpointProof},
{Name: "Findnode/BasicFindnode", Fn: BasicFindnode},
{Name: "Findnode/UnsolicitedNeighbors", Fn: UnsolicitedNeighbors},