2017-10-11 14:20:51 +00:00
|
|
|
package api_test
|
|
|
|
|
|
|
|
import (
|
2018-02-14 16:32:36 +00:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2017-10-11 14:20:51 +00:00
|
|
|
"testing"
|
|
|
|
|
2018-06-08 11:29:50 +00:00
|
|
|
"github.com/status-im/status-go/params"
|
2018-04-18 15:13:27 +00:00
|
|
|
"github.com/status-im/status-go/t/e2e"
|
2018-02-08 12:52:47 +00:00
|
|
|
. "github.com/status-im/status-go/t/utils"
|
2017-10-11 14:20:51 +00:00
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAPIBackendTestSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(APIBackendTestSuite))
|
|
|
|
}
|
|
|
|
|
|
|
|
type APIBackendTestSuite struct {
|
|
|
|
e2e.BackendTestSuite
|
|
|
|
}
|
|
|
|
|
2018-06-08 11:29:50 +00:00
|
|
|
// FIXME(tiabc): There's also a test with the same name in node/manager_test.go
|
2018-04-05 09:45:26 +00:00
|
|
|
// so this test should only check StatusBackend logic with a mocked version of the underlying StatusNode.
|
2017-10-11 14:20:51 +00:00
|
|
|
func (s *APIBackendTestSuite) TestNetworkSwitching() {
|
2018-04-18 15:13:27 +00:00
|
|
|
// Get test node configuration.
|
2018-03-02 09:25:30 +00:00
|
|
|
nodeConfig, err := MakeTestNodeConfig(GetNetworkID())
|
2017-10-11 14:20:51 +00:00
|
|
|
s.NoError(err)
|
|
|
|
|
|
|
|
s.False(s.Backend.IsNodeRunning())
|
2018-02-09 13:37:56 +00:00
|
|
|
s.NoError(s.Backend.StartNode(nodeConfig))
|
2017-10-11 14:20:51 +00:00
|
|
|
s.True(s.Backend.IsNodeRunning())
|
|
|
|
|
2018-04-05 09:45:26 +00:00
|
|
|
firstHash, err := e2e.FirstBlockHash(s.Backend.StatusNode())
|
2017-10-11 14:20:51 +00:00
|
|
|
s.NoError(err)
|
2017-10-26 13:11:24 +00:00
|
|
|
s.Equal(GetHeadHash(), firstHash)
|
2017-10-11 14:20:51 +00:00
|
|
|
|
|
|
|
// now stop node, and make sure that a new node, on different network can be started
|
2018-02-09 13:37:56 +00:00
|
|
|
s.NoError(s.Backend.StopNode())
|
2017-10-11 14:20:51 +00:00
|
|
|
|
|
|
|
// start new node with completely different config
|
2018-03-02 09:25:30 +00:00
|
|
|
nodeConfig, err = MakeTestNodeConfig(GetNetworkID())
|
2017-10-11 14:20:51 +00:00
|
|
|
s.NoError(err)
|
|
|
|
|
|
|
|
s.False(s.Backend.IsNodeRunning())
|
2018-02-09 13:37:56 +00:00
|
|
|
s.NoError(s.Backend.StartNode(nodeConfig))
|
2017-10-11 14:20:51 +00:00
|
|
|
s.True(s.Backend.IsNodeRunning())
|
|
|
|
|
|
|
|
// make sure we are on another network indeed
|
2018-04-05 09:45:26 +00:00
|
|
|
firstHash, err = e2e.FirstBlockHash(s.Backend.StatusNode())
|
2017-10-11 14:20:51 +00:00
|
|
|
s.NoError(err)
|
2017-10-26 13:11:24 +00:00
|
|
|
s.Equal(GetHeadHash(), firstHash)
|
2017-10-11 14:20:51 +00:00
|
|
|
|
2018-02-09 13:37:56 +00:00
|
|
|
s.NoError(s.Backend.StopNode())
|
2017-10-11 14:20:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *APIBackendTestSuite) TestResetChainData() {
|
2018-02-14 16:32:36 +00:00
|
|
|
if GetNetworkID() != params.StatusChainNetworkID {
|
|
|
|
s.T().Skip("test must be running on status network")
|
|
|
|
}
|
2017-10-11 14:20:51 +00:00
|
|
|
require := s.Require()
|
|
|
|
require.NotNil(s.Backend)
|
2018-02-14 16:32:36 +00:00
|
|
|
path, err := ioutil.TempDir("/tmp", "status-reset-chain-test")
|
|
|
|
require.NoError(err)
|
|
|
|
defer func() { s.NoError(os.RemoveAll(path)) }()
|
2017-10-11 14:20:51 +00:00
|
|
|
|
2018-02-14 16:32:36 +00:00
|
|
|
s.StartTestBackend(e2e.WithDataDir(path))
|
2017-10-11 14:20:51 +00:00
|
|
|
defer s.StopTestBackend()
|
|
|
|
|
2018-04-09 07:16:43 +00:00
|
|
|
EnsureNodeSync(s.Backend.StatusNode().EnsureSync)
|
2017-10-11 14:20:51 +00:00
|
|
|
|
2018-02-09 13:37:56 +00:00
|
|
|
require.NoError(s.Backend.ResetChainData())
|
|
|
|
|
2017-10-11 14:20:51 +00:00
|
|
|
s.True(s.Backend.IsNodeRunning()) // new node, with previous config should be running
|
|
|
|
|
|
|
|
// make sure we can read the first byte, and it is valid (for Rinkeby)
|
2018-04-05 09:45:26 +00:00
|
|
|
firstHash, err := e2e.FirstBlockHash(s.Backend.StatusNode())
|
2017-10-11 14:20:51 +00:00
|
|
|
s.NoError(err)
|
2017-10-26 13:11:24 +00:00
|
|
|
s.Equal(GetHeadHash(), firstHash)
|
2017-10-11 14:20:51 +00:00
|
|
|
}
|
|
|
|
|
2018-06-08 11:29:50 +00:00
|
|
|
// FIXME(tiabc): There's also a test with the same name in node/manager_test.go
|
2018-04-05 09:45:26 +00:00
|
|
|
// so this test should only check StatusBackend logic with a mocked version of the underlying StatusNode.
|
2017-10-11 14:20:51 +00:00
|
|
|
func (s *APIBackendTestSuite) TestRestartNode() {
|
|
|
|
require := s.Require()
|
|
|
|
require.NotNil(s.Backend)
|
|
|
|
|
2017-10-25 22:24:01 +00:00
|
|
|
// get config
|
2018-03-02 09:25:30 +00:00
|
|
|
nodeConfig, err := MakeTestNodeConfig(GetNetworkID())
|
2017-10-24 10:35:13 +00:00
|
|
|
s.NoError(err)
|
|
|
|
|
|
|
|
s.False(s.Backend.IsNodeRunning())
|
2018-02-09 13:37:56 +00:00
|
|
|
s.NoError(s.Backend.StartNode(nodeConfig))
|
2017-10-24 10:35:13 +00:00
|
|
|
s.True(s.Backend.IsNodeRunning())
|
2017-10-11 14:20:51 +00:00
|
|
|
|
2018-04-05 09:45:26 +00:00
|
|
|
firstHash, err := e2e.FirstBlockHash(s.Backend.StatusNode())
|
2017-10-11 14:20:51 +00:00
|
|
|
s.NoError(err)
|
2017-10-26 13:11:24 +00:00
|
|
|
s.Equal(GetHeadHash(), firstHash)
|
2017-10-11 14:20:51 +00:00
|
|
|
|
|
|
|
s.True(s.Backend.IsNodeRunning())
|
2018-02-09 13:37:56 +00:00
|
|
|
require.NoError(s.Backend.RestartNode())
|
2017-10-11 14:20:51 +00:00
|
|
|
s.True(s.Backend.IsNodeRunning()) // new node, with previous config should be running
|
|
|
|
|
|
|
|
// make sure we can read the first byte, and it is valid (for Rinkeby)
|
2018-04-05 09:45:26 +00:00
|
|
|
firstHash, err = e2e.FirstBlockHash(s.Backend.StatusNode())
|
2017-10-11 14:20:51 +00:00
|
|
|
s.NoError(err)
|
2017-10-26 13:11:24 +00:00
|
|
|
s.Equal(GetHeadHash(), firstHash)
|
2017-10-11 14:20:51 +00:00
|
|
|
}
|