2017-05-16 12:09:52 +00:00
|
|
|
package node_test
|
|
|
|
|
|
|
|
import (
|
2017-05-25 13:14:52 +00:00
|
|
|
"encoding/json"
|
|
|
|
"math/rand"
|
2017-05-16 12:09:52 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/accounts"
|
|
|
|
"github.com/ethereum/go-ethereum/accounts/keystore"
|
|
|
|
"github.com/ethereum/go-ethereum/les"
|
|
|
|
gethnode "github.com/ethereum/go-ethereum/node"
|
|
|
|
"github.com/ethereum/go-ethereum/rpc"
|
|
|
|
whisper "github.com/ethereum/go-ethereum/whisper/whisperv5"
|
2017-10-11 14:20:51 +00:00
|
|
|
"github.com/status-im/status-go/e2e"
|
2017-08-10 13:35:58 +00:00
|
|
|
"github.com/status-im/status-go/geth/log"
|
2017-05-16 12:09:52 +00:00
|
|
|
"github.com/status-im/status-go/geth/node"
|
|
|
|
"github.com/status-im/status-go/geth/params"
|
2017-09-25 18:22:57 +00:00
|
|
|
"github.com/status-im/status-go/geth/signal"
|
2017-10-21 17:04:07 +00:00
|
|
|
. "github.com/status-im/status-go/testing"
|
2017-05-16 12:09:52 +00:00
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestManagerTestSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(ManagerTestSuite))
|
|
|
|
}
|
|
|
|
|
|
|
|
type ManagerTestSuite struct {
|
2017-10-11 14:20:51 +00:00
|
|
|
e2e.NodeManagerTestSuite
|
2017-05-16 12:09:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ManagerTestSuite) SetupTest() {
|
|
|
|
s.NodeManager = node.NewNodeManager()
|
|
|
|
}
|
|
|
|
|
2017-10-11 14:20:51 +00:00
|
|
|
func (s *ManagerTestSuite) TestReferencesWithoutStartedNode() {
|
|
|
|
var testCases = []struct {
|
2017-05-16 12:09:52 +00:00
|
|
|
name string
|
|
|
|
initFn func() (interface{}, error)
|
|
|
|
expectedErr error
|
|
|
|
}{
|
2017-05-25 13:14:52 +00:00
|
|
|
{
|
|
|
|
"non-null manager, no running node, RestartNode()",
|
|
|
|
func() (interface{}, error) {
|
|
|
|
return s.NodeManager.RestartNode()
|
|
|
|
},
|
|
|
|
node.ErrNoRunningNode,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"non-null manager, no running node, ResetChainData()",
|
|
|
|
func() (interface{}, error) {
|
|
|
|
return s.NodeManager.ResetChainData()
|
|
|
|
},
|
|
|
|
node.ErrNoRunningNode,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"non-null manager, no running node, PopulateStaticPeers()",
|
|
|
|
func() (interface{}, error) {
|
|
|
|
return nil, s.NodeManager.PopulateStaticPeers()
|
|
|
|
},
|
|
|
|
node.ErrNoRunningNode,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"non-null manager, no running node, AddPeer()",
|
|
|
|
func() (interface{}, error) {
|
|
|
|
return nil, s.NodeManager.AddPeer("enode://da3bf389a031f33fb55c9f5f54fde8473912402d27fffaa50efd74c0d0515f3a61daf6d52151f2876b19c15828e6f670352bff432b5ec457652e74755e8c864f@51.15.62.116:30303")
|
|
|
|
},
|
|
|
|
node.ErrNoRunningNode,
|
|
|
|
},
|
2017-05-16 12:09:52 +00:00
|
|
|
{
|
|
|
|
"non-null manager, no running node, get NodeConfig",
|
|
|
|
func() (interface{}, error) {
|
|
|
|
return s.NodeManager.NodeConfig()
|
|
|
|
},
|
|
|
|
node.ErrNoRunningNode,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"non-null manager, no running node, get Node",
|
|
|
|
func() (interface{}, error) {
|
|
|
|
return s.NodeManager.Node()
|
|
|
|
},
|
|
|
|
node.ErrNoRunningNode,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"non-null manager, no running node, get LES",
|
|
|
|
func() (interface{}, error) {
|
|
|
|
return s.NodeManager.LightEthereumService()
|
|
|
|
},
|
|
|
|
node.ErrNoRunningNode,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"non-null manager, no running node, get Whisper",
|
|
|
|
func() (interface{}, error) {
|
|
|
|
return s.NodeManager.WhisperService()
|
|
|
|
},
|
|
|
|
node.ErrNoRunningNode,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"non-null manager, no running node, get AccountManager",
|
|
|
|
func() (interface{}, error) {
|
|
|
|
return s.NodeManager.AccountManager()
|
|
|
|
},
|
|
|
|
node.ErrNoRunningNode,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"non-null manager, no running node, get AccountKeyStore",
|
|
|
|
func() (interface{}, error) {
|
|
|
|
return s.NodeManager.AccountKeyStore()
|
|
|
|
},
|
|
|
|
node.ErrNoRunningNode,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"non-null manager, no running node, get RPC Client",
|
|
|
|
func() (interface{}, error) {
|
2017-09-14 20:14:31 +00:00
|
|
|
return s.NodeManager.RPCClient(), nil
|
2017-05-28 13:57:30 +00:00
|
|
|
},
|
2017-09-19 11:40:43 +00:00
|
|
|
nil,
|
2017-05-28 13:57:30 +00:00
|
|
|
},
|
2017-05-16 12:09:52 +00:00
|
|
|
}
|
2017-10-11 14:20:51 +00:00
|
|
|
for _, tc := range testCases {
|
|
|
|
s.T().Log(tc.name)
|
|
|
|
obj, err := tc.initFn()
|
2017-05-16 12:09:52 +00:00
|
|
|
s.Nil(obj)
|
2017-10-11 14:20:51 +00:00
|
|
|
s.Equal(tc.expectedErr, err)
|
2017-05-16 12:09:52 +00:00
|
|
|
}
|
2017-10-11 14:20:51 +00:00
|
|
|
}
|
2017-05-16 12:09:52 +00:00
|
|
|
|
2017-10-11 14:20:51 +00:00
|
|
|
func (s *ManagerTestSuite) TestReferencesWithStartedNode() {
|
2017-09-02 17:04:23 +00:00
|
|
|
s.StartTestNode(params.RinkebyNetworkID)
|
2017-05-16 12:09:52 +00:00
|
|
|
defer s.StopTestNode()
|
2017-10-11 14:20:51 +00:00
|
|
|
|
|
|
|
var testCases = []struct {
|
2017-05-16 12:09:52 +00:00
|
|
|
name string
|
|
|
|
initFn func() (interface{}, error)
|
|
|
|
expectedType interface{}
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"node is running, get NodeConfig",
|
|
|
|
func() (interface{}, error) {
|
|
|
|
return s.NodeManager.NodeConfig()
|
|
|
|
},
|
|
|
|
¶ms.NodeConfig{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"node is running, get Node",
|
|
|
|
func() (interface{}, error) {
|
|
|
|
return s.NodeManager.Node()
|
|
|
|
},
|
|
|
|
&gethnode.Node{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"node is running, get LES",
|
|
|
|
func() (interface{}, error) {
|
|
|
|
return s.NodeManager.LightEthereumService()
|
|
|
|
},
|
|
|
|
&les.LightEthereum{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"node is running, get Whisper",
|
|
|
|
func() (interface{}, error) {
|
|
|
|
return s.NodeManager.WhisperService()
|
|
|
|
},
|
|
|
|
&whisper.Whisper{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"node is running, get AccountManager",
|
|
|
|
func() (interface{}, error) {
|
|
|
|
return s.NodeManager.AccountManager()
|
|
|
|
},
|
|
|
|
&accounts.Manager{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"node is running, get AccountKeyStore",
|
|
|
|
func() (interface{}, error) {
|
|
|
|
return s.NodeManager.AccountKeyStore()
|
|
|
|
},
|
|
|
|
&keystore.KeyStore{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"node is running, get RPC Client",
|
|
|
|
func() (interface{}, error) {
|
2017-09-14 20:14:31 +00:00
|
|
|
return s.NodeManager.RPCClient(), nil
|
2017-05-16 12:09:52 +00:00
|
|
|
},
|
|
|
|
&rpc.Client{},
|
|
|
|
},
|
|
|
|
}
|
2017-10-11 14:20:51 +00:00
|
|
|
for _, tc := range testCases {
|
|
|
|
s.T().Log(tc.name)
|
|
|
|
obj, err := tc.initFn()
|
2017-05-16 12:09:52 +00:00
|
|
|
s.NoError(err)
|
|
|
|
s.NotNil(obj)
|
2017-10-11 14:20:51 +00:00
|
|
|
s.IsType(tc.expectedType, obj)
|
2017-05-16 12:09:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ManagerTestSuite) TestNodeStartStop() {
|
2017-10-23 11:05:52 +00:00
|
|
|
nodeConfig, err := e2e.MakeTestNodeConfig(params.StatusChainNetworkID)
|
2017-10-11 14:20:51 +00:00
|
|
|
s.NoError(err)
|
2017-05-16 12:09:52 +00:00
|
|
|
|
|
|
|
// try stopping non-started node
|
2017-10-11 14:20:51 +00:00
|
|
|
s.False(s.NodeManager.IsNodeRunning())
|
2017-05-25 13:14:52 +00:00
|
|
|
_, err = s.NodeManager.StopNode()
|
2017-10-11 14:20:51 +00:00
|
|
|
s.Equal(err, node.ErrNoRunningNode)
|
2017-05-16 12:09:52 +00:00
|
|
|
|
2017-10-11 14:20:51 +00:00
|
|
|
// start node
|
|
|
|
s.False(s.NodeManager.IsNodeRunning())
|
2017-05-16 12:09:52 +00:00
|
|
|
nodeStarted, err := s.NodeManager.StartNode(nodeConfig)
|
2017-10-11 14:20:51 +00:00
|
|
|
s.NoError(err)
|
|
|
|
// wait till node is started
|
|
|
|
<-nodeStarted
|
|
|
|
s.True(s.NodeManager.IsNodeRunning())
|
2017-05-16 12:09:52 +00:00
|
|
|
|
|
|
|
// try starting another node (w/o stopping the previously started node)
|
|
|
|
_, err = s.NodeManager.StartNode(nodeConfig)
|
2017-10-11 14:20:51 +00:00
|
|
|
s.Equal(err, node.ErrNodeExists)
|
2017-05-16 12:09:52 +00:00
|
|
|
|
2017-10-11 14:20:51 +00:00
|
|
|
// now stop node
|
2017-05-25 13:14:52 +00:00
|
|
|
nodeStopped, err := s.NodeManager.StopNode()
|
2017-10-11 14:20:51 +00:00
|
|
|
s.NoError(err)
|
2017-05-25 13:14:52 +00:00
|
|
|
<-nodeStopped
|
2017-10-11 14:20:51 +00:00
|
|
|
s.False(s.NodeManager.IsNodeRunning())
|
2017-05-16 12:09:52 +00:00
|
|
|
|
|
|
|
// start new node with exactly the same config
|
|
|
|
nodeStarted, err = s.NodeManager.StartNode(nodeConfig)
|
2017-10-11 14:20:51 +00:00
|
|
|
s.NoError(err)
|
|
|
|
// wait till node is started
|
2017-05-16 12:09:52 +00:00
|
|
|
<-nodeStarted
|
2017-10-11 14:20:51 +00:00
|
|
|
s.True(s.NodeManager.IsNodeRunning())
|
2017-05-16 12:09:52 +00:00
|
|
|
|
2017-10-11 14:20:51 +00:00
|
|
|
// finally stop the node
|
|
|
|
nodeStopped, err = s.NodeManager.StopNode()
|
|
|
|
s.NoError(err)
|
|
|
|
<-nodeStopped
|
2017-05-16 12:09:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ManagerTestSuite) TestNetworkSwitching() {
|
|
|
|
// get Ropsten config
|
2017-10-11 14:20:51 +00:00
|
|
|
nodeConfig, err := e2e.MakeTestNodeConfig(params.RopstenNetworkID)
|
|
|
|
s.NoError(err)
|
|
|
|
s.False(s.NodeManager.IsNodeRunning())
|
2017-05-16 12:09:52 +00:00
|
|
|
nodeStarted, err := s.NodeManager.StartNode(nodeConfig)
|
2017-10-11 14:20:51 +00:00
|
|
|
s.NoError(err)
|
|
|
|
// wait till node is started
|
|
|
|
<-nodeStarted
|
|
|
|
s.True(s.NodeManager.IsNodeRunning())
|
2017-05-16 12:09:52 +00:00
|
|
|
|
2017-10-11 14:20:51 +00:00
|
|
|
firstHash, err := e2e.FirstBlockHash(s.NodeManager)
|
|
|
|
s.NoError(err)
|
|
|
|
s.Equal("0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d", firstHash)
|
2017-05-16 12:09:52 +00:00
|
|
|
|
|
|
|
// now stop node, and make sure that a new node, on different network can be started
|
2017-05-25 13:14:52 +00:00
|
|
|
nodeStopped, err := s.NodeManager.StopNode()
|
2017-10-11 14:20:51 +00:00
|
|
|
s.NoError(err)
|
2017-05-25 13:14:52 +00:00
|
|
|
<-nodeStopped
|
2017-10-11 14:20:51 +00:00
|
|
|
s.False(s.NodeManager.IsNodeRunning())
|
2017-05-16 12:09:52 +00:00
|
|
|
|
|
|
|
// start new node with completely different config
|
2017-10-11 14:20:51 +00:00
|
|
|
nodeConfig, err = e2e.MakeTestNodeConfig(params.RinkebyNetworkID)
|
|
|
|
s.NoError(err)
|
2017-05-16 12:09:52 +00:00
|
|
|
nodeStarted, err = s.NodeManager.StartNode(nodeConfig)
|
2017-10-11 14:20:51 +00:00
|
|
|
s.NoError(err)
|
|
|
|
// wait till node is started
|
2017-05-16 12:09:52 +00:00
|
|
|
<-nodeStarted
|
2017-10-11 14:20:51 +00:00
|
|
|
s.True(s.NodeManager.IsNodeRunning())
|
2017-05-16 12:09:52 +00:00
|
|
|
|
|
|
|
// make sure we are on another network indeed
|
2017-10-11 14:20:51 +00:00
|
|
|
firstHash, err = e2e.FirstBlockHash(s.NodeManager)
|
|
|
|
s.NoError(err)
|
|
|
|
s.Equal("0x6341fd3daf94b748c72ced5a5b26028f2474f5f00d824504e4fa37a75767e177", firstHash)
|
2017-05-16 12:09:52 +00:00
|
|
|
|
2017-10-11 14:20:51 +00:00
|
|
|
nodeStopped, err = s.NodeManager.StopNode()
|
|
|
|
s.NoError(err)
|
|
|
|
<-nodeStopped
|
2017-05-16 12:09:52 +00:00
|
|
|
}
|
|
|
|
|
2017-10-11 14:20:51 +00:00
|
|
|
func (s *ManagerTestSuite) TestStartNodeWithUpstreamEnabled() {
|
|
|
|
nodeConfig, err := e2e.MakeTestNodeConfig(params.RopstenNetworkID)
|
|
|
|
s.NoError(err)
|
|
|
|
|
|
|
|
nodeConfig.UpstreamConfig.Enabled = true
|
|
|
|
nodeConfig.UpstreamConfig.URL = "https://ropsten.infura.io/nKmXgiFgc2KqtoQ8BCGJ"
|
|
|
|
|
|
|
|
nodeStarted, err := s.NodeManager.StartNode(nodeConfig)
|
|
|
|
s.NoError(err)
|
|
|
|
<-nodeStarted
|
|
|
|
s.True(s.NodeManager.IsNodeRunning())
|
|
|
|
nodeStopped, err := s.NodeManager.StopNode()
|
|
|
|
s.NoError(err)
|
|
|
|
<-nodeStopped
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(adam): fix this test to not use a different directory for blockchain data
|
2017-05-16 12:09:52 +00:00
|
|
|
func (s *ManagerTestSuite) TestResetChainData() {
|
2017-10-11 14:20:51 +00:00
|
|
|
s.T().Skip()
|
2017-05-16 12:09:52 +00:00
|
|
|
|
2017-09-02 17:04:23 +00:00
|
|
|
s.StartTestNode(params.RinkebyNetworkID)
|
2017-05-16 12:09:52 +00:00
|
|
|
defer s.StopTestNode()
|
|
|
|
|
2017-10-21 17:04:07 +00:00
|
|
|
s.NoError(EnsureNodeSync(s.NodeManager), "cannot ensure node synchronization")
|
2017-05-16 12:09:52 +00:00
|
|
|
|
2017-10-11 14:20:51 +00:00
|
|
|
// reset chain data
|
2017-05-24 14:13:30 +00:00
|
|
|
nodeReady, err := s.NodeManager.ResetChainData()
|
2017-10-11 14:20:51 +00:00
|
|
|
s.NoError(err)
|
|
|
|
// new node, with previous config should be running
|
2017-05-24 14:13:30 +00:00
|
|
|
<-nodeReady
|
2017-10-11 14:20:51 +00:00
|
|
|
s.True(s.NodeManager.IsNodeRunning())
|
2017-05-16 12:09:52 +00:00
|
|
|
|
|
|
|
// make sure we can read the first byte, and it is valid (for Rinkeby)
|
2017-10-11 14:20:51 +00:00
|
|
|
firstHash, err := e2e.FirstBlockHash(s.NodeManager)
|
|
|
|
s.NoError(err)
|
|
|
|
s.Equal("0x6341fd3daf94b748c72ced5a5b26028f2474f5f00d824504e4fa37a75767e177", firstHash)
|
2017-05-25 13:14:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ManagerTestSuite) TestRestartNode() {
|
2017-09-02 17:04:23 +00:00
|
|
|
s.StartTestNode(params.RinkebyNetworkID)
|
2017-05-25 13:14:52 +00:00
|
|
|
defer s.StopTestNode()
|
|
|
|
|
|
|
|
s.True(s.NodeManager.IsNodeRunning())
|
|
|
|
nodeReady, err := s.NodeManager.RestartNode()
|
2017-10-11 14:20:51 +00:00
|
|
|
s.NoError(err)
|
|
|
|
// new node, with previous config should be running
|
2017-05-25 13:14:52 +00:00
|
|
|
<-nodeReady
|
2017-10-11 14:20:51 +00:00
|
|
|
s.True(s.NodeManager.IsNodeRunning())
|
2017-05-25 13:14:52 +00:00
|
|
|
|
|
|
|
// make sure we can read the first byte, and it is valid (for Rinkeby)
|
2017-10-11 14:20:51 +00:00
|
|
|
firstHash, err := e2e.FirstBlockHash(s.NodeManager)
|
|
|
|
s.NoError(err)
|
|
|
|
s.Equal("0x6341fd3daf94b748c72ced5a5b26028f2474f5f00d824504e4fa37a75767e177", firstHash)
|
2017-05-25 13:14:52 +00:00
|
|
|
}
|
|
|
|
|
2017-10-11 14:20:51 +00:00
|
|
|
// TODO(adam): race conditions should be tested with -race flag and unit tests, if possible.
|
|
|
|
// Research if it's possible to do the same with unit tests.
|
2017-05-25 13:14:52 +00:00
|
|
|
func (s *ManagerTestSuite) TestRaceConditions() {
|
|
|
|
cnt := 25
|
|
|
|
progress := make(chan struct{}, cnt)
|
|
|
|
rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
|
|
|
|
|
2017-10-20 09:06:22 +00:00
|
|
|
nodeConfig1, e := e2e.MakeTestNodeConfig(params.RopstenNetworkID)
|
|
|
|
s.NoError(e)
|
2017-05-25 13:14:52 +00:00
|
|
|
|
2017-10-20 09:06:22 +00:00
|
|
|
nodeConfig2, e := e2e.MakeTestNodeConfig(params.RinkebyNetworkID)
|
|
|
|
s.NoError(e)
|
2017-05-25 13:14:52 +00:00
|
|
|
|
|
|
|
nodeConfigs := []*params.NodeConfig{nodeConfig1, nodeConfig2}
|
|
|
|
|
|
|
|
var funcsToTest = []func(*params.NodeConfig){
|
|
|
|
func(config *params.NodeConfig) {
|
|
|
|
log.Info("StartNode()")
|
|
|
|
_, err := s.NodeManager.StartNode(config)
|
|
|
|
s.T().Logf("StartNode() for network: %d, error: %v", config.NetworkID, err)
|
|
|
|
progress <- struct{}{}
|
|
|
|
},
|
|
|
|
func(config *params.NodeConfig) {
|
|
|
|
log.Info("StopNode()")
|
|
|
|
_, err := s.NodeManager.StopNode()
|
|
|
|
s.T().Logf("StopNode() for network: %d, error: %v", config.NetworkID, err)
|
|
|
|
progress <- struct{}{}
|
|
|
|
},
|
|
|
|
func(config *params.NodeConfig) {
|
|
|
|
log.Info("Node()")
|
|
|
|
_, err := s.NodeManager.Node()
|
|
|
|
s.T().Logf("Node(), error: %v", err)
|
|
|
|
progress <- struct{}{}
|
|
|
|
},
|
|
|
|
func(config *params.NodeConfig) {
|
|
|
|
log.Info("IsNodeRunning()")
|
|
|
|
s.T().Logf("IsNodeRunning(), result: %v", s.NodeManager.IsNodeRunning())
|
|
|
|
progress <- struct{}{}
|
|
|
|
},
|
|
|
|
func(config *params.NodeConfig) {
|
|
|
|
log.Info("PopulateStaticPeers()")
|
|
|
|
s.T().Logf("PopulateStaticPeers(), error: %v", s.NodeManager.PopulateStaticPeers())
|
|
|
|
progress <- struct{}{}
|
|
|
|
},
|
2017-10-11 14:20:51 +00:00
|
|
|
// TODO(adam): quarantined until it uses a different datadir
|
|
|
|
// as otherwise it wipes out cached blockchain data.
|
|
|
|
// func(config *params.NodeConfig) {
|
|
|
|
// log.Info("ResetChainData()")
|
|
|
|
// _, err := s.NodeManager.ResetChainData()
|
|
|
|
// s.T().Logf("ResetChainData(), error: %v", err)
|
|
|
|
// progress <- struct{}{}
|
|
|
|
// },
|
2017-05-25 13:14:52 +00:00
|
|
|
func(config *params.NodeConfig) {
|
|
|
|
log.Info("RestartNode()")
|
|
|
|
_, err := s.NodeManager.RestartNode()
|
|
|
|
s.T().Logf("RestartNode(), error: %v", err)
|
|
|
|
progress <- struct{}{}
|
|
|
|
},
|
|
|
|
func(config *params.NodeConfig) {
|
|
|
|
log.Info("NodeConfig()")
|
|
|
|
_, err := s.NodeManager.NodeConfig()
|
|
|
|
s.T().Logf("NodeConfig(), error: %v", err)
|
|
|
|
progress <- struct{}{}
|
|
|
|
},
|
|
|
|
func(config *params.NodeConfig) {
|
|
|
|
log.Info("LightEthereumService()")
|
|
|
|
_, err := s.NodeManager.LightEthereumService()
|
|
|
|
s.T().Logf("LightEthereumService(), error: %v", err)
|
|
|
|
progress <- struct{}{}
|
|
|
|
},
|
|
|
|
func(config *params.NodeConfig) {
|
|
|
|
log.Info("WhisperService()")
|
|
|
|
_, err := s.NodeManager.WhisperService()
|
|
|
|
s.T().Logf("WhisperService(), error: %v", err)
|
|
|
|
progress <- struct{}{}
|
|
|
|
},
|
|
|
|
func(config *params.NodeConfig) {
|
|
|
|
log.Info("AccountManager()")
|
|
|
|
_, err := s.NodeManager.AccountManager()
|
|
|
|
s.T().Logf("AccountManager(), error: %v", err)
|
|
|
|
progress <- struct{}{}
|
|
|
|
},
|
|
|
|
func(config *params.NodeConfig) {
|
|
|
|
log.Info("AccountKeyStore()")
|
|
|
|
_, err := s.NodeManager.AccountKeyStore()
|
|
|
|
s.T().Logf("AccountKeyStore(), error: %v", err)
|
|
|
|
progress <- struct{}{}
|
|
|
|
},
|
|
|
|
func(config *params.NodeConfig) {
|
|
|
|
log.Info("RPCClient()")
|
2017-09-14 20:14:31 +00:00
|
|
|
s.NodeManager.RPCClient()
|
2017-05-28 13:57:30 +00:00
|
|
|
progress <- struct{}{}
|
|
|
|
},
|
2017-05-25 13:14:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// increase StartNode()/StopNode() population
|
|
|
|
for i := 0; i < 5; i++ {
|
|
|
|
funcsToTest = append(funcsToTest, funcsToTest[0], funcsToTest[1])
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < cnt; i++ {
|
|
|
|
randConfig := nodeConfigs[rnd.Intn(len(nodeConfigs))]
|
|
|
|
randFunc := funcsToTest[rnd.Intn(len(funcsToTest))]
|
|
|
|
|
|
|
|
if rnd.Intn(100) > 75 { // introduce random delays
|
|
|
|
time.Sleep(500 * time.Millisecond)
|
|
|
|
}
|
|
|
|
go randFunc(randConfig)
|
|
|
|
}
|
|
|
|
|
|
|
|
for range progress {
|
|
|
|
cnt -= 1
|
|
|
|
if cnt <= 0 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
time.Sleep(2 * time.Second) // so that we see some logs
|
2017-10-23 11:05:52 +00:00
|
|
|
nodeStopped, _ := s.NodeManager.StopNode() // just in case we have a node running
|
2017-10-20 09:06:22 +00:00
|
|
|
|
2017-05-25 13:14:52 +00:00
|
|
|
if nodeStopped != nil {
|
|
|
|
<-nodeStopped
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ManagerTestSuite) TestNodeStartCrash() {
|
|
|
|
// let's listen for node.crashed signal
|
2017-10-11 14:20:51 +00:00
|
|
|
signalReceived := make(chan struct{})
|
2017-09-25 18:22:57 +00:00
|
|
|
signal.SetDefaultNodeNotificationHandler(func(jsonEvent string) {
|
|
|
|
var envelope signal.Envelope
|
2017-05-25 13:14:52 +00:00
|
|
|
err := json.Unmarshal([]byte(jsonEvent), &envelope)
|
2017-10-11 14:20:51 +00:00
|
|
|
s.NoError(err)
|
2017-05-25 13:14:52 +00:00
|
|
|
|
2017-09-25 18:22:57 +00:00
|
|
|
if envelope.Type == signal.EventNodeCrashed {
|
2017-10-11 14:20:51 +00:00
|
|
|
close(signalReceived)
|
2017-05-25 13:14:52 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2017-10-11 14:20:51 +00:00
|
|
|
nodeConfig, err := e2e.MakeTestNodeConfig(params.RinkebyNetworkID)
|
|
|
|
s.NoError(err)
|
|
|
|
|
|
|
|
// start node outside the manager (on the same port), so that manager node.Start() method fails
|
|
|
|
outsideNode, err := node.MakeNode(nodeConfig)
|
|
|
|
s.NoError(err)
|
|
|
|
err = outsideNode.Start()
|
|
|
|
s.NoError(err)
|
|
|
|
|
2017-05-25 13:14:52 +00:00
|
|
|
// now try starting using node manager
|
|
|
|
nodeStarted, err := s.NodeManager.StartNode(nodeConfig)
|
2017-10-11 14:20:51 +00:00
|
|
|
s.NoError(err) // no error is thrown, as node is started in separate routine
|
|
|
|
<-nodeStarted // no deadlock either, as manager should close the channel on error
|
|
|
|
s.False(s.NodeManager.IsNodeRunning())
|
|
|
|
|
|
|
|
select {
|
|
|
|
case <-time.After(5 * time.Second):
|
|
|
|
s.FailNow("timed out waiting for signal")
|
|
|
|
case <-signalReceived:
|
|
|
|
}
|
2017-05-25 13:14:52 +00:00
|
|
|
|
|
|
|
// stop outside node, and re-try
|
2017-10-11 14:20:51 +00:00
|
|
|
err = outsideNode.Stop()
|
|
|
|
s.NoError(err)
|
|
|
|
signalReceived = make(chan struct{})
|
2017-05-25 13:14:52 +00:00
|
|
|
nodeStarted, err = s.NodeManager.StartNode(nodeConfig)
|
2017-10-11 14:20:51 +00:00
|
|
|
s.NoError(err) // again, no error
|
|
|
|
<-nodeStarted // no deadlock, and no signal this time, manager should be able to start node
|
|
|
|
s.True(s.NodeManager.IsNodeRunning())
|
2017-05-25 13:14:52 +00:00
|
|
|
|
2017-10-11 14:20:51 +00:00
|
|
|
select {
|
|
|
|
case <-time.After(5 * time.Second):
|
|
|
|
case <-signalReceived:
|
|
|
|
s.FailNow("signal should not be received")
|
|
|
|
}
|
2017-05-25 13:14:52 +00:00
|
|
|
|
|
|
|
// cleanup
|
2017-10-20 09:06:22 +00:00
|
|
|
s.NodeManager.StopNode() //nolint: errcheck
|
2017-09-25 18:22:57 +00:00
|
|
|
signal.ResetDefaultNodeNotificationHandler()
|
2017-05-16 12:09:52 +00:00
|
|
|
}
|