diff --git a/.mockery.yaml b/.mockery.yaml index 4d37ea5..4f123f4 100644 --- a/.mockery.yaml +++ b/.mockery.yaml @@ -2,7 +2,7 @@ with-expecter: true packages: github.com/rollkit/go-execution: interfaces: - Execute: + Executor: config: dir: mocks outpkg: mocks diff --git a/Makefile b/Makefile index bee687c..38dbc08 100644 --- a/Makefile +++ b/Makefile @@ -89,8 +89,8 @@ proto-lint: check-proto-deps .PHONY: proto-lint ## mock-gen: Re-generates DA mock -mock-gen: mocks/Execute.go +mock-gen: mocks/mock_Executor.go .PHONY: mock-gen -mocks/Execute.go: execution.go .mockery.yaml +mocks/mock_Executor.go: execution.go .mockery.yaml @mockery \ No newline at end of file diff --git a/mocks/mock_Execute.go b/mocks/mock_Execute.go deleted file mode 100644 index d561d3d..0000000 --- a/mocks/mock_Execute.go +++ /dev/null @@ -1,276 +0,0 @@ -// Code generated by mockery v2.46.3. DO NOT EDIT. - -package mocks - -import ( - time "time" - - mock "github.com/stretchr/testify/mock" - - types "github.com/rollkit/go-execution/types" -) - -// MockExecute is an autogenerated mock type for the Execute type -type MockExecute struct { - mock.Mock -} - -type MockExecute_Expecter struct { - mock *mock.Mock -} - -func (_m *MockExecute) EXPECT() *MockExecute_Expecter { - return &MockExecute_Expecter{mock: &_m.Mock} -} - -// ExecuteTxs provides a mock function with given fields: txs, blockHeight, timestamp, prevStateRoot -func (_m *MockExecute) ExecuteTxs(txs []types.Tx, blockHeight uint64, timestamp time.Time, prevStateRoot types.Hash) (types.Hash, uint64, error) { - ret := _m.Called(txs, blockHeight, timestamp, prevStateRoot) - - if len(ret) == 0 { - panic("no return value specified for ExecuteTxs") - } - - var r0 types.Hash - var r1 uint64 - var r2 error - if rf, ok := ret.Get(0).(func([]types.Tx, uint64, time.Time, types.Hash) (types.Hash, uint64, error)); ok { - return rf(txs, blockHeight, timestamp, prevStateRoot) - } - if rf, ok := ret.Get(0).(func([]types.Tx, uint64, time.Time, types.Hash) types.Hash); ok { - r0 = rf(txs, blockHeight, timestamp, prevStateRoot) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(types.Hash) - } - } - - if rf, ok := ret.Get(1).(func([]types.Tx, uint64, time.Time, types.Hash) uint64); ok { - r1 = rf(txs, blockHeight, timestamp, prevStateRoot) - } else { - r1 = ret.Get(1).(uint64) - } - - if rf, ok := ret.Get(2).(func([]types.Tx, uint64, time.Time, types.Hash) error); ok { - r2 = rf(txs, blockHeight, timestamp, prevStateRoot) - } else { - r2 = ret.Error(2) - } - - return r0, r1, r2 -} - -// MockExecute_ExecuteTxs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ExecuteTxs' -type MockExecute_ExecuteTxs_Call struct { - *mock.Call -} - -// ExecuteTxs is a helper method to define mock.On call -// - txs []types.Tx -// - blockHeight uint64 -// - timestamp time.Time -// - prevStateRoot types.Hash -func (_e *MockExecute_Expecter) ExecuteTxs(txs interface{}, blockHeight interface{}, timestamp interface{}, prevStateRoot interface{}) *MockExecute_ExecuteTxs_Call { - return &MockExecute_ExecuteTxs_Call{Call: _e.mock.On("ExecuteTxs", txs, blockHeight, timestamp, prevStateRoot)} -} - -func (_c *MockExecute_ExecuteTxs_Call) Run(run func(txs []types.Tx, blockHeight uint64, timestamp time.Time, prevStateRoot types.Hash)) *MockExecute_ExecuteTxs_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].([]types.Tx), args[1].(uint64), args[2].(time.Time), args[3].(types.Hash)) - }) - return _c -} - -func (_c *MockExecute_ExecuteTxs_Call) Return(updatedStateRoot types.Hash, maxBytes uint64, err error) *MockExecute_ExecuteTxs_Call { - _c.Call.Return(updatedStateRoot, maxBytes, err) - return _c -} - -func (_c *MockExecute_ExecuteTxs_Call) RunAndReturn(run func([]types.Tx, uint64, time.Time, types.Hash) (types.Hash, uint64, error)) *MockExecute_ExecuteTxs_Call { - _c.Call.Return(run) - return _c -} - -// GetTxs provides a mock function with given fields: -func (_m *MockExecute) GetTxs() ([]types.Tx, error) { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for GetTxs") - } - - var r0 []types.Tx - var r1 error - if rf, ok := ret.Get(0).(func() ([]types.Tx, error)); ok { - return rf() - } - if rf, ok := ret.Get(0).(func() []types.Tx); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]types.Tx) - } - } - - if rf, ok := ret.Get(1).(func() error); ok { - r1 = rf() - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// MockExecute_GetTxs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetTxs' -type MockExecute_GetTxs_Call struct { - *mock.Call -} - -// GetTxs is a helper method to define mock.On call -func (_e *MockExecute_Expecter) GetTxs() *MockExecute_GetTxs_Call { - return &MockExecute_GetTxs_Call{Call: _e.mock.On("GetTxs")} -} - -func (_c *MockExecute_GetTxs_Call) Run(run func()) *MockExecute_GetTxs_Call { - _c.Call.Run(func(args mock.Arguments) { - run() - }) - return _c -} - -func (_c *MockExecute_GetTxs_Call) Return(_a0 []types.Tx, _a1 error) *MockExecute_GetTxs_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *MockExecute_GetTxs_Call) RunAndReturn(run func() ([]types.Tx, error)) *MockExecute_GetTxs_Call { - _c.Call.Return(run) - return _c -} - -// InitChain provides a mock function with given fields: genesisTime, initialHeight, chainID -func (_m *MockExecute) InitChain(genesisTime time.Time, initialHeight uint64, chainID string) (types.Hash, uint64, error) { - ret := _m.Called(genesisTime, initialHeight, chainID) - - if len(ret) == 0 { - panic("no return value specified for InitChain") - } - - var r0 types.Hash - var r1 uint64 - var r2 error - if rf, ok := ret.Get(0).(func(time.Time, uint64, string) (types.Hash, uint64, error)); ok { - return rf(genesisTime, initialHeight, chainID) - } - if rf, ok := ret.Get(0).(func(time.Time, uint64, string) types.Hash); ok { - r0 = rf(genesisTime, initialHeight, chainID) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(types.Hash) - } - } - - if rf, ok := ret.Get(1).(func(time.Time, uint64, string) uint64); ok { - r1 = rf(genesisTime, initialHeight, chainID) - } else { - r1 = ret.Get(1).(uint64) - } - - if rf, ok := ret.Get(2).(func(time.Time, uint64, string) error); ok { - r2 = rf(genesisTime, initialHeight, chainID) - } else { - r2 = ret.Error(2) - } - - return r0, r1, r2 -} - -// MockExecute_InitChain_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'InitChain' -type MockExecute_InitChain_Call struct { - *mock.Call -} - -// InitChain is a helper method to define mock.On call -// - genesisTime time.Time -// - initialHeight uint64 -// - chainID string -func (_e *MockExecute_Expecter) InitChain(genesisTime interface{}, initialHeight interface{}, chainID interface{}) *MockExecute_InitChain_Call { - return &MockExecute_InitChain_Call{Call: _e.mock.On("InitChain", genesisTime, initialHeight, chainID)} -} - -func (_c *MockExecute_InitChain_Call) Run(run func(genesisTime time.Time, initialHeight uint64, chainID string)) *MockExecute_InitChain_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(time.Time), args[1].(uint64), args[2].(string)) - }) - return _c -} - -func (_c *MockExecute_InitChain_Call) Return(stateRoot types.Hash, maxBytes uint64, err error) *MockExecute_InitChain_Call { - _c.Call.Return(stateRoot, maxBytes, err) - return _c -} - -func (_c *MockExecute_InitChain_Call) RunAndReturn(run func(time.Time, uint64, string) (types.Hash, uint64, error)) *MockExecute_InitChain_Call { - _c.Call.Return(run) - return _c -} - -// SetFinal provides a mock function with given fields: blockHeight -func (_m *MockExecute) SetFinal(blockHeight uint64) error { - ret := _m.Called(blockHeight) - - if len(ret) == 0 { - panic("no return value specified for SetFinal") - } - - var r0 error - if rf, ok := ret.Get(0).(func(uint64) error); ok { - r0 = rf(blockHeight) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// MockExecute_SetFinal_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetFinal' -type MockExecute_SetFinal_Call struct { - *mock.Call -} - -// SetFinal is a helper method to define mock.On call -// - blockHeight uint64 -func (_e *MockExecute_Expecter) SetFinal(blockHeight interface{}) *MockExecute_SetFinal_Call { - return &MockExecute_SetFinal_Call{Call: _e.mock.On("SetFinal", blockHeight)} -} - -func (_c *MockExecute_SetFinal_Call) Run(run func(blockHeight uint64)) *MockExecute_SetFinal_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(uint64)) - }) - return _c -} - -func (_c *MockExecute_SetFinal_Call) Return(_a0 error) *MockExecute_SetFinal_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *MockExecute_SetFinal_Call) RunAndReturn(run func(uint64) error) *MockExecute_SetFinal_Call { - _c.Call.Return(run) - return _c -} - -// NewMockExecute creates a new instance of MockExecute. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewMockExecute(t interface { - mock.TestingT - Cleanup(func()) -}) *MockExecute { - mock := &MockExecute{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/mocks/mock_Executor.go b/mocks/mock_Executor.go new file mode 100644 index 0000000..7245228 --- /dev/null +++ b/mocks/mock_Executor.go @@ -0,0 +1,277 @@ +// Code generated by mockery v2.46.0. DO NOT EDIT. + +package mocks + +import ( + header "github.com/celestiaorg/go-header" + mock "github.com/stretchr/testify/mock" + + time "time" + + types "github.com/rollkit/go-execution/types" +) + +// MockExecutor is an autogenerated mock type for the Executor type +type MockExecutor struct { + mock.Mock +} + +type MockExecutor_Expecter struct { + mock *mock.Mock +} + +func (_m *MockExecutor) EXPECT() *MockExecutor_Expecter { + return &MockExecutor_Expecter{mock: &_m.Mock} +} + +// ExecuteTxs provides a mock function with given fields: txs, blockHeight, timestamp, prevStateRoot +func (_m *MockExecutor) ExecuteTxs(txs []types.Tx, blockHeight uint64, timestamp time.Time, prevStateRoot header.Hash) (header.Hash, uint64, error) { + ret := _m.Called(txs, blockHeight, timestamp, prevStateRoot) + + if len(ret) == 0 { + panic("no return value specified for ExecuteTxs") + } + + var r0 header.Hash + var r1 uint64 + var r2 error + if rf, ok := ret.Get(0).(func([]types.Tx, uint64, time.Time, header.Hash) (header.Hash, uint64, error)); ok { + return rf(txs, blockHeight, timestamp, prevStateRoot) + } + if rf, ok := ret.Get(0).(func([]types.Tx, uint64, time.Time, header.Hash) header.Hash); ok { + r0 = rf(txs, blockHeight, timestamp, prevStateRoot) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(header.Hash) + } + } + + if rf, ok := ret.Get(1).(func([]types.Tx, uint64, time.Time, header.Hash) uint64); ok { + r1 = rf(txs, blockHeight, timestamp, prevStateRoot) + } else { + r1 = ret.Get(1).(uint64) + } + + if rf, ok := ret.Get(2).(func([]types.Tx, uint64, time.Time, header.Hash) error); ok { + r2 = rf(txs, blockHeight, timestamp, prevStateRoot) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockExecutor_ExecuteTxs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ExecuteTxs' +type MockExecutor_ExecuteTxs_Call struct { + *mock.Call +} + +// ExecuteTxs is a helper method to define mock.On call +// - txs []types.Tx +// - blockHeight uint64 +// - timestamp time.Time +// - prevStateRoot header.Hash +func (_e *MockExecutor_Expecter) ExecuteTxs(txs interface{}, blockHeight interface{}, timestamp interface{}, prevStateRoot interface{}) *MockExecutor_ExecuteTxs_Call { + return &MockExecutor_ExecuteTxs_Call{Call: _e.mock.On("ExecuteTxs", txs, blockHeight, timestamp, prevStateRoot)} +} + +func (_c *MockExecutor_ExecuteTxs_Call) Run(run func(txs []types.Tx, blockHeight uint64, timestamp time.Time, prevStateRoot header.Hash)) *MockExecutor_ExecuteTxs_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].([]types.Tx), args[1].(uint64), args[2].(time.Time), args[3].(header.Hash)) + }) + return _c +} + +func (_c *MockExecutor_ExecuteTxs_Call) Return(updatedStateRoot header.Hash, maxBytes uint64, err error) *MockExecutor_ExecuteTxs_Call { + _c.Call.Return(updatedStateRoot, maxBytes, err) + return _c +} + +func (_c *MockExecutor_ExecuteTxs_Call) RunAndReturn(run func([]types.Tx, uint64, time.Time, header.Hash) (header.Hash, uint64, error)) *MockExecutor_ExecuteTxs_Call { + _c.Call.Return(run) + return _c +} + +// GetTxs provides a mock function with given fields: +func (_m *MockExecutor) GetTxs() ([]types.Tx, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetTxs") + } + + var r0 []types.Tx + var r1 error + if rf, ok := ret.Get(0).(func() ([]types.Tx, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() []types.Tx); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]types.Tx) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MockExecutor_GetTxs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetTxs' +type MockExecutor_GetTxs_Call struct { + *mock.Call +} + +// GetTxs is a helper method to define mock.On call +func (_e *MockExecutor_Expecter) GetTxs() *MockExecutor_GetTxs_Call { + return &MockExecutor_GetTxs_Call{Call: _e.mock.On("GetTxs")} +} + +func (_c *MockExecutor_GetTxs_Call) Run(run func()) *MockExecutor_GetTxs_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockExecutor_GetTxs_Call) Return(_a0 []types.Tx, _a1 error) *MockExecutor_GetTxs_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MockExecutor_GetTxs_Call) RunAndReturn(run func() ([]types.Tx, error)) *MockExecutor_GetTxs_Call { + _c.Call.Return(run) + return _c +} + +// InitChain provides a mock function with given fields: genesisTime, initialHeight, chainID +func (_m *MockExecutor) InitChain(genesisTime time.Time, initialHeight uint64, chainID string) (header.Hash, uint64, error) { + ret := _m.Called(genesisTime, initialHeight, chainID) + + if len(ret) == 0 { + panic("no return value specified for InitChain") + } + + var r0 header.Hash + var r1 uint64 + var r2 error + if rf, ok := ret.Get(0).(func(time.Time, uint64, string) (header.Hash, uint64, error)); ok { + return rf(genesisTime, initialHeight, chainID) + } + if rf, ok := ret.Get(0).(func(time.Time, uint64, string) header.Hash); ok { + r0 = rf(genesisTime, initialHeight, chainID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(header.Hash) + } + } + + if rf, ok := ret.Get(1).(func(time.Time, uint64, string) uint64); ok { + r1 = rf(genesisTime, initialHeight, chainID) + } else { + r1 = ret.Get(1).(uint64) + } + + if rf, ok := ret.Get(2).(func(time.Time, uint64, string) error); ok { + r2 = rf(genesisTime, initialHeight, chainID) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MockExecutor_InitChain_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'InitChain' +type MockExecutor_InitChain_Call struct { + *mock.Call +} + +// InitChain is a helper method to define mock.On call +// - genesisTime time.Time +// - initialHeight uint64 +// - chainID string +func (_e *MockExecutor_Expecter) InitChain(genesisTime interface{}, initialHeight interface{}, chainID interface{}) *MockExecutor_InitChain_Call { + return &MockExecutor_InitChain_Call{Call: _e.mock.On("InitChain", genesisTime, initialHeight, chainID)} +} + +func (_c *MockExecutor_InitChain_Call) Run(run func(genesisTime time.Time, initialHeight uint64, chainID string)) *MockExecutor_InitChain_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(time.Time), args[1].(uint64), args[2].(string)) + }) + return _c +} + +func (_c *MockExecutor_InitChain_Call) Return(stateRoot header.Hash, maxBytes uint64, err error) *MockExecutor_InitChain_Call { + _c.Call.Return(stateRoot, maxBytes, err) + return _c +} + +func (_c *MockExecutor_InitChain_Call) RunAndReturn(run func(time.Time, uint64, string) (header.Hash, uint64, error)) *MockExecutor_InitChain_Call { + _c.Call.Return(run) + return _c +} + +// SetFinal provides a mock function with given fields: blockHeight +func (_m *MockExecutor) SetFinal(blockHeight uint64) error { + ret := _m.Called(blockHeight) + + if len(ret) == 0 { + panic("no return value specified for SetFinal") + } + + var r0 error + if rf, ok := ret.Get(0).(func(uint64) error); ok { + r0 = rf(blockHeight) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MockExecutor_SetFinal_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetFinal' +type MockExecutor_SetFinal_Call struct { + *mock.Call +} + +// SetFinal is a helper method to define mock.On call +// - blockHeight uint64 +func (_e *MockExecutor_Expecter) SetFinal(blockHeight interface{}) *MockExecutor_SetFinal_Call { + return &MockExecutor_SetFinal_Call{Call: _e.mock.On("SetFinal", blockHeight)} +} + +func (_c *MockExecutor_SetFinal_Call) Run(run func(blockHeight uint64)) *MockExecutor_SetFinal_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(uint64)) + }) + return _c +} + +func (_c *MockExecutor_SetFinal_Call) Return(_a0 error) *MockExecutor_SetFinal_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MockExecutor_SetFinal_Call) RunAndReturn(run func(uint64) error) *MockExecutor_SetFinal_Call { + _c.Call.Return(run) + return _c +} + +// NewMockExecutor creates a new instance of MockExecutor. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockExecutor(t interface { + mock.TestingT + Cleanup(func()) +}) *MockExecutor { + mock := &MockExecutor{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/proxy/grpc/client_server_test.go b/proxy/grpc/client_server_test.go index 0c4e86e..14b22b5 100644 --- a/proxy/grpc/client_server_test.go +++ b/proxy/grpc/client_server_test.go @@ -17,7 +17,7 @@ import ( ) func TestClientServer(t *testing.T) { - mockExec := mocks.NewMockExecute(t) + mockExec := mocks.NewMockExecutor(t) config := &grpcproxy.Config{ DefaultTimeout: 5 * time.Second, MaxRequestSize: bufSize, diff --git a/proxy/jsonrpc/client_server_test.go b/proxy/jsonrpc/client_server_test.go index 02b82b7..2295663 100644 --- a/proxy/jsonrpc/client_server_test.go +++ b/proxy/jsonrpc/client_server_test.go @@ -14,7 +14,7 @@ import ( ) func TestClientServer(t *testing.T) { - mockExec := mocks.NewMockExecute(t) + mockExec := mocks.NewMockExecutor(t) config := &jsonrpcproxy.Config{ DefaultTimeout: 5 * time.Second, MaxRequestSize: 1024 * 1024,