2019-08-22 18:11:52 +00:00
|
|
|
package testing
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2023-03-17 18:52:56 +00:00
|
|
|
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
2021-05-17 18:32:04 +00:00
|
|
|
"google.golang.org/protobuf/proto"
|
2019-08-22 18:11:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// MockBroadcaster implements p2p.Broadcaster for testing.
|
|
|
|
type MockBroadcaster struct {
|
2021-07-29 16:33:18 +00:00
|
|
|
BroadcastCalled bool
|
|
|
|
BroadcastMessages []proto.Message
|
|
|
|
BroadcastAttestations []*ethpb.Attestation
|
2019-08-22 18:11:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Broadcast records a broadcast occurred.
|
2021-03-08 14:42:05 +00:00
|
|
|
func (m *MockBroadcaster) Broadcast(_ context.Context, msg proto.Message) error {
|
2019-08-22 18:11:52 +00:00
|
|
|
m.BroadcastCalled = true
|
2021-03-08 14:42:05 +00:00
|
|
|
m.BroadcastMessages = append(m.BroadcastMessages, msg)
|
2019-08-22 18:11:52 +00:00
|
|
|
return nil
|
|
|
|
}
|
2020-06-09 22:40:48 +00:00
|
|
|
|
|
|
|
// BroadcastAttestation records a broadcast occurred.
|
2021-07-29 16:33:18 +00:00
|
|
|
func (m *MockBroadcaster) BroadcastAttestation(_ context.Context, _ uint64, a *ethpb.Attestation) error {
|
2020-06-09 22:40:48 +00:00
|
|
|
m.BroadcastCalled = true
|
2021-07-29 16:33:18 +00:00
|
|
|
m.BroadcastAttestations = append(m.BroadcastAttestations, a)
|
2020-06-09 22:40:48 +00:00
|
|
|
return nil
|
|
|
|
}
|
2021-08-27 01:34:20 +00:00
|
|
|
|
|
|
|
// BroadcastSyncCommitteeMessage records a broadcast occurred.
|
|
|
|
func (m *MockBroadcaster) BroadcastSyncCommitteeMessage(_ context.Context, _ uint64, _ *ethpb.SyncCommitteeMessage) error {
|
|
|
|
m.BroadcastCalled = true
|
|
|
|
return nil
|
|
|
|
}
|