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:
Igor Sirotin 2024-12-07 12:10:38 +00:00 committed by GitHub
parent 3a0080281f
commit dfb591874a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 3 deletions

View File

@ -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
}

View File

@ -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)
}