p2pfixtures

package
v0.29.0-stable-cadence-4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2022 License: AGPL-3.0 Imports: 42 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddNodesToEachOthersPeerStore

func AddNodesToEachOthersPeerStore(t *testing.T, nodes []p2p.LibP2PNode, ids flow.IdentityList)

AddNodesToEachOthersPeerStore adds the dialing address of all nodes to the peer store of all other nodes. However, it does not connect them to each other.

func CreateNode

func CreateNode(t *testing.T, nodeID flow.Identifier, networkKey crypto.PrivateKey, sporkID flow.Identifier, logger zerolog.Logger, opts ...nodeOpt) p2p.LibP2PNode

func EnsureConnected

func EnsureConnected(t *testing.T, ctx context.Context, nodes []p2p.LibP2PNode)

EnsureConnected ensures that the given nodes are connected to each other. It fails the test if any of the nodes is not connected to any other node.

func EnsureMessageExchangeOverUnicast

func EnsureMessageExchangeOverUnicast(t *testing.T, ctx context.Context, nodes []p2p.LibP2PNode, inbounds []chan string, messageFactory func() string)

EnsureMessageExchangeOverUnicast ensures that the given nodes exchange arbitrary messages on through unicasting (i.e., stream creation). It fails the test if any of the nodes does not receive the message from the other nodes. The "inbounds" parameter specifies the inbound channel of the nodes on which the messages are received. The "messageFactory" parameter specifies the function that creates unique messages to be sent.

func EnsureNoPubsubExchangeBetweenGroups

func EnsureNoPubsubExchangeBetweenGroups(t *testing.T, ctx context.Context, groupA []p2p.LibP2PNode, groupB []p2p.LibP2PNode, messageFactory func() (interface{}, channels.Topic))

EnsureNoPubsubExchangeBetweenGroups ensures that no pubsub message is exchanged between the given groups of nodes.

func EnsureNoPubsubMessageExchange

func EnsureNoPubsubMessageExchange(t *testing.T, ctx context.Context, from []p2p.LibP2PNode, to []p2p.LibP2PNode, messageFactory func() (interface{}, channels.Topic))

EnsureNoPubsubMessageExchange ensures that the no pubsub message is exchanged "from" the given nodes "to" the given nodes.

func EnsureNoStreamCreation

func EnsureNoStreamCreation(t *testing.T, ctx context.Context, from []p2p.LibP2PNode, to []p2p.LibP2PNode, errorCheckers ...func(*testing.T, error))

EnsureNoStreamCreation ensures that no stream is created "from" the given nodes "to" the given nodes.

func EnsureNoStreamCreationBetweenGroups

func EnsureNoStreamCreationBetweenGroups(t *testing.T, ctx context.Context, groupA []p2p.LibP2PNode, groupB []p2p.LibP2PNode, errorCheckers ...func(*testing.T, error))

EnsureNoStreamCreationBetweenGroups ensures that no stream is created between the given groups of nodes.

func EnsureNotConnected

func EnsureNotConnected(t *testing.T, ctx context.Context, from []p2p.LibP2PNode, to []p2p.LibP2PNode)

EnsureNotConnected ensures that no connection exists from "from" nodes to "to" nodes.

func EnsureNotConnectedBetweenGroups

func EnsureNotConnectedBetweenGroups(t *testing.T, ctx context.Context, groupA []p2p.LibP2PNode, groupB []p2p.LibP2PNode)

EnsureNotConnectedBetweenGroups ensures no connection exists between the given groups of nodes.

func EnsurePubsubMessageExchange

func EnsurePubsubMessageExchange(t *testing.T, ctx context.Context, nodes []p2p.LibP2PNode, messageFactory func() (interface{}, channels.Topic))

EnsurePubsubMessageExchange ensures that the given nodes exchange the given message on the given channel through pubsub.

func EnsureStreamCreation

func EnsureStreamCreation(t *testing.T, ctx context.Context, from []p2p.LibP2PNode, to []p2p.LibP2PNode)

EnsureStreamCreation ensures that a stream is created between each of the "from" nodes to each of the "to" nodes.

func EnsureStreamCreationInBothDirections

func EnsureStreamCreationInBothDirections(t *testing.T, ctx context.Context, nodes []p2p.LibP2PNode)

EnsureStreamCreationInBothDirections ensure that between each pair of nodes in the given list, a stream is created in both directions.

func HasSubReceivedMessage

func HasSubReceivedMessage(t *testing.T, ctx context.Context, expectedMessage []byte, sub *pubsub.Subscription) bool

HasSubReceivedMessage checks that the subscription have received the given message within the given timeout by the context. It returns true if the subscription has received the message, false otherwise.

func LetNodesDiscoverEachOther

func LetNodesDiscoverEachOther(t *testing.T, ctx context.Context, nodes []p2p.LibP2PNode, ids flow.IdentityList)

LetNodesDiscoverEachOther connects all nodes to each other on the pubsub mesh.

func LongStringMessageFactoryFixture

func LongStringMessageFactoryFixture(t *testing.T) func() string

LongStringMessageFactoryFixture returns a function that creates a long unique string message.

func MustEncodeEvent

func MustEncodeEvent(t *testing.T, v interface{}, channel channels.Channel) []byte

MustEncodeEvent encodes and returns the given event and fails the test if it faces any issue while encoding.

func NetworkingKeyFixtures

func NetworkingKeyFixtures(t *testing.T) crypto.PrivateKey

NetworkingKeyFixtures is a test helper that generates a ECDSA flow key pair.

func NodeFixture

