@@ -27,6 +27,7 @@ import (
27
27
"github.com/ethereum/go-ethereum/crypto"
28
28
"github.com/ethereum/go-ethereum/internal/utesting"
29
29
"github.com/ethereum/go-ethereum/p2p/discover/v4wire"
30
+ "github.com/ethereum/go-ethereum/p2p/enode"
30
31
)
31
32
32
33
const (
@@ -501,6 +502,36 @@ func FindnodeAmplificationWrongIP(t *utesting.T) {
501
502
}
502
503
}
503
504
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
+
504
535
var AllTests = []utesting.Test {
505
536
{Name : "Ping/Basic" , Fn : BasicPing },
506
537
{Name : "Ping/WrongTo" , Fn : PingWrongTo },
@@ -510,6 +541,7 @@ var AllTests = []utesting.Test{
510
541
{Name : "Ping/PastExpiration" , Fn : PingPastExpiration },
511
542
{Name : "Ping/WrongPacketType" , Fn : WrongPacketType },
512
543
{Name : "Ping/BondThenPingWithWrongFrom" , Fn : BondThenPingWithWrongFrom },
544
+ {Name : "ENRRequest" , Fn : ENRRequest },
513
545
{Name : "Findnode/WithoutEndpointProof" , Fn : FindnodeWithoutEndpointProof },
514
546
{Name : "Findnode/BasicFindnode" , Fn : BasicFindnode },
515
547
{Name : "Findnode/UnsolicitedNeighbors" , Fn : UnsolicitedNeighbors },
0 commit comments