prysm-pulse/validator/rpc/health_test.go
Preston Van Loon eb694ab5d5
Update rules_go and fix proto conflicts (#8596)
* Update rules_go and fix proto conflicts

* gaz

* Update generated code

* more emptypb fixes

* gaz

Co-authored-by: Victor Farazdagi <simple.square@gmail.com>
2021-03-11 18:03:19 -06:00

59 lines
1.5 KiB
Go

package rpc
import (
"context"
"testing"
"time"
ptypes "github.com/gogo/protobuf/types"
"github.com/golang/protobuf/ptypes/empty"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
pb "github.com/prysmaticlabs/prysm/proto/validator/accounts/v2"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
"github.com/prysmaticlabs/prysm/validator/client"
)
type mockSyncChecker struct {
syncing bool
}
func (m *mockSyncChecker) Syncing(_ context.Context) (bool, error) {
return m.syncing, nil
}
type mockGenesisFetcher struct{}
func (m *mockGenesisFetcher) GenesisInfo(_ context.Context) (*ethpb.Genesis, error) {
genesis, err := ptypes.TimestampProto(time.Unix(0, 0))
if err != nil {
log.Info(err)
return nil, err
}
return &ethpb.Genesis{
GenesisTime: genesis,
}, nil
}
func TestServer_GetBeaconNodeConnection(t *testing.T) {
ctx := context.Background()
endpoint := "localhost:90210"
vs, err := client.NewValidatorService(ctx, &client.Config{})
require.NoError(t, err)
s := &Server{
walletInitialized: true,
validatorService: vs,
syncChecker: &mockSyncChecker{syncing: false},
genesisFetcher: &mockGenesisFetcher{},
nodeGatewayEndpoint: endpoint,
}
got, err := s.GetBeaconNodeConnection(ctx, &empty.Empty{})
require.NoError(t, err)
want := &pb.NodeConnectionResponse{
BeaconNodeEndpoint: endpoint,
Connected: false,
Syncing: false,
GenesisTime: uint64(time.Unix(0, 0).Unix()),
}
require.DeepEqual(t, want, got)
}