2018-08-01 22:08:44 +00:00
|
|
|
package rpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"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
|
|
|
rpcService := NewRPCService(context.Background(), &Config{Port: "9999", CertFlag: "alice.crt", KeyFlag: "alice.key"})
|
2018-08-01 22:08:44 +00:00
|
|
|
|
|
|
|
rpcService.Start()
|
|
|
|
|
|
|
|
testutil.AssertLogsContain(t, hook, "Starting service")
|
|
|
|
testutil.AssertLogsContain(t, hook, fmt.Sprintf("RPC server listening on port :%s", rpcService.port))
|
|
|
|
|
|
|
|
rpcService.Stop()
|
|
|
|
testutil.AssertLogsContain(t, hook, "Stopping service")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBadEndpoint(t *testing.T) {
|
|
|
|
hook := logTest.NewGlobal()
|
|
|
|
rpcService := NewRPCService(context.Background(), &Config{Port: "ralph merkle!!!"})
|
|
|
|
|
|
|
|
rpcService.Start()
|
|
|
|
|
|
|
|
testutil.AssertLogsContain(t, hook, "Starting service")
|
|
|
|
testutil.AssertLogsContain(t, hook, fmt.Sprintf("Could not listen to port :%s", rpcService.port))
|
|
|
|
|
|
|
|
rpcService.Stop()
|
|
|
|
testutil.AssertLogsContain(t, hook, "Stopping service")
|
|
|
|
}
|
2018-08-09 22:54:59 +00:00
|
|
|
|
|
|
|
func TestInsecureEndpoint(t *testing.T) {
|
|
|
|
hook := logTest.NewGlobal()
|
|
|
|
rpcService := NewRPCService(context.Background(), &Config{Port: "9999"})
|
|
|
|
|
|
|
|
rpcService.Start()
|
|
|
|
|
|
|
|
testutil.AssertLogsContain(t, hook, "Starting service")
|
|
|
|
testutil.AssertLogsContain(t, hook, fmt.Sprintf("RPC server listening on port :%s", rpcService.port))
|
|
|
|
testutil.AssertLogsContain(t, hook, "You are using an insecure gRPC connection")
|
|
|
|
|
|
|
|
rpcService.Stop()
|
|
|
|
testutil.AssertLogsContain(t, hook, "Stopping service")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRPCMethods(t *testing.T) {
|
|
|
|
s := &Service{}
|
|
|
|
if _, err := s.FetchShuffledValidatorIndices(context.Background(), nil); err == nil {
|
|
|
|
t.Error("Wanted error: unimplemented, received nil")
|
|
|
|
}
|
|
|
|
if _, err := s.ProposeBlock(context.Background(), nil); err == nil {
|
|
|
|
t.Error("Wanted error: unimplemented, received nil")
|
|
|
|
}
|
|
|
|
if _, err := s.SignBlock(context.Background(), nil); err == nil {
|
|
|
|
t.Error("Wanted error: unimplemented, received nil")
|
|
|
|
}
|
|
|
|
if err := s.LatestBeaconBlock(nil, nil); err == nil {
|
|
|
|
t.Error("Wanted error: unimplemented, received nil")
|
|
|
|
}
|
|
|
|
if err := s.LatestCrystallizedState(nil, nil); err == nil {
|
|
|
|
t.Error("Wanted error: unimplemented, received nil")
|
|
|
|
}
|
|
|
|
}
|