2019-09-23 21:43:53 +00:00
|
|
|
package p2p
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2022-07-01 15:34:11 +00:00
|
|
|
bh "github.com/libp2p/go-libp2p/p2p/host/blank"
|
|
|
|
swarmt "github.com/libp2p/go-libp2p/p2p/net/swarm/testing"
|
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
|
|
|
)
|
|
|
|
|
|
|
|
func TestMakePeer_InvalidMultiaddress(t *testing.T) {
|
|
|
|
_, err := MakePeer("/ip4")
|
2020-07-14 16:51:39 +00:00
|
|
|
assert.ErrorContains(t, "failed to parse multiaddr \"/ip4\"", err, "Expect error when invalid multiaddress was provided")
|
2019-09-23 21:43:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestMakePeer_OK(t *testing.T) {
|
|
|
|
a, err := MakePeer("/ip4/127.0.0.1/tcp/5678/p2p/QmUn6ycS8Fu6L462uZvuEfDoSgYX6kqP4aSZWMa7z1tWAX")
|
2020-07-14 16:51:39 +00:00
|
|
|
require.NoError(t, err, "Unexpected error when making a valid peer")
|
|
|
|
assert.Equal(t, "QmUn6ycS8Fu6L462uZvuEfDoSgYX6kqP4aSZWMa7z1tWAX", a.ID.Pretty(), "Unexpected peer ID")
|
2019-09-23 21:43:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDialRelayNode_InvalidPeerString(t *testing.T) {
|
2020-07-14 16:51:39 +00:00
|
|
|
err := dialRelayNode(context.Background(), nil, "/ip4")
|
|
|
|
assert.ErrorContains(t, "failed to parse multiaddr \"/ip4\"", err, "Expected to fail with invalid peer string")
|
2019-09-23 21:43:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDialRelayNode_OK(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
2022-01-14 14:06:20 +00:00
|
|
|
relay := bh.NewBlankHost(swarmt.GenSwarm(t))
|
|
|
|
host := bh.NewBlankHost(swarmt.GenSwarm(t))
|
2019-09-23 21:43:53 +00:00
|
|
|
relayAddr := fmt.Sprintf("%s/p2p/%s", relay.Addrs()[0], relay.ID().Pretty())
|
|
|
|
|
2020-07-14 16:51:39 +00:00
|
|
|
assert.NoError(t, dialRelayNode(ctx, host, relayAddr), "Unexpected error when dialing relay node")
|
|
|
|
assert.Equal(t, relay.ID(), host.Peerstore().PeerInfo(relay.ID()).ID, "Host peerstore does not have peer info on relay node")
|
2019-09-23 21:43:53 +00:00
|
|
|
}
|