2020-09-14 18:42:08 +00:00
|
|
|
package testing
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/p2p/enr"
|
|
|
|
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
2022-10-07 07:24:51 +00:00
|
|
|
"github.com/libp2p/go-libp2p/core/control"
|
|
|
|
"github.com/libp2p/go-libp2p/core/host"
|
|
|
|
"github.com/libp2p/go-libp2p/core/network"
|
|
|
|
"github.com/libp2p/go-libp2p/core/peer"
|
2020-09-14 18:42:08 +00:00
|
|
|
"github.com/multiformats/go-multiaddr"
|
2022-08-16 12:20:13 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v3/beacon-chain/p2p/encoder"
|
|
|
|
"github.com/prysmaticlabs/prysm/v3/beacon-chain/p2p/peers"
|
|
|
|
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
|
|
|
"github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1/metadata"
|
2021-07-23 13:07:40 +00:00
|
|
|
"google.golang.org/protobuf/proto"
|
2020-09-14 18:42:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// FakeP2P stack
|
|
|
|
type FakeP2P struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewFuzzTestP2P - Create a new fake p2p stack.
|
|
|
|
func NewFuzzTestP2P() *FakeP2P {
|
|
|
|
return &FakeP2P{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Encoding -- fake.
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ *FakeP2P) Encoding() encoder.NetworkEncoding {
|
2020-09-14 18:42:08 +00:00
|
|
|
return &encoder.SszNetworkEncoder{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddConnectionHandler -- fake.
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ *FakeP2P) AddConnectionHandler(_, _ func(ctx context.Context, id peer.ID) error) {
|
2020-09-14 18:42:08 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddDisconnectionHandler -- fake.
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ *FakeP2P) AddDisconnectionHandler(_ func(ctx context.Context, id peer.ID) error) {
|
2020-09-14 18:42:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// AddPingMethod -- fake.
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ *FakeP2P) AddPingMethod(_ func(ctx context.Context, id peer.ID) error) {
|
2020-09-14 18:42:08 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// PeerID -- fake.
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ *FakeP2P) PeerID() peer.ID {
|
2020-10-12 08:11:05 +00:00
|
|
|
return "fake"
|
2020-09-14 18:42:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ENR returns the enr of the local peer.
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ *FakeP2P) ENR() *enr.Record {
|
2020-09-14 18:42:08 +00:00
|
|
|
return new(enr.Record)
|
|
|
|
}
|
|
|
|
|
2021-01-07 13:35:42 +00:00
|
|
|
// DiscoveryAddresses -- fake
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ *FakeP2P) DiscoveryAddresses() ([]multiaddr.Multiaddr, error) {
|
2020-12-17 18:03:18 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2020-09-14 18:42:08 +00:00
|
|
|
// FindPeersWithSubnet mocks the p2p func.
|
2022-02-01 08:51:17 +00:00
|
|
|
func (_ *FakeP2P) FindPeersWithSubnet(_ context.Context, _ string, _ uint64, _ int) (bool, error) {
|
2020-09-14 18:42:08 +00:00
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// RefreshENR mocks the p2p func.
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ *FakeP2P) RefreshENR() {}
|
2020-09-14 18:42:08 +00:00
|
|
|
|
|
|
|
// LeaveTopic -- fake.
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ *FakeP2P) LeaveTopic(_ string) error {
|
2020-09-14 18:42:08 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Metadata -- fake.
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ *FakeP2P) Metadata() metadata.Metadata {
|
2020-09-14 18:42:08 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Peers -- fake.
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ *FakeP2P) Peers() *peers.Status {
|
2020-09-14 18:42:08 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// PublishToTopic -- fake.
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ *FakeP2P) PublishToTopic(_ context.Context, _ string, _ []byte, _ ...pubsub.PubOpt) error {
|
2020-09-14 18:42:08 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Send -- fake.
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ *FakeP2P) Send(_ context.Context, _ interface{}, _ string, _ peer.ID) (network.Stream, error) {
|
2020-09-14 18:42:08 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// PubSub -- fake.
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ *FakeP2P) PubSub() *pubsub.PubSub {
|
2020-09-14 18:42:08 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// MetadataSeq -- fake.
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ *FakeP2P) MetadataSeq() uint64 {
|
2020-09-14 18:42:08 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetStreamHandler -- fake.
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ *FakeP2P) SetStreamHandler(_ string, _ network.StreamHandler) {
|
2020-09-14 18:42:08 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// SubscribeToTopic -- fake.
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ *FakeP2P) SubscribeToTopic(_ string, _ ...pubsub.SubOpt) (*pubsub.Subscription, error) {
|
2020-09-14 18:42:08 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// JoinTopic -- fake.
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ *FakeP2P) JoinTopic(_ string, _ ...pubsub.TopicOpt) (*pubsub.Topic, error) {
|
2020-09-14 18:42:08 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Host -- fake.
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ *FakeP2P) Host() host.Host {
|
2020-09-14 18:42:08 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disconnect -- fake.
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ *FakeP2P) Disconnect(_ peer.ID) error {
|
2020-09-14 18:42:08 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Broadcast -- fake.
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ *FakeP2P) Broadcast(_ context.Context, _ proto.Message) error {
|
2020-09-14 18:42:08 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// BroadcastAttestation -- fake.
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ *FakeP2P) BroadcastAttestation(_ context.Context, _ uint64, _ *ethpb.Attestation) error {
|
2020-09-14 18:42:08 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-08-27 01:34:20 +00:00
|
|
|
// BroadcastSyncCommitteeMessage -- fake.
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ *FakeP2P) BroadcastSyncCommitteeMessage(_ context.Context, _ uint64, _ *ethpb.SyncCommitteeMessage) error {
|
2021-08-27 01:34:20 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-01-26 23:13:28 +00:00
|
|
|
// BroadcastBLSChanges mocks a broadcast BLS change ocurred
|
|
|
|
func (_ *FakeP2P) BroadcastBLSChanges(_ context.Context, _ []*ethpb.SignedBLSToExecutionChange) {
|
|
|
|
}
|
|
|
|
|
2020-09-14 18:42:08 +00:00
|
|
|
// InterceptPeerDial -- fake.
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ *FakeP2P) InterceptPeerDial(peer.ID) (allow bool) {
|
2020-09-14 18:42:08 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// InterceptAddrDial -- fake.
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ *FakeP2P) InterceptAddrDial(peer.ID, multiaddr.Multiaddr) (allow bool) {
|
2020-09-14 18:42:08 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// InterceptAccept -- fake.
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ *FakeP2P) InterceptAccept(_ network.ConnMultiaddrs) (allow bool) {
|
2020-09-14 18:42:08 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// InterceptSecured -- fake.
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ *FakeP2P) InterceptSecured(network.Direction, peer.ID, network.ConnMultiaddrs) (allow bool) {
|
2020-09-14 18:42:08 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// InterceptUpgraded -- fake.
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ *FakeP2P) InterceptUpgraded(network.Conn) (allow bool, reason control.DisconnectReason) {
|
2020-09-14 18:42:08 +00:00
|
|
|
return true, 0
|
|
|
|
}
|