mirror of
https://github.com/status-im/status-go.git
synced 2025-03-04 00:21:01 +00:00
Made EnsureNodeSync() throws a panic instead of returning an error (#431)
EnsureNodeSync() has been changed to return no error anymore, Instead in case of an internal error or a timeout a panic is thrown.
This commit is contained in:
parent
c500fbc423
commit
e14b2331eb
@ -215,11 +215,7 @@ func testResetChainData(t *testing.T) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := EnsureNodeSync(statusAPI.NodeManager()); err != nil {
|
EnsureNodeSync(statusAPI.NodeManager())
|
||||||
t.Errorf("cannot ensure node synchronization: %v", err)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
testCompleteTransaction(t)
|
testCompleteTransaction(t)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
@ -735,11 +731,7 @@ func testCompleteTransaction(t *testing.T) bool {
|
|||||||
txQueue := txQueueManager.TransactionQueue()
|
txQueue := txQueueManager.TransactionQueue()
|
||||||
|
|
||||||
txQueue.Reset()
|
txQueue.Reset()
|
||||||
|
EnsureNodeSync(statusAPI.NodeManager())
|
||||||
if err := EnsureNodeSync(statusAPI.NodeManager()); err != nil {
|
|
||||||
t.Errorf("cannot ensure node synchronization: %v", err)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// log into account from which transactions will be sent
|
// log into account from which transactions will be sent
|
||||||
if err := statusAPI.SelectAccount(TestConfig.Account1.Address, TestConfig.Account1.Password); err != nil {
|
if err := statusAPI.SelectAccount(TestConfig.Account1.Address, TestConfig.Account1.Password); err != nil {
|
||||||
@ -1373,10 +1365,7 @@ func startTestNode(t *testing.T) <-chan struct{} {
|
|||||||
// sync
|
// sync
|
||||||
if syncRequired {
|
if syncRequired {
|
||||||
t.Logf("Sync is required")
|
t.Logf("Sync is required")
|
||||||
if err := EnsureNodeSync(statusAPI.NodeManager()); err != nil {
|
EnsureNodeSync(statusAPI.NodeManager())
|
||||||
t.Errorf("cannot ensure node synchronization: %v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
time.Sleep(5 * time.Second)
|
time.Sleep(5 * time.Second)
|
||||||
}
|
}
|
||||||
|
@ -242,7 +242,7 @@ func (s *APIBackendTestSuite) TestResetChainData() {
|
|||||||
s.StartTestBackend(params.RinkebyNetworkID)
|
s.StartTestBackend(params.RinkebyNetworkID)
|
||||||
defer s.StopTestBackend()
|
defer s.StopTestBackend()
|
||||||
|
|
||||||
s.NoError(EnsureNodeSync(s.Backend.NodeManager()), "cannot ensure node synchronization")
|
EnsureNodeSync(s.Backend.NodeManager())
|
||||||
|
|
||||||
s.True(s.Backend.IsNodeRunning())
|
s.True(s.Backend.IsNodeRunning())
|
||||||
nodeReady, err := s.Backend.ResetChainData()
|
nodeReady, err := s.Backend.ResetChainData()
|
||||||
|
@ -39,7 +39,7 @@ func (s *JailRPCTestSuite) TestJailRPCSend() {
|
|||||||
s.StartTestBackend(params.StatusChainNetworkID)
|
s.StartTestBackend(params.StatusChainNetworkID)
|
||||||
defer s.StopTestBackend()
|
defer s.StopTestBackend()
|
||||||
|
|
||||||
s.NoError(EnsureNodeSync(s.Backend.NodeManager()), "cannot ensure node synchronization")
|
EnsureNodeSync(s.Backend.NodeManager())
|
||||||
|
|
||||||
// load Status JS and add test command to it
|
// load Status JS and add test command to it
|
||||||
s.jail.BaseJS(baseStatusJSCode)
|
s.jail.BaseJS(baseStatusJSCode)
|
||||||
@ -112,7 +112,7 @@ func (s *JailRPCTestSuite) TestContractDeployment() {
|
|||||||
s.StartTestBackend(params.StatusChainNetworkID)
|
s.StartTestBackend(params.StatusChainNetworkID)
|
||||||
defer s.StopTestBackend()
|
defer s.StopTestBackend()
|
||||||
|
|
||||||
s.NoError(EnsureNodeSync(s.Backend.NodeManager()), "cannot ensure node synchronization")
|
EnsureNodeSync(s.Backend.NodeManager())
|
||||||
|
|
||||||
// obtain VM for a given chat (to send custom JS to jailed version of Send())
|
// obtain VM for a given chat (to send custom JS to jailed version of Send())
|
||||||
s.jail.Parse(testChatID, "")
|
s.jail.Parse(testChatID, "")
|
||||||
@ -198,7 +198,7 @@ func (s *JailRPCTestSuite) TestJailVMPersistence() {
|
|||||||
s.StartTestBackend(params.StatusChainNetworkID)
|
s.StartTestBackend(params.StatusChainNetworkID)
|
||||||
defer s.StopTestBackend()
|
defer s.StopTestBackend()
|
||||||
|
|
||||||
s.NoError(EnsureNodeSync(s.Backend.NodeManager()), "cannot ensure node synchronization")
|
EnsureNodeSync(s.Backend.NodeManager())
|
||||||
|
|
||||||
// log into account from which transactions will be sent
|
// log into account from which transactions will be sent
|
||||||
err := s.Backend.AccountManager().SelectAccount(TestConfig.Account1.Address, TestConfig.Account1.Password)
|
err := s.Backend.AccountManager().SelectAccount(TestConfig.Account1.Address, TestConfig.Account1.Password)
|
||||||
|
@ -296,7 +296,7 @@ func (s *ManagerTestSuite) TestResetChainData() {
|
|||||||
s.StartTestNode(params.RinkebyNetworkID)
|
s.StartTestNode(params.RinkebyNetworkID)
|
||||||
defer s.StopTestNode()
|
defer s.StopTestNode()
|
||||||
|
|
||||||
s.NoError(EnsureNodeSync(s.NodeManager), "cannot ensure node synchronization")
|
EnsureNodeSync(s.NodeManager)
|
||||||
|
|
||||||
// reset chain data
|
// reset chain data
|
||||||
nodeReady, err := s.NodeManager.ResetChainData()
|
nodeReady, err := s.NodeManager.ResetChainData()
|
||||||
|
@ -6,13 +6,14 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"math/big"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
"github.com/status-im/status-go/e2e"
|
"github.com/status-im/status-go/e2e"
|
||||||
"github.com/status-im/status-go/geth/node"
|
"github.com/status-im/status-go/geth/node"
|
||||||
"github.com/status-im/status-go/geth/params"
|
"github.com/status-im/status-go/geth/params"
|
||||||
. "github.com/status-im/status-go/testing"
|
. "github.com/status-im/status-go/testing"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
"math/big"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRPCTestSuite(t *testing.T) {
|
func TestRPCTestSuite(t *testing.T) {
|
||||||
@ -143,7 +144,7 @@ func (s *RPCTestSuite) TestCallContextResult() {
|
|||||||
s.StartTestNode(params.StatusChainNetworkID)
|
s.StartTestNode(params.StatusChainNetworkID)
|
||||||
defer s.StopTestNode()
|
defer s.StopTestNode()
|
||||||
|
|
||||||
s.Require().NoError(EnsureNodeSync(s.NodeManager))
|
EnsureNodeSync(s.NodeManager)
|
||||||
|
|
||||||
client := s.NodeManager.RPCClient()
|
client := s.NodeManager.RPCClient()
|
||||||
s.NotNil(client)
|
s.NotNil(client)
|
||||||
|
@ -35,7 +35,7 @@ func (s *TransactionsTestSuite) TestCallRPCSendTransaction() {
|
|||||||
s.StartTestBackend(params.StatusChainNetworkID)
|
s.StartTestBackend(params.StatusChainNetworkID)
|
||||||
defer s.StopTestBackend()
|
defer s.StopTestBackend()
|
||||||
|
|
||||||
s.NoError(EnsureNodeSync(s.Backend.NodeManager()), "cannot ensure node synchronization")
|
EnsureNodeSync(s.Backend.NodeManager())
|
||||||
|
|
||||||
err := s.Backend.AccountManager().SelectAccount(TestConfig.Account1.Address, TestConfig.Account1.Password)
|
err := s.Backend.AccountManager().SelectAccount(TestConfig.Account1.Address, TestConfig.Account1.Password)
|
||||||
s.NoError(err)
|
s.NoError(err)
|
||||||
@ -142,7 +142,7 @@ func (s *TransactionsTestSuite) TestSendContractTx() {
|
|||||||
s.StartTestBackend(params.StatusChainNetworkID)
|
s.StartTestBackend(params.StatusChainNetworkID)
|
||||||
defer s.StopTestBackend()
|
defer s.StopTestBackend()
|
||||||
|
|
||||||
s.NoError(EnsureNodeSync(s.Backend.NodeManager()), "cannot ensure node synchronization")
|
EnsureNodeSync(s.Backend.NodeManager())
|
||||||
|
|
||||||
sampleAddress, _, _, err := s.Backend.AccountManager().CreateAccount(TestConfig.Account1.Password)
|
sampleAddress, _, _, err := s.Backend.AccountManager().CreateAccount(TestConfig.Account1.Password)
|
||||||
s.NoError(err)
|
s.NoError(err)
|
||||||
@ -229,7 +229,7 @@ func (s *TransactionsTestSuite) TestSendEther() {
|
|||||||
s.StartTestBackend(params.StatusChainNetworkID)
|
s.StartTestBackend(params.StatusChainNetworkID)
|
||||||
defer s.StopTestBackend()
|
defer s.StopTestBackend()
|
||||||
|
|
||||||
s.NoError(EnsureNodeSync(s.Backend.NodeManager()))
|
EnsureNodeSync(s.Backend.NodeManager())
|
||||||
|
|
||||||
backend := s.LightEthereumService().StatusBackend
|
backend := s.LightEthereumService().StatusBackend
|
||||||
s.NotNil(backend)
|
s.NotNil(backend)
|
||||||
@ -369,7 +369,7 @@ func (s *TransactionsTestSuite) TestDoubleCompleteQueuedTransactions() {
|
|||||||
s.StartTestBackend(params.StatusChainNetworkID)
|
s.StartTestBackend(params.StatusChainNetworkID)
|
||||||
defer s.StopTestBackend()
|
defer s.StopTestBackend()
|
||||||
|
|
||||||
s.NoError(EnsureNodeSync(s.Backend.NodeManager()), "cannot ensure node synchronization")
|
EnsureNodeSync(s.Backend.NodeManager())
|
||||||
|
|
||||||
backend := s.LightEthereumService().StatusBackend
|
backend := s.LightEthereumService().StatusBackend
|
||||||
s.NotNil(backend)
|
s.NotNil(backend)
|
||||||
@ -446,7 +446,7 @@ func (s *TransactionsTestSuite) TestDiscardQueuedTransaction() {
|
|||||||
s.StartTestBackend(params.StatusChainNetworkID)
|
s.StartTestBackend(params.StatusChainNetworkID)
|
||||||
defer s.StopTestBackend()
|
defer s.StopTestBackend()
|
||||||
|
|
||||||
s.NoError(EnsureNodeSync(s.Backend.NodeManager()), "cannot ensure node synchronization")
|
EnsureNodeSync(s.Backend.NodeManager())
|
||||||
|
|
||||||
backend := s.LightEthereumService().StatusBackend
|
backend := s.LightEthereumService().StatusBackend
|
||||||
s.NotNil(backend)
|
s.NotNil(backend)
|
||||||
@ -526,8 +526,7 @@ func (s *TransactionsTestSuite) TestCompleteMultipleQueuedTransactions() {
|
|||||||
s.StartTestBackend(params.StatusChainNetworkID)
|
s.StartTestBackend(params.StatusChainNetworkID)
|
||||||
defer s.StopTestBackend()
|
defer s.StopTestBackend()
|
||||||
|
|
||||||
s.NoError(EnsureNodeSync(s.Backend.NodeManager()), "cannot ensure node synchronization")
|
EnsureNodeSync(s.Backend.NodeManager())
|
||||||
|
|
||||||
s.TxQueueManager().TransactionQueue().Reset()
|
s.TxQueueManager().TransactionQueue().Reset()
|
||||||
|
|
||||||
// log into account from which transactions will be sent
|
// log into account from which transactions will be sent
|
||||||
@ -620,7 +619,7 @@ func (s *TransactionsTestSuite) TestDiscardMultipleQueuedTransactions() {
|
|||||||
s.StartTestBackend(params.StatusChainNetworkID)
|
s.StartTestBackend(params.StatusChainNetworkID)
|
||||||
defer s.StopTestBackend()
|
defer s.StopTestBackend()
|
||||||
|
|
||||||
s.NoError(EnsureNodeSync(s.Backend.NodeManager()), "cannot ensure node synchronization")
|
EnsureNodeSync(s.Backend.NodeManager())
|
||||||
|
|
||||||
backend := s.LightEthereumService().StatusBackend
|
backend := s.LightEthereumService().StatusBackend
|
||||||
s.NotNil(backend)
|
s.NotNil(backend)
|
||||||
|
@ -2,7 +2,6 @@ package integration
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -69,23 +68,23 @@ func LoadFromFile(filename string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// EnsureNodeSync waits until node synchronzation is done to continue
|
// EnsureNodeSync waits until node synchronzation is done to continue
|
||||||
// with tests afterwards. Returns an error in case of a timeout.
|
// with tests afterwards. Panics in case of an error or a timeout.
|
||||||
func EnsureNodeSync(nodeManager common.NodeManager) error {
|
func EnsureNodeSync(nodeManager common.NodeManager) {
|
||||||
nc, err := nodeManager.NodeConfig()
|
nc, err := nodeManager.NodeConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("can't retrieve NodeConfig")
|
panic("can't retrieve NodeConfig")
|
||||||
}
|
}
|
||||||
// Don't wait for any blockchain sync for the local private chain as blocks are never mined.
|
// Don't wait for any blockchain sync for the local private chain as blocks are never mined.
|
||||||
if nc.NetworkID == params.StatusChainNetworkID {
|
if nc.NetworkID == params.StatusChainNetworkID {
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
les, err := nodeManager.LightEthereumService()
|
les, err := nodeManager.LightEthereumService()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
panic(err)
|
||||||
}
|
}
|
||||||
if les == nil {
|
if les == nil {
|
||||||
return errors.New("LightEthereumService is nil")
|
panic("LightEthereumService is nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
timeouter := time.NewTimer(20 * time.Minute)
|
timeouter := time.NewTimer(20 * time.Minute)
|
||||||
@ -96,7 +95,7 @@ func EnsureNodeSync(nodeManager common.NodeManager) error {
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-timeouter.C:
|
case <-timeouter.C:
|
||||||
return errors.New("timout during node synchronization")
|
panic("timout during node synchronization")
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
downloader := les.Downloader()
|
downloader := les.Downloader()
|
||||||
|
|
||||||
@ -105,10 +104,9 @@ func EnsureNodeSync(nodeManager common.NodeManager) error {
|
|||||||
progress := downloader.Progress()
|
progress := downloader.Progress()
|
||||||
|
|
||||||
if !isSyncing && progress.HighestBlock > 0 && progress.CurrentBlock >= progress.HighestBlock {
|
if !isSyncing && progress.HighestBlock > 0 && progress.CurrentBlock >= progress.HighestBlock {
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user