Move all tests to retrieve NetworkId from flag or default to statuschain

This commit is contained in:
Alexander Ewetumo 2017-10-23 17:03:07 +01:00
parent a98238ad97
commit 7718bd5990
13 changed files with 74 additions and 52 deletions

View File

@ -7,6 +7,29 @@ These tests are run against public testnets: Ropsten and Rinkeby.
e2e package contains a few utilities which are described in a [godoc](https://godoc.org/github.com/status-im/status-go/e2e).
### Flags
#### 1. `-network`
The `-network` flag is used to provide either a network id or network name which specifies the ethereum network to use
for running all test. It by default uses the `StatusChain` network.
#### Usage
To use the `mainnet` network for testing using network name:
```bash
go test -v ./e2e/... -args -network=mainnet
```
To use the `ropsten` network for testing using network id:
```bash
go test -v ./e2e/... -args -network=3
```
It's important to ensure before the flag that the `-args` flag is included else
the `-network` flag or any other custom flag will not be respected or parsed.
## Run
`make test-e2e`

View File

@ -19,7 +19,7 @@ type AccountsRPCTestSuite struct {
}
func (s *AccountsTestSuite) TestRPCEthAccounts() {
s.StartTestBackend(params.StatusChainNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
// log into test account

View File

@ -22,7 +22,7 @@ type AccountsTestSuite struct {
}
func (s *AccountsTestSuite) TestAccountsList() {
s.StartTestBackend(params.RinkebyNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
accounts, err := s.Backend.AccountManager().Accounts()
@ -83,7 +83,7 @@ func (s *AccountsTestSuite) TestAccountsList() {
}
func (s *AccountsTestSuite) TestCreateChildAccount() {
s.StartTestBackend(params.RinkebyNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
keyStore, err := s.Backend.NodeManager().AccountKeyStore()
@ -131,7 +131,7 @@ func (s *AccountsTestSuite) TestCreateChildAccount() {
}
func (s *AccountsTestSuite) TestRecoverAccount() {
s.StartTestBackend(params.RinkebyNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
keyStore, err := s.Backend.NodeManager().AccountKeyStore()
@ -183,7 +183,7 @@ func (s *AccountsTestSuite) TestRecoverAccount() {
}
func (s *AccountsTestSuite) TestSelectAccount() {
s.StartTestBackend(params.RinkebyNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
// test to see if the account was injected in whisper
@ -218,7 +218,7 @@ func (s *AccountsTestSuite) TestSelectAccount() {
}
func (s *AccountsTestSuite) TestSelectedAccountOnRestart() {
s.StartTestBackend(params.RinkebyNetworkID)
s.StartTestBackend()
// we need to make sure that selected account is injected as identity into Whisper
whisperService := s.WhisperService()

View File

@ -56,10 +56,10 @@ func (s *APITestSuite) TestRaceConditions() {
progress := make(chan struct{}, cnt)
rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
nodeConfig1, err := e2e.MakeTestNodeConfig(params.StatusChainNetworkID)
nodeConfig1, err := e2e.MakeTestNodeConfig(e2e.GetNetworkID())
s.NoError(err)
nodeConfig2, err := e2e.MakeTestNodeConfig(params.RinkebyNetworkID)
nodeConfig2, err := e2e.MakeTestNodeConfig(e2e.GetNetworkID())
s.NoError(err)
nodeConfigs := []*params.NodeConfig{nodeConfig1, nodeConfig2}
@ -129,7 +129,7 @@ func (s *APITestSuite) TestCellsRemovedAfterSwitchAccount() {
}
)
config, err := e2e.MakeTestNodeConfig(params.StatusChainNetworkID)
config, err := e2e.MakeTestNodeConfig(e2e.GetNetworkID())
require.NoError(err)
err = s.api.StartNode(config)
require.NoError(err)
@ -166,7 +166,7 @@ func (s *APITestSuite) TestLogoutRemovesCells() {
require = s.Require()
)
config, err := e2e.MakeTestNodeConfig(params.StatusChainNetworkID)
config, err := e2e.MakeTestNodeConfig(e2e.GetNetworkID())
require.NoError(err)
err = s.api.StartNode(config)
require.NoError(err)

View File

@ -34,10 +34,10 @@ func (s *APIBackendTestSuite) TestRaceConditions() {
progress := make(chan struct{}, cnt)
rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
nodeConfig1, err := e2e.MakeTestNodeConfig(params.StatusChainNetworkID)
nodeConfig1, err := e2e.MakeTestNodeConfig(e2e.GetNetworkID())
require.NoError(err)
nodeConfig2, err := e2e.MakeTestNodeConfig(params.RinkebyNetworkID)
nodeConfig2, err := e2e.MakeTestNodeConfig(e2e.GetNetworkID())
require.NoError(err)
nodeConfigs := []*params.NodeConfig{nodeConfig1, nodeConfig2}
@ -191,7 +191,7 @@ func (s *APIBackendTestSuite) TestRaceConditions() {
// so this test should only check StatusBackend logic with a mocked version of the underlying NodeManager.
func (s *APIBackendTestSuite) TestNetworkSwitching() {
// get Ropsten config
nodeConfig, err := e2e.MakeTestNodeConfig(params.RopstenNetworkID)
nodeConfig, err := e2e.MakeTestNodeConfig(e2e.GetNetworkID())
s.NoError(err)
s.False(s.Backend.IsNodeRunning())
@ -211,7 +211,7 @@ func (s *APIBackendTestSuite) TestNetworkSwitching() {
<-nodeStopped
// start new node with completely different config
nodeConfig, err = e2e.MakeTestNodeConfig(params.RinkebyNetworkID)
nodeConfig, err = e2e.MakeTestNodeConfig(e2e.GetNetworkID())
s.NoError(err)
s.False(s.Backend.IsNodeRunning())
@ -239,7 +239,7 @@ func (s *APIBackendTestSuite) TestResetChainData() {
require := s.Require()
require.NotNil(s.Backend)
s.StartTestBackend(params.RinkebyNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
s.NoError(EnsureNodeSync(s.Backend.NodeManager()), "cannot ensure node synchronization")
@ -262,7 +262,7 @@ func (s *APIBackendTestSuite) TestRestartNode() {
require := s.Require()
require.NotNil(s.Backend)
s.StartTestBackend(params.RinkebyNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
firstHash, err := e2e.FirstBlockHash(s.Backend.NodeManager())

View File

@ -36,7 +36,7 @@ func (s *JailRPCTestSuite) SetupTest() {
}
func (s *JailRPCTestSuite) TestJailRPCSend() {
s.StartTestBackend(params.StatusChainNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
s.NoError(EnsureNodeSync(s.Backend.NodeManager()), "cannot ensure node synchronization")
@ -69,7 +69,7 @@ func (s *JailRPCTestSuite) TestJailRPCSend() {
}
func (s *JailRPCTestSuite) TestIsConnected() {
s.StartTestBackend(params.StatusChainNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
s.jail.Parse(testChatID, "")
@ -96,7 +96,7 @@ func (s *JailRPCTestSuite) TestIsConnected() {
// regression test: eth_getTransactionReceipt with invalid transaction hash should return null
func (s *JailRPCTestSuite) TestRegressionGetTransactionReceipt() {
s.StartTestBackend(params.StatusChainNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
rpcClient := s.Backend.NodeManager().RPCClient()
@ -109,7 +109,7 @@ func (s *JailRPCTestSuite) TestRegressionGetTransactionReceipt() {
}
func (s *JailRPCTestSuite) TestContractDeployment() {
s.StartTestBackend(params.StatusChainNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
s.NoError(EnsureNodeSync(s.Backend.NodeManager()), "cannot ensure node synchronization")
@ -195,7 +195,7 @@ func (s *JailRPCTestSuite) TestContractDeployment() {
}
func (s *JailRPCTestSuite) TestJailVMPersistence() {
s.StartTestBackend(params.StatusChainNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
s.NoError(EnsureNodeSync(s.Backend.NodeManager()), "cannot ensure node synchronization")

View File

@ -126,7 +126,7 @@ func (s *ManagerTestSuite) TestReferencesWithoutStartedNode() {
}
func (s *ManagerTestSuite) TestReferencesWithStartedNode() {
s.StartTestNode(params.RinkebyNetworkID)
s.StartTestNode()
defer s.StopTestNode()
var testCases = []struct {
@ -194,7 +194,7 @@ func (s *ManagerTestSuite) TestReferencesWithStartedNode() {
}
func (s *ManagerTestSuite) TestNodeStartStop() {
nodeConfig, err := e2e.MakeTestNodeConfig(params.StatusChainNetworkID)
nodeConfig, err := e2e.MakeTestNodeConfig(e2e.GetNetworkID())
s.NoError(err)
// try stopping non-started node
@ -235,7 +235,7 @@ func (s *ManagerTestSuite) TestNodeStartStop() {
func (s *ManagerTestSuite) TestNetworkSwitching() {
// get Ropsten config
nodeConfig, err := e2e.MakeTestNodeConfig(params.RopstenNetworkID)
nodeConfig, err := e2e.MakeTestNodeConfig(e2e.GetNetworkID())
s.NoError(err)
s.False(s.NodeManager.IsNodeRunning())
nodeStarted, err := s.NodeManager.StartNode(nodeConfig)
@ -255,7 +255,7 @@ func (s *ManagerTestSuite) TestNetworkSwitching() {
s.False(s.NodeManager.IsNodeRunning())
// start new node with completely different config
nodeConfig, err = e2e.MakeTestNodeConfig(params.RinkebyNetworkID)
nodeConfig, err = e2e.MakeTestNodeConfig(e2e.GetNetworkID())
s.NoError(err)
nodeStarted, err = s.NodeManager.StartNode(nodeConfig)
s.NoError(err)
@ -274,7 +274,7 @@ func (s *ManagerTestSuite) TestNetworkSwitching() {
}
func (s *ManagerTestSuite) TestStartNodeWithUpstreamEnabled() {
nodeConfig, err := e2e.MakeTestNodeConfig(params.RopstenNetworkID)
nodeConfig, err := e2e.MakeTestNodeConfig(e2e.GetNetworkID())
s.NoError(err)
nodeConfig.UpstreamConfig.Enabled = true
@ -293,7 +293,7 @@ func (s *ManagerTestSuite) TestStartNodeWithUpstreamEnabled() {
func (s *ManagerTestSuite) TestResetChainData() {
s.T().Skip()
s.StartTestNode(params.RinkebyNetworkID)
s.StartTestNode()
defer s.StopTestNode()
s.NoError(EnsureNodeSync(s.NodeManager), "cannot ensure node synchronization")
@ -312,7 +312,7 @@ func (s *ManagerTestSuite) TestResetChainData() {
}
func (s *ManagerTestSuite) TestRestartNode() {
s.StartTestNode(params.RinkebyNetworkID)
s.StartTestNode()
defer s.StopTestNode()
s.True(s.NodeManager.IsNodeRunning())
@ -335,10 +335,10 @@ func (s *ManagerTestSuite) TestRaceConditions() {
progress := make(chan struct{}, cnt)
rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
nodeConfig1, e := e2e.MakeTestNodeConfig(params.RopstenNetworkID)
nodeConfig1, e := e2e.MakeTestNodeConfig(e2e.GetNetworkID())
s.NoError(e)
nodeConfig2, e := e2e.MakeTestNodeConfig(params.RinkebyNetworkID)
nodeConfig2, e := e2e.MakeTestNodeConfig(e2e.GetNetworkID())
s.NoError(e)
nodeConfigs := []*params.NodeConfig{nodeConfig1, nodeConfig2}
@ -466,7 +466,7 @@ func (s *ManagerTestSuite) TestNodeStartCrash() {
}
})
nodeConfig, err := e2e.MakeTestNodeConfig(params.RinkebyNetworkID)
nodeConfig, err := e2e.MakeTestNodeConfig(e2e.GetNetworkID())
s.NoError(err)
// start node outside the manager (on the same port), so that manager node.Start() method fails

View File

@ -24,7 +24,7 @@ func (s *RPCClientTestSuite) SetupTest() {
}
func (s *RPCClientTestSuite) TestNewClient() {
config, err := e2e.MakeTestNodeConfig(params.RinkebyNetworkID)
config, err := e2e.MakeTestNodeConfig(e2e.GetNetworkID())
s.NoError(err)
nodeStarted, err := s.NodeManager.StartNode(config)

View File

@ -30,7 +30,7 @@ func (s *RPCTestSuite) SetupTest() {
func (s *RPCTestSuite) TestCallRPC() {
for _, upstreamEnabled := range []bool{false, true} {
nodeConfig, err := e2e.MakeTestNodeConfig(params.RinkebyNetworkID)
nodeConfig, err := e2e.MakeTestNodeConfig(e2e.GetNetworkID())
s.NoError(err)
nodeConfig.IPCEnabled = false
@ -121,7 +121,7 @@ func (s *RPCTestSuite) TestCallRPC() {
// TestCallRawResult checks if returned response is a valid JSON-RPC response.
func (s *RPCTestSuite) TestCallRawResult() {
nodeConfig, err := e2e.MakeTestNodeConfig(params.StatusChainNetworkID)
nodeConfig, err := e2e.MakeTestNodeConfig(e2e.GetNetworkID())
s.NoError(err)
nodeStarted, err := s.NodeManager.StartNode(nodeConfig)

View File

@ -18,8 +18,8 @@ type NodeManagerTestSuite struct {
// StartTestNode initiazes a NodeManager instances with configuration retrieved
// from the test config.
func (s *NodeManagerTestSuite) StartTestNode(networkID int, opts ...TestNodeOption) {
nodeConfig, err := MakeTestNodeConfig(networkID)
func (s *NodeManagerTestSuite) StartTestNode(opts ...TestNodeOption) {
nodeConfig, err := MakeTestNodeConfig(GetNetworkID())
s.NoError(err)
// Apply any options altering node config.
@ -68,8 +68,8 @@ func (s *BackendTestSuite) TearDownTest() {
}
// StartTestBackend imports some keys and starts a node.
func (s *BackendTestSuite) StartTestBackend(networkID int, opts ...TestNodeOption) {
nodeConfig, err := MakeTestNodeConfig(networkID)
func (s *BackendTestSuite) StartTestBackend(opts ...TestNodeOption) {
nodeConfig, err := MakeTestNodeConfig(GetNetworkID())
s.NoError(err)
// Apply any options altering node config.

View File

@ -32,7 +32,7 @@ type TransactionsTestSuite struct {
}
func (s *TransactionsTestSuite) TestCallRPCSendTransaction() {
s.StartTestBackend(params.StatusChainNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
s.NoError(EnsureNodeSync(s.Backend.NodeManager()), "cannot ensure node synchronization")
@ -139,7 +139,7 @@ func (s *TransactionsTestSuite) TestCallRPCSendTransactionUpstream() {
// FIXME(tiabc): Sometimes it fails due to "no suitable peers found".
func (s *TransactionsTestSuite) TestSendContractTx() {
s.StartTestBackend(params.StatusChainNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
s.NoError(EnsureNodeSync(s.Backend.NodeManager()), "cannot ensure node synchronization")
@ -226,7 +226,7 @@ func (s *TransactionsTestSuite) TestSendContractTx() {
}
func (s *TransactionsTestSuite) TestSendEther() {
s.StartTestBackend(params.StatusChainNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
s.NoError(EnsureNodeSync(s.Backend.NodeManager()))
@ -366,7 +366,7 @@ func (s *TransactionsTestSuite) TestSendEtherTxUpstream() {
}
func (s *TransactionsTestSuite) TestDoubleCompleteQueuedTransactions() {
s.StartTestBackend(params.StatusChainNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
s.NoError(EnsureNodeSync(s.Backend.NodeManager()), "cannot ensure node synchronization")
@ -443,7 +443,7 @@ func (s *TransactionsTestSuite) TestDoubleCompleteQueuedTransactions() {
}
func (s *TransactionsTestSuite) TestDiscardQueuedTransaction() {
s.StartTestBackend(params.StatusChainNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
s.NoError(EnsureNodeSync(s.Backend.NodeManager()), "cannot ensure node synchronization")
@ -523,7 +523,7 @@ func (s *TransactionsTestSuite) TestDiscardQueuedTransaction() {
}
func (s *TransactionsTestSuite) TestCompleteMultipleQueuedTransactions() {
s.StartTestBackend(params.StatusChainNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
s.NoError(EnsureNodeSync(s.Backend.NodeManager()), "cannot ensure node synchronization")
@ -617,7 +617,7 @@ func (s *TransactionsTestSuite) TestCompleteMultipleQueuedTransactions() {
}
func (s *TransactionsTestSuite) TestDiscardMultipleQueuedTransactions() {
s.StartTestBackend(params.StatusChainNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
s.NoError(EnsureNodeSync(s.Backend.NodeManager()), "cannot ensure node synchronization")
@ -733,7 +733,7 @@ func (s *TransactionsTestSuite) TestDiscardMultipleQueuedTransactions() {
}
func (s *TransactionsTestSuite) TestNonExistentQueuedTransactions() {
s.StartTestBackend(params.StatusChainNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
backend := s.LightEthereumService().StatusBackend
@ -752,7 +752,7 @@ func (s *TransactionsTestSuite) TestNonExistentQueuedTransactions() {
}
func (s *TransactionsTestSuite) TestEvictionOfQueuedTransactions() {
s.StartTestBackend(params.StatusChainNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
backend := s.LightEthereumService().StatusBackend

View File

@ -81,7 +81,7 @@ func (s *WhisperJailTestSuite) GetAccountKey(account struct {
// TODO(adamb) Uncomment when issue #336 is fixed.
/*
func (s *WhisperJailTestSuite) DontTestJailWhisper() {
s.StartTestBackend(params.StatusChainNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
_, accountKey1Hex, err := s.GetAccountKey(TestConfig.Account1)
@ -375,7 +375,7 @@ func (s *WhisperJailTestSuite) DontTestJailWhisper() {
*/
func (s *WhisperJailTestSuite) TestEncryptedAnonymousMessage() {
s.StartTestBackend(params.StatusChainNetworkID)
s.StartTestBackend()
defer s.StopTestBackend()
accountKey2, accountKey2Hex, err := s.GetAccountKey(TestConfig.Account2)

View File

@ -9,7 +9,6 @@ import (
"github.com/status-im/status-go/e2e"
"github.com/status-im/status-go/geth/account"
"github.com/status-im/status-go/geth/node"
"github.com/status-im/status-go/geth/params"
. "github.com/status-im/status-go/testing"
"github.com/stretchr/testify/suite"
)
@ -30,7 +29,7 @@ func (s *WhisperTestSuite) SetupTest() {
// TODO(adam): can anyone explain what this test is testing?
// I don't see any race condition testing here.
func (s *WhisperTestSuite) TestWhisperFilterRace() {
s.StartTestNode(params.RinkebyNetworkID)
s.StartTestNode()
defer s.StopTestNode()
whisperService, err := s.NodeManager.WhisperService()
@ -95,7 +94,7 @@ func (s *WhisperTestSuite) TestWhisperFilterRace() {
}
func (s *WhisperTestSuite) TestLogout() {
s.StartTestNode(params.RinkebyNetworkID)
s.StartTestNode()
defer s.StopTestNode()
whisperService, err := s.NodeManager.WhisperService()