@@ -20,6 +20,7 @@ import (
2020 "github.com/OffchainLabs/prysm/v7/testing/assert"
2121 "github.com/OffchainLabs/prysm/v7/testing/require"
2222 prysmTime "github.com/OffchainLabs/prysm/v7/time"
23+ "github.com/ethereum/go-ethereum/p2p/enode"
2324 "github.com/libp2p/go-libp2p"
2425 "github.com/libp2p/go-libp2p/core/event"
2526 "github.com/libp2p/go-libp2p/core/host"
@@ -406,18 +407,24 @@ func TestService_SubscribeReachabilityEvents(t *testing.T) {
406407 hook := logTest .NewGlobal ()
407408 ctx := t .Context ()
408409
409- h , _ , _ := createHost (t , 0 )
410+ h , pkey , _ := createHost (t , 0 )
410411 defer func () {
411412 if err := h .Close (); err != nil {
412413 t .Fatal (err )
413414 }
414415 }()
415416
416- // Create service with the host
417+ // Create a LocalNode for ENR testing (without static IP set)
418+ db , err := enode .OpenDB ("" )
419+ require .NoError (t , err )
420+ t .Cleanup (func () { db .Close () })
421+ localNode := enode .NewLocalNode (db , pkey )
422+
417423 s := & Service {
418- ctx : ctx ,
419- host : h ,
420- cfg : & Config {EnableAutoNAT : true },
424+ ctx : ctx ,
425+ host : h ,
426+ cfg : & Config {EnableAutoNAT : true },
427+ dv5Listener : testp2p .NewMockListener (localNode , nil ),
421428 }
422429
423430 // Get an emitter for the reachability event
@@ -455,4 +462,9 @@ func TestService_SubscribeReachabilityEvents(t *testing.T) {
455462 require .LogsContain (t , hook , "/ip4/192.168.1.1/tcp/9000" )
456463 require .LogsContain (t , hook , "/ip4/10.0.0.1/tcp/9001" )
457464 require .LogsContain (t , hook , "/ip4/172.16.0.1/tcp/9002" )
465+
466+ // Verify the ENR was updated with the reachable address
467+ require .LogsContain (t , hook , "Updated ENR IP from AutoNAT reachability" )
468+ nodeRecord := localNode .Node ()
469+ assert .Equal (t , "192.168.1.1" , nodeRecord .IP ().String (), "ENR should contain the reachable IP address" )
458470}
0 commit comments