Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ethrpc/multicall.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ func (p *Provider) BatchCall(ctx context.Context, calls []multicall.Call, option

_, err := p.Do(ctx, calls_...)
if err != nil {
if err, ok := err.(BatchError); ok {
for i, err := range err.ErrorMap() {
if batchErr, ok := err.(BatchError); ok {
for i, err := range batchErr.ErrorMap() {
if err != nil {
if calls[i].AllowFailure {
if revertData, ok := revertDataFromError(err); ok {
Expand Down
22 changes: 22 additions & 0 deletions ethrpc/multicall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package ethrpc_test

import (
"context"
"errors"
"fmt"
"math/big"
"net/http"
"testing"

"github.com/0xsequence/ethkit/ethrpc"
Expand All @@ -15,6 +17,26 @@ import (

var multicallAddress = common.HexToAddress("0xcA11bde05977b3631167028862bE2a173976CA11")

type errorHTTPClient struct {
err error
}

func (c errorHTTPClient) Do(*http.Request) (*http.Response, error) {
return nil, c.err
}

func TestBatchCallPreservesTransportError(t *testing.T) {
transportErr := errors.New("transport unavailable")
provider, err := ethrpc.NewProvider("http://example.invalid", ethrpc.WithHTTPClient(errorHTTPClient{err: transportErr}))
assert.NoError(t, err)

_, _, err = provider.BatchCall(context.Background(), []multicall.Call{{
Multicall3Call3Value: multicall.Multicall3Call3Value{Target: multicallAddress},
}})

assert.ErrorIs(t, err, transportErr)
}

func TestMulticall(t *testing.T) {
ctx := context.Background()

Expand Down