mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 21:07:18 +00:00
47fdb3b99a
* Revert "Rename `NewService` to `New` (#8337)"
This reverts commit d121b19145
.
# Conflicts:
# beacon-chain/sync/initial-sync/round_robin_test.go
* fix name in test
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
73 lines
2.1 KiB
Go
73 lines
2.1 KiB
Go
package rpc
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"io/ioutil"
|
|
"testing"
|
|
"time"
|
|
|
|
mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
|
|
mockPOW "github.com/prysmaticlabs/prysm/beacon-chain/powchain/testing"
|
|
mockSync "github.com/prysmaticlabs/prysm/beacon-chain/sync/initial-sync/testing"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
|
"github.com/sirupsen/logrus"
|
|
logTest "github.com/sirupsen/logrus/hooks/test"
|
|
)
|
|
|
|
func init() {
|
|
logrus.SetLevel(logrus.DebugLevel)
|
|
logrus.SetOutput(ioutil.Discard)
|
|
}
|
|
|
|
func TestLifecycle_OK(t *testing.T) {
|
|
hook := logTest.NewGlobal()
|
|
chainService := &mock.ChainService{
|
|
Genesis: time.Now(),
|
|
}
|
|
rpcService := NewService(context.Background(), &Config{
|
|
Port: "7348",
|
|
SyncService: &mockSync.Sync{IsSyncing: false},
|
|
BlockReceiver: chainService,
|
|
AttestationReceiver: chainService,
|
|
HeadFetcher: chainService,
|
|
GenesisTimeFetcher: chainService,
|
|
POWChainService: &mockPOW.POWChain{},
|
|
StateNotifier: chainService.StateNotifier(),
|
|
})
|
|
|
|
rpcService.Start()
|
|
|
|
require.LogsContain(t, hook, "listening on port")
|
|
assert.NoError(t, rpcService.Stop())
|
|
}
|
|
|
|
func TestStatus_CredentialError(t *testing.T) {
|
|
credentialErr := errors.New("credentialError")
|
|
s := &Service{credentialError: credentialErr, syncService: &mockSync.Sync{IsSyncing: false}}
|
|
|
|
assert.ErrorContains(t, s.credentialError.Error(), s.Status())
|
|
}
|
|
|
|
func TestRPC_InsecureEndpoint(t *testing.T) {
|
|
hook := logTest.NewGlobal()
|
|
chainService := &mock.ChainService{Genesis: time.Now()}
|
|
rpcService := NewService(context.Background(), &Config{
|
|
Port: "7777",
|
|
SyncService: &mockSync.Sync{IsSyncing: false},
|
|
BlockReceiver: chainService,
|
|
GenesisTimeFetcher: chainService,
|
|
AttestationReceiver: chainService,
|
|
HeadFetcher: chainService,
|
|
POWChainService: &mockPOW.POWChain{},
|
|
StateNotifier: chainService.StateNotifier(),
|
|
})
|
|
|
|
rpcService.Start()
|
|
|
|
require.LogsContain(t, hook, "listening on port")
|
|
require.LogsContain(t, hook, "You are using an insecure gRPC server")
|
|
assert.NoError(t, rpcService.Stop())
|
|
}
|