fixing error (#574)

This commit is contained in:
Nishant Das 2018-09-27 01:06:45 +08:00 committed by GitHub
parent c37ad4b446
commit 542ddef9e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 7 deletions

View File

@ -66,7 +66,7 @@ type Service struct {
grpcServer *grpc.Server
canonicalBlockChan chan *types.Block
canonicalStateChan chan *types.CrystallizedState
incomingAttestation chan *pbp2p.AggregatedAttestation
incomingAttestation chan *types.Attestation
devMode bool
}
@ -99,7 +99,7 @@ func NewRPCService(ctx context.Context, cfg *Config) *Service {
withKey: cfg.KeyFlag,
canonicalBlockChan: make(chan *types.Block, cfg.SubscriptionBuf),
canonicalStateChan: make(chan *types.CrystallizedState, cfg.SubscriptionBuf),
incomingAttestation: make(chan *pbp2p.AggregatedAttestation, cfg.SubscriptionBuf),
incomingAttestation: make(chan *types.Attestation, cfg.SubscriptionBuf),
devMode: cfg.DevMode,
}
}
@ -310,7 +310,7 @@ func (s *Service) LatestAttestation(req *empty.Empty, stream pb.BeaconService_La
select {
case attestation := <-s.incomingAttestation:
log.Info("Sending attestation to RPC clients")
if err := stream.Send(attestation); err != nil {
if err := stream.Send(attestation.Proto()); err != nil {
return err
}
case <-sub.Err():

View File

@ -327,9 +327,10 @@ func TestLatestAttestation(t *testing.T) {
defer ctrl.Finish()
exitRoutine := make(chan bool)
attestation := &types.Attestation{}
mockStream := internal.NewMockBeaconService_LatestAttestationServer(ctrl)
mockStream.EXPECT().Send(&pbp2p.AggregatedAttestation{}).Return(errors.New("something wrong"))
mockStream.EXPECT().Send(attestation.Proto()).Return(errors.New("something wrong"))
// Tests a faulty stream.
go func(tt *testing.T) {
if err := rpcService.LatestAttestation(&empty.Empty{}, mockStream); err.Error() != "something wrong" {
@ -337,10 +338,11 @@ func TestLatestAttestation(t *testing.T) {
}
<-exitRoutine
}(t)
rpcService.incomingAttestation <- &pbp2p.AggregatedAttestation{}
rpcService.incomingAttestation <- attestation
mockStream = internal.NewMockBeaconService_LatestAttestationServer(ctrl)
mockStream.EXPECT().Send(&pbp2p.AggregatedAttestation{}).Return(nil)
mockStream.EXPECT().Send(attestation.Proto()).Return(nil)
// Tests a good stream.
go func(tt *testing.T) {
@ -349,7 +351,7 @@ func TestLatestAttestation(t *testing.T) {
}
<-exitRoutine
}(t)
rpcService.incomingAttestation <- &pbp2p.AggregatedAttestation{}
rpcService.incomingAttestation <- attestation
testutil.AssertLogsContain(t, hook, "Sending attestation to RPC clients")
rpcService.cancel()
exitRoutine <- true