mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-31 23:41:22 +00:00
68 lines
1.5 KiB
Go
68 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())
|
|
client.EXPECT().StreamBlocks(
|
|
gomock.Any(),
|
|
&ptypes.Empty{},
|
|
).Return(stream, nil)
|
|
stream.EXPECT().Context().Return(ctx).AnyTimes()
|
|
stream.EXPECT().Recv().Return(
|
|
ðpb.SignedBeaconBlock{},
|
|
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 := ðpb.Attestation{
|
|
Data: ðpb.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)
|
|
}
|