diff --git a/action/protocol/execution/evm/evm_test.go b/action/protocol/execution/evm/evm_test.go index 1108dd1505..e8781b7ab2 100644 --- a/action/protocol/execution/evm/evm_test.go +++ b/action/protocol/execution/evm/evm_test.go @@ -60,13 +60,16 @@ func TestExecuteContractFailure(t *testing.T) { ChainID: 1, EvmNetworkID: 100, }) - retval, receipt, err := ExecuteContract(ctx, sm, e, - func(uint64) (hash.Hash256, error) { + ctx = WithHelperCtx(ctx, HelperContext{ + GetBlockHash: func(uint64) (hash.Hash256, error) { return hash.ZeroHash256, nil }, - func(context.Context, protocol.StateManager, address.Address, *big.Int, *big.Int) (*action.TransactionLog, error) { + DepositGasFunc: func(context.Context, protocol.StateManager, address.Address, *big.Int, *big.Int) (*action.TransactionLog, error) { return nil, nil - }, nil) + }, + Sgd: nil, + }) + retval, receipt, err := ExecuteContract(ctx, sm, e) require.Nil(t, retval) require.Nil(t, receipt) require.Error(t, err) @@ -255,11 +258,14 @@ func TestConstantinople(t *testing.T) { GasLimit: testutil.TestGasLimit, BlockHeight: e.height, })) + fCtx = WithHelperCtx(fCtx, HelperContext{ + GetBlockHash: func(uint64) (hash.Hash256, error) { + return hash.ZeroHash256, nil + }, + }) stateDB, err := prepareStateDB(fCtx, sm) require.NoError(err) - ps, err := newParams(fCtx, ex, stateDB, func(uint64) (hash.Hash256, error) { - return hash.ZeroHash256, nil - }) + ps, err := newParams(fCtx, ex, stateDB) require.NoError(err) var evmConfig vm.Config diff --git a/action/protocol/execution/protocol_test.go b/action/protocol/execution/protocol_test.go index fe5664d89a..d33fb28aa5 100644 --- a/action/protocol/execution/protocol_test.go +++ b/action/protocol/execution/protocol_test.go @@ -283,8 +283,10 @@ func readExecution( if err != nil { return nil, nil, err } - - return sf.SimulateExecution(ctx, addr, exec, dao.GetBlockHash) + ctx = evm.WithHelperCtx(ctx, evm.HelperContext{ + GetBlockHash: dao.GetBlockHash, + }) + return sf.SimulateExecution(ctx, addr, exec) } func runExecutions( diff --git a/e2etest/staking_test.go b/e2etest/staking_test.go index 316aeeac8a..1c1a1b58bc 100644 --- a/e2etest/staking_test.go +++ b/e2etest/staking_test.go @@ -22,6 +22,7 @@ import ( "github.com/iotexproject/iotex-core/action" "github.com/iotexproject/iotex-core/action/protocol" + "github.com/iotexproject/iotex-core/action/protocol/execution/evm" "github.com/iotexproject/iotex-core/action/protocol/poll" "github.com/iotexproject/iotex-core/blockchain/genesis" "github.com/iotexproject/iotex-core/config" @@ -121,7 +122,10 @@ func TestStakingContract(t *testing.T) { return nil, err } - data, _, err := sf.SimulateExecution(ctx, addr, ex, dao.GetBlockHash) + ctx = evm.WithHelperCtx(ctx, evm.HelperContext{ + GetBlockHash: dao.GetBlockHash, + }) + data, _, err := sf.SimulateExecution(ctx, addr, ex) return data, err }) diff --git a/state/factory/factory_test.go b/state/factory/factory_test.go index 8b229e422b..9f15e4f7b3 100644 --- a/state/factory/factory_test.go +++ b/state/factory/factory_test.go @@ -30,6 +30,7 @@ import ( "github.com/iotexproject/iotex-core/action/protocol" "github.com/iotexproject/iotex-core/action/protocol/account" accountutil "github.com/iotexproject/iotex-core/action/protocol/account/util" + "github.com/iotexproject/iotex-core/action/protocol/execution/evm" "github.com/iotexproject/iotex-core/action/protocol/poll" "github.com/iotexproject/iotex-core/action/protocol/rewarding" "github.com/iotexproject/iotex-core/action/protocol/rolldpos" @@ -1223,9 +1224,12 @@ func testSimulateExecution(ctx context.Context, sf Factory, t *testing.T) { addr, err := address.FromString(address.ZeroAddress) require.NoError(err) - _, _, err = sf.SimulateExecution(ctx, addr, ex, func(uint64) (hash.Hash256, error) { - return hash.ZeroHash256, nil + ctx = evm.WithHelperCtx(ctx, evm.HelperContext{ + GetBlockHash: func(uint64) (hash.Hash256, error) { + return hash.ZeroHash256, nil + }, }) + _, _, err = sf.SimulateExecution(ctx, addr, ex) require.NoError(err) } diff --git a/test/mock/mock_factory/mock_factory.go b/test/mock/mock_factory/mock_factory.go index 65ed2dac26..2aed6bd37d 100644 --- a/test/mock/mock_factory/mock_factory.go +++ b/test/mock/mock_factory/mock_factory.go @@ -12,7 +12,6 @@ import ( address "github.com/iotexproject/iotex-address/address" action "github.com/iotexproject/iotex-core/action" protocol "github.com/iotexproject/iotex-core/action/protocol" - evm "github.com/iotexproject/iotex-core/action/protocol/execution/evm" actpool "github.com/iotexproject/iotex-core/actpool" block "github.com/iotexproject/iotex-core/blockchain/block" state "github.com/iotexproject/iotex-core/state" @@ -144,9 +143,9 @@ func (mr *MockFactoryMockRecorder) Register(arg0 interface{}) *gomock.Call { } // SimulateExecution mocks base method. -func (m *MockFactory) SimulateExecution(arg0 context.Context, arg1 address.Address, arg2 *action.Execution, arg3 evm.GetBlockHash) ([]byte, *action.Receipt, error) { +func (m *MockFactory) SimulateExecution(arg0 context.Context, arg1 address.Address, arg2 *action.Execution) ([]byte, *action.Receipt, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SimulateExecution", arg0, arg1, arg2, arg3) + ret := m.ctrl.Call(m, "SimulateExecution", arg0, arg1, arg2) ret0, _ := ret[0].([]byte) ret1, _ := ret[1].(*action.Receipt) ret2, _ := ret[2].(error) @@ -154,9 +153,9 @@ func (m *MockFactory) SimulateExecution(arg0 context.Context, arg1 address.Addre } // SimulateExecution indicates an expected call of SimulateExecution. -func (mr *MockFactoryMockRecorder) SimulateExecution(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { +func (mr *MockFactoryMockRecorder) SimulateExecution(arg0, arg1, arg2 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SimulateExecution", reflect.TypeOf((*MockFactory)(nil).SimulateExecution), arg0, arg1, arg2, arg3) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SimulateExecution", reflect.TypeOf((*MockFactory)(nil).SimulateExecution), arg0, arg1, arg2) } // Start mocks base method.