Documentation ¶
Overview ¶
Package testing includes useful utilities for mocking a beacon node's p2p service for unit tests.
Index ¶
- type FakeP2P
- func (p *FakeP2P) AddConnectionHandler(_, _ func(ctx context.Context, id peer.ID) error)
- func (p *FakeP2P) AddDisconnectionHandler(_ func(ctx context.Context, id peer.ID) error)
- func (p *FakeP2P) AddPingMethod(_ func(ctx context.Context, id peer.ID) error)
- func (p *FakeP2P) Broadcast(_ context.Context, _ proto.Message) error
- func (p *FakeP2P) BroadcastAttestation(_ context.Context, _ uint64, _ *ethpb.Attestation) error
- func (p *FakeP2P) Disconnect(_ peer.ID) error
- func (p *FakeP2P) DiscoveryAddresses() ([]multiaddr.Multiaddr, error)
- func (p *FakeP2P) ENR() *enr.Record
- func (p *FakeP2P) Encoding() encoder.NetworkEncoding
- func (p *FakeP2P) FindPeersWithSubnet(_ context.Context, _ string, _, _ uint64) (bool, error)
- func (p *FakeP2P) Host() host.Host
- func (p *FakeP2P) InterceptAccept(_ network.ConnMultiaddrs) (allow bool)
- func (p *FakeP2P) InterceptAddrDial(peer.ID, multiaddr.Multiaddr) (allow bool)
- func (p *FakeP2P) InterceptPeerDial(peer.ID) (allow bool)
- func (p *FakeP2P) InterceptSecured(network.Direction, peer.ID, network.ConnMultiaddrs) (allow bool)
- func (p *FakeP2P) InterceptUpgraded(network.Conn) (allow bool, reason control.DisconnectReason)
- func (p *FakeP2P) JoinTopic(_ string, _ ...pubsub.TopicOpt) (*pubsub.Topic, error)
- func (p *FakeP2P) LeaveTopic(_ string) error
- func (p *FakeP2P) Metadata() *pb.MetaData
- func (p *FakeP2P) MetadataSeq() uint64
- func (p *FakeP2P) PeerID() peer.ID
- func (p *FakeP2P) Peers() *peers.Status
- func (p *FakeP2P) PubSub() *pubsub.PubSub
- func (p *FakeP2P) PublishToTopic(_ context.Context, _ string, _ []byte, _ ...pubsub.PubOpt) error
- func (p *FakeP2P) RefreshENR()
- func (p *FakeP2P) Send(_ context.Context, _ interface{}, _ string, _ peer.ID) (network.Stream, error)
- func (p *FakeP2P) SetStreamHandler(_ string, _ network.StreamHandler)
- func (p *FakeP2P) SubscribeToTopic(_ string, _ ...pubsub.SubOpt) (*pubsub.Subscription, error)
- type MockBroadcaster
- type MockHost
- func (m *MockHost) Addrs() []ma.Multiaddr
- func (m *MockHost) Close() error
- func (m *MockHost) ConnManager() connmgr.ConnManager
- func (m *MockHost) Connect(ctx context.Context, pi peer.AddrInfo) error
- func (m *MockHost) EventBus() event.Bus
- func (m *MockHost) ID() peer.ID
- func (m *MockHost) Mux() protocol.Switch
- func (m *MockHost) Network() network.Network
- func (m *MockHost) NewStream(ctx context.Context, p peer.ID, pids ...protocol.ID) (network.Stream, error)
- func (m *MockHost) Peerstore() peerstore.Peerstore
- func (m *MockHost) RemoveStreamHandler(pid protocol.ID)
- func (m *MockHost) SetStreamHandler(pid protocol.ID, handler network.StreamHandler)
- func (m *MockHost) SetStreamHandlerMatch(protocol.ID, func(string) bool, network.StreamHandler)
- type MockMetadataProvider
- type MockPeerManager
- func (m MockPeerManager) AddPingMethod(_ func(ctx context.Context, id peer.ID) error)
- func (m *MockPeerManager) Disconnect(peer.ID) error
- func (m MockPeerManager) DiscoveryAddresses() ([]multiaddr.Multiaddr, error)
- func (m MockPeerManager) ENR() *enr.Record
- func (m MockPeerManager) FindPeersWithSubnet(_ context.Context, _ string, _, _ uint64) (bool, error)
- func (m *MockPeerManager) Host() host.Host
- func (m *MockPeerManager) PeerID() peer.ID
- func (m MockPeerManager) RefreshENR()
- type MockPeersProvider
- type TestP2P
- func (p *TestP2P) AddConnectionHandler(f, _ func(ctx context.Context, id peer.ID) error)
- func (p *TestP2P) AddDisconnectionHandler(f func(ctx context.Context, id peer.ID) error)
- func (p *TestP2P) AddPingMethod(_ func(ctx context.Context, id peer.ID) error)
- func (p *TestP2P) Broadcast(_ context.Context, _ proto.Message) error
- func (p *TestP2P) BroadcastAttestation(_ context.Context, _ uint64, _ *ethpb.Attestation) error
- func (p *TestP2P) Connect(b *TestP2P)
- func (p *TestP2P) Disconnect(pid peer.ID) error
- func (p *TestP2P) DiscoveryAddresses() ([]multiaddr.Multiaddr, error)
- func (p *TestP2P) ENR() *enr.Record
- func (p *TestP2P) Encoding() encoder.NetworkEncoding
- func (p *TestP2P) FindPeersWithSubnet(_ context.Context, _ string, _, _ uint64) (bool, error)
- func (p *TestP2P) ForkDigest() ([4]byte, error)
- func (p *TestP2P) Host() host.Host
- func (p *TestP2P) InterceptAccept(_ network.ConnMultiaddrs) (allow bool)
- func (p *TestP2P) InterceptAddrDial(peer.ID, multiaddr.Multiaddr) (allow bool)
- func (p *TestP2P) InterceptPeerDial(peer.ID) (allow bool)
- func (p *TestP2P) InterceptSecured(network.Direction, peer.ID, network.ConnMultiaddrs) (allow bool)
- func (p *TestP2P) InterceptUpgraded(network.Conn) (allow bool, reason control.DisconnectReason)
- func (p *TestP2P) JoinTopic(topic string, opts ...pubsub.TopicOpt) (*pubsub.Topic, error)
- func (p *TestP2P) LeaveTopic(topic string) error
- func (p *TestP2P) Metadata() *pb.MetaData
- func (p *TestP2P) MetadataSeq() uint64
- func (p *TestP2P) PeerID() peer.ID
- func (p *TestP2P) Peers() *peers.Status
- func (p *TestP2P) PubSub() *pubsub.PubSub
- func (p *TestP2P) PublishToTopic(ctx context.Context, topic string, data []byte, opts ...pubsub.PubOpt) error
- func (p *TestP2P) ReceivePubSub(topic string, msg proto.Message)
- func (p *TestP2P) ReceiveRPC(topic string, msg proto.Message)
- func (p *TestP2P) RefreshENR()
- func (p *TestP2P) Send(ctx context.Context, msg interface{}, topic string, pid peer.ID) (network.Stream, error)
- func (p *TestP2P) SetStreamHandler(topic string, handler network.StreamHandler)
- func (p *TestP2P) Started() bool
- func (p *TestP2P) SubscribeToTopic(topic string, opts ...pubsub.SubOpt) (*pubsub.Subscription, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FakeP2P ¶ added in v1.0.0
type FakeP2P struct { }
FakeP2P stack
func NewFuzzTestP2P ¶ added in v1.0.0
func NewFuzzTestP2P() *FakeP2P
NewFuzzTestP2P - Create a new fake p2p stack.
func (*FakeP2P) AddConnectionHandler ¶ added in v1.0.0
AddConnectionHandler -- fake.
func (*FakeP2P) AddDisconnectionHandler ¶ added in v1.0.0
AddDisconnectionHandler -- fake.
func (*FakeP2P) AddPingMethod ¶ added in v1.0.0
AddPingMethod -- fake.
func (*FakeP2P) BroadcastAttestation ¶ added in v1.0.0
BroadcastAttestation -- fake.
func (*FakeP2P) Disconnect ¶ added in v1.0.0
Disconnect -- fake.
func (*FakeP2P) DiscoveryAddresses ¶ added in v1.1.0
DiscoveryAddresses -- fake
func (*FakeP2P) Encoding ¶ added in v1.0.0
func (p *FakeP2P) Encoding() encoder.NetworkEncoding
Encoding -- fake.
func (*FakeP2P) FindPeersWithSubnet ¶ added in v1.0.0
FindPeersWithSubnet mocks the p2p func.
func (*FakeP2P) InterceptAccept ¶ added in v1.0.0
func (p *FakeP2P) InterceptAccept(_ network.ConnMultiaddrs) (allow bool)
InterceptAccept -- fake.
func (*FakeP2P) InterceptAddrDial ¶ added in v1.0.0
InterceptAddrDial -- fake.
func (*FakeP2P) InterceptPeerDial ¶ added in v1.0.0
InterceptPeerDial -- fake.
func (*FakeP2P) InterceptSecured ¶ added in v1.0.0
InterceptSecured -- fake.
func (*FakeP2P) InterceptUpgraded ¶ added in v1.0.0
InterceptUpgraded -- fake.
func (*FakeP2P) LeaveTopic ¶ added in v1.0.0
LeaveTopic -- fake.
func (*FakeP2P) MetadataSeq ¶ added in v1.0.0
MetadataSeq -- fake.
func (*FakeP2P) PublishToTopic ¶ added in v1.0.0
PublishToTopic -- fake.
func (*FakeP2P) RefreshENR ¶ added in v1.0.0
func (p *FakeP2P) RefreshENR()
RefreshENR mocks the p2p func.
func (*FakeP2P) Send ¶ added in v1.0.0
func (p *FakeP2P) Send(_ context.Context, _ interface{}, _ string, _ peer.ID) (network.Stream, error)
Send -- fake.
func (*FakeP2P) SetStreamHandler ¶ added in v1.0.0
func (p *FakeP2P) SetStreamHandler(_ string, _ network.StreamHandler)
SetStreamHandler -- fake.
func (*FakeP2P) SubscribeToTopic ¶ added in v1.0.0
SubscribeToTopic -- fake.
type MockBroadcaster ¶
MockBroadcaster implements p2p.Broadcaster for testing.
func (*MockBroadcaster) BroadcastAttestation ¶ added in v1.0.0
func (m *MockBroadcaster) BroadcastAttestation(_ context.Context, _ uint64, _ *ethpb.Attestation) error
BroadcastAttestation records a broadcast occurred.
type MockHost ¶ added in v1.1.0
MockHost is a fake implementation of libp2p2's Host interface.
func (*MockHost) ConnManager ¶ added in v1.1.0
func (m *MockHost) ConnManager() connmgr.ConnManager
ConnManager --
func (*MockHost) NewStream ¶ added in v1.1.0
func (m *MockHost) NewStream(ctx context.Context, p peer.ID, pids ...protocol.ID) (network.Stream, error)
NewStream --
func (*MockHost) RemoveStreamHandler ¶ added in v1.1.0
RemoveStreamHandler --
func (*MockHost) SetStreamHandler ¶ added in v1.1.0
func (m *MockHost) SetStreamHandler(pid protocol.ID, handler network.StreamHandler)
SetStreamHandler --
func (*MockHost) SetStreamHandlerMatch ¶ added in v1.1.0
SetStreamHandlerMatch --
type MockMetadataProvider ¶ added in v1.1.0
MockMetadataProvider is a fake implementation of the MetadataProvider interface.
func (*MockMetadataProvider) Metadata ¶ added in v1.1.0
func (m *MockMetadataProvider) Metadata() *pb.MetaData
Metadata --
func (*MockMetadataProvider) MetadataSeq ¶ added in v1.1.0
func (m *MockMetadataProvider) MetadataSeq() uint64
MetadataSeq --
type MockPeerManager ¶ added in v1.0.0
type MockPeerManager struct { Enr *enr.Record PID peer.ID BHost host.Host DiscoveryAddr []multiaddr.Multiaddr FailDiscoveryAddr bool }
MockPeerManager is mock of the PeerManager interface.
func (MockPeerManager) AddPingMethod ¶ added in v1.0.0
AddPingMethod .
func (*MockPeerManager) Disconnect ¶ added in v1.0.0
func (m *MockPeerManager) Disconnect(peer.ID) error
Disconnect .
func (MockPeerManager) DiscoveryAddresses ¶ added in v1.1.0
func (m MockPeerManager) DiscoveryAddresses() ([]multiaddr.Multiaddr, error)
DiscoveryAddresses .
func (MockPeerManager) FindPeersWithSubnet ¶ added in v1.0.0
func (m MockPeerManager) FindPeersWithSubnet(_ context.Context, _ string, _, _ uint64) (bool, error)
FindPeersWithSubnet .
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) ClearPeers ¶ added in v1.2.0
func (m *MockPeersProvider) ClearPeers()
ClearPeers removes all known peers.
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 ¶
NewTestP2P initializes a new p2p test service.
func (*TestP2P) AddConnectionHandler ¶
AddConnectionHandler handles the connection with a newly connected peer.
func (*TestP2P) AddDisconnectionHandler ¶
AddDisconnectionHandler --
func (*TestP2P) AddPingMethod ¶ added in v1.0.0
AddPingMethod mocks the p2p func.
func (*TestP2P) BroadcastAttestation ¶ added in v1.0.0
BroadcastAttestation broadcasts an attestation.
func (*TestP2P) Disconnect ¶
Disconnect from a peer.
func (*TestP2P) DiscoveryAddresses ¶ added in v1.1.0
DiscoveryAddresses --
func (*TestP2P) Encoding ¶
func (p *TestP2P) Encoding() encoder.NetworkEncoding
Encoding returns ssz encoding.
func (*TestP2P) FindPeersWithSubnet ¶ added in v0.3.8
FindPeersWithSubnet mocks the p2p func.
func (*TestP2P) ForkDigest ¶ added in v1.0.0
ForkDigest mocks the p2p func.
func (*TestP2P) InterceptAccept ¶ added in v1.0.0
func (p *TestP2P) InterceptAccept(_ network.ConnMultiaddrs) (allow bool)
InterceptAccept .
func (*TestP2P) InterceptAddrDial ¶ added in v1.0.0
InterceptAddrDial .
func (*TestP2P) InterceptPeerDial ¶ added in v1.0.0
InterceptPeerDial .
func (*TestP2P) InterceptSecured ¶ added in v1.0.0
InterceptSecured .
func (*TestP2P) InterceptUpgraded ¶ added in v1.0.0
InterceptUpgraded .
func (*TestP2P) JoinTopic ¶ added in v1.0.0
JoinTopic will join PubSub topic, if not already joined.
func (*TestP2P) LeaveTopic ¶ added in v1.0.0
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) MetadataSeq ¶ added in v1.0.0
MetadataSeq mocks metadata sequence number.
func (*TestP2P) 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 ¶
ReceivePubSub simulates an incoming message over pubsub on a given topic.
func (*TestP2P) ReceiveRPC ¶
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) 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.