diff --git a/core/services/pipeline/task.eth_call_test.go b/core/services/pipeline/task.eth_call_test.go index e91c1cbba84..28af94ba25c 100644 --- a/core/services/pipeline/task.eth_call_test.go +++ b/core/services/pipeline/task.eth_call_test.go @@ -6,7 +6,6 @@ import ( "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/common/hexutil" "github.com/pkg/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" @@ -54,42 +53,25 @@ func TestETHCallTask(t *testing.T) { expectedErrorContains string }{ { - "happy with empty from", // name - "0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF", // contract - "", // from - "$(foo)", // data - "0", // evmChainID - "", // gas - "", // block - nil, // specGasLimit - pipeline.NewVarsFrom(map[string]interface{}{ // vars + "happy with empty from", + "0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF", + "", + "$(foo)", + "0", + "", + "", + nil, + pipeline.NewVarsFrom(map[string]interface{}{ "foo": []byte("foo bar"), }), - nil, // inputs - func(ethClient *evmclimocks.Client, config *pipelinemocks.Config) { // setupClientMocks + nil, + func(ethClient *evmclimocks.Client, config *pipelinemocks.Config) { contractAddr := common.HexToAddress("0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF") ethClient. - On("CallContext", - mock.Anything, - mock.Anything, - "eth_call", - map[string]interface{}{ - "from": common.Address{}, - "to": &contractAddr, - "gas": hexutil.Uint64(uint64(drJobTypeGasLimit)), - "input": hexutil.Bytes([]byte("foo bar")), - "gasPrice": (*hexutil.Big)(nil), - "maxFeePerGas": (*hexutil.Big)(nil), - "maxPriorityFeePerGas": (*hexutil.Big)(nil), - }, - "latest").Return(nil).Run(func(args mock.Arguments) { - resp := args.Get(1).(*hexutil.Bytes) - *resp = []byte("baz quux") - }) + On("CallContract", mock.Anything, ethereum.CallMsg{To: &contractAddr, Gas: uint64(drJobTypeGasLimit), Data: []byte("foo bar")}, (*big.Int)(nil)). + Return([]byte("baz quux"), nil) }, - []byte("baz quux"), // expected - nil, // expecedErrorCause - "", // expectedErrorContains + []byte("baz quux"), nil, "", }, { "happy with gas limit per task", @@ -98,37 +80,20 @@ func TestETHCallTask(t *testing.T) { "$(foo)", "0", "$(gasLimit)", - "", // block + "", nil, pipeline.NewVarsFrom(map[string]interface{}{ "foo": []byte("foo bar"), "gasLimit": 100_000, }), nil, - func(ethClient *evmclimocks.Client, config *pipelinemocks.Config) { // setupClientMocks + func(ethClient *evmclimocks.Client, config *pipelinemocks.Config) { contractAddr := common.HexToAddress("0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF") ethClient. - On("CallContext", - mock.Anything, - mock.Anything, - "eth_call", - map[string]interface{}{ - "from": common.Address{}, - "to": &contractAddr, - "gas": hexutil.Uint64(uint64(100_000)), - "input": hexutil.Bytes([]byte("foo bar")), - "gasPrice": (*hexutil.Big)(nil), - "maxFeePerGas": (*hexutil.Big)(nil), - "maxPriorityFeePerGas": (*hexutil.Big)(nil), - }, - "latest").Return(nil).Run(func(args mock.Arguments) { - resp := args.Get(1).(*hexutil.Bytes) - *resp = []byte("baz quux") - }) + On("CallContract", mock.Anything, ethereum.CallMsg{To: &contractAddr, Gas: 100_000, Data: []byte("foo bar")}, (*big.Int)(nil)). + Return([]byte("baz quux"), nil) }, - []byte("baz quux"), - nil, - "", + []byte("baz quux"), nil, "", }, { "happy with gas limit per spec", @@ -137,36 +102,19 @@ func TestETHCallTask(t *testing.T) { "$(foo)", "0", "", - "pending", // block + "", &specGasLimit, pipeline.NewVarsFrom(map[string]interface{}{ "foo": []byte("foo bar"), }), nil, - func(ethClient *evmclimocks.Client, config *pipelinemocks.Config) { // setupClientMocks + func(ethClient *evmclimocks.Client, config *pipelinemocks.Config) { contractAddr := common.HexToAddress("0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF") ethClient. - On("CallContext", - mock.Anything, - mock.Anything, - "eth_call", - map[string]interface{}{ - "from": common.Address{}, - "to": &contractAddr, - "gas": hexutil.Uint64(uint64(specGasLimit)), - "input": hexutil.Bytes([]byte("foo bar")), - "gasPrice": (*hexutil.Big)(nil), - "maxFeePerGas": (*hexutil.Big)(nil), - "maxPriorityFeePerGas": (*hexutil.Big)(nil), - }, - "pending").Return(nil).Run(func(args mock.Arguments) { - resp := args.Get(1).(*hexutil.Bytes) - *resp = []byte("baz quux") - }) + On("CallContract", mock.Anything, ethereum.CallMsg{To: &contractAddr, Gas: uint64(specGasLimit), Data: []byte("foo bar")}, (*big.Int)(nil)). + Return([]byte("baz quux"), nil) }, - []byte("baz quux"), // expected - nil, - "", + []byte("baz quux"), nil, "", }, { "happy with from addr", @@ -175,33 +123,18 @@ func TestETHCallTask(t *testing.T) { "$(foo)", "0", "", - "pending", // block + "", nil, pipeline.NewVarsFrom(map[string]interface{}{ "foo": []byte("foo bar"), }), nil, - func(ethClient *evmclimocks.Client, config *pipelinemocks.Config) { // setupClientMocks + func(ethClient *evmclimocks.Client, config *pipelinemocks.Config) { contractAddr := common.HexToAddress("0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF") fromAddr := common.HexToAddress("0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF") ethClient. - On("CallContext", - mock.Anything, - mock.Anything, - "eth_call", - map[string]interface{}{ - "from": fromAddr, - "to": &contractAddr, - "gas": hexutil.Uint64(drJobTypeGasLimit), - "input": hexutil.Bytes([]byte("foo bar")), - "gasPrice": (*hexutil.Big)(nil), - "maxFeePerGas": (*hexutil.Big)(nil), - "maxPriorityFeePerGas": (*hexutil.Big)(nil), - }, - "pending").Return(nil).Run(func(args mock.Arguments) { - resp := args.Get(1).(*hexutil.Bytes) - *resp = []byte("baz quux") - }) + On("CallContract", mock.Anything, ethereum.CallMsg{To: &contractAddr, Gas: uint64(drJobTypeGasLimit), From: fromAddr, Data: []byte("foo bar")}, (*big.Int)(nil)). + Return([]byte("baz quux"), nil) }, []byte("baz quux"), nil, "", }, @@ -285,24 +218,6 @@ func TestETHCallTask(t *testing.T) { func(ethClient *evmclimocks.Client, config *pipelinemocks.Config) {}, nil, pipeline.ErrTooManyErrors, "task inputs", }, - { - "invalid block", // name - "0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF", // contract - "", // from - "$(foo)", // data - "0", // evmChainID - "", // gas - "invalidblock", // block - nil, // specGasLimit - pipeline.NewVarsFrom(map[string]interface{}{ // vars - "foo": []byte("foo bar"), - }), - nil, // inputs - func(ethClient *evmclimocks.Client, config *pipelinemocks.Config) {}, // setupClientMocks - nil, // expected - nil, // expectedErrorCause - "unsupported block param", // expectedErrorContains - }, { "missing chainID", "0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF", @@ -325,6 +240,48 @@ func TestETHCallTask(t *testing.T) { }, nil, nil, chains.ErrNoSuchChainID.Error(), }, + { + "simulate using latest block", + "0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF", + "", + "$(foo)", + "0", + "", + "latest", + nil, + pipeline.NewVarsFrom(map[string]interface{}{ + "foo": []byte("foo bar"), + }), + nil, + func(ethClient *evmclimocks.Client, config *pipelinemocks.Config) { + contractAddr := common.HexToAddress("0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF") + ethClient. + On("CallContract", mock.Anything, ethereum.CallMsg{To: &contractAddr, Gas: uint64(drJobTypeGasLimit), Data: []byte("foo bar")}, (*big.Int)(nil)). + Return([]byte("baz quux"), nil) + }, + []byte("baz quux"), nil, "", + }, + { + "simulate using pending block", + "0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF", + "", + "$(foo)", + "0", + "", + "pending", + nil, + pipeline.NewVarsFrom(map[string]interface{}{ + "foo": []byte("foo bar"), + }), + nil, + func(ethClient *evmclimocks.Client, config *pipelinemocks.Config) { + contractAddr := common.HexToAddress("0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF") + ethClient. + On("PendingCallContract", mock.Anything, ethereum.CallMsg{To: &contractAddr, Gas: uint64(drJobTypeGasLimit), Data: []byte("foo bar")}). + Return([]byte("baz quux"), nil) + }, + []byte("baz quux"), nil, "", + }, } for _, test := range tests {