github.com/status-im/status-go@v1.1.0/services/wallet/transfer/downloader_test.go (about)

     1  package transfer
     2  
     3  import (
     4  	"context"
     5  	"math/big"
     6  	"testing"
     7  
     8  	"github.com/ethereum/go-ethereum/common"
     9  	"github.com/ethereum/go-ethereum/core/types"
    10  
    11  	"github.com/golang/mock/gomock"
    12  
    13  	mock_client "github.com/status-im/status-go/rpc/chain/mock/client"
    14  	walletCommon "github.com/status-im/status-go/services/wallet/common"
    15  
    16  	"github.com/stretchr/testify/require"
    17  )
    18  
    19  func TestERC20Downloader_getHeadersInRange(t *testing.T) {
    20  	mockCtrl := gomock.NewController(t)
    21  	defer mockCtrl.Finish()
    22  
    23  	mockClientIface := mock_client.NewMockClientInterface(mockCtrl)
    24  
    25  	accounts := []common.Address{
    26  		common.HexToAddress("0x1"),
    27  	}
    28  	chainID := walletCommon.EthereumMainnet
    29  	signer := types.LatestSignerForChainID(big.NewInt(int64(chainID)))
    30  	mockClientIface.EXPECT().NetworkID().Return(chainID).AnyTimes()
    31  
    32  	downloader := NewERC20TransfersDownloader(
    33  		mockClientIface,
    34  		accounts,
    35  		signer,
    36  		false,
    37  	)
    38  
    39  	ctx := context.Background()
    40  
    41  	_, err := downloader.GetHeadersInRange(ctx, big.NewInt(10), big.NewInt(0))
    42  	require.Error(t, err)
    43  
    44  	mockClientIface.EXPECT().FilterLogs(ctx, gomock.Any()).Return(nil, nil).AnyTimes()
    45  	_, err = downloader.GetHeadersInRange(ctx, big.NewInt(0), big.NewInt(10))
    46  	require.NoError(t, err)
    47  }