@@ -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
3233const (
@@ -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+
504535var 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