mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 21:07:18 +00:00
d9fd2521af
* applies assertion funcs to p2p/encoder tests * applies assertion funcs to p2p/peers tests * addr_factory_test + broadcaster_test updated * connection_gater_test updated * applies assertion funcs to p2p/service tests * Merge branch 'master' into p2p-apply-testutils-assertions * minor fixes * Merge branch 'master' into p2p-apply-testutils-assertions * Merge refs/heads/master into p2p-apply-testutils-assertions
39 lines
1.5 KiB
Go
39 lines
1.5 KiB
Go
package p2p
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"testing"
|
|
|
|
bh "github.com/libp2p/go-libp2p-blankhost"
|
|
swarmt "github.com/libp2p/go-libp2p-swarm/testing"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
|
)
|
|
|
|
func TestMakePeer_InvalidMultiaddress(t *testing.T) {
|
|
_, err := MakePeer("/ip4")
|
|
assert.ErrorContains(t, "failed to parse multiaddr \"/ip4\"", err, "Expect error when invalid multiaddress was provided")
|
|
}
|
|
|
|
func TestMakePeer_OK(t *testing.T) {
|
|
a, err := MakePeer("/ip4/127.0.0.1/tcp/5678/p2p/QmUn6ycS8Fu6L462uZvuEfDoSgYX6kqP4aSZWMa7z1tWAX")
|
|
require.NoError(t, err, "Unexpected error when making a valid peer")
|
|
assert.Equal(t, "QmUn6ycS8Fu6L462uZvuEfDoSgYX6kqP4aSZWMa7z1tWAX", a.ID.Pretty(), "Unexpected peer ID")
|
|
}
|
|
|
|
func TestDialRelayNode_InvalidPeerString(t *testing.T) {
|
|
err := dialRelayNode(context.Background(), nil, "/ip4")
|
|
assert.ErrorContains(t, "failed to parse multiaddr \"/ip4\"", err, "Expected to fail with invalid peer string")
|
|
}
|
|
|
|
func TestDialRelayNode_OK(t *testing.T) {
|
|
ctx := context.Background()
|
|
relay := bh.NewBlankHost(swarmt.GenSwarm(t, ctx))
|
|
host := bh.NewBlankHost(swarmt.GenSwarm(t, ctx))
|
|
relayAddr := fmt.Sprintf("%s/p2p/%s", relay.Addrs()[0], relay.ID().Pretty())
|
|
|
|
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")
|
|
}
|