diff --git a/e2e/rpc/rpc_test.go b/e2e/rpc/rpc_test.go index 977afdf62..1b7e31f8a 100644 --- a/e2e/rpc/rpc_test.go +++ b/e2e/rpc/rpc_test.go @@ -181,7 +181,7 @@ func (s *RPCTestSuite) TestCallContextResult() { defer cancel() var balance hexutil.Big - err := client.CallContext(ctx, &balance, "eth_getBalance", "0xbF164ca341326a03b547c05B343b2E21eFAe24b9", "latest") + err := client.CallContext(ctx, &balance, "eth_getBalance", TestConfig.Account1.Address, "latest") s.NoError(err) s.True(balance.ToInt().Cmp(big.NewInt(0)) > 0, "balance should be higher than 0") } diff --git a/geth/common/types.go b/geth/common/types.go index 2ceae3718..03d32affb 100644 --- a/geth/common/types.go +++ b/geth/common/types.go @@ -75,6 +75,9 @@ type NodeManager interface { // AddPeer adds URL of static peer AddPeer(url string) error + // PeerCount returns number of connected peers + PeerCount() int + // LightEthereumService exposes reference to LES service running on top of the node LightEthereumService() (*les.LightEthereum, error) diff --git a/geth/common/types_mock.go b/geth/common/types_mock.go index eb00e8fb0..2fbd5c068 100644 --- a/geth/common/types_mock.go +++ b/geth/common/types_mock.go @@ -156,6 +156,18 @@ func (mr *MockNodeManagerMockRecorder) AddPeer(url interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddPeer", reflect.TypeOf((*MockNodeManager)(nil).AddPeer), url) } +// PeerCount mocks base method +func (m *MockNodeManager) PeerCount() int { + ret := m.ctrl.Call(m, "PeerCount") + ret0, _ := ret[0].(int) + return ret0 +} + +// PeerCount indicates an expected call of PeerCount +func (mr *MockNodeManagerMockRecorder) PeerCount() *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PeerCount", reflect.TypeOf((*MockNodeManager)(nil).PeerCount)) +} + // LightEthereumService mocks base method func (m *MockNodeManager) LightEthereumService() (*les.LightEthereum, error) { ret := m.ctrl.Call(m, "LightEthereumService") diff --git a/geth/node/manager.go b/geth/node/manager.go index 6819ba185..9d30f654a 100644 --- a/geth/node/manager.go +++ b/geth/node/manager.go @@ -295,6 +295,13 @@ func (m *NodeManager) addPeer(url string) error { return nil } +func (m *NodeManager) PeerCount() int { + if m.node == nil || m.node.Server() == nil { + return 0 + } + return m.node.Server().PeerCount() +} + // ResetChainData remove chain data from data directory. // Node is stopped, and new node is started, with clean data directory. func (m *NodeManager) ResetChainData() (<-chan struct{}, error) { diff --git a/testing/testing.go b/testing/testing.go index 84a60ef5a..0bb87b704 100644 --- a/testing/testing.go +++ b/testing/testing.go @@ -12,6 +12,7 @@ import ( "time" "github.com/status-im/status-go/geth/common" + "github.com/status-im/status-go/geth/log" "github.com/status-im/status-go/geth/params" _ "github.com/stretchr/testify/suite" // required to register testify flags @@ -113,22 +114,32 @@ func EnsureNodeSync(nodeManager common.NodeManager) { defer timeout.Stop() ticker := time.NewTicker(1 * time.Second) defer ticker.Stop() - for { select { case <-timeout.C: panic("timeout during node synchronization") case <-ticker.C: downloader := les.Downloader() - - if downloader != nil { - isSyncing := downloader.Synchronising() - progress := downloader.Progress() - - if !isSyncing && progress.HighestBlock > 0 && progress.CurrentBlock >= progress.HighestBlock { - return - } + if downloader == nil { + continue } + if nodeManager.PeerCount() == 0 { + log.Debug("No establishished connections with a peers, continue waiting for a sync") + continue + } + if downloader.Synchronising() { + log.Debug("synchronization is in progress") + continue + } + progress := downloader.Progress() + if progress.CurrentBlock >= progress.HighestBlock { + return + } + log.Debug( + fmt.Sprintf("synchronization is not finished yet: current block %d < highest block %d", + progress.CurrentBlock, progress.HighestBlock), + ) + } } }