testing

package
v1.0.0-alpha.23 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2020 License: GPL-3.0 Imports: 25 Imported by: 0

Documentation

Overview

Package testing includes useful utilities for mocking a beacon node's p2p service for unit tests.

Index

Constants

This section is empty.

Variables

This section is empty.

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.

func (*MockBroadcaster) BroadcastAttestation added in v1.0.0

func (m *MockBroadcaster) BroadcastAttestation(ctx context.Context, subnet uint64, att *ethpb.Attestation) error

BroadcastAttestation records a broadcast occurred.

type MockPeerManager added in v1.0.0

type MockPeerManager struct {
	Enr   *enr.Record
	PID   peer.ID
	BHost host.Host
}

MockPeerManager is mock of the PeerManager interface.

func (MockPeerManager) AddPingMethod added in v1.0.0

func (m MockPeerManager) AddPingMethod(reqFunc func(ctx context.Context, id peer.ID) error)

AddPingMethod .

func (*MockPeerManager) Disconnect added in v1.0.0

func (m *MockPeerManager) Disconnect(peer.ID) error

Disconnect .

func (MockPeerManager) ENR added in v1.0.0

func (m MockPeerManager) ENR() *enr.Record

ENR .

func (MockPeerManager) FindPeersWithSubnet added in v1.0.0

func (m MockPeerManager) FindPeersWithSubnet(ctx context.Context, index uint64) (bool, error)

FindPeersWithSubnet .

func (*MockPeerManager) Host added in v1.0.0

func (m *MockPeerManager) Host() host.Host

Host .

func (*MockPeerManager) PeerID added in v1.0.0

func (m *MockPeerManager) PeerID() peer.ID

PeerID .

func (MockPeerManager) RefreshENR added in v1.0.0

func (m MockPeerManager) RefreshENR()

RefreshENR .

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 {
	BHost host.Host

	BroadcastCalled bool
	DelaySend       bool
	Digest          [4]byte

	LocalMetadata *pb.MetaData
	// 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) AddPingMethod added in v1.0.0

func (p *TestP2P) AddPingMethod(reqFunc func(ctx context.Context, id peer.ID) error)

AddPingMethod mocks the p2p func.

func (*TestP2P) Broadcast

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

Broadcast a message.

func (*TestP2P) BroadcastAttestation added in v1.0.0

func (p *TestP2P) BroadcastAttestation(ctx context.Context, subnet uint64, att *ethpb.Attestation) error

BroadcastAttestation broadcasts an attestation.

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) ENR added in v1.0.0

func (p *TestP2P) ENR() *enr.Record

ENR returns the enr of the local peer.

func (*TestP2P) Encoding

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

Encoding returns ssz encoding.

func (*TestP2P) FindPeersWithSubnet added in v0.3.8

func (p *TestP2P) FindPeersWithSubnet(ctx context.Context, index uint64) (bool, error)

FindPeersWithSubnet mocks the p2p func.

func (*TestP2P) ForkDigest added in v1.0.0

func (p *TestP2P) ForkDigest() ([4]byte, error)

ForkDigest mocks the p2p func.

func (*TestP2P) Host

func (p *TestP2P) Host() host.Host

Host returns the libp2p host of the local peer.

func (*TestP2P) InterceptAccept added in v1.0.0

func (p *TestP2P) InterceptAccept(n network.ConnMultiaddrs) (allow bool)

InterceptAccept .

func (*TestP2P) InterceptAddrDial added in v1.0.0

func (p *TestP2P) InterceptAddrDial(peer.ID, multiaddr.Multiaddr) (allow bool)

InterceptAddrDial .

func (*TestP2P) InterceptPeerDial added in v1.0.0

func (p *TestP2P) InterceptPeerDial(peer.ID) (allow bool)

InterceptPeerDial .

func (*TestP2P) InterceptSecured added in v1.0.0

func (p *TestP2P) InterceptSecured(network.Direction, peer.ID, network.ConnMultiaddrs) (allow bool)

InterceptSecured .

func (*TestP2P) InterceptUpgraded added in v1.0.0

func (p *TestP2P) InterceptUpgraded(network.Conn) (allow bool, reason control.DisconnectReason)

InterceptUpgraded .

func (*TestP2P) JoinTopic added in v1.0.0

func (p *TestP2P) JoinTopic(topic string, opts ...pubsub.TopicOpt) (*pubsub.Topic, error)

JoinTopic will join PubSub topic, if not already joined.

func (*TestP2P) LeaveTopic added in v1.0.0

func (p *TestP2P) LeaveTopic(topic string) error

LeaveTopic closes topic and removes corresponding handler from list of joined topics. This method will return error if there are outstanding event handlers or subscriptions.

func (*TestP2P) Metadata added in v1.0.0

func (p *TestP2P) Metadata() *pb.MetaData

Metadata mocks the peer's metadata.

func (*TestP2P) MetadataSeq added in v1.0.0

func (p *TestP2P) MetadataSeq() uint64

MetadataSeq mocks metadata sequence number.

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) PublishToTopic added in v1.0.0

func (p *TestP2P) PublishToTopic(ctx context.Context, topic string, data []byte, opts ...pubsub.PubOpt) error

PublishToTopic publishes message to previously joined topic.

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) RefreshENR added in v0.3.8

func (p *TestP2P) RefreshENR()

RefreshENR mocks the p2p func.

func (*TestP2P) Send

func (p *TestP2P) Send(ctx context.Context, msg interface{}, topic string, 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.

func (*TestP2P) SubscribeToTopic added in v1.0.0

func (p *TestP2P) SubscribeToTopic(topic string, opts ...pubsub.SubOpt) (*pubsub.Subscription, error)

SubscribeToTopic joins (if necessary) and subscribes to PubSub topic.

Jump to

Keyboard shortcuts

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