github.com/prysmaticlabs/prysm@v1.4.4/beacon-chain/p2p/testing/mock_host.go (about) 1 package testing 2 3 import ( 4 "context" 5 6 "github.com/libp2p/go-libp2p-core/connmgr" 7 "github.com/libp2p/go-libp2p-core/event" 8 "github.com/libp2p/go-libp2p-core/network" 9 "github.com/libp2p/go-libp2p-core/peer" 10 "github.com/libp2p/go-libp2p-core/peerstore" 11 "github.com/libp2p/go-libp2p-core/protocol" 12 ma "github.com/multiformats/go-multiaddr" 13 ) 14 15 // MockHost is a fake implementation of libp2p2's Host interface. 16 type MockHost struct { 17 Addresses []ma.Multiaddr 18 } 19 20 // ID -- 21 func (m *MockHost) ID() peer.ID { 22 return "" 23 } 24 25 // Peerstore -- 26 func (m *MockHost) Peerstore() peerstore.Peerstore { 27 return nil 28 } 29 30 // Addrs -- 31 func (m *MockHost) Addrs() []ma.Multiaddr { 32 return m.Addresses 33 } 34 35 // Network -- 36 func (m *MockHost) Network() network.Network { 37 return nil 38 } 39 40 // Mux -- 41 func (m *MockHost) Mux() protocol.Switch { 42 return nil 43 } 44 45 // Connect -- 46 func (m *MockHost) Connect(ctx context.Context, pi peer.AddrInfo) error { 47 return nil 48 } 49 50 // SetStreamHandler -- 51 func (m *MockHost) SetStreamHandler(pid protocol.ID, handler network.StreamHandler) {} 52 53 // SetStreamHandlerMatch -- 54 func (m *MockHost) SetStreamHandlerMatch(protocol.ID, func(string) bool, network.StreamHandler) {} 55 56 // RemoveStreamHandler -- 57 func (m *MockHost) RemoveStreamHandler(pid protocol.ID) {} 58 59 // NewStream -- 60 func (m *MockHost) NewStream(ctx context.Context, p peer.ID, pids ...protocol.ID) (network.Stream, error) { 61 return nil, nil 62 } 63 64 // Close -- 65 func (m *MockHost) Close() error { 66 return nil 67 } 68 69 // ConnManager -- 70 func (m *MockHost) ConnManager() connmgr.ConnManager { 71 return nil 72 } 73 74 // EventBus -- 75 func (m *MockHost) EventBus() event.Bus { 76 return nil 77 }