2018-08-01 22:08:44 +00:00
|
|
|
package rpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2019-02-04 21:54:30 +00:00
|
|
|
"errors"
|
2018-08-01 22:08:44 +00:00
|
|
|
"fmt"
|
2018-08-18 03:34:56 +00:00
|
|
|
"io/ioutil"
|
2018-08-01 22:08:44 +00:00
|
|
|
"testing"
|
|
|
|
|
2019-09-05 16:04:06 +00:00
|
|
|
mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
|
2019-11-05 03:00:51 +00:00
|
|
|
mockPOW "github.com/prysmaticlabs/prysm/beacon-chain/powchain/testing"
|
2019-09-20 17:54:32 +00:00
|
|
|
mockSync "github.com/prysmaticlabs/prysm/beacon-chain/sync/initial-sync/testing"
|
2018-08-01 22:08:44 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
2018-08-18 03:34:56 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2018-08-01 22:08:44 +00:00
|
|
|
logTest "github.com/sirupsen/logrus/hooks/test"
|
|
|
|
)
|
|
|
|
|
2018-08-18 03:34:56 +00:00
|
|
|
func init() {
|
|
|
|
logrus.SetLevel(logrus.DebugLevel)
|
|
|
|
logrus.SetOutput(ioutil.Discard)
|
|
|
|
}
|
|
|
|
|
2019-02-22 15:11:26 +00:00
|
|
|
func TestLifecycle_OK(t *testing.T) {
|
2018-08-01 22:08:44 +00:00
|
|
|
hook := logTest.NewGlobal()
|
2019-09-07 02:39:14 +00:00
|
|
|
rpcService := NewService(context.Background(), &Config{
|
2019-09-09 21:13:50 +00:00
|
|
|
Port: "7348",
|
|
|
|
CertFlag: "alice.crt",
|
|
|
|
KeyFlag: "alice.key",
|
|
|
|
SyncService: &mockSync.Sync{IsSyncing: false},
|
|
|
|
BlockReceiver: &mock.ChainService{},
|
|
|
|
AttestationReceiver: &mock.ChainService{},
|
|
|
|
HeadFetcher: &mock.ChainService{},
|
|
|
|
StateFeedListener: &mock.ChainService{},
|
2019-11-05 03:00:51 +00:00
|
|
|
POWChainService: &mockPOW.POWChain{},
|
2018-09-05 03:35:32 +00:00
|
|
|
})
|
2018-08-01 22:08:44 +00:00
|
|
|
|
|
|
|
rpcService.Start()
|
|
|
|
|
2019-10-01 20:05:17 +00:00
|
|
|
testutil.AssertLogsContain(t, hook, "listening on port")
|
2018-08-01 22:08:44 +00:00
|
|
|
|
|
|
|
rpcService.Stop()
|
2019-02-04 21:54:30 +00:00
|
|
|
|
2018-08-01 22:08:44 +00:00
|
|
|
}
|
|
|
|
|
2019-02-22 15:11:26 +00:00
|
|
|
func TestStatus_CredentialError(t *testing.T) {
|
2019-02-04 21:54:30 +00:00
|
|
|
credentialErr := errors.New("credentialError")
|
|
|
|
s := &Service{credentialError: credentialErr}
|
|
|
|
|
|
|
|
if err := s.Status(); err != s.credentialError {
|
|
|
|
t.Errorf("Wanted: %v, got: %v", s.credentialError, s.Status())
|
|
|
|
}
|
2018-08-01 22:08:44 +00:00
|
|
|
}
|
2018-08-09 22:54:59 +00:00
|
|
|
|
2019-02-22 15:11:26 +00:00
|
|
|
func TestRPC_InsecureEndpoint(t *testing.T) {
|
2018-08-09 22:54:59 +00:00
|
|
|
hook := logTest.NewGlobal()
|
2019-09-07 02:39:14 +00:00
|
|
|
rpcService := NewService(context.Background(), &Config{
|
2019-09-09 21:13:50 +00:00
|
|
|
Port: "7777",
|
|
|
|
SyncService: &mockSync.Sync{IsSyncing: false},
|
|
|
|
BlockReceiver: &mock.ChainService{},
|
|
|
|
AttestationReceiver: &mock.ChainService{},
|
|
|
|
HeadFetcher: &mock.ChainService{},
|
|
|
|
StateFeedListener: &mock.ChainService{},
|
2019-11-05 03:00:51 +00:00
|
|
|
POWChainService: &mockPOW.POWChain{},
|
2018-09-21 14:32:20 +00:00
|
|
|
})
|
2018-08-09 22:54:59 +00:00
|
|
|
|
|
|
|
rpcService.Start()
|
|
|
|
|
2019-10-01 20:05:17 +00:00
|
|
|
testutil.AssertLogsContain(t, hook, fmt.Sprint("listening on port"))
|
2018-08-09 22:54:59 +00:00
|
|
|
testutil.AssertLogsContain(t, hook, "You are using an insecure gRPC connection")
|
|
|
|
|
|
|
|
rpcService.Stop()
|
|
|
|
}
|