github.com/prysmaticlabs/prysm@v1.4.4/validator/rpc/health_test.go (about)

     1  package rpc
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/golang/protobuf/ptypes/empty"
     9  	ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
    10  	pb "github.com/prysmaticlabs/prysm/proto/validator/accounts/v2"
    11  	"github.com/prysmaticlabs/prysm/shared/testutil/require"
    12  	"github.com/prysmaticlabs/prysm/validator/client"
    13  	"google.golang.org/protobuf/types/known/timestamppb"
    14  )
    15  
    16  type mockSyncChecker struct {
    17  	syncing bool
    18  }
    19  
    20  func (m *mockSyncChecker) Syncing(_ context.Context) (bool, error) {
    21  	return m.syncing, nil
    22  }
    23  
    24  type mockGenesisFetcher struct{}
    25  
    26  func (m *mockGenesisFetcher) GenesisInfo(_ context.Context) (*ethpb.Genesis, error) {
    27  	genesis := timestamppb.New(time.Unix(0, 0))
    28  	return &ethpb.Genesis{
    29  		GenesisTime: genesis,
    30  	}, nil
    31  }
    32  
    33  func TestServer_GetBeaconNodeConnection(t *testing.T) {
    34  	ctx := context.Background()
    35  	endpoint := "localhost:90210"
    36  	vs, err := client.NewValidatorService(ctx, &client.Config{})
    37  	require.NoError(t, err)
    38  	s := &Server{
    39  		walletInitialized:   true,
    40  		validatorService:    vs,
    41  		syncChecker:         &mockSyncChecker{syncing: false},
    42  		genesisFetcher:      &mockGenesisFetcher{},
    43  		nodeGatewayEndpoint: endpoint,
    44  	}
    45  	got, err := s.GetBeaconNodeConnection(ctx, &empty.Empty{})
    46  	require.NoError(t, err)
    47  	want := &pb.NodeConnectionResponse{
    48  		BeaconNodeEndpoint: endpoint,
    49  		Connected:          false,
    50  		Syncing:            false,
    51  		GenesisTime:        uint64(time.Unix(0, 0).Unix()),
    52  	}
    53  	require.DeepEqual(t, want, got)
    54  }