go-ethereum: github.com/axiomzen/go-ethereum/p2p/testing Index | Files

package testing

import "github.com/axiomzen/go-ethereum/p2p/testing"

Index

Package Files

peerpool.go protocolsession.go protocoltester.go

func Wrap Uses

func Wrap(msg interface{}) interface{}

type Disconnect Uses

type Disconnect struct {
    Peer  enode.ID // discconnected peer
    Error error    // disconnect reason
}

Disconnect represents a disconnect event, used and checked by TestDisconnected

type Exchange Uses

type Exchange struct {
    Label    string
    Triggers []Trigger
    Expects  []Expect
    Timeout  time.Duration
}

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 Uses

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 Uses

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 Uses

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 Uses

func (s *ProtocolSession) TestExchanges(exchanges ...Exchange) error

TestExchanges tests a series of exchanges against the session

type ProtocolTester Uses

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 Uses

func NewProtocolTester(prvkey *ecdsa.PrivateKey, nodeCount 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 Uses

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

func (*ProtocolTester) Stop Uses

func (t *ProtocolTester) Stop()

Stop stops the p2p server

type TestPeer Uses

type TestPeer interface {
    ID() enode.ID
    Drop()
}

type TestPeerPool Uses

type TestPeerPool struct {
    // contains filtered or unexported fields
}

TestPeerPool is an example peerPool to demonstrate registration of peer connections

func NewTestPeerPool Uses

func NewTestPeerPool() *TestPeerPool

func (*TestPeerPool) Add Uses

func (p *TestPeerPool) Add(peer TestPeer)

func (*TestPeerPool) Get Uses

func (p *TestPeerPool) Get(id enode.ID) TestPeer

func (*TestPeerPool) Has Uses

func (p *TestPeerPool) Has(id enode.ID) bool

func (*TestPeerPool) Remove Uses

func (p *TestPeerPool) Remove(peer TestPeer)

type Trigger Uses

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

type WrappedMsg Uses

type WrappedMsg struct {
    Context []byte
    Size    uint32
    Payload []byte
}

Package testing imports 17 packages (graph). Updated 2019-07-06. Refresh now. Tools for package owners.