testing

package
v0.3.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 12, 2020 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TopicMappings = map[reflect.Type]string{
	reflect.TypeOf(&pb.Status{}):                     "/eth2/beacon_chain/req/status/1",
	reflect.TypeOf(new(uint64)):                      "/eth2/beacon_chain/req/goodbye/1",
	reflect.TypeOf(&pb.BeaconBlocksByRangeRequest{}): "/eth2/beacon_chain/req/beacon_blocks_by_range/1",
	reflect.TypeOf([][32]byte{}):                     "/eth2/beacon_chain/req/beacon_blocks_by_root/1",
}

TopicMappings are the protocol ids for the different types of requests.

Functions

This section is empty.

Types

type MockBroadcaster

type MockBroadcaster struct {
	BroadcastCalled bool
}

MockBroadcaster implements p2p.Broadcaster for testing.

func (*MockBroadcaster) Broadcast

Broadcast records a broadcast occurred.

type MockPeersProvider added in v0.3.0

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

MockPeersProvider implements PeersProvider for testing.

func (*MockPeersProvider) Peers added in v0.3.0

func (m *MockPeersProvider) Peers() *peers.Status

Peers provides access the peer status.

type TestP2P

type TestP2P struct {
	Host host.Host

	BroadcastCalled bool
	DelaySend       bool
	// contains filtered or unexported fields
}

TestP2P represents a p2p implementation that can be used for testing.

func NewTestP2P

func NewTestP2P(t *testing.T) *TestP2P

NewTestP2P initializes a new p2p test service.

func (*TestP2P) AddConnectionHandler

func (p *TestP2P) AddConnectionHandler(f func(ctx context.Context, id peer.ID) error)

AddConnectionHandler handles the connection with a newly connected peer.

func (*TestP2P) AddDisconnectionHandler

func (p *TestP2P) AddDisconnectionHandler(f func(ctx context.Context, id peer.ID) error)

AddDisconnectionHandler --

func (*TestP2P) Broadcast

func (p *TestP2P) Broadcast(ctx context.Context, msg proto.Message) error

Broadcast a message.

func (*TestP2P) Connect

func (p *TestP2P) Connect(b *TestP2P)

Connect two test peers together.

func (*TestP2P) Disconnect

func (p *TestP2P) Disconnect(pid peer.ID) error

Disconnect from a peer.

func (*TestP2P) Encoding

func (p *TestP2P) Encoding() encoder.NetworkEncoding

Encoding returns ssz encoding.

func (*TestP2P) PeerID

func (p *TestP2P) PeerID() peer.ID

PeerID returns the Peer ID of the local peer.

func (*TestP2P) Peers added in v0.3.0

func (p *TestP2P) Peers() *peers.Status

Peers returns the peer status.

func (*TestP2P) PubSub

func (p *TestP2P) PubSub() *pubsub.PubSub

PubSub returns reference underlying floodsub. This test library uses floodsub to ensure all connected peers receive the message.

func (*TestP2P) ReceivePubSub

func (p *TestP2P) ReceivePubSub(topic string, msg proto.Message)

ReceivePubSub simulates an incoming message over pubsub on a given topic.

func (*TestP2P) ReceiveRPC

func (p *TestP2P) ReceiveRPC(topic string, msg proto.Message)

ReceiveRPC simulates an incoming RPC.

func (*TestP2P) Send

func (p *TestP2P) Send(ctx context.Context, msg interface{}, pid peer.ID) (network.Stream, error)

Send a message to a specific peer.

func (*TestP2P) SetStreamHandler

func (p *TestP2P) SetStreamHandler(topic string, handler network.StreamHandler)

SetStreamHandler for RPC.

func (*TestP2P) Started

func (p *TestP2P) Started() bool

Started always returns true.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL