mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-06 01:32:18 +00:00
71 lines
1.5 KiB
Go
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 := ðpb.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 := ð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)
|
||
|
}
|