2020-06-18 03:53:46 +00:00
|
|
|
package testing
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-01-14 20:48:40 +00:00
|
|
|
"errors"
|
2020-06-18 03:53:46 +00:00
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/p2p/enr"
|
|
|
|
"github.com/libp2p/go-libp2p-core/host"
|
|
|
|
"github.com/libp2p/go-libp2p-core/peer"
|
2020-12-17 18:03:18 +00:00
|
|
|
"github.com/multiformats/go-multiaddr"
|
2020-06-18 03:53:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// MockPeerManager is mock of the PeerManager interface.
|
|
|
|
type MockPeerManager struct {
|
2021-01-14 20:48:40 +00:00
|
|
|
Enr *enr.Record
|
|
|
|
PID peer.ID
|
|
|
|
BHost host.Host
|
|
|
|
DiscoveryAddr []multiaddr.Multiaddr
|
|
|
|
FailDiscoveryAddr bool
|
2020-06-18 03:53:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Disconnect .
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ *MockPeerManager) Disconnect(peer.ID) error {
|
2020-06-18 03:53:46 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// PeerID .
|
|
|
|
func (m *MockPeerManager) PeerID() peer.ID {
|
|
|
|
return m.PID
|
|
|
|
}
|
|
|
|
|
|
|
|
// Host .
|
|
|
|
func (m *MockPeerManager) Host() host.Host {
|
|
|
|
return m.BHost
|
|
|
|
}
|
|
|
|
|
|
|
|
// ENR .
|
|
|
|
func (m MockPeerManager) ENR() *enr.Record {
|
|
|
|
return m.Enr
|
|
|
|
}
|
|
|
|
|
2021-01-07 13:35:42 +00:00
|
|
|
// DiscoveryAddresses .
|
|
|
|
func (m MockPeerManager) DiscoveryAddresses() ([]multiaddr.Multiaddr, error) {
|
2021-01-14 20:48:40 +00:00
|
|
|
if m.FailDiscoveryAddr {
|
|
|
|
return nil, errors.New("fail")
|
|
|
|
}
|
|
|
|
return m.DiscoveryAddr, nil
|
2020-12-17 18:03:18 +00:00
|
|
|
}
|
|
|
|
|
2020-06-18 03:53:46 +00:00
|
|
|
// RefreshENR .
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ MockPeerManager) RefreshENR() {}
|
2020-06-18 03:53:46 +00:00
|
|
|
|
|
|
|
// FindPeersWithSubnet .
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ MockPeerManager) FindPeersWithSubnet(_ context.Context, _ string, _, _ uint64) (bool, error) {
|
2020-06-18 03:53:46 +00:00
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddPingMethod .
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ MockPeerManager) AddPingMethod(_ func(ctx context.Context, id peer.ID) error) {}
|