Skip to content

Commit d4a3bf1

Browse files
authored
cmd/devp2p/internal/v4test: add test for ENRRequest (#32303)
This adds a cross-client protocol test for a recently discovered bug in Nethermind.
1 parent 4d9d728 commit d4a3bf1

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

cmd/devp2p/internal/v4test/discv4tests.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/ethereum/go-ethereum/crypto"
2828
"github.com/ethereum/go-ethereum/internal/utesting"
2929
"github.com/ethereum/go-ethereum/p2p/discover/v4wire"
30+
"github.com/ethereum/go-ethereum/p2p/enode"
3031
)
3132

3233
const (
@@ -501,6 +502,36 @@ func FindnodeAmplificationWrongIP(t *utesting.T) {
501502
}
502503
}
503504

505+
func ENRRequest(t *utesting.T) {
506+
t.Log(`This test sends an ENRRequest packet and expects a response containing a valid ENR.`)
507+
508+
te := newTestEnv(Remote, Listen1, Listen2)
509+
defer te.close()
510+
bond(t, te)
511+
512+
req := &v4wire.ENRRequest{Expiration: futureExpiration()}
513+
hash := te.send(te.l1, req)
514+
515+
response, _, err := te.read(te.l1)
516+
if err != nil {
517+
t.Fatal("read error:", err)
518+
}
519+
enrResp, ok := response.(*v4wire.ENRResponse)
520+
if !ok {
521+
t.Fatalf("expected ENRResponse packet, got %T", response)
522+
}
523+
if !bytes.Equal(enrResp.ReplyTok, hash) {
524+
t.Errorf("wrong hash in response packet: got %x, want %x", enrResp.ReplyTok, hash)
525+
}
526+
node, err := enode.New(enode.ValidSchemes, &enrResp.Record)
527+
if err != nil {
528+
t.Errorf("invalid record in response: %v", err)
529+
}
530+
if node.ID() != te.remote.ID() {
531+
t.Errorf("wrong node ID in response: got %v, want %v", node.ID(), te.remote.ID())
532+
}
533+
}
534+
504535
var AllTests = []utesting.Test{
505536
{Name: "Ping/Basic", Fn: BasicPing},
506537
{Name: "Ping/WrongTo", Fn: PingWrongTo},
@@ -510,6 +541,7 @@ var AllTests = []utesting.Test{
510541
{Name: "Ping/PastExpiration", Fn: PingPastExpiration},
511542
{Name: "Ping/WrongPacketType", Fn: WrongPacketType},
512543
{Name: "Ping/BondThenPingWithWrongFrom", Fn: BondThenPingWithWrongFrom},
544+
{Name: "ENRRequest", Fn: ENRRequest},
513545
{Name: "Findnode/WithoutEndpointProof", Fn: FindnodeWithoutEndpointProof},
514546
{Name: "Findnode/BasicFindnode", Fn: BasicFindnode},
515547
{Name: "Findnode/UnsolicitedNeighbors", Fn: UnsolicitedNeighbors},

0 commit comments

Comments
 (0)