feat(wallet)_: add new API to restart the wallet reload timer

- Added `restartWalletReloadTimer` method in `api.go` to expose an API for restarting the wallet reload timer.
- Implemented `Restart` method in `reader.go` to stop and start the wallet reader.
- Updated reader_test.go to comply with minimum test coverage threshold
This commit is contained in:
belalshehab 2024-07-03 03:42:41 +03:00 committed by Belal Shehab
parent f8984b26e0
commit f98c411b32
3 changed files with 27 additions and 1 deletions

View File

@ -873,3 +873,7 @@ func (api *API) SignTypedDataV4(typedJson string, address string, password strin
} }
return types.HexBytes(sig), err return types.HexBytes(sig), err
} }
func (api *API) RestartWalletReloadTimer(ctx context.Context) error {
return api.s.reader.Restart()
}

View File

@ -143,6 +143,11 @@ func (r *Reader) Stop() {
r.lastWalletTokenUpdateTimestamp = sync.Map{} r.lastWalletTokenUpdateTimestamp = sync.Map{}
} }
func (r *Reader) Restart() error {
r.Stop()
return r.Start()
}
func (r *Reader) triggerWalletReload() { func (r *Reader) triggerWalletReload() {
r.cancelDelayedWalletReload() r.cancelDelayedWalletReload()

View File

@ -15,6 +15,7 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/event"
"github.com/status-im/status-go/rpc/chain" "github.com/status-im/status-go/rpc/chain"
mock_client "github.com/status-im/status-go/rpc/chain/mock/client" mock_client "github.com/status-im/status-go/rpc/chain/mock/client"
"github.com/status-im/status-go/services/wallet/testutils" "github.com/status-im/status-go/services/wallet/testutils"
@ -165,8 +166,9 @@ func setupReader(t *testing.T) (*Reader, *mock_token.MockManagerInterface, *mock
mockCtrl := gomock.NewController(t) mockCtrl := gomock.NewController(t)
mockTokenManager := mock_token.NewMockManagerInterface(mockCtrl) mockTokenManager := mock_token.NewMockManagerInterface(mockCtrl)
tokenBalanceStorage := mock_balance_persistence.NewMockTokenBalancesStorage(mockCtrl) tokenBalanceStorage := mock_balance_persistence.NewMockTokenBalancesStorage(mockCtrl)
eventsFeed := &event.Feed{}
return NewReader(mockTokenManager, nil, tokenBalanceStorage, nil), mockTokenManager, tokenBalanceStorage, mockCtrl return NewReader(mockTokenManager, nil, tokenBalanceStorage, eventsFeed), mockTokenManager, tokenBalanceStorage, mockCtrl
} }
func TestGetCachedWalletTokensWithoutMarketData(t *testing.T) { func TestGetCachedWalletTokensWithoutMarketData(t *testing.T) {
@ -1023,3 +1025,18 @@ func TestFetchBalances(t *testing.T) {
require.True(t, reader.isBalanceCacheValid(addresses)) require.True(t, reader.isBalanceCacheValid(addresses))
} }
func TestReaderRestart(t *testing.T) {
reader, _, _, mockCtrl := setupReader(t)
defer mockCtrl.Finish()
err := reader.Start()
require.NoError(t, err)
require.NotNil(t, reader.walletEventsWatcher)
previousWalletEventsWatcher := reader.walletEventsWatcher
err = reader.Restart()
require.NoError(t, err)
require.NotNil(t, reader.walletEventsWatcher)
require.NotEqual(t, previousWalletEventsWatcher, reader.walletEventsWatcher)
}