Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Disconnect ¶
Disconnect represents a disconnect event, used and checked by TestDisconnected
type Exchange ¶
Exchange is the basic units of protocol tests the triggers and expects in the arrays are run immediately and asynchronously thus one cannot have multiple expects for the SAME peer with DIFFERENT message types because it's unpredictable which expect will receive which message (with expect #1 and #2, messages might be sent #2 and #1, and both expects will complain about wrong message code) an exchange is defined on a session
type Expect ¶
type Expect struct { Msg interface{} // type of message to expect Code uint64 // code of message is now given Peer enode.ID // the peer that expects the message Timeout time.Duration // timeout duration for receiving }
Expect is part of an exchange, outgoing message from the pivot node received by a peer
type ProtocolSession ¶
type ProtocolSession struct { Server *p2p.Server Nodes []*enode.Node // contains filtered or unexported fields }
ProtocolSession is a quasi simulation of a pivot node running a service and a number of dummy peers that can send (trigger) or receive (expect) messages
func (*ProtocolSession) TestDisconnected ¶
func (s *ProtocolSession) TestDisconnected(disconnects ...*Disconnect) error
TestDisconnected tests the disconnections given as arguments the disconnect structs describe what disconnect error is expected on which peer
func (*ProtocolSession) TestExchanges ¶
func (s *ProtocolSession) TestExchanges(exchanges ...Exchange) error
TestExchanges tests a series of exchanges against the session
type ProtocolTester ¶
type ProtocolTester struct { *ProtocolSession // contains filtered or unexported fields }
ProtocolTester is the tester environment used for unit testing protocol message exchanges. It uses p2p/simulations framework
func NewProtocolTester ¶
func NewProtocolTester(id enode.ID, n int, run func(*p2p.Peer, p2p.MsgReadWriter) error) *ProtocolTester
NewProtocolTester constructs a new ProtocolTester it takes as argument the pivot node id, the number of dummy peers and the protocol run function called on a peer connection by the p2p server
func (*ProtocolTester) Connect ¶
func (t *ProtocolTester) Connect(selfID enode.ID, peers ...*adapters.NodeConfig)
Connect brings up the remote peer node and connects it using the p2p/simulations network connection with the in memory network adapter
type TestPeerPool ¶
type TestPeerPool struct {
// contains filtered or unexported fields
}
TestPeerPool is an example peerPool to demonstrate registration of peer connections
func NewTestPeerPool ¶
func NewTestPeerPool() *TestPeerPool
func (*TestPeerPool) Add ¶
func (p *TestPeerPool) Add(peer TestPeer)
func (*TestPeerPool) Remove ¶
func (p *TestPeerPool) Remove(peer TestPeer)
type Trigger ¶
type Trigger struct { Msg interface{} // type of message to be sent Code uint64 // code of message is given Peer enode.ID // the peer to send the message to Timeout time.Duration // timeout duration for the sending }
Trigger is part of the exchange, incoming message for the pivot node sent by a peer