From 7718bd5990ac110c7418201ee79e3045a5158873 Mon Sep 17 00:00:00 2001 From: Alexander Ewetumo Date: Mon, 23 Oct 2017 17:03:07 +0100 Subject: [PATCH] Move all tests to retrieve NetworkId from flag or default to statuschain --- e2e/README.md | 23 +++++++++++++++++++++++ e2e/accounts/accounts_rpc_test.go | 2 +- e2e/accounts/accounts_test.go | 10 +++++----- e2e/api/api_test.go | 8 ++++---- e2e/api/backend_test.go | 12 ++++++------ e2e/jail/jail_rpc_test.go | 10 +++++----- e2e/node/manager_test.go | 20 ++++++++++---------- e2e/rpc/client_test.go | 2 +- e2e/rpc/rpc_test.go | 4 ++-- e2e/suites.go | 8 ++++---- e2e/transactions/transactions_test.go | 18 +++++++++--------- e2e/whisper/whisper_jail_test.go | 4 ++-- e2e/whisper/whisper_test.go | 5 ++--- 13 files changed, 74 insertions(+), 52 deletions(-) diff --git a/e2e/README.md b/e2e/README.md index 4f0965f66..3dc7e1309 100644 --- a/e2e/README.md +++ b/e2e/README.md @@ -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` diff --git a/e2e/accounts/accounts_rpc_test.go b/e2e/accounts/accounts_rpc_test.go index 755128d5c..0ee9cd26c 100644 --- a/e2e/accounts/accounts_rpc_test.go +++ b/e2e/accounts/accounts_rpc_test.go @@ -19,7 +19,7 @@ type AccountsRPCTestSuite struct { } func (s *AccountsTestSuite) TestRPCEthAccounts() { - s.StartTestBackend(params.StatusChainNetworkID) + s.StartTestBackend() defer s.StopTestBackend() // log into test account diff --git a/e2e/accounts/accounts_test.go b/e2e/accounts/accounts_test.go index 59895c002..6e5fce0c2 100644 --- a/e2e/accounts/accounts_test.go +++ b/e2e/accounts/accounts_test.go @@ -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() diff --git a/e2e/api/api_test.go b/e2e/api/api_test.go index d94f9e081..c0a5ca885 100644 --- a/e2e/api/api_test.go +++ b/e2e/api/api_test.go @@ -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) diff --git a/e2e/api/backend_test.go b/e2e/api/backend_test.go index 24d584f1b..0d9dc9950 100644 --- a/e2e/api/backend_test.go +++ b/e2e/api/backend_test.go @@ -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()) diff --git a/e2e/jail/jail_rpc_test.go b/e2e/jail/jail_rpc_test.go index 2b2408f76..fd8474cac 100644 --- a/e2e/jail/jail_rpc_test.go +++ b/e2e/jail/jail_rpc_test.go @@ -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") diff --git a/e2e/node/manager_test.go b/e2e/node/manager_test.go index 5a7e4223d..8690f23bd 100644 --- a/e2e/node/manager_test.go +++ b/e2e/node/manager_test.go @@ -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 diff --git a/e2e/rpc/client_test.go b/e2e/rpc/client_test.go index 18c0ce71f..273a8fe5f 100644 --- a/e2e/rpc/client_test.go +++ b/e2e/rpc/client_test.go @@ -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) diff --git a/e2e/rpc/rpc_test.go b/e2e/rpc/rpc_test.go index 3b9a45155..6db1651d1 100644 --- a/e2e/rpc/rpc_test.go +++ b/e2e/rpc/rpc_test.go @@ -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) diff --git a/e2e/suites.go b/e2e/suites.go index 17d9b1635..5afbe5505 100644 --- a/e2e/suites.go +++ b/e2e/suites.go @@ -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. diff --git a/e2e/transactions/transactions_test.go b/e2e/transactions/transactions_test.go index 31a1b27c0..86a2eb675 100644 --- a/e2e/transactions/transactions_test.go +++ b/e2e/transactions/transactions_test.go @@ -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 diff --git a/e2e/whisper/whisper_jail_test.go b/e2e/whisper/whisper_jail_test.go index ea0209e6d..ebd8f4fbd 100644 --- a/e2e/whisper/whisper_jail_test.go +++ b/e2e/whisper/whisper_jail_test.go @@ -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) diff --git a/e2e/whisper/whisper_test.go b/e2e/whisper/whisper_test.go index ac8b0fcf5..c304487f2 100644 --- a/e2e/whisper/whisper_test.go +++ b/e2e/whisper/whisper_test.go @@ -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()