mirror of
https://github.com/status-im/status-go.git
synced 2025-02-22 19:58:29 +00:00
fix_: check group error in GetBalancesAtByChain (#6169)
* fix_: check group error in GetBalancesAtByChain * fix_: properly wrap error * test_: FetchBalancesForChain check error
This commit is contained in:
parent
3a0080281f
commit
dfb591874a
@ -2,13 +2,14 @@ package balancefetcher
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"math/big"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
@ -23,6 +24,10 @@ import (
|
||||
var NativeChainAddress = common.HexToAddress("0x")
|
||||
var requestTimeout = 20 * time.Second
|
||||
|
||||
var (
|
||||
errScanningContract = errors.New("error scanning contract")
|
||||
)
|
||||
|
||||
const (
|
||||
tokenChunkSize = 500
|
||||
)
|
||||
@ -69,8 +74,7 @@ func (bf *DefaultBalanceFetcher) fetchBalancesForChain(parent context.Context, c
|
||||
|
||||
ethScanContract, availableAtBlock, err := bf.contractMaker.NewEthScan(client.NetworkID())
|
||||
if err != nil {
|
||||
logutils.ZapLogger().Error("error scanning contract", zap.Error(err))
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, errScanningContract.Error())
|
||||
}
|
||||
|
||||
fetchChainBalance := false
|
||||
@ -320,5 +324,9 @@ func (bf *DefaultBalanceFetcher) GetBalancesAtByChain(parent context.Context, cl
|
||||
case <-parent.Done():
|
||||
return nil, parent.Err()
|
||||
}
|
||||
if group.Error() != nil {
|
||||
logutils.ZapLogger().Error("failed to get balances by chain", zap.Error(group.Error()))
|
||||
return nil, group.Error()
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
@ -382,4 +382,13 @@ func TestBalanceFetcherGetBalancesAtByChain(t *testing.T) {
|
||||
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expectedBalances, balances)
|
||||
|
||||
// Test errors
|
||||
chainClients = map[uint64]chain.ClientInterface{
|
||||
w_common.ArbitrumMainnet: chainClientArb,
|
||||
}
|
||||
balances, err = bf.GetBalancesAtByChain(ctx, chainClients, nil, nil, atBlocks)
|
||||
require.Error(t, err)
|
||||
require.ErrorContains(t, err, errScanningContract.Error())
|
||||
require.Nil(t, balances)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user