prysm-pulse/slasher/beaconclient/receivers_test.go
Raul Jordan a7325315a8
Include Beacon Client Package in Slasher (#4835)
* begin beacon client

* adding in the proper receivers

* include all parts of the beacon client

* all comments included

* visibility and package comment
2020-02-11 15:35:31 -06:00

71 lines
1.5 KiB
Go

package beaconclient
import (
"context"
"testing"
ptypes "github.com/gogo/protobuf/types"
"github.com/golang/mock/gomock"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/event"
"github.com/prysmaticlabs/prysm/shared/mock"
)
func TestService_ReceiveBlocks(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
client := mock.NewMockBeaconChainClient(ctrl)
bs := Service{
client: client,
blockFeed: new(event.Feed),
}
stream := mock.NewMockBeaconChain_StreamBlocksClient(ctrl)
ctx, cancel := context.WithCancel(context.Background())
block := &ethpb.BeaconBlock{
Slot: 5,
}
client.EXPECT().StreamBlocks(
gomock.Any(),
&ptypes.Empty{},
).Return(stream, nil)
stream.EXPECT().Context().Return(ctx).AnyTimes()
stream.EXPECT().Recv().Return(
block,
nil,
).Do(func() {
cancel()
})
bs.receiveBlocks(ctx)
}
func TestService_ReceiveAttestations(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
client := mock.NewMockBeaconChainClient(ctrl)
bs := Service{
client: client,
blockFeed: new(event.Feed),
}
stream := mock.NewMockBeaconChain_StreamAttestationsClient(ctrl)
ctx, cancel := context.WithCancel(context.Background())
att := &ethpb.Attestation{
Data: &ethpb.AttestationData{
Slot: 5,
},
}
client.EXPECT().StreamAttestations(
gomock.Any(),
&ptypes.Empty{},
).Return(stream, nil)
stream.EXPECT().Context().Return(ctx).AnyTimes()
stream.EXPECT().Recv().Return(
att,
nil,
).Do(func() {
cancel()
})
bs.receiveAttestations(ctx)
}