github.com/decred/dcrlnd@v0.7.6/tor/tor_test.go (about) 1 package tor 2 3 import ( 4 "fmt" 5 "net" 6 "testing" 7 8 "github.com/stretchr/testify/require" 9 ) 10 11 const ( 12 testOnion = "ld47qlr6h2b7hrrf.onion" 13 testFakeIP = "fd87:d87e:eb43:58f9:f82e:3e3e:83f3:c625" 14 ) 15 16 // TestOnionHostToFakeIP tests that an onion host address can be converted into 17 // a fake tcp6 address successfully. 18 func TestOnionHostToFakeIP(t *testing.T) { 19 ip, err := OnionHostToFakeIP(testOnion) 20 require.NoError(t, err) 21 require.Equal(t, testFakeIP, ip.String()) 22 } 23 24 // TestFakeIPToOnionHost tests that a fake tcp6 address can be converted back 25 // into its original .onion host address successfully. 26 func TestFakeIPToOnionHost(t *testing.T) { 27 tcpAddr, err := net.ResolveTCPAddr( 28 "tcp6", fmt.Sprintf("[%s]:8333", testFakeIP), 29 ) 30 require.NoError(t, err) 31 require.True(t, IsOnionFakeIP(tcpAddr)) 32 33 onionHost, err := FakeIPToOnionHost(tcpAddr) 34 require.NoError(t, err) 35 require.Equal(t, fmt.Sprintf("%s:8333", testOnion), onionHost.String()) 36 }