2020-09-03 23:25:56 +00:00
|
|
|
package rpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
2020-09-08 20:54:56 +00:00
|
|
|
"time"
|
2020-09-03 23:25:56 +00:00
|
|
|
|
2021-03-12 00:03:19 +00:00
|
|
|
"github.com/golang/protobuf/ptypes/empty"
|
2021-06-02 23:49:52 +00:00
|
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
|
2020-09-03 23:25:56 +00:00
|
|
|
pb "github.com/prysmaticlabs/prysm/proto/validator/accounts/v2"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
|
|
|
"github.com/prysmaticlabs/prysm/validator/client"
|
2021-05-17 18:32:04 +00:00
|
|
|
"google.golang.org/protobuf/types/known/timestamppb"
|
2020-09-03 23:25:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type mockSyncChecker struct {
|
|
|
|
syncing bool
|
|
|
|
}
|
|
|
|
|
2020-10-12 08:11:05 +00:00
|
|
|
func (m *mockSyncChecker) Syncing(_ context.Context) (bool, error) {
|
2020-09-03 23:25:56 +00:00
|
|
|
return m.syncing, nil
|
|
|
|
}
|
|
|
|
|
2020-09-08 20:54:56 +00:00
|
|
|
type mockGenesisFetcher struct{}
|
|
|
|
|
2020-10-12 08:11:05 +00:00
|
|
|
func (m *mockGenesisFetcher) GenesisInfo(_ context.Context) (*ethpb.Genesis, error) {
|
2021-05-17 18:32:04 +00:00
|
|
|
genesis := timestamppb.New(time.Unix(0, 0))
|
2020-09-08 20:54:56 +00:00
|
|
|
return ðpb.Genesis{
|
2020-09-08 22:35:31 +00:00
|
|
|
GenesisTime: genesis,
|
2020-09-08 20:54:56 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2020-09-03 23:25:56 +00:00
|
|
|
func TestServer_GetBeaconNodeConnection(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
endpoint := "localhost:90210"
|
2020-09-04 19:03:18 +00:00
|
|
|
vs, err := client.NewValidatorService(ctx, &client.Config{})
|
2020-09-03 23:25:56 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
s := &Server{
|
2020-09-04 19:03:18 +00:00
|
|
|
walletInitialized: true,
|
|
|
|
validatorService: vs,
|
2020-09-08 20:02:12 +00:00
|
|
|
syncChecker: &mockSyncChecker{syncing: false},
|
2020-09-08 20:54:56 +00:00
|
|
|
genesisFetcher: &mockGenesisFetcher{},
|
2020-09-04 19:03:18 +00:00
|
|
|
nodeGatewayEndpoint: endpoint,
|
2020-09-03 23:25:56 +00:00
|
|
|
}
|
2021-03-12 00:03:19 +00:00
|
|
|
got, err := s.GetBeaconNodeConnection(ctx, &empty.Empty{})
|
2020-09-03 23:25:56 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
want := &pb.NodeConnectionResponse{
|
2020-09-08 22:35:31 +00:00
|
|
|
BeaconNodeEndpoint: endpoint,
|
|
|
|
Connected: false,
|
|
|
|
Syncing: false,
|
|
|
|
GenesisTime: uint64(time.Unix(0, 0).Unix()),
|
2020-09-03 23:25:56 +00:00
|
|
|
}
|
|
|
|
require.DeepEqual(t, want, got)
|
|
|
|
}
|