Documentation ¶
Index ¶
- func MakeChannelDesc(chID p2p.ChannelID) p2p.ChannelDescriptor
- func NodeInSlice(id types.NodeID, ids []types.NodeID) bool
- func RequireEmpty(t *testing.T, channels ...*p2p.Channel)
- func RequireError(t *testing.T, channel *p2p.Channel, peerError p2p.PeerError)
- func RequireNoUpdates(t *testing.T, peerUpdates *p2p.PeerUpdates)
- func RequireReceive(t *testing.T, channel *p2p.Channel, expect p2p.Envelope)
- func RequireReceiveUnordered(t *testing.T, channel *p2p.Channel, expect []p2p.Envelope)
- func RequireSend(t *testing.T, channel *p2p.Channel, envelope p2p.Envelope)
- func RequireSendReceive(t *testing.T, channel *p2p.Channel, peerID types.NodeID, send proto.Message, ...)
- 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(t *testing.T, chDesc p2p.ChannelDescriptor, messageType proto.Message, ...) map[types.NodeID]*p2p.Channel
- func (n *Network) MakeChannelsNoCleanup(t *testing.T, chDesc p2p.ChannelDescriptor, messageType proto.Message, ...) map[types.NodeID]*p2p.Channel
- func (n *Network) MakeNode(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(t *testing.T, id types.NodeID)
- func (n *Network) Start(t *testing.T)
- type NetworkOptions
- type Node
- func (n *Node) MakeChannel(t *testing.T, chDesc p2p.ChannelDescriptor, messageType proto.Message, ...) *p2p.Channel
- func (n *Node) MakeChannelNoCleanup(t *testing.T, chDesc p2p.ChannelDescriptor, messageType proto.Message, ...) *p2p.Channel
- func (n *Node) MakePeerUpdates(t *testing.T) *p2p.PeerUpdates
- func (n *Node) MakePeerUpdatesNoRequireEmpty(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 ¶
func RequireNoUpdates(t *testing.T, peerUpdates *p2p.PeerUpdates)
RequireNoUpdates requires that a PeerUpdates subscription is empty.
func RequireReceive ¶
RequireReceive requires that the given envelope is received on the channel.
func RequireReceiveUnordered ¶
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( 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 ¶
func MakeNetwork(t *testing.T, opts NetworkOptions) *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( t *testing.T, chDesc p2p.ChannelDescriptor, messageType proto.Message, size int, ) 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( t *testing.T, chDesc p2p.ChannelDescriptor, messageType proto.Message, size int, ) 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(t *testing.T, 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.
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 }
Node is a node in a Network, with a Router and a PeerManager.
func (*Node) MakeChannel ¶
func (n *Node) MakeChannel(t *testing.T, chDesc p2p.ChannelDescriptor, messageType proto.Message, size int) *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( t *testing.T, chDesc p2p.ChannelDescriptor, messageType proto.Message, size int, ) *p2p.Channel
MakeChannelNoCleanup opens a channel, with automatic error handling. The caller must ensure proper cleanup of the channel.
func (*Node) MakePeerUpdates ¶
func (n *Node) MakePeerUpdates(t *testing.T) *p2p.PeerUpdates
MakePeerUpdates opens a peer update subscription, with automatic cleanup. It checks that all updates have been consumed during cleanup.
func (*Node) MakePeerUpdatesNoRequireEmpty ¶
func (n *Node) MakePeerUpdatesNoRequireEmpty(t *testing.T) *p2p.PeerUpdates
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.