Documentation ¶
Index ¶
- func MakeChannelDesc(chID p2p.ChannelID) *p2p.ChannelDescriptor
- func NodeInSlice(id types.NodeID, ids []types.NodeID) bool
- func RequireEmpty(ctx context.Context, t *testing.T, channels ...p2p.Channel)
- func RequireError(ctx context.Context, t *testing.T, channel p2p.Channel, ...)
- func RequireNoUpdates(ctx context.Context, t *testing.T, peerUpdates *p2p.PeerUpdates)
- func RequireReceive(ctx context.Context, t *testing.T, channel p2p.Channel, expect p2p.Envelope)
- func RequireReceiveUnordered(ctx context.Context, t *testing.T, channel p2p.Channel, expect []*p2p.Envelope)
- func RequireSend(ctx context.Context, t *testing.T, channel p2p.Channel, envelope p2p.Envelope)
- func RequireSendReceive(ctx context.Context, t *testing.T, channel p2p.Channel, peerID types.NodeID, ...)
- func RequireUpdate(t *testing.T, peerUpdates *p2p.PeerUpdates, expect p2p.PeerUpdate)
- func RequireUpdates(t *testing.T, peerUpdates *p2p.PeerUpdates, expect []p2p.PeerUpdate)
- func WithLoggerAttrs(ctx context.Context, attrs ...interface{}) context.Context
- type Message
- type Network
- func (n *Network) AnyNode() *Node
- func (n *Network) MakeChannels(ctx context.Context, t *testing.T, chDesc *p2p.ChannelDescriptor) map[types.NodeID]p2p.Channel
- func (n *Network) MakeChannelsNoCleanup(ctx context.Context, t *testing.T, chDesc *p2p.ChannelDescriptor) map[types.NodeID]p2p.Channel
- func (n *Network) MakeNode(ctx context.Context, t *testing.T, proTxHash crypto.ProTxHash, ...) *Node
- func (n *Network) NodeByProTxHash(proTxHash types.ProTxHash) *Node
- func (n *Network) NodeIDs() []types.NodeID
- func (n *Network) Peers(id types.NodeID) []*Node
- func (n *Network) Remove(ctx context.Context, t *testing.T, id types.NodeID)
- func (n *Network) Start(ctx context.Context, t *testing.T)
- type NetworkOptions
- type Node
- func (n *Node) MakeChannel(ctx context.Context, t *testing.T, chDesc *p2p.ChannelDescriptor) p2p.Channel
- func (n *Node) MakeChannelNoCleanup(ctx context.Context, t *testing.T, chDesc *p2p.ChannelDescriptor) p2p.Channel
- func (n *Node) MakePeerUpdates(ctx context.Context, t *testing.T) *p2p.PeerUpdates
- func (n *Node) MakePeerUpdatesNoRequireEmpty(ctx context.Context, _t *testing.T) *p2p.PeerUpdates
- type NodeOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MakeChannelDesc ¶
func MakeChannelDesc(chID p2p.ChannelID) *p2p.ChannelDescriptor
func RequireEmpty ¶
RequireEmpty requires that the given channel is empty.
func RequireError ¶
RequireError requires that the given peer error is submitted for a peer.
func RequireNoUpdates ¶
RequireNoUpdates requires that a PeerUpdates subscription is empty.
func RequireReceive ¶
RequireReceive requires that the given envelope is received on the channel.
func RequireReceiveUnordered ¶
func RequireReceiveUnordered(ctx context.Context, t *testing.T, channel p2p.Channel, expect []*p2p.Envelope)
RequireReceiveUnordered requires that the given envelopes are all received on the channel, ignoring order.
func RequireSend ¶
RequireSend requires that the given envelope is sent on the channel.
func RequireSendReceive ¶
func RequireSendReceive( ctx context.Context, t *testing.T, channel p2p.Channel, peerID types.NodeID, send proto.Message, )
RequireSendReceive requires that a given Protobuf message is sent to the given peer, and then that the given response is received back.
func RequireUpdate ¶
func RequireUpdate(t *testing.T, peerUpdates *p2p.PeerUpdates, expect p2p.PeerUpdate)
RequireUpdate requires that a PeerUpdates subscription yields the given update.
func RequireUpdates ¶
func RequireUpdates(t *testing.T, peerUpdates *p2p.PeerUpdates, expect []p2p.PeerUpdate)
RequireUpdates requires that a PeerUpdates subscription yields the given updates in the given order.
Types ¶
type Network ¶
Network sets up an in-memory network that can be used for high-level P2P testing. It creates an arbitrary number of nodes that are connected to each other, and can open channels across all nodes with custom reactors.
func MakeNetwork ¶
func MakeNetwork(ctx context.Context, t *testing.T, opts NetworkOptions, logger log.Logger) *Network
MakeNetwork creates a test network with the given number of nodes and connects them to each other.
func (*Network) MakeChannels ¶
func (n *Network) MakeChannels( ctx context.Context, t *testing.T, chDesc *p2p.ChannelDescriptor, ) map[types.NodeID]p2p.Channel
MakeChannels makes a channel on all nodes and returns them, automatically doing error checks and cleanups.
func (*Network) MakeChannelsNoCleanup ¶
func (n *Network) MakeChannelsNoCleanup( ctx context.Context, t *testing.T, chDesc *p2p.ChannelDescriptor, ) map[types.NodeID]p2p.Channel
MakeChannelsNoCleanup makes a channel on all nodes and returns them, automatically doing error checks. The caller must ensure proper cleanup of all the channels.
func (*Network) MakeNode ¶
func (n *Network) MakeNode(ctx context.Context, t *testing.T, proTxHash crypto.ProTxHash, opts NodeOptions) *Node
MakeNode creates a new Node configured for the network with a running peer manager, but does not add it to the existing network. Callers are responsible for updating peering relationships.
func (*Network) NodeByProTxHash ¶
NodeByProTxHash returns a node with the given proTxHash or `nil` if not found.
type NetworkOptions ¶
type NetworkOptions struct { Config *config.Config NumNodes int BufferSize int NodeOpts NodeOptions ProTxHashes []crypto.ProTxHash }
NetworkOptions is an argument structure to parameterize the MakeNetwork function.
type Node ¶
type Node struct { NodeID types.NodeID NodeInfo types.NodeInfo NodeAddress p2p.NodeAddress PrivKey crypto.PrivKey Router *p2p.Router Client *p2pclient.Client PeerManager *p2p.PeerManager Transport *p2p.MemoryTransport // contains filtered or unexported fields }
Node is a node in a Network, with a Router and a PeerManager.
func (*Node) MakeChannel ¶
func (n *Node) MakeChannel( ctx context.Context, t *testing.T, chDesc *p2p.ChannelDescriptor, ) p2p.Channel
MakeChannel opens a channel, with automatic error handling and cleanup. On test cleanup, it also checks that the channel is empty, to make sure all expected messages have been asserted.
func (*Node) MakeChannelNoCleanup ¶
func (n *Node) MakeChannelNoCleanup( ctx context.Context, t *testing.T, chDesc *p2p.ChannelDescriptor, ) p2p.Channel
MakeChannelNoCleanup opens a channel, with automatic error handling. The caller must ensure proper cleanup of the channel.
func (*Node) MakePeerUpdates ¶
MakePeerUpdates opens a peer update subscription, with automatic cleanup. It checks that all updates have been consumed during cleanup.
func (*Node) MakePeerUpdatesNoRequireEmpty ¶
MakePeerUpdatesNoRequireEmpty opens a peer update subscription, with automatic cleanup. It does *not* check that all updates have been consumed, but will close the update channel.