|
|
@ -2,8 +2,11 @@ package p2p |
|
|
|
|
|
|
|
import ( |
|
|
|
"bytes" |
|
|
|
"net" |
|
|
|
"strings" |
|
|
|
"testing" |
|
|
|
|
|
|
|
"github.com/stretchr/testify/require" |
|
|
|
"github.com/tendermint/tendermint/libs/log" |
|
|
|
) |
|
|
|
|
|
|
@ -45,3 +48,32 @@ func TestListener(t *testing.T) { |
|
|
|
// Close the server, no longer needed.
|
|
|
|
l.Stop() |
|
|
|
} |
|
|
|
|
|
|
|
func TestExternalAddress(t *testing.T) { |
|
|
|
{ |
|
|
|
// Create a listener with no external addr. Should default
|
|
|
|
// to local ipv4.
|
|
|
|
l := NewDefaultListener("tcp://:8001", "", false, log.TestingLogger()) |
|
|
|
lAddr := l.ExternalAddress().String() |
|
|
|
_, _, err := net.SplitHostPort(lAddr) |
|
|
|
require.Nil(t, err) |
|
|
|
spl := strings.Split(lAddr, ".") |
|
|
|
require.Equal(t, len(spl), 4) |
|
|
|
l.Stop() |
|
|
|
} |
|
|
|
|
|
|
|
{ |
|
|
|
// Create a listener with set external ipv4 addr.
|
|
|
|
setExAddr := "8.8.8.8:8080" |
|
|
|
l := NewDefaultListener("tcp://:8001", setExAddr, false, log.TestingLogger()) |
|
|
|
lAddr := l.ExternalAddress().String() |
|
|
|
require.Equal(t, lAddr, setExAddr) |
|
|
|
l.Stop() |
|
|
|
} |
|
|
|
|
|
|
|
{ |
|
|
|
// Invalid external addr causes panic
|
|
|
|
setExAddr := "awrlsckjnal:8080" |
|
|
|
require.Panics(t, func() { NewDefaultListener("tcp://:8001", setExAddr, false, log.TestingLogger()) }) |
|
|
|
} |
|
|
|
} |