2019-09-23 21:43:53 +00:00
|
|
|
package p2p
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
ma "github.com/multiformats/go-multiaddr"
|
2023-03-17 18:52:56 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v4/testing/assert"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/testing/require"
|
2019-09-23 21:43:53 +00:00
|
|
|
)
|
|
|
|
|
2020-06-25 09:16:30 +00:00
|
|
|
func TestRelayAddrs_OnlyFactory(t *testing.T) {
|
2019-09-23 21:43:53 +00:00
|
|
|
relay := "/ip4/127.0.0.1/tcp/6660/p2p/QmQ7zhY7nGY66yK1n8hLGevfVyjbtvHSgtZuXkCH9oTrgi"
|
|
|
|
f := withRelayAddrs(relay)
|
|
|
|
|
|
|
|
a, err := ma.NewMultiaddr("/ip4/127.0.0.1/tcp/33201/p2p/QmaXZhW44pwQxBSeLkE5FNeLz8tGTTEsRciFg1DNWXXrWG")
|
2020-07-14 16:51:39 +00:00
|
|
|
require.NoError(t, err)
|
2019-09-23 21:43:53 +00:00
|
|
|
addrs := []ma.Multiaddr{a}
|
|
|
|
|
|
|
|
result := f(addrs)
|
2020-07-14 16:51:39 +00:00
|
|
|
assert.Equal(t, 2, len(result), "Unexpected number of addresses")
|
2019-09-23 21:43:53 +00:00
|
|
|
|
2020-02-05 16:37:33 +00:00
|
|
|
expected := "/ip4/127.0.0.1/tcp/6660/p2p/QmQ7zhY7nGY66yK1n8hLGevfVyjbtvHSgtZuXkCH9oTrgi/p2p-circuit/ip4/127.0.0.1/tcp/33201/p2p/QmaXZhW44pwQxBSeLkE5FNeLz8tGTTEsRciFg1DNWXXrWG"
|
2020-08-25 15:23:06 +00:00
|
|
|
assert.Equal(t, expected, result[1].String(), "Address at index 1 (%s) is not the expected p2p-circuit address", result[1].String())
|
2019-09-23 21:43:53 +00:00
|
|
|
}
|
2020-06-25 09:16:30 +00:00
|
|
|
|
|
|
|
func TestRelayAddrs_UseNonRelayAddrs(t *testing.T) {
|
|
|
|
relay := "/ip4/127.0.0.1/tcp/6660/p2p/QmQ7zhY7nGY66yK1n8hLGevfVyjbtvHSgtZuXkCH9oTrgi"
|
|
|
|
f := withRelayAddrs(relay)
|
|
|
|
|
|
|
|
expected := []string{
|
|
|
|
"/ip4/127.0.0.1/tcp/6660/p2p/QmQ7zhY7nGY66yK1n8hLGevfVyjbtvHSgtZuXkCH9oTrgi/p2p-circuit/ip4/127.0.0.1/tcp/33201/p2p/QmaXZhW44pwQxBSeLkE5FNeLz8tGTTEsRciFg1DNWXXrWG",
|
|
|
|
"/ip4/127.0.0.1/tcp/6660/p2p/QmQ7zhY7nGY66yK1n8hLGevfVyjbtvHSgtZuXkCH9oTrgi/p2p-circuit/ip4/127.0.0.1/tcp/33203/p2p/QmaXZhW44pwQxBSeLkE5FNeLz8tGTTEsRciFg1DNWXXrWG",
|
|
|
|
}
|
|
|
|
|
|
|
|
addrs := make([]ma.Multiaddr, len(expected))
|
|
|
|
for i, addr := range expected {
|
|
|
|
a, err := ma.NewMultiaddr(addr)
|
2020-08-25 15:23:06 +00:00
|
|
|
require.NoError(t, err)
|
2020-06-25 09:16:30 +00:00
|
|
|
addrs[i] = a
|
|
|
|
}
|
|
|
|
|
|
|
|
result := f(addrs)
|
2020-07-14 16:51:39 +00:00
|
|
|
assert.Equal(t, 2, len(result), "Unexpected number of addresses")
|
|
|
|
assert.DeepEqual(t, addrs, result)
|
2020-06-25 09:16:30 +00:00
|
|
|
}
|