prysm-pulse/validator/rpc/health_test.go
Radosław Kapka a0679c70d3
Service constructors and Start() - better separation of concerns (#10532)
* move waitForStateInitialization to Start

* remove channel

* handle error in test

* fix service tests

* use fatal log

* deterministic-genesis

* sync

* rpc

* monitor

* validator-client

* test fixes

Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
2022-04-16 02:45:35 +00:00

55 lines
1.4 KiB
Go

package rpc
import (
"context"
"testing"
"time"
"github.com/golang/protobuf/ptypes/empty"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
pb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/validator-client"
"github.com/prysmaticlabs/prysm/testing/require"
"github.com/prysmaticlabs/prysm/validator/client"
"google.golang.org/protobuf/types/known/timestamppb"
)
type mockSyncChecker struct {
syncing bool
}
func (m *mockSyncChecker) Syncing(_ context.Context) (bool, error) {
return m.syncing, nil
}
type mockGenesisFetcher struct{}
func (_ *mockGenesisFetcher) GenesisInfo(_ context.Context) (*ethpb.Genesis, error) {
genesis := timestamppb.New(time.Unix(0, 0))
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: true,
Syncing: false,
GenesisTime: uint64(time.Unix(0, 0).Unix()),
}
require.DeepEqual(t, want, got)
}