-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix losing batch call errors for individual requests (#12127)
* Fixed losing batch call errors for individual requests * Fixed linting * Added comments * Fixed linting * Improved error check in test
- Loading branch information
1 parent
ec28bb9
commit d10b471
Showing
11 changed files
with
1,258 additions
and
135 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package client_test | ||
|
||
import ( | ||
"errors" | ||
"math/big" | ||
"testing" | ||
"time" | ||
|
||
"github.com/ethereum/go-ethereum/common/hexutil" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
"github.com/ethereum/go-ethereum/rpc" | ||
"github.com/stretchr/testify/mock" | ||
"github.com/stretchr/testify/require" | ||
|
||
commonclient "github.com/smartcontractkit/chainlink/v2/common/client" | ||
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/client" | ||
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/client/mocks" | ||
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils" | ||
) | ||
|
||
func newMockRpc(t *testing.T) *mocks.RPCCLient { | ||
mockRpc := mocks.NewRPCCLient(t) | ||
mockRpc.On("Dial", mock.Anything).Return(nil).Once() | ||
mockRpc.On("Close").Return(nil).Once() | ||
mockRpc.On("ChainID", mock.Anything).Return(testutils.FixtureChainID, nil).Once() | ||
mockRpc.On("Subscribe", mock.Anything, mock.Anything, mock.Anything).Return(client.NewMockSubscription(), nil).Once() | ||
mockRpc.On("SetAliveLoopSub", mock.Anything).Return().Once() | ||
return mockRpc | ||
} | ||
|
||
func TestChainClient_BatchCallContext(t *testing.T) { | ||
t.Parallel() | ||
|
||
t.Run("batch requests return errors", func(t *testing.T) { | ||
ctx := testutils.Context(t) | ||
rpcError := errors.New("something went wrong") | ||
blockNumResp := "" | ||
blockNum := hexutil.EncodeBig(big.NewInt(42)) | ||
b := []rpc.BatchElem{ | ||
{ | ||
Method: "eth_getBlockByNumber", | ||
Args: []interface{}{blockNum, true}, | ||
Result: &types.Block{}, | ||
}, | ||
{ | ||
Method: "eth_blockNumber", | ||
Result: &blockNumResp, | ||
}, | ||
} | ||
|
||
mockRpc := newMockRpc(t) | ||
mockRpc.On("BatchCallContext", mock.Anything, b).Run(func(args mock.Arguments) { | ||
reqs := args.Get(1).([]rpc.BatchElem) | ||
for i := 0; i < len(reqs); i++ { | ||
elem := &reqs[i] | ||
elem.Error = rpcError | ||
} | ||
}).Return(nil).Once() | ||
|
||
client := client.NewChainClientWithMockedRpc(t, commonclient.NodeSelectionModeRoundRobin, time.Second*0, time.Second*0, testutils.FixtureChainID, mockRpc) | ||
err := client.Dial(ctx) | ||
require.NoError(t, err) | ||
|
||
err = client.BatchCallContext(ctx, b) | ||
require.NoError(t, err) | ||
for _, elem := range b { | ||
require.ErrorIs(t, rpcError, elem.Error) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.