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, ...)
- 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)
- type Message
- type Network
- 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, opts NodeOptions) *Node
- func (n *Network) NodeIDs() []types.NodeID
- func (n *Network) Peers(id types.NodeID) []*Node
- func (n *Network) RandomNode() *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, receive 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 Message ¶
type Message = gogotypes.StringValue
Message is a simple message containing a string-typed Value field.
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 ¶
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 ¶
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.
type NetworkOptions ¶
type NetworkOptions struct { NumNodes int BufferSize int NodeOpts NodeOptions }
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 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.