[#779] common.NodeManager removal

This commit is contained in:
Adrià Cidre 2018-03-27 18:30:37 +02:00
parent 9a2a311352
commit 1b724a81a5
No known key found for this signature in database
GPG Key ID: D246A27D58A92CAB
20 changed files with 215 additions and 364 deletions

View File

@ -14,7 +14,7 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/status-im/status-go/cmd/statusd/debug"
"github.com/status-im/status-go/geth/api"
"github.com/status-im/status-go/geth/common"
"github.com/status-im/status-go/geth/node"
"github.com/status-im/status-go/geth/params"
"github.com/status-im/status-go/metrics"
nodemetrics "github.com/status-im/status-go/metrics/node"
@ -182,7 +182,7 @@ func startDebug(backend *api.StatusBackend) error {
}
// startCollectingStats collects various stats about the node and other protocols like Whisper.
func startCollectingStats(interruptCh <-chan struct{}, nodeManager common.NodeManager) {
func startCollectingStats(interruptCh <-chan struct{}, nodeManager *node.Manager) {
logger.Info("Starting stats", "stats", *statsAddr)
@ -332,7 +332,7 @@ Options:
// haltOnInterruptSignal catches interrupt signal (SIGINT) and
// stops the node. It times out after 5 seconds
// if the node can not be stopped.
func haltOnInterruptSignal(nodeManager common.NodeManager) <-chan struct{} {
func haltOnInterruptSignal(nodeManager *node.Manager) <-chan struct{} {
interruptCh := make(chan struct{})
go func() {
signalCh := make(chan os.Signal, 1)

View File

@ -4,7 +4,7 @@ import (
"context"
"time"
"github.com/status-im/status-go/geth/common"
"github.com/status-im/status-go/geth/node"
)
func createContextFromTimeout(timeout int) (context.Context, context.CancelFunc) {
@ -19,7 +19,7 @@ func createContextFromTimeout(timeout int) (context.Context, context.CancelFunc)
// It returns an exit code (`0` if successful or `1` in case of error)
// that can be used in `os.Exit` to exit immediately when the function returns.
// The special exit code `-1` is used if execution was interrupted.
func syncAndStopNode(interruptCh <-chan struct{}, nodeManager common.NodeManager, timeout int) (exitCode int) {
func syncAndStopNode(interruptCh <-chan struct{}, nodeManager *node.Manager, timeout int) (exitCode int) {
logger.Info("syncAndStopNode: node will synchronize the chain and exit", "timeoutInMins", timeout)

View File

@ -0,0 +1,62 @@
// Code generated by MockGen. DO NOT EDIT.
// Source: geth/account/accounts.go
// Package transactions is a generated GoMock package.
package account
import (
reflect "reflect"
accounts "github.com/ethereum/go-ethereum/accounts"
keystore "github.com/ethereum/go-ethereum/accounts/keystore"
gomock "github.com/golang/mock/gomock"
)
// MockGethServiceProvider is a mock of GethServiceProvider interface
type MockGethServiceProvider struct {
ctrl *gomock.Controller
recorder *MockGethServiceProviderMockRecorder
}
// MockGethServiceProviderMockRecorder is the mock recorder for MockGethServiceProvider
type MockGethServiceProviderMockRecorder struct {
mock *MockGethServiceProvider
}
// NewMockGethServiceProvider creates a new mock instance
func NewMockGethServiceProvider(ctrl *gomock.Controller) *MockGethServiceProvider {
mock := &MockGethServiceProvider{ctrl: ctrl}
mock.recorder = &MockGethServiceProviderMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use
func (m *MockGethServiceProvider) EXPECT() *MockGethServiceProviderMockRecorder {
return m.recorder
}
// AccountManager mocks base method
func (m *MockGethServiceProvider) AccountManager() (*accounts.Manager, error) {
ret := m.ctrl.Call(m, "AccountManager")
ret0, _ := ret[0].(*accounts.Manager)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// AccountManager indicates an expected call of AccountManager
func (mr *MockGethServiceProviderMockRecorder) AccountManager() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AccountManager", reflect.TypeOf((*MockGethServiceProvider)(nil).AccountManager))
}
// AccountKeyStore mocks base method
func (m *MockGethServiceProvider) AccountKeyStore() (*keystore.KeyStore, error) {
ret := m.ctrl.Call(m, "AccountKeyStore")
ret0, _ := ret[0].(*keystore.KeyStore)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// AccountKeyStore indicates an expected call of AccountKeyStore
func (mr *MockGethServiceProviderMockRecorder) AccountKeyStore() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AccountKeyStore", reflect.TypeOf((*MockGethServiceProvider)(nil).AccountKeyStore))
}

View File

@ -119,8 +119,8 @@ var (
)
func TestManagerTestSuite(t *testing.T) {
nodeManager := newMockNodeManager(t)
accManager := NewManager(nodeManager)
gethServiceProvider := newMockGethServiceProvider(t)
accManager := NewManager(gethServiceProvider)
keyStoreDir, err := ioutil.TempDir(os.TempDir(), "accounts")
require.NoError(t, err)
@ -130,7 +130,7 @@ func TestManagerTestSuite(t *testing.T) {
testPassword := "test-password"
// Initial test - create test account
nodeManager.EXPECT().AccountKeyStore().Return(keyStore, nil)
gethServiceProvider.EXPECT().AccountKeyStore().Return(keyStore, nil)
addr, pubKey, mnemonic, err := accManager.CreateAccount(testPassword)
require.NoError(t, err)
require.NotEmpty(t, addr)
@ -144,27 +144,27 @@ func TestManagerTestSuite(t *testing.T) {
pubKey,
mnemonic,
},
nodeManager: nodeManager,
accManager: accManager,
keyStore: keyStore,
gethAccManager: accounts.NewManager(),
gethServiceProvider: gethServiceProvider,
accManager: accManager,
keyStore: keyStore,
gethAccManager: accounts.NewManager(),
}
suite.Run(t, s)
}
func newMockNodeManager(t *testing.T) *common.MockNodeManager {
func newMockGethServiceProvider(t *testing.T) *MockGethServiceProvider {
ctrl := gomock.NewController(t)
return common.NewMockNodeManager(ctrl)
return NewMockGethServiceProvider(ctrl)
}
type ManagerTestSuite struct {
suite.Suite
testAccount
nodeManager *common.MockNodeManager
accManager *Manager
keyStore *keystore.KeyStore
gethAccManager *accounts.Manager
gethServiceProvider *MockGethServiceProvider
accManager *Manager
keyStore *keystore.KeyStore
gethAccManager *accounts.Manager
}
type testAccount struct {
@ -178,8 +178,8 @@ type testAccount struct {
// Stating the amount of times for mock calls kills the flexibility for
// development so this is a good workaround to use with EXPECT().Func().AnyTimes()
func (s *ManagerTestSuite) reinitMock() {
s.nodeManager = newMockNodeManager(s.T())
s.accManager.geth = s.nodeManager
s.gethServiceProvider = newMockGethServiceProvider(s.T())
s.accManager.geth = s.gethServiceProvider
}
// SetupTest is used here for reinitializing the mock before every
@ -190,23 +190,23 @@ func (s *ManagerTestSuite) SetupTest() {
func (s *ManagerTestSuite) TestCreateAccount() {
// Don't fail on empty password
s.nodeManager.EXPECT().AccountKeyStore().Return(s.keyStore, nil)
s.gethServiceProvider.EXPECT().AccountKeyStore().Return(s.keyStore, nil)
_, _, _, err := s.accManager.CreateAccount(s.password)
s.NoError(err)
s.nodeManager.EXPECT().AccountKeyStore().Return(nil, errKeyStore)
s.gethServiceProvider.EXPECT().AccountKeyStore().Return(nil, errKeyStore)
_, _, _, err = s.accManager.CreateAccount(s.password)
s.Equal(errKeyStore, err)
}
func (s *ManagerTestSuite) TestRecoverAccount() {
s.nodeManager.EXPECT().AccountKeyStore().Return(s.keyStore, nil)
s.gethServiceProvider.EXPECT().AccountKeyStore().Return(s.keyStore, nil)
addr, pubKey, err := s.accManager.RecoverAccount(s.password, s.mnemonic)
s.NoError(err)
s.Equal(s.address, addr)
s.Equal(s.pubKey, pubKey)
s.nodeManager.EXPECT().AccountKeyStore().Return(nil, errKeyStore)
s.gethServiceProvider.EXPECT().AccountKeyStore().Return(nil, errKeyStore)
_, _, err = s.accManager.RecoverAccount(s.password, s.mnemonic)
s.Equal(errKeyStore, err)
}
@ -252,7 +252,7 @@ func (s *ManagerTestSuite) TestSelectAccount() {
for _, testCase := range testCases {
s.T().Run(testCase.name, func(t *testing.T) {
s.reinitMock()
s.nodeManager.EXPECT().AccountKeyStore().Return(testCase.accountKeyStoreReturn...).AnyTimes()
s.gethServiceProvider.EXPECT().AccountKeyStore().Return(testCase.accountKeyStoreReturn...).AnyTimes()
err := s.accManager.SelectAccount(testCase.address, testCase.password)
s.Equal(testCase.expectedError, err)
})
@ -264,14 +264,14 @@ func (s *ManagerTestSuite) TestCreateChildAccount() {
// and an address is not provided.
s.accManager.selectedAccount = nil
s.T().Run("fail_noAccount", func(t *testing.T) {
s.nodeManager.EXPECT().AccountKeyStore().Return(s.keyStore, nil).AnyTimes()
s.gethServiceProvider.EXPECT().AccountKeyStore().Return(s.keyStore, nil).AnyTimes()
_, _, err := s.accManager.CreateChildAccount("", s.password)
s.Equal(ErrNoAccountSelected, err)
})
// Now, select the test account for rest of the test cases.
s.reinitMock()
s.nodeManager.EXPECT().AccountKeyStore().Return(s.keyStore, nil).AnyTimes()
s.gethServiceProvider.EXPECT().AccountKeyStore().Return(s.keyStore, nil).AnyTimes()
err := s.accManager.SelectAccount(s.address, s.password)
s.NoError(err)
@ -315,7 +315,7 @@ func (s *ManagerTestSuite) TestCreateChildAccount() {
for _, testCase := range testCases {
s.T().Run(testCase.name, func(t *testing.T) {
s.reinitMock()
s.nodeManager.EXPECT().AccountKeyStore().Return(testCase.accountKeyStoreReturn...).AnyTimes()
s.gethServiceProvider.EXPECT().AccountKeyStore().Return(testCase.accountKeyStoreReturn...).AnyTimes()
childAddr, childPubKey, err := s.accManager.CreateChildAccount(testCase.address, testCase.password)
if testCase.expectedError != nil {
s.Equal(testCase.expectedError, err)
@ -337,24 +337,24 @@ func (s *ManagerTestSuite) TestLogout() {
// TestAccounts tests cases for (*Manager).Accounts.
func (s *ManagerTestSuite) TestAccounts() {
// Select the test account
s.nodeManager.EXPECT().AccountKeyStore().Return(s.keyStore, nil).AnyTimes()
s.gethServiceProvider.EXPECT().AccountKeyStore().Return(s.keyStore, nil).AnyTimes()
err := s.accManager.SelectAccount(s.address, s.password)
s.NoError(err)
// Success
s.nodeManager.EXPECT().AccountManager().Return(s.gethAccManager, nil)
s.gethServiceProvider.EXPECT().AccountManager().Return(s.gethAccManager, nil)
accs, err := s.accManager.Accounts()
s.NoError(err)
s.NotNil(accs)
// Can't get an account manager
s.nodeManager.EXPECT().AccountManager().Return(nil, errAccManager)
s.gethServiceProvider.EXPECT().AccountManager().Return(nil, errAccManager)
_, err = s.accManager.Accounts()
s.Equal(errAccManager, err)
// Selected account is nil but doesn't fail
s.accManager.selectedAccount = nil
s.nodeManager.EXPECT().AccountManager().Return(s.gethAccManager, nil)
s.gethServiceProvider.EXPECT().AccountManager().Return(s.gethAccManager, nil)
accs, err = s.accManager.Accounts()
s.NoError(err)
s.NotNil(accs)
@ -401,7 +401,7 @@ func (s *ManagerTestSuite) TestAddressToDecryptedAccount() {
for _, testCase := range testCases {
s.T().Run(testCase.name, func(t *testing.T) {
s.reinitMock()
s.nodeManager.EXPECT().AccountKeyStore().Return(testCase.accountKeyStoreReturn...).AnyTimes()
s.gethServiceProvider.EXPECT().AccountKeyStore().Return(testCase.accountKeyStoreReturn...).AnyTimes()
acc, key, err := s.accManager.AddressToDecryptedAccount(testCase.address, testCase.password)
if testCase.expectedError != nil {
s.Equal(testCase.expectedError, err)

View File

@ -10,6 +10,7 @@ import (
"github.com/status-im/status-go/geth/account"
"github.com/status-im/status-go/geth/common"
"github.com/status-im/status-go/geth/jail"
"github.com/status-im/status-go/geth/node"
"github.com/status-im/status-go/geth/params"
"github.com/status-im/status-go/geth/transactions"
)
@ -35,7 +36,7 @@ func NewStatusAPIWithBackend(b *StatusBackend) *StatusAPI {
}
// NodeManager returns reference to node manager
func (api *StatusAPI) NodeManager() common.NodeManager {
func (api *StatusAPI) NodeManager() *node.Manager {
return api.b.NodeManager()
}

View File

@ -34,7 +34,7 @@ var (
// StatusBackend implements Status.im service
type StatusBackend struct {
mu sync.Mutex
nodeManager *node.NodeManager
nodeManager *node.Manager
accountManager *account.Manager
txQueueManager *transactions.Manager
jailManager jail.Manager
@ -47,7 +47,7 @@ type StatusBackend struct {
func NewStatusBackend() *StatusBackend {
defer log.Info("Status backend initialized")
nodeManager := node.NewNodeManager()
nodeManager := node.NewManager()
accountManager := account.NewManager(nodeManager)
txQueueManager := transactions.NewManager(nodeManager)
jailManager := jail.New(nodeManager)
@ -64,7 +64,7 @@ func NewStatusBackend() *StatusBackend {
}
// NodeManager returns reference to node manager
func (b *StatusBackend) NodeManager() *node.NodeManager {
func (b *StatusBackend) NodeManager() *node.Manager {
return b.nodeManager
}

View File

@ -10,15 +10,9 @@ import (
"strings"
"time"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/les"
"github.com/ethereum/go-ethereum/node"
whisper "github.com/ethereum/go-ethereum/whisper/whisperv6"
"github.com/status-im/status-go/geth/params"
"github.com/status-im/status-go/geth/rpc"
"github.com/status-im/status-go/static"
)
@ -27,52 +21,6 @@ var (
ErrDeprecatedMethod = errors.New("Method is depricated and will be removed in future release")
)
// NodeManager defines expected methods for managing Status node
type NodeManager interface {
// StartNode start Status node, fails if node is already started
StartNode(config *params.NodeConfig) error
// EnsureSync waits until blockchain is synchronized.
EnsureSync(ctx context.Context) error
// StopNode stop the running Status node.
// Stopped node cannot be resumed, one starts a new node instead.
StopNode() error
// IsNodeRunning confirm that node is running
IsNodeRunning() bool
// NodeConfig returns reference to running node's configuration
NodeConfig() (*params.NodeConfig, error)
// Node returns underlying Status node
Node() (*node.Node, error)
// PopulateStaticPeers populates node's list of static bootstrap peers
PopulateStaticPeers() error
// AddPeer adds URL of static peer
AddPeer(url string) error
// PeerCount returns number of connected peers
PeerCount() int
// LightEthereumService exposes reference to LES service running on top of the node
LightEthereumService() (*les.LightEthereum, error)
// WhisperService returns reference to running Whisper service
WhisperService() (*whisper.Whisper, error)
// AccountManager returns reference to node's account manager
AccountManager() (*accounts.Manager, error)
// AccountKeyStore returns reference to account manager's keystore
AccountKeyStore() (*keystore.KeyStore, error)
// RPCClient exposes reference to RPC client connected to the running node
RPCClient() *rpc.Client
}
// TransactionResult is a JSON returned from transaction complete function (used internally)
type TransactionResult struct {
Hash common.Hash

View File

@ -1,216 +0,0 @@
// Code generated by MockGen. DO NOT EDIT.
// Source: geth/common/types.go
// Package common is a generated GoMock package.
package common
import (
context "context"
reflect "reflect"
accounts "github.com/ethereum/go-ethereum/accounts"
keystore "github.com/ethereum/go-ethereum/accounts/keystore"
les "github.com/ethereum/go-ethereum/les"
node "github.com/ethereum/go-ethereum/node"
whisperv6 "github.com/ethereum/go-ethereum/whisper/whisperv6"
gomock "github.com/golang/mock/gomock"
params "github.com/status-im/status-go/geth/params"
rpc "github.com/status-im/status-go/geth/rpc"
)
// MockNodeManager is a mock of NodeManager interface
type MockNodeManager struct {
ctrl *gomock.Controller
recorder *MockNodeManagerMockRecorder
}
// MockNodeManagerMockRecorder is the mock recorder for MockNodeManager
type MockNodeManagerMockRecorder struct {
mock *MockNodeManager
}
// NewMockNodeManager creates a new mock instance
func NewMockNodeManager(ctrl *gomock.Controller) *MockNodeManager {
mock := &MockNodeManager{ctrl: ctrl}
mock.recorder = &MockNodeManagerMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use
func (m *MockNodeManager) EXPECT() *MockNodeManagerMockRecorder {
return m.recorder
}
// StartNode mocks base method
func (m *MockNodeManager) StartNode(config *params.NodeConfig) error {
ret := m.ctrl.Call(m, "StartNode", config)
ret0, _ := ret[0].(error)
return ret0
}
// StartNode indicates an expected call of StartNode
func (mr *MockNodeManagerMockRecorder) StartNode(config interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StartNode", reflect.TypeOf((*MockNodeManager)(nil).StartNode), config)
}
// EnsureSync mocks base method
func (m *MockNodeManager) EnsureSync(ctx context.Context) error {
ret := m.ctrl.Call(m, "EnsureSync", ctx)
ret0, _ := ret[0].(error)
return ret0
}
// EnsureSync indicates an expected call of EnsureSync
func (mr *MockNodeManagerMockRecorder) EnsureSync(ctx interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EnsureSync", reflect.TypeOf((*MockNodeManager)(nil).EnsureSync), ctx)
}
// StopNode mocks base method
func (m *MockNodeManager) StopNode() error {
ret := m.ctrl.Call(m, "StopNode")
ret0, _ := ret[0].(error)
return ret0
}
// StopNode indicates an expected call of StopNode
func (mr *MockNodeManagerMockRecorder) StopNode() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StopNode", reflect.TypeOf((*MockNodeManager)(nil).StopNode))
}
// IsNodeRunning mocks base method
func (m *MockNodeManager) IsNodeRunning() bool {
ret := m.ctrl.Call(m, "IsNodeRunning")
ret0, _ := ret[0].(bool)
return ret0
}
// IsNodeRunning indicates an expected call of IsNodeRunning
func (mr *MockNodeManagerMockRecorder) IsNodeRunning() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsNodeRunning", reflect.TypeOf((*MockNodeManager)(nil).IsNodeRunning))
}
// NodeConfig mocks base method
func (m *MockNodeManager) NodeConfig() (*params.NodeConfig, error) {
ret := m.ctrl.Call(m, "NodeConfig")
ret0, _ := ret[0].(*params.NodeConfig)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// NodeConfig indicates an expected call of NodeConfig
func (mr *MockNodeManagerMockRecorder) NodeConfig() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeConfig", reflect.TypeOf((*MockNodeManager)(nil).NodeConfig))
}
// Node mocks base method
func (m *MockNodeManager) Node() (*node.Node, error) {
ret := m.ctrl.Call(m, "Node")
ret0, _ := ret[0].(*node.Node)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// Node indicates an expected call of Node
func (mr *MockNodeManagerMockRecorder) Node() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Node", reflect.TypeOf((*MockNodeManager)(nil).Node))
}
// PopulateStaticPeers mocks base method
func (m *MockNodeManager) PopulateStaticPeers() error {
ret := m.ctrl.Call(m, "PopulateStaticPeers")
ret0, _ := ret[0].(error)
return ret0
}
// PopulateStaticPeers indicates an expected call of PopulateStaticPeers
func (mr *MockNodeManagerMockRecorder) PopulateStaticPeers() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PopulateStaticPeers", reflect.TypeOf((*MockNodeManager)(nil).PopulateStaticPeers))
}
// AddPeer mocks base method
func (m *MockNodeManager) AddPeer(url string) error {
ret := m.ctrl.Call(m, "AddPeer", url)
ret0, _ := ret[0].(error)
return ret0
}
// AddPeer indicates an expected call of AddPeer
func (mr *MockNodeManagerMockRecorder) AddPeer(url interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddPeer", reflect.TypeOf((*MockNodeManager)(nil).AddPeer), url)
}
// PeerCount mocks base method
func (m *MockNodeManager) PeerCount() int {
ret := m.ctrl.Call(m, "PeerCount")
ret0, _ := ret[0].(int)
return ret0
}
// PeerCount indicates an expected call of PeerCount
func (mr *MockNodeManagerMockRecorder) PeerCount() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PeerCount", reflect.TypeOf((*MockNodeManager)(nil).PeerCount))
}
// LightEthereumService mocks base method
func (m *MockNodeManager) LightEthereumService() (*les.LightEthereum, error) {
ret := m.ctrl.Call(m, "LightEthereumService")
ret0, _ := ret[0].(*les.LightEthereum)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// LightEthereumService indicates an expected call of LightEthereumService
func (mr *MockNodeManagerMockRecorder) LightEthereumService() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LightEthereumService", reflect.TypeOf((*MockNodeManager)(nil).LightEthereumService))
}
// WhisperService mocks base method
func (m *MockNodeManager) WhisperService() (*whisperv6.Whisper, error) {
ret := m.ctrl.Call(m, "WhisperService")
ret0, _ := ret[0].(*whisperv6.Whisper)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// WhisperService indicates an expected call of WhisperService
func (mr *MockNodeManagerMockRecorder) WhisperService() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WhisperService", reflect.TypeOf((*MockNodeManager)(nil).WhisperService))
}
// AccountManager mocks base method
func (m *MockNodeManager) AccountManager() (*accounts.Manager, error) {
ret := m.ctrl.Call(m, "AccountManager")
ret0, _ := ret[0].(*accounts.Manager)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// AccountManager indicates an expected call of AccountManager
func (mr *MockNodeManagerMockRecorder) AccountManager() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AccountManager", reflect.TypeOf((*MockNodeManager)(nil).AccountManager))
}
// AccountKeyStore mocks base method
func (m *MockNodeManager) AccountKeyStore() (*keystore.KeyStore, error) {
ret := m.ctrl.Call(m, "AccountKeyStore")
ret0, _ := ret[0].(*keystore.KeyStore)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// AccountKeyStore indicates an expected call of AccountKeyStore
func (mr *MockNodeManagerMockRecorder) AccountKeyStore() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AccountKeyStore", reflect.TypeOf((*MockNodeManager)(nil).AccountKeyStore))
}
// RPCClient mocks base method
func (m *MockNodeManager) RPCClient() *rpc.Client {
ret := m.ctrl.Call(m, "RPCClient")
ret0, _ := ret[0].(*rpc.Client)
return ret0
}
// RPCClient indicates an expected call of RPCClient
func (mr *MockNodeManagerMockRecorder) RPCClient() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RPCClient", reflect.TypeOf((*MockNodeManager)(nil).RPCClient))
}

View File

@ -40,10 +40,10 @@ type RPCClientError error
// EthNodeError is reported when node crashed on start up.
type EthNodeError error
// NodeManager manages Status node (which abstracts contained geth node)
// Manager manages Status node (which abstracts contained geth node)
// nolint: golint
// should be fixed at https://github.com/status-im/status-go/issues/200
type NodeManager struct {
type Manager struct {
mu sync.RWMutex
config *params.NodeConfig // Status node configuration
node *node.Node // reference to Geth P2P stack/node
@ -54,22 +54,22 @@ type NodeManager struct {
log log.Logger
}
// NewNodeManager makes new instance of node manager
func NewNodeManager() *NodeManager {
return &NodeManager{
log: log.New("package", "status-go/geth/node.NodeManager"),
// NewManager makes new instance of node manager
func NewManager() *Manager {
return &Manager{
log: log.New("package", "status-go/geth/node.Manager"),
}
}
// StartNode start Status node, fails if node is already started
func (m *NodeManager) StartNode(config *params.NodeConfig) error {
func (m *Manager) StartNode(config *params.NodeConfig) error {
m.mu.Lock()
defer m.mu.Unlock()
return m.startNode(config)
}
// startNode start Status node, fails if node is already started
func (m *NodeManager) startNode(config *params.NodeConfig) error {
func (m *Manager) startNode(config *params.NodeConfig) error {
if err := m.isNodeAvailable(); err == nil {
return ErrNodeExists
}
@ -105,14 +105,14 @@ func (m *NodeManager) startNode(config *params.NodeConfig) error {
}
// StopNode stop Status node. Stopped node cannot be resumed.
func (m *NodeManager) StopNode() error {
func (m *Manager) StopNode() error {
m.mu.Lock()
defer m.mu.Unlock()
return m.stopNode()
}
// stopNode stop Status node. Stopped node cannot be resumed.
func (m *NodeManager) stopNode() error {
func (m *Manager) stopNode() error {
if err := m.isNodeAvailable(); err != nil {
return err
}
@ -128,7 +128,7 @@ func (m *NodeManager) stopNode() error {
}
// ResetChainData removes chain data if node is not running.
func (m *NodeManager) ResetChainData(config *params.NodeConfig) error {
func (m *Manager) ResetChainData(config *params.NodeConfig) error {
if m.IsNodeRunning() {
return ErrNodeExists
}
@ -147,7 +147,7 @@ func (m *NodeManager) ResetChainData(config *params.NodeConfig) error {
}
// IsNodeRunning confirm that node is running
func (m *NodeManager) IsNodeRunning() bool {
func (m *Manager) IsNodeRunning() bool {
m.mu.RLock()
defer m.mu.RUnlock()
@ -158,7 +158,7 @@ func (m *NodeManager) IsNodeRunning() bool {
}
// Node returns underlying Status node
func (m *NodeManager) Node() (*node.Node, error) {
func (m *Manager) Node() (*node.Node, error) {
m.mu.RLock()
defer m.mu.RUnlock()
@ -169,14 +169,14 @@ func (m *NodeManager) Node() (*node.Node, error) {
}
// PopulateStaticPeers connects current node with our publicly available LES/SHH/Swarm cluster
func (m *NodeManager) PopulateStaticPeers() error {
func (m *Manager) PopulateStaticPeers() error {
m.mu.RLock()
defer m.mu.RUnlock()
return m.populateStaticPeers()
}
// populateStaticPeers connects current node with our publicly available LES/SHH/Swarm cluster
func (m *NodeManager) populateStaticPeers() error {
func (m *Manager) populateStaticPeers() error {
if err := m.isNodeAvailable(); err != nil {
return err
}
@ -197,7 +197,7 @@ func (m *NodeManager) populateStaticPeers() error {
return nil
}
func (m *NodeManager) removeStaticPeers() error {
func (m *Manager) removeStaticPeers() error {
if !m.config.ClusterConfig.Enabled {
m.log.Info("Static peers are disabled")
return nil
@ -218,7 +218,7 @@ func (m *NodeManager) removeStaticPeers() error {
}
// ReconnectStaticPeers removes and adds static peers to a server.
func (m *NodeManager) ReconnectStaticPeers() error {
func (m *Manager) ReconnectStaticPeers() error {
m.mu.Lock()
defer m.mu.Unlock()
if err := m.removeStaticPeers(); err != nil {
@ -228,7 +228,7 @@ func (m *NodeManager) ReconnectStaticPeers() error {
}
// AddPeer adds new static peer node
func (m *NodeManager) AddPeer(url string) error {
func (m *Manager) AddPeer(url string) error {
m.mu.RLock()
defer m.mu.RUnlock()
if err := m.isNodeAvailable(); err != nil {
@ -238,7 +238,7 @@ func (m *NodeManager) AddPeer(url string) error {
}
// addPeer adds new static peer node
func (m *NodeManager) addPeer(url string) error {
func (m *Manager) addPeer(url string) error {
// Try to add the url as a static peer and return
parsedNode, err := discover.ParseNode(url)
if err != nil {
@ -248,7 +248,7 @@ func (m *NodeManager) addPeer(url string) error {
return nil
}
func (m *NodeManager) removePeer(url string) error {
func (m *Manager) removePeer(url string) error {
parsedNode, err := discover.ParseNode(url)
if err != nil {
return err
@ -258,7 +258,7 @@ func (m *NodeManager) removePeer(url string) error {
}
// PeerCount returns the number of connected peers.
func (m *NodeManager) PeerCount() int {
func (m *Manager) PeerCount() int {
if !m.IsNodeRunning() {
return 0
}
@ -266,7 +266,7 @@ func (m *NodeManager) PeerCount() int {
}
// NodeConfig exposes reference to running node's configuration
func (m *NodeManager) NodeConfig() (*params.NodeConfig, error) {
func (m *Manager) NodeConfig() (*params.NodeConfig, error) {
m.mu.RLock()
defer m.mu.RUnlock()
@ -277,7 +277,7 @@ func (m *NodeManager) NodeConfig() (*params.NodeConfig, error) {
}
// LightEthereumService exposes reference to LES service running on top of the node
func (m *NodeManager) LightEthereumService() (*les.LightEthereum, error) {
func (m *Manager) LightEthereumService() (*les.LightEthereum, error) {
m.mu.RLock()
defer m.mu.RUnlock()
@ -297,7 +297,7 @@ func (m *NodeManager) LightEthereumService() (*les.LightEthereum, error) {
}
// WhisperService exposes reference to Whisper service running on top of the node
func (m *NodeManager) WhisperService() (*whisper.Whisper, error) {
func (m *Manager) WhisperService() (*whisper.Whisper, error) {
m.mu.RLock()
defer m.mu.RUnlock()
@ -317,7 +317,7 @@ func (m *NodeManager) WhisperService() (*whisper.Whisper, error) {
}
// AccountManager exposes reference to node's accounts manager
func (m *NodeManager) AccountManager() (*accounts.Manager, error) {
func (m *Manager) AccountManager() (*accounts.Manager, error) {
m.mu.RLock()
defer m.mu.RUnlock()
@ -332,7 +332,7 @@ func (m *NodeManager) AccountManager() (*accounts.Manager, error) {
}
// AccountKeyStore exposes reference to accounts key store
func (m *NodeManager) AccountKeyStore() (*keystore.KeyStore, error) {
func (m *Manager) AccountKeyStore() (*keystore.KeyStore, error) {
m.mu.RLock()
defer m.mu.RUnlock()
@ -358,14 +358,14 @@ func (m *NodeManager) AccountKeyStore() (*keystore.KeyStore, error) {
}
// RPCClient exposes reference to RPC client connected to the running node.
func (m *NodeManager) RPCClient() *rpc.Client {
func (m *Manager) RPCClient() *rpc.Client {
m.mu.Lock()
defer m.mu.Unlock()
return m.rpcClient
}
// isNodeAvailable check if we have a node running and make sure is fully started
func (m *NodeManager) isNodeAvailable() error {
func (m *Manager) isNodeAvailable() error {
if m.node == nil || m.node.Server() == nil {
return ErrNoRunningNode
}
@ -377,7 +377,7 @@ const tickerResolution = time.Second
// EnsureSync waits until blockchain synchronization
// is complete and returns.
func (m *NodeManager) EnsureSync(ctx context.Context) error {
func (m *Manager) EnsureSync(ctx context.Context) error {
// Don't wait for any blockchain sync for the
// local private chain as blocks are never mined.
if m.config.NetworkID == params.StatusChainNetworkID {
@ -387,7 +387,7 @@ func (m *NodeManager) EnsureSync(ctx context.Context) error {
return m.ensureSync(ctx)
}
func (m *NodeManager) ensureSync(ctx context.Context) error {
func (m *Manager) ensureSync(ctx context.Context) error {
les, err := m.LightEthereumService()
if err != nil {
return fmt.Errorf("failed to get LES service: %v", err)

View File

@ -0,0 +1,47 @@
// Code generated by MockGen. DO NOT EDIT.
// Source: geth/transactions/txqueue_manager_test.go
// Package transactions is a generated GoMock package.
package transactions
import (
reflect "reflect"
gomock "github.com/golang/mock/gomock"
rpc "github.com/status-im/status-go/geth/rpc"
)
// MocktestRPCClientProvider is a mock of testRPCClientProvider interface
type MocktestRPCClientProvider struct {
ctrl *gomock.Controller
recorder *MocktestRPCClientProviderMockRecorder
}
// MocktestRPCClientProviderMockRecorder is the mock recorder for MocktestRPCClientProvider
type MocktestRPCClientProviderMockRecorder struct {
mock *MocktestRPCClientProvider
}
// NewMocktestRPCClientProvider creates a new mock instance
func NewMocktestRPCClientProvider(ctrl *gomock.Controller) *MocktestRPCClientProvider {
mock := &MocktestRPCClientProvider{ctrl: ctrl}
mock.recorder = &MocktestRPCClientProviderMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use
func (m *MocktestRPCClientProvider) EXPECT() *MocktestRPCClientProviderMockRecorder {
return m.recorder
}
// RPCClient mocks base method
func (m *MocktestRPCClientProvider) RPCClient() *rpc.Client {
ret := m.ctrl.Call(m, "RPCClient")
ret0, _ := ret[0].(*rpc.Client)
return ret0
}
// RPCClient indicates an expected call of RPCClient
func (mr *MocktestRPCClientProviderMockRecorder) RPCClient() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RPCClient", reflect.TypeOf((*MocktestRPCClientProvider)(nil).RPCClient))
}

View File

@ -27,38 +27,34 @@ import (
. "github.com/status-im/status-go/t/utils"
)
func TestTxQueueTestSuite(t *testing.T) {
suite.Run(t, new(TxQueueTestSuite))
}
type TxQueueTestSuite struct {
suite.Suite
nodeManagerMockCtrl *gomock.Controller
nodeManagerMock *common.MockNodeManager
server *gethrpc.Server
client *gethrpc.Client
txServiceMockCtrl *gomock.Controller
txServiceMock *fake.MockPublicTransactionPoolAPI
nodeConfig *params.NodeConfig
rpcClientMockCtrl *gomock.Controller
rpcClientMock *MocktestRPCClientProvider
server *gethrpc.Server
client *gethrpc.Client
txServiceMockCtrl *gomock.Controller
txServiceMock *fake.MockPublicTransactionPoolAPI
nodeConfig *params.NodeConfig
manager *Manager
}
func (s *TxQueueTestSuite) SetupTest() {
s.nodeManagerMockCtrl = gomock.NewController(s.T())
s.rpcClientMockCtrl = gomock.NewController(s.T())
s.txServiceMockCtrl = gomock.NewController(s.T())
s.nodeManagerMock = common.NewMockNodeManager(s.nodeManagerMockCtrl)
s.rpcClientMock = NewMocktestRPCClientProvider(s.rpcClientMockCtrl)
s.server, s.txServiceMock = fake.NewTestServer(s.txServiceMockCtrl)
s.client = gethrpc.DialInProc(s.server)
rpclient, _ := rpc.NewClient(s.client, params.UpstreamRPCConfig{})
s.nodeManagerMock.EXPECT().RPCClient().Return(rpclient)
s.rpcClientMock.EXPECT().RPCClient().Return(rpclient)
nodeConfig, err := params.NewNodeConfig("/tmp", "", params.RopstenNetworkID, true)
s.Require().NoError(err)
s.nodeConfig = nodeConfig
s.manager = NewManager(s.nodeManagerMock)
s.manager = NewManager(s.rpcClientMock)
s.manager.DisableNotificactions()
s.manager.completionTimeout = time.Second
s.manager.rpcCallTimeout = time.Second
@ -67,7 +63,7 @@ func (s *TxQueueTestSuite) SetupTest() {
func (s *TxQueueTestSuite) TearDownTest() {
s.manager.Stop()
s.nodeManagerMockCtrl.Finish()
s.rpcClientMockCtrl.Finish()
s.txServiceMockCtrl.Finish()
s.server.Stop()
s.client.Close()

View File

@ -73,7 +73,7 @@ func (s *APIBackendTestSuite) TestRaceConditions() {
log.Info("NodeManager()")
instance := s.Backend.NodeManager()
s.NotNil(instance)
s.IsType(&node.NodeManager{}, instance)
s.IsType(&node.Manager{}, instance)
s.T().Logf("NodeManager(), result: %v", instance)
progress <- struct{}{}
},

View File

@ -36,7 +36,7 @@ type JailTestSuite struct {
}
func (s *JailTestSuite) SetupTest() {
s.NodeManager = node.NewNodeManager()
s.NodeManager = node.NewManager()
s.Jail = jail.New(s.NodeManager)
}

View File

@ -27,7 +27,7 @@ type ManagerTestSuite struct {
}
func (s *ManagerTestSuite) SetupTest() {
s.NodeManager = node.NewNodeManager()
s.NodeManager = node.NewManager()
}
func (s *ManagerTestSuite) TestReferencesWithoutStartedNode() {

View File

@ -19,7 +19,7 @@ func TestRPCClientTestSuite(t *testing.T) {
}
func (s *RPCClientTestSuite) SetupTest() {
s.NodeManager = node.NewNodeManager()
s.NodeManager = node.NewManager()
s.NotNil(s.NodeManager)
}

View File

@ -26,7 +26,7 @@ type RPCTestSuite struct {
}
func (s *RPCTestSuite) SetupTest() {
s.NodeManager = node.NewNodeManager()
s.NodeManager = node.NewManager()
s.NotNil(s.NodeManager)
}

View File

@ -18,7 +18,7 @@ import (
// NodeManagerTestSuite defines a test suit with NodeManager.
type NodeManagerTestSuite struct {
suite.Suite
NodeManager *node.NodeManager
NodeManager *node.Manager
}
// All general log messages in this package should be routed through this logger.

View File

@ -4,7 +4,7 @@ import (
"context"
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/status-im/status-go/geth/common"
"github.com/status-im/status-go/geth/node"
"github.com/status-im/status-go/geth/params"
)
@ -27,7 +27,7 @@ func WithDataDir(path string) TestNodeOption {
}
// FirstBlockHash validates Attach operation for the NodeManager.
func FirstBlockHash(nodeManager common.NodeManager) (string, error) {
func FirstBlockHash(nodeManager *node.Manager) (string, error) {
// obtain RPC client for running node
runningNode, err := nodeManager.Node()
if err != nil {

View File

@ -21,7 +21,7 @@ type MailServiceSuite struct {
}
func (s *MailServiceSuite) SetupTest() {
s.NodeManager = node.NewNodeManager()
s.NodeManager = node.NewManager()
}
// TestShhRequestMessagesRPCMethodAvailability tests if `shh_requestMessages` is available

View File

@ -14,6 +14,7 @@ import (
"testing"
"time"
"github.com/ethereum/go-ethereum/les"
"github.com/ethereum/go-ethereum/log"
"github.com/status-im/status-go/geth/common"
"github.com/status-im/status-go/geth/params"
@ -95,10 +96,22 @@ func LoadFromFile(filename string) string {
return buf.String()
}
// LightEthereumProvider interface to be used on EnsureNodeSync
// TODO (adriacidre) This interface name should be reviewed as it has a lot
// of unrelated methods.
type LightEthereumProvider interface {
// NodeConfig returns reference to running node's configuration
NodeConfig() (*params.NodeConfig, error)
// LightEthereumService exposes reference to LES service running on top of the node
LightEthereumService() (*les.LightEthereum, error)
// PeerCount returns number of connected peers
PeerCount() int
}
// EnsureNodeSync waits until node synchronzation is done to continue
// with tests afterwards. Panics in case of an error or a timeout.
func EnsureNodeSync(nodeManager common.NodeManager) {
nc, err := nodeManager.NodeConfig()
func EnsureNodeSync(lesProvider LightEthereumProvider) {
nc, err := lesProvider.NodeConfig()
if err != nil {
panic("can't retrieve NodeConfig")
}
@ -107,7 +120,7 @@ func EnsureNodeSync(nodeManager common.NodeManager) {
return
}
les, err := nodeManager.LightEthereumService()
les, err := lesProvider.LightEthereumService()
if err != nil {
panic(err)
}
@ -129,7 +142,7 @@ func EnsureNodeSync(nodeManager common.NodeManager) {
if downloader == nil {
continue
}
if nodeManager.PeerCount() == 0 {
if lesProvider.PeerCount() == 0 {
logger.Debug("No establishished connections with a peers, continue waiting for a sync")
continue
}