ceremonyclient/go-libp2p/p2p/transport/quicreuse/quic_multiaddr_test.go

35 lines
1.0 KiB
Go
Raw Normal View History

2023-08-21 03:50:38 +00:00
package quicreuse
import (
"net"
"testing"
ma "github.com/multiformats/go-multiaddr"
"github.com/quic-go/quic-go"
"github.com/stretchr/testify/require"
)
func TestConvertToQuicMultiaddr(t *testing.T) {
addr := &net.UDPAddr{IP: net.IPv4(192, 168, 0, 42), Port: 1337}
2024-06-08 11:32:45 +00:00
maddr, err := ToQuicMultiaddr(addr, quic.Version1)
2023-08-21 03:50:38 +00:00
require.NoError(t, err)
2024-06-08 11:32:45 +00:00
require.Equal(t, "/ip4/192.168.0.42/udp/1337/quic-v1", maddr.String())
2023-08-21 03:50:38 +00:00
}
func TestConvertToQuicV1Multiaddr(t *testing.T) {
addr := &net.UDPAddr{IP: net.IPv4(192, 168, 0, 42), Port: 1337}
maddr, err := ToQuicMultiaddr(addr, quic.Version1)
require.NoError(t, err)
2024-06-08 11:32:45 +00:00
require.Equal(t, "/ip4/192.168.0.42/udp/1337/quic-v1", maddr.String())
2023-08-21 03:50:38 +00:00
}
func TestConvertFromQuicV1Multiaddr(t *testing.T) {
maddr, err := ma.NewMultiaddr("/ip4/192.168.0.42/udp/1337/quic-v1")
require.NoError(t, err)
udpAddr, v, err := FromQuicMultiaddr(maddr)
require.NoError(t, err)
2024-06-08 11:32:45 +00:00
require.Equal(t, net.IPv4(192, 168, 0, 42), udpAddr.IP)
require.Equal(t, 1337, udpAddr.Port)
require.Equal(t, quic.Version1, v)
2023-08-21 03:50:38 +00:00
}