fix(wallet)_: prevent backwards range in GetHeadersInRange

This commit is contained in:
Dario Gabriel Lipicar 2024-08-12 17:27:54 -03:00 committed by Anthony Laibe
parent c54ba02e3a
commit ab8f1ea709
2 changed files with 54 additions and 0 deletions

View File

@ -534,6 +534,13 @@ func (d *ERC20TransfersDownloader) blocksFromLogs(parent context.Context, logs [
func (d *ERC20TransfersDownloader) GetHeadersInRange(parent context.Context, from, to *big.Int) ([]*DBHeader, error) {
start := time.Now()
log.Debug("get erc20 transfers in range start", "chainID", d.client.NetworkID(), "from", from, "to", to, "accounts", d.accounts)
// TODO #16062: Figure out real root cause of invalid range
if from != nil && to != nil && from.Cmp(to) > 0 {
log.Error("invalid range", "chainID", d.client.NetworkID(), "from", from, "to", to, "accounts", d.accounts)
return nil, errors.New("invalid range")
}
headers := []*DBHeader{}
ctx := context.Background()
var err error

View File

@ -0,0 +1,47 @@
package transfer
import (
"context"
"math/big"
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/golang/mock/gomock"
mock_client "github.com/status-im/status-go/rpc/chain/mock/client"
walletCommon "github.com/status-im/status-go/services/wallet/common"
"github.com/stretchr/testify/require"
)
func TestERC20Downloader_getHeadersInRange(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
mockClientIface := mock_client.NewMockClientInterface(mockCtrl)
accounts := []common.Address{
common.HexToAddress("0x1"),
}
chainID := walletCommon.EthereumMainnet
signer := types.LatestSignerForChainID(big.NewInt(int64(chainID)))
mockClientIface.EXPECT().NetworkID().Return(chainID).AnyTimes()
downloader := NewERC20TransfersDownloader(
mockClientIface,
accounts,
signer,
false,
)
ctx := context.Background()
_, err := downloader.GetHeadersInRange(ctx, big.NewInt(10), big.NewInt(0))
require.Error(t, err)
mockClientIface.EXPECT().FilterLogs(ctx, gomock.Any()).Return(nil, nil).AnyTimes()
_, err = downloader.GetHeadersInRange(ctx, big.NewInt(0), big.NewInt(10))
require.NoError(t, err)
}