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
|
|
|
|
|
|
|
ptypes "github.com/gogo/protobuf/types"
|
2020-09-08 20:54:56 +00:00
|
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/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"
|
|
|
|
)
|
|
|
|
|
|
|
|
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) {
|
2020-09-08 20:54:56 +00:00
|
|
|
genesis, err := ptypes.TimestampProto(time.Unix(0, 0))
|
|
|
|
if err != nil {
|
2020-09-08 22:35:31 +00:00
|
|
|
log.Info(err)
|
2020-09-08 20:54:56 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
got, err := s.GetBeaconNodeConnection(ctx, &ptypes.Empty{})
|
|
|
|
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)
|
|
|
|
}
|