func NodeFixture(
	t *testing.T,
	sporkID flow.Identifier,
	dhtPrefix string,
	opts ...NodeFixtureParameterOption,
) (p2p.LibP2PNode, flow.Identity)

NodeFixture is a test fixture that creates a single libp2p node with the given key, spork id, and options. It returns the node and its identity.

func NodesFixture

func NodesFixture(t *testing.T, sporkID flow.Identifier, dhtPrefix string, count int, opts ...NodeFixtureParameterOption) ([]p2p.LibP2PNode,
	flow.IdentityList)

NodesFixture is a test fixture that creates a number of libp2p nodes with the given callback function for stream handling. It returns the nodes and their identities.

func PeerIdFixture

func PeerIdFixture(t *testing.T) peer.ID

PeerIdFixture creates a random and unique peer ID (libp2p node ID).

func PeerIdsFixture

func PeerIdsFixture(t *testing.T, n int) []peer.ID

PeerIdsFixture creates random and unique peer IDs (libp2p node IDs).

func SilentNodeFixture

func SilentNodeFixture(t *testing.T) (net.Listener, flow.Identity)

SilentNodeFixture returns a TCP listener and a node which never replies

func StartNode

func StartNode(t *testing.T, ctx irrecoverable.SignalerContext, node p2p.LibP2PNode, timeout time.Duration)

StartNode start a single node using the provided context, timing out if nodes are not all Ready() before duration expires

func StartNodes

func StartNodes(t *testing.T, ctx irrecoverable.SignalerContext, nodes []p2p.LibP2PNode, timeout time.Duration)

StartNodes start all nodes in the input slice using the provided context, timing out if nodes are not all Ready() before duration expires

func StopNode

func StopNode(t *testing.T, node p2p.LibP2PNode, cancel context.CancelFunc, timeout time.Duration)

StopNode stops a single node using the provided cancel func, timing out if nodes are not all Done() before duration expires

func StopNodes

func StopNodes(t *testing.T, nodes []p2p.LibP2PNode, cancel context.CancelFunc, timeout time.Duration)

StopNodes stops all nodes in the input slice using the provided cancel func, timing out if nodes are not all Done() before duration expires

func StreamHandlerFixture

func StreamHandlerFixture(t *testing.T) (func(s network.Stream), chan string)

StreamHandlerFixture returns a stream handler that writes the received message to the given channel.

func SubMustNeverReceiveAnyMessage

func SubMustNeverReceiveAnyMessage(t *testing.T, ctx context.Context, sub *pubsub.Subscription)

SubMustNeverReceiveAnyMessage checks that the subscription never receives any message within the given timeout by the context.

func SubMustReceiveMessage

func SubMustReceiveMessage(t *testing.T, ctx context.Context, expectedMessage []byte, sub *pubsub.Subscription)

SubMustReceiveMessage checks that the subscription have received the given message within the given timeout by the context.

func SubsMustNeverReceiveAnyMessage

func SubsMustNeverReceiveAnyMessage(t *testing.T, ctx context.Context, subs []*pubsub.Subscription)

SubsMustNeverReceiveAnyMessage checks that all subscriptions never receive any message within the given timeout by the context.

func SubsMustReceiveMessage

func SubsMustReceiveMessage(t *testing.T, ctx context.Context, expectedMessage []byte, subs []*pubsub.Subscription)

SubsMustReceiveMessage checks that all subscriptions receive the given message within the given timeout by the context.

func WithSubscriptionFilter

func WithSubscriptionFilter(filter pubsub.SubscriptionFilter) nodeOpt

Types

type NodeFixtureParameterOption

type NodeFixtureParameterOption func(*NodeFixtureParameters)

func WithAppSpecificScore

func WithAppSpecificScore(score func(peer.ID) float64) NodeFixtureParameterOption

func WithConnectionGater

func WithConnectionGater(connGater connmgr.ConnectionGater) NodeFixtureParameterOption

func WithDHTOptions

func WithDHTOptions(opts ...dht.Option) NodeFixtureParameterOption

func WithDefaultStreamHandler

func WithDefaultStreamHandler(handler network.StreamHandler) NodeFixtureParameterOption

func WithLogger

func WithLogger(logger zerolog.Logger) NodeFixtureParameterOption

func WithNetworkingAddress

func WithNetworkingAddress(address string) NodeFixtureParameterOption

func WithNetworkingPrivateKey

func WithNetworkingPrivateKey(key crypto.PrivateKey) NodeFixtureParameterOption

func WithPeerManagerEnabled

func WithPeerManagerEnabled(connectionPruning bool, updateInterval time.Duration, peerProvider p2p.PeersProvider) NodeFixtureParameterOption

func WithPeerScoringEnabled

func WithPeerScoringEnabled(idProvider module.IdentityProvider) NodeFixtureParameterOption

func WithPreferredUnicasts

func WithPreferredUnicasts(unicasts []unicast.ProtocolName) NodeFixtureParameterOption

func WithRole

func WithRole(role flow.Role) NodeFixtureParameterOption

type NodeFixtureParameters

type NodeFixtureParameters struct {
	HandlerFunc        network.StreamHandler
	Unicasts           []unicast.ProtocolName
	Key                crypto.PrivateKey
	Address            string
	DhtOptions         []dht.Option
	Role               flow.Role
	Logger             zerolog.Logger
	PeerScoringEnabled bool
	IdProvider         module.IdentityProvider
	AppSpecificScore   func(peer.ID) float64 // overrides GossipSub scoring for sake of testing.
	ConnectionPruning  bool                  // peer manager parameter
	UpdateInterval     time.Duration         // peer manager parameter
	PeerProvider       p2p.PeersProvider     // peer manager parameter
	ConnGater          connmgr.ConnectionGater
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL