2018-08-01 22:08:44 +00:00
|
|
|
package rpcclient
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
2018-08-09 22:54:59 +00:00
|
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1"
|
2018-08-01 22:08:44 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
|
|
|
logTest "github.com/sirupsen/logrus/hooks/test"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestLifecycle(t *testing.T) {
|
|
|
|
hook := logTest.NewGlobal()
|
2018-08-08 22:43:25 +00:00
|
|
|
rpcClientService := NewRPCClient(
|
|
|
|
context.Background(),
|
|
|
|
&Config{
|
|
|
|
Endpoint: "merkle tries",
|
|
|
|
CertFlag: "alice.crt",
|
|
|
|
},
|
|
|
|
)
|
2018-08-01 22:08:44 +00:00
|
|
|
rpcClientService.Start()
|
|
|
|
testutil.AssertLogsContain(t, hook, "Starting service")
|
|
|
|
rpcClientService.Stop()
|
|
|
|
testutil.AssertLogsContain(t, hook, "Stopping service")
|
|
|
|
}
|
2018-08-09 22:54:59 +00:00
|
|
|
|
|
|
|
func TestInsecure(t *testing.T) {
|
|
|
|
hook := logTest.NewGlobal()
|
|
|
|
rpcClientService := NewRPCClient(
|
|
|
|
context.Background(),
|
|
|
|
&Config{
|
|
|
|
Endpoint: "merkle tries",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
rpcClientService.Start()
|
|
|
|
testutil.AssertLogsContain(t, hook, "Starting service")
|
|
|
|
testutil.AssertLogsContain(t, hook, "You are using an insecure gRPC connection")
|
|
|
|
rpcClientService.Stop()
|
|
|
|
testutil.AssertLogsContain(t, hook, "Stopping service")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBeaconServiceClient(t *testing.T) {
|
|
|
|
rpcClientService := NewRPCClient(
|
|
|
|
context.Background(),
|
|
|
|
&Config{
|
|
|
|
Endpoint: "merkle tries",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
rpcClientService.conn = nil
|
|
|
|
client := rpcClientService.BeaconServiceClient()
|
|
|
|
if _, ok := client.(pb.BeaconServiceClient); !ok {
|
|
|
|
t.Error("Beacon service client function does not implement interface")
|
|
|
|
}
|
|
|
|
}
|
2018-09-17 04:13:04 +00:00
|
|
|
|
|
|
|
func TestProposerServiceClient(t *testing.T) {
|
|
|
|
rpcClientService := NewRPCClient(
|
|
|
|
context.Background(),
|
|
|
|
&Config{
|
|
|
|
Endpoint: "merkle tries",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
rpcClientService.conn = nil
|
|
|
|
client := rpcClientService.ProposerServiceClient()
|
|
|
|
if _, ok := client.(pb.ProposerServiceClient); !ok {
|
|
|
|
t.Error("Beacon service client function does not implement interface")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAttesterServiceClient(t *testing.T) {
|
|
|
|
rpcClientService := NewRPCClient(
|
|
|
|
context.Background(),
|
|
|
|
&Config{
|
|
|
|
Endpoint: "merkle tries",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
rpcClientService.conn = nil
|
|
|
|
client := rpcClientService.AttesterServiceClient()
|
|
|
|
if _, ok := client.(pb.AttesterServiceClient); !ok {
|
|
|
|
t.Error("Beacon service client function does not implement interface")
|
|
|
|
}
|
|
|
|
}
|