mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-02-26 07:37:20 +00:00
cmd/devp2p/internal/v4test: add test for ENRRequest (#32303)
This adds a cross-client protocol test for a recently discovered bug in Nethermind.
This commit is contained in:
parent
4d9d72806c
commit
d4a3bf1b23
1 changed files with 32 additions and 0 deletions
|
|
@ -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},
|
||||
|
|
|
|||
Loading…
Reference in a new issue