From d9e0c8ed1dc25ee7317c16b29e74f40e20c7e392 Mon Sep 17 00:00:00 2001 From: begmaroman Date: Tue, 23 Jan 2024 08:58:55 +0100 Subject: [PATCH 1/2] Added mockery configuration --- .mockery.yaml | 45 +++++ Makefile | 2 +- client/client.go | 26 ++- client/client_test.go | 2 +- db/db.go | 4 - etherman/etherman.go | 2 - mocks/client.generated.go | 81 +++++++- mocks/client_factory.generated.go | 47 ----- mocks/clientfactory.generated.go | 83 ++++++++ mocks/db.generated.go | 185 ++++++++++++++++++ mocks/eth_client.generated.go | 67 +++++++ mocks/eth_client_factory.generated.go | 37 ++++ mocks/etherman.generated.go | 261 ++++++++++++++++++++++++++ mocks/sequencer_tracker.generated.go | 36 ++++ mocks/subscription.generated.go | 62 ++++++ mocks/tx.generated.go | 210 +++++++++++++++++++++ sequencer/tracker.go | 2 - sequencer/tracker_test.go | 2 - synchronizer/batches.go | 4 +- synchronizer/batches_test.go | 4 +- test/e2e/e2e_test.go | 2 +- types/factories.go | 4 - 22 files changed, 1077 insertions(+), 91 deletions(-) create mode 100644 .mockery.yaml delete mode 100644 mocks/client_factory.generated.go create mode 100644 mocks/clientfactory.generated.go diff --git a/.mockery.yaml b/.mockery.yaml new file mode 100644 index 00000000..ac8e3600 --- /dev/null +++ b/.mockery.yaml @@ -0,0 +1,45 @@ +with-expecter: true +dir: "mocks" +filename: "{{.InterfaceName | lower }}.generated.go" +mockname: "{{.InterfaceName}}" +outpkg: "mocks" +packages: + github.com/ethereum/go-ethereum/event: + config: + interfaces: + Subscription: + config: + github.com/0xPolygon/cdk-data-availability/db: + config: + interfaces: + DB: + config: + Tx: + config: + github.com/0xPolygon/cdk-data-availability/client: + config: + interfaces: + ClientFactory: + config: + Client: + config: + github.com/0xPolygon/cdk-data-availability/etherman: + config: + interfaces: + Etherman: + config: + github.com/0xPolygon/cdk-data-availability/sequencer: + config: + interfaces: + ISequencerTracker: + config: + filename: sequencer_tracker.generated.go + github.com/0xPolygon/cdk-data-availability/types: + config: + interfaces: + IEthClient: + config: + filename: eth_client.generated.go + IEthClientFactory: + config: + filename: eth_client_factory.generated.go \ No newline at end of file diff --git a/Makefile b/Makefile index 4dface90..ef9fff9a 100644 --- a/Makefile +++ b/Makefile @@ -58,7 +58,7 @@ LDFLAGS += -X 'github.com/0xPolygon/cdk-data-availability.BuildDate=$(DATE)' .PHONY: generate generate: ## Generates mocks and other autogenerated types - $(GOENVVARS) go generate ./... + mockery .PHONY: build build: ## Builds the binary locally into ./dist diff --git a/client/client.go b/client/client.go index a486b6b1..8b8df0fc 100644 --- a/client/client.go +++ b/client/client.go @@ -10,17 +10,13 @@ import ( "github.com/ethereum/go-ethereum/common" ) -// IClientFactory interface for the client factory -// -//go:generate mockery --name IClientFactory --output ../mocks --case=underscore --filename client_factory.generated.go -type IClientFactory interface { - New(url string) IClient +// ClientFactory interface for the client factory +type ClientFactory interface { + New(url string) Client } -// IClient is the interface that defines the implementation of all the endpoints -// -//go:generate mockery --name IClient --output ../mocks --case=underscore --filename client.generated.go -type IClient interface { +// Client is the interface that defines the implementation of all the endpoints +type Client interface { GetOffChainData(ctx context.Context, hash common.Hash) ([]byte, error) SignSequence(signedSequence types.SignedSequence) ([]byte, error) } @@ -29,25 +25,25 @@ type IClient interface { type Factory struct{} // New returns an implementation of the data committee node client -func (f *Factory) New(url string) IClient { +func (f *Factory) New(url string) Client { return New(url) } // Client wraps all the available endpoints of the data abailability committee node server -type Client struct { +type client struct { url string } // New returns a client ready to be used -func New(url string) *Client { - return &Client{ +func New(url string) *client { + return &client{ url: url, } } // SignSequence sends a request to sign the given sequence by the data committee member // if successful returns the signature. The signature should be validated after using this method! -func (c *Client) SignSequence(signedSequence types.SignedSequence) ([]byte, error) { +func (c *client) SignSequence(signedSequence types.SignedSequence) ([]byte, error) { response, err := rpc.JSONRPCCall(c.url, "datacom_signSequence", signedSequence) if err != nil { return nil, err @@ -66,7 +62,7 @@ func (c *Client) SignSequence(signedSequence types.SignedSequence) ([]byte, erro } // GetOffChainData returns data based on it's hash -func (c *Client) GetOffChainData(ctx context.Context, hash common.Hash) ([]byte, error) { +func (c *client) GetOffChainData(ctx context.Context, hash common.Hash) ([]byte, error) { response, err := rpc.JSONRPCCallWithContext(ctx, c.url, "sync_getOffChainData", hash) if err != nil { return nil, err diff --git a/client/client_test.go b/client/client_test.go index 0a52ae6d..2eb73530 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -156,7 +156,7 @@ func TestClient_GetOffChainData(t *testing.T) { })) defer svr.Close() - c := &Client{url: svr.URL} + c := &client{url: svr.URL} got, err := c.GetOffChainData(context.Background(), tt.hash) if tt.err != nil { diff --git a/db/db.go b/db/db.go index 4a2adbe2..db1aad18 100644 --- a/db/db.go +++ b/db/db.go @@ -17,8 +17,6 @@ var ( ) // DB defines functions that a DB instance should implement -// -//go:generate mockery --name DB --output ../mocks --case=underscore --filename db.generated.go type DB interface { BeginStateTransaction(ctx context.Context) (Tx, error) Exists(ctx context.Context, key common.Hash) bool @@ -29,8 +27,6 @@ type DB interface { } // Tx is the interface that defines functions a db tx has to implement -// -//go:generate mockery --name Tx --output ../mocks --case=underscore --filename tx.generated.go type Tx interface { sqlx.ExecerContext sqlx.QueryerContext diff --git a/etherman/etherman.go b/etherman/etherman.go index ff24d1e9..0b41f9c8 100644 --- a/etherman/etherman.go +++ b/etherman/etherman.go @@ -17,8 +17,6 @@ import ( ) // Etherman defines functions that should be implemented by Etherman -// -//go:generate mockery --name Etherman --output ../mocks --case=underscore --filename etherman.generated.go type Etherman interface { GetCurrentDataCommittee() (*DataCommittee, error) GetCurrentDataCommitteeMembers() ([]DataCommitteeMember, error) diff --git a/mocks/client.generated.go b/mocks/client.generated.go index b92d1f88..333f1c35 100644 --- a/mocks/client.generated.go +++ b/mocks/client.generated.go @@ -12,13 +12,21 @@ import ( types "github.com/0xPolygon/cdk-data-availability/types" ) -// IClient is an autogenerated mock type for the IClient type -type IClient struct { +// Client is an autogenerated mock type for the Client type +type Client struct { mock.Mock } +type Client_Expecter struct { + mock *mock.Mock +} + +func (_m *Client) EXPECT() *Client_Expecter { + return &Client_Expecter{mock: &_m.Mock} +} + // GetOffChainData provides a mock function with given fields: ctx, hash -func (_m *IClient) GetOffChainData(ctx context.Context, hash common.Hash) ([]byte, error) { +func (_m *Client) GetOffChainData(ctx context.Context, hash common.Hash) ([]byte, error) { ret := _m.Called(ctx, hash) if len(ret) == 0 { @@ -47,8 +55,37 @@ func (_m *IClient) GetOffChainData(ctx context.Context, hash common.Hash) ([]byt return r0, r1 } +// Client_GetOffChainData_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetOffChainData' +type Client_GetOffChainData_Call struct { + *mock.Call +} + +// GetOffChainData is a helper method to define mock.On call +// - ctx context.Context +// - hash common.Hash +func (_e *Client_Expecter) GetOffChainData(ctx interface{}, hash interface{}) *Client_GetOffChainData_Call { + return &Client_GetOffChainData_Call{Call: _e.mock.On("GetOffChainData", ctx, hash)} +} + +func (_c *Client_GetOffChainData_Call) Run(run func(ctx context.Context, hash common.Hash)) *Client_GetOffChainData_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(common.Hash)) + }) + return _c +} + +func (_c *Client_GetOffChainData_Call) Return(_a0 []byte, _a1 error) *Client_GetOffChainData_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Client_GetOffChainData_Call) RunAndReturn(run func(context.Context, common.Hash) ([]byte, error)) *Client_GetOffChainData_Call { + _c.Call.Return(run) + return _c +} + // SignSequence provides a mock function with given fields: signedSequence -func (_m *IClient) SignSequence(signedSequence types.SignedSequence) ([]byte, error) { +func (_m *Client) SignSequence(signedSequence types.SignedSequence) ([]byte, error) { ret := _m.Called(signedSequence) if len(ret) == 0 { @@ -77,13 +114,41 @@ func (_m *IClient) SignSequence(signedSequence types.SignedSequence) ([]byte, er return r0, r1 } -// NewIClient creates a new instance of IClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// Client_SignSequence_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SignSequence' +type Client_SignSequence_Call struct { + *mock.Call +} + +// SignSequence is a helper method to define mock.On call +// - signedSequence types.SignedSequence +func (_e *Client_Expecter) SignSequence(signedSequence interface{}) *Client_SignSequence_Call { + return &Client_SignSequence_Call{Call: _e.mock.On("SignSequence", signedSequence)} +} + +func (_c *Client_SignSequence_Call) Run(run func(signedSequence types.SignedSequence)) *Client_SignSequence_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(types.SignedSequence)) + }) + return _c +} + +func (_c *Client_SignSequence_Call) Return(_a0 []byte, _a1 error) *Client_SignSequence_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Client_SignSequence_Call) RunAndReturn(run func(types.SignedSequence) ([]byte, error)) *Client_SignSequence_Call { + _c.Call.Return(run) + return _c +} + +// NewClient creates a new instance of Client. 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 NewIClient(t interface { +func NewClient(t interface { mock.TestingT Cleanup(func()) -}) *IClient { - mock := &IClient{} +}) *Client { + mock := &Client{} mock.Mock.Test(t) t.Cleanup(func() { mock.AssertExpectations(t) }) diff --git a/mocks/client_factory.generated.go b/mocks/client_factory.generated.go deleted file mode 100644 index 97008927..00000000 --- a/mocks/client_factory.generated.go +++ /dev/null @@ -1,47 +0,0 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. - -package mocks - -import ( - client "github.com/0xPolygon/cdk-data-availability/client" - mock "github.com/stretchr/testify/mock" -) - -// IClientFactory is an autogenerated mock type for the IClientFactory type -type IClientFactory struct { - mock.Mock -} - -// New provides a mock function with given fields: url -func (_m *IClientFactory) New(url string) client.IClient { - ret := _m.Called(url) - - if len(ret) == 0 { - panic("no return value specified for New") - } - - var r0 client.IClient - if rf, ok := ret.Get(0).(func(string) client.IClient); ok { - r0 = rf(url) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(client.IClient) - } - } - - return r0 -} - -// NewIClientFactory creates a new instance of IClientFactory. 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 NewIClientFactory(t interface { - mock.TestingT - Cleanup(func()) -}) *IClientFactory { - mock := &IClientFactory{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/mocks/clientfactory.generated.go b/mocks/clientfactory.generated.go new file mode 100644 index 00000000..64176b08 --- /dev/null +++ b/mocks/clientfactory.generated.go @@ -0,0 +1,83 @@ +// Code generated by mockery v2.38.0. DO NOT EDIT. + +package mocks + +import ( + client "github.com/0xPolygon/cdk-data-availability/client" + mock "github.com/stretchr/testify/mock" +) + +// ClientFactory is an autogenerated mock type for the ClientFactory type +type ClientFactory struct { + mock.Mock +} + +type ClientFactory_Expecter struct { + mock *mock.Mock +} + +func (_m *ClientFactory) EXPECT() *ClientFactory_Expecter { + return &ClientFactory_Expecter{mock: &_m.Mock} +} + +// New provides a mock function with given fields: url +func (_m *ClientFactory) New(url string) client.Client { + ret := _m.Called(url) + + if len(ret) == 0 { + panic("no return value specified for New") + } + + var r0 client.Client + if rf, ok := ret.Get(0).(func(string) client.Client); ok { + r0 = rf(url) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(client.Client) + } + } + + return r0 +} + +// ClientFactory_New_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'New' +type ClientFactory_New_Call struct { + *mock.Call +} + +// New is a helper method to define mock.On call +// - url string +func (_e *ClientFactory_Expecter) New(url interface{}) *ClientFactory_New_Call { + return &ClientFactory_New_Call{Call: _e.mock.On("New", url)} +} + +func (_c *ClientFactory_New_Call) Run(run func(url string)) *ClientFactory_New_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *ClientFactory_New_Call) Return(_a0 client.Client) *ClientFactory_New_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ClientFactory_New_Call) RunAndReturn(run func(string) client.Client) *ClientFactory_New_Call { + _c.Call.Return(run) + return _c +} + +// NewClientFactory creates a new instance of ClientFactory. 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 NewClientFactory(t interface { + mock.TestingT + Cleanup(func()) +}) *ClientFactory { + mock := &ClientFactory{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/db.generated.go b/mocks/db.generated.go index 221e5752..f893c772 100644 --- a/mocks/db.generated.go +++ b/mocks/db.generated.go @@ -21,6 +21,14 @@ type DB struct { mock.Mock } +type DB_Expecter struct { + mock *mock.Mock +} + +func (_m *DB) EXPECT() *DB_Expecter { + return &DB_Expecter{mock: &_m.Mock} +} + // BeginStateTransaction provides a mock function with given fields: ctx func (_m *DB) BeginStateTransaction(ctx context.Context) (db.Tx, error) { ret := _m.Called(ctx) @@ -51,6 +59,34 @@ func (_m *DB) BeginStateTransaction(ctx context.Context) (db.Tx, error) { return r0, r1 } +// DB_BeginStateTransaction_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'BeginStateTransaction' +type DB_BeginStateTransaction_Call struct { + *mock.Call +} + +// BeginStateTransaction is a helper method to define mock.On call +// - ctx context.Context +func (_e *DB_Expecter) BeginStateTransaction(ctx interface{}) *DB_BeginStateTransaction_Call { + return &DB_BeginStateTransaction_Call{Call: _e.mock.On("BeginStateTransaction", ctx)} +} + +func (_c *DB_BeginStateTransaction_Call) Run(run func(ctx context.Context)) *DB_BeginStateTransaction_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *DB_BeginStateTransaction_Call) Return(_a0 db.Tx, _a1 error) *DB_BeginStateTransaction_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *DB_BeginStateTransaction_Call) RunAndReturn(run func(context.Context) (db.Tx, error)) *DB_BeginStateTransaction_Call { + _c.Call.Return(run) + return _c +} + // Exists provides a mock function with given fields: ctx, key func (_m *DB) Exists(ctx context.Context, key common.Hash) bool { ret := _m.Called(ctx, key) @@ -69,6 +105,35 @@ func (_m *DB) Exists(ctx context.Context, key common.Hash) bool { return r0 } +// DB_Exists_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Exists' +type DB_Exists_Call struct { + *mock.Call +} + +// Exists is a helper method to define mock.On call +// - ctx context.Context +// - key common.Hash +func (_e *DB_Expecter) Exists(ctx interface{}, key interface{}) *DB_Exists_Call { + return &DB_Exists_Call{Call: _e.mock.On("Exists", ctx, key)} +} + +func (_c *DB_Exists_Call) Run(run func(ctx context.Context, key common.Hash)) *DB_Exists_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(common.Hash)) + }) + return _c +} + +func (_c *DB_Exists_Call) Return(_a0 bool) *DB_Exists_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *DB_Exists_Call) RunAndReturn(run func(context.Context, common.Hash) bool) *DB_Exists_Call { + _c.Call.Return(run) + return _c +} + // GetLastProcessedBlock provides a mock function with given fields: ctx, task func (_m *DB) GetLastProcessedBlock(ctx context.Context, task string) (uint64, error) { ret := _m.Called(ctx, task) @@ -97,6 +162,35 @@ func (_m *DB) GetLastProcessedBlock(ctx context.Context, task string) (uint64, e return r0, r1 } +// DB_GetLastProcessedBlock_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetLastProcessedBlock' +type DB_GetLastProcessedBlock_Call struct { + *mock.Call +} + +// GetLastProcessedBlock is a helper method to define mock.On call +// - ctx context.Context +// - task string +func (_e *DB_Expecter) GetLastProcessedBlock(ctx interface{}, task interface{}) *DB_GetLastProcessedBlock_Call { + return &DB_GetLastProcessedBlock_Call{Call: _e.mock.On("GetLastProcessedBlock", ctx, task)} +} + +func (_c *DB_GetLastProcessedBlock_Call) Run(run func(ctx context.Context, task string)) *DB_GetLastProcessedBlock_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *DB_GetLastProcessedBlock_Call) Return(_a0 uint64, _a1 error) *DB_GetLastProcessedBlock_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *DB_GetLastProcessedBlock_Call) RunAndReturn(run func(context.Context, string) (uint64, error)) *DB_GetLastProcessedBlock_Call { + _c.Call.Return(run) + return _c +} + // GetOffChainData provides a mock function with given fields: ctx, key, dbTx func (_m *DB) GetOffChainData(ctx context.Context, key common.Hash, dbTx sqlx.QueryerContext) (types.ArgBytes, error) { ret := _m.Called(ctx, key, dbTx) @@ -127,6 +221,36 @@ func (_m *DB) GetOffChainData(ctx context.Context, key common.Hash, dbTx sqlx.Qu return r0, r1 } +// DB_GetOffChainData_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetOffChainData' +type DB_GetOffChainData_Call struct { + *mock.Call +} + +// GetOffChainData is a helper method to define mock.On call +// - ctx context.Context +// - key common.Hash +// - dbTx sqlx.QueryerContext +func (_e *DB_Expecter) GetOffChainData(ctx interface{}, key interface{}, dbTx interface{}) *DB_GetOffChainData_Call { + return &DB_GetOffChainData_Call{Call: _e.mock.On("GetOffChainData", ctx, key, dbTx)} +} + +func (_c *DB_GetOffChainData_Call) Run(run func(ctx context.Context, key common.Hash, dbTx sqlx.QueryerContext)) *DB_GetOffChainData_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(common.Hash), args[2].(sqlx.QueryerContext)) + }) + return _c +} + +func (_c *DB_GetOffChainData_Call) Return(_a0 types.ArgBytes, _a1 error) *DB_GetOffChainData_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *DB_GetOffChainData_Call) RunAndReturn(run func(context.Context, common.Hash, sqlx.QueryerContext) (types.ArgBytes, error)) *DB_GetOffChainData_Call { + _c.Call.Return(run) + return _c +} + // StoreLastProcessedBlock provides a mock function with given fields: ctx, task, block, dbTx func (_m *DB) StoreLastProcessedBlock(ctx context.Context, task string, block uint64, dbTx sqlx.ExecerContext) error { ret := _m.Called(ctx, task, block, dbTx) @@ -145,6 +269,37 @@ func (_m *DB) StoreLastProcessedBlock(ctx context.Context, task string, block ui return r0 } +// DB_StoreLastProcessedBlock_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'StoreLastProcessedBlock' +type DB_StoreLastProcessedBlock_Call struct { + *mock.Call +} + +// StoreLastProcessedBlock is a helper method to define mock.On call +// - ctx context.Context +// - task string +// - block uint64 +// - dbTx sqlx.ExecerContext +func (_e *DB_Expecter) StoreLastProcessedBlock(ctx interface{}, task interface{}, block interface{}, dbTx interface{}) *DB_StoreLastProcessedBlock_Call { + return &DB_StoreLastProcessedBlock_Call{Call: _e.mock.On("StoreLastProcessedBlock", ctx, task, block, dbTx)} +} + +func (_c *DB_StoreLastProcessedBlock_Call) Run(run func(ctx context.Context, task string, block uint64, dbTx sqlx.ExecerContext)) *DB_StoreLastProcessedBlock_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(uint64), args[3].(sqlx.ExecerContext)) + }) + return _c +} + +func (_c *DB_StoreLastProcessedBlock_Call) Return(_a0 error) *DB_StoreLastProcessedBlock_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *DB_StoreLastProcessedBlock_Call) RunAndReturn(run func(context.Context, string, uint64, sqlx.ExecerContext) error) *DB_StoreLastProcessedBlock_Call { + _c.Call.Return(run) + return _c +} + // StoreOffChainData provides a mock function with given fields: ctx, od, dbTx func (_m *DB) StoreOffChainData(ctx context.Context, od []types.OffChainData, dbTx sqlx.ExecerContext) error { ret := _m.Called(ctx, od, dbTx) @@ -163,6 +318,36 @@ func (_m *DB) StoreOffChainData(ctx context.Context, od []types.OffChainData, db return r0 } +// DB_StoreOffChainData_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'StoreOffChainData' +type DB_StoreOffChainData_Call struct { + *mock.Call +} + +// StoreOffChainData is a helper method to define mock.On call +// - ctx context.Context +// - od []types.OffChainData +// - dbTx sqlx.ExecerContext +func (_e *DB_Expecter) StoreOffChainData(ctx interface{}, od interface{}, dbTx interface{}) *DB_StoreOffChainData_Call { + return &DB_StoreOffChainData_Call{Call: _e.mock.On("StoreOffChainData", ctx, od, dbTx)} +} + +func (_c *DB_StoreOffChainData_Call) Run(run func(ctx context.Context, od []types.OffChainData, dbTx sqlx.ExecerContext)) *DB_StoreOffChainData_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]types.OffChainData), args[2].(sqlx.ExecerContext)) + }) + return _c +} + +func (_c *DB_StoreOffChainData_Call) Return(_a0 error) *DB_StoreOffChainData_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *DB_StoreOffChainData_Call) RunAndReturn(run func(context.Context, []types.OffChainData, sqlx.ExecerContext) error) *DB_StoreOffChainData_Call { + _c.Call.Return(run) + return _c +} + // NewDB creates a new instance of DB. 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 NewDB(t interface { diff --git a/mocks/eth_client.generated.go b/mocks/eth_client.generated.go index 9e386284..be264b67 100644 --- a/mocks/eth_client.generated.go +++ b/mocks/eth_client.generated.go @@ -19,6 +19,14 @@ type IEthClient struct { mock.Mock } +type IEthClient_Expecter struct { + mock *mock.Mock +} + +func (_m *IEthClient) EXPECT() *IEthClient_Expecter { + return &IEthClient_Expecter{mock: &_m.Mock} +} + // BlockByNumber provides a mock function with given fields: ctx, number func (_m *IEthClient) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) { ret := _m.Called(ctx, number) @@ -49,6 +57,35 @@ func (_m *IEthClient) BlockByNumber(ctx context.Context, number *big.Int) (*type return r0, r1 } +// IEthClient_BlockByNumber_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'BlockByNumber' +type IEthClient_BlockByNumber_Call struct { + *mock.Call +} + +// BlockByNumber is a helper method to define mock.On call +// - ctx context.Context +// - number *big.Int +func (_e *IEthClient_Expecter) BlockByNumber(ctx interface{}, number interface{}) *IEthClient_BlockByNumber_Call { + return &IEthClient_BlockByNumber_Call{Call: _e.mock.On("BlockByNumber", ctx, number)} +} + +func (_c *IEthClient_BlockByNumber_Call) Run(run func(ctx context.Context, number *big.Int)) *IEthClient_BlockByNumber_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*big.Int)) + }) + return _c +} + +func (_c *IEthClient_BlockByNumber_Call) Return(_a0 *types.Block, _a1 error) *IEthClient_BlockByNumber_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *IEthClient_BlockByNumber_Call) RunAndReturn(run func(context.Context, *big.Int) (*types.Block, error)) *IEthClient_BlockByNumber_Call { + _c.Call.Return(run) + return _c +} + // CodeAt provides a mock function with given fields: ctx, account, blockNumber func (_m *IEthClient) CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error) { ret := _m.Called(ctx, account, blockNumber) @@ -79,6 +116,36 @@ func (_m *IEthClient) CodeAt(ctx context.Context, account common.Address, blockN return r0, r1 } +// IEthClient_CodeAt_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CodeAt' +type IEthClient_CodeAt_Call struct { + *mock.Call +} + +// CodeAt is a helper method to define mock.On call +// - ctx context.Context +// - account common.Address +// - blockNumber *big.Int +func (_e *IEthClient_Expecter) CodeAt(ctx interface{}, account interface{}, blockNumber interface{}) *IEthClient_CodeAt_Call { + return &IEthClient_CodeAt_Call{Call: _e.mock.On("CodeAt", ctx, account, blockNumber)} +} + +func (_c *IEthClient_CodeAt_Call) Run(run func(ctx context.Context, account common.Address, blockNumber *big.Int)) *IEthClient_CodeAt_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(common.Address), args[2].(*big.Int)) + }) + return _c +} + +func (_c *IEthClient_CodeAt_Call) Return(_a0 []byte, _a1 error) *IEthClient_CodeAt_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *IEthClient_CodeAt_Call) RunAndReturn(run func(context.Context, common.Address, *big.Int) ([]byte, error)) *IEthClient_CodeAt_Call { + _c.Call.Return(run) + return _c +} + // NewIEthClient creates a new instance of IEthClient. 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 NewIEthClient(t interface { diff --git a/mocks/eth_client_factory.generated.go b/mocks/eth_client_factory.generated.go index 8ec2008f..e0857eae 100644 --- a/mocks/eth_client_factory.generated.go +++ b/mocks/eth_client_factory.generated.go @@ -14,6 +14,14 @@ type IEthClientFactory struct { mock.Mock } +type IEthClientFactory_Expecter struct { + mock *mock.Mock +} + +func (_m *IEthClientFactory) EXPECT() *IEthClientFactory_Expecter { + return &IEthClientFactory_Expecter{mock: &_m.Mock} +} + // CreateEthClient provides a mock function with given fields: ctx, url func (_m *IEthClientFactory) CreateEthClient(ctx context.Context, url string) (types.IEthClient, error) { ret := _m.Called(ctx, url) @@ -44,6 +52,35 @@ func (_m *IEthClientFactory) CreateEthClient(ctx context.Context, url string) (t return r0, r1 } +// IEthClientFactory_CreateEthClient_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateEthClient' +type IEthClientFactory_CreateEthClient_Call struct { + *mock.Call +} + +// CreateEthClient is a helper method to define mock.On call +// - ctx context.Context +// - url string +func (_e *IEthClientFactory_Expecter) CreateEthClient(ctx interface{}, url interface{}) *IEthClientFactory_CreateEthClient_Call { + return &IEthClientFactory_CreateEthClient_Call{Call: _e.mock.On("CreateEthClient", ctx, url)} +} + +func (_c *IEthClientFactory_CreateEthClient_Call) Run(run func(ctx context.Context, url string)) *IEthClientFactory_CreateEthClient_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *IEthClientFactory_CreateEthClient_Call) Return(_a0 types.IEthClient, _a1 error) *IEthClientFactory_CreateEthClient_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *IEthClientFactory_CreateEthClient_Call) RunAndReturn(run func(context.Context, string) (types.IEthClient, error)) *IEthClientFactory_CreateEthClient_Call { + _c.Call.Return(run) + return _c +} + // NewIEthClientFactory creates a new instance of IEthClientFactory. 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 NewIEthClientFactory(t interface { diff --git a/mocks/etherman.generated.go b/mocks/etherman.generated.go index a07df823..ea285b09 100644 --- a/mocks/etherman.generated.go +++ b/mocks/etherman.generated.go @@ -26,6 +26,14 @@ type Etherman struct { mock.Mock } +type Etherman_Expecter struct { + mock *mock.Mock +} + +func (_m *Etherman) EXPECT() *Etherman_Expecter { + return &Etherman_Expecter{mock: &_m.Mock} +} + // FilterSequenceBatches provides a mock function with given fields: opts, numBatch func (_m *Etherman) FilterSequenceBatches(opts *bind.FilterOpts, numBatch []uint64) (*cdkvalidium.CdkvalidiumSequenceBatchesIterator, error) { ret := _m.Called(opts, numBatch) @@ -56,6 +64,35 @@ func (_m *Etherman) FilterSequenceBatches(opts *bind.FilterOpts, numBatch []uint return r0, r1 } +// Etherman_FilterSequenceBatches_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FilterSequenceBatches' +type Etherman_FilterSequenceBatches_Call struct { + *mock.Call +} + +// FilterSequenceBatches is a helper method to define mock.On call +// - opts *bind.FilterOpts +// - numBatch []uint64 +func (_e *Etherman_Expecter) FilterSequenceBatches(opts interface{}, numBatch interface{}) *Etherman_FilterSequenceBatches_Call { + return &Etherman_FilterSequenceBatches_Call{Call: _e.mock.On("FilterSequenceBatches", opts, numBatch)} +} + +func (_c *Etherman_FilterSequenceBatches_Call) Run(run func(opts *bind.FilterOpts, numBatch []uint64)) *Etherman_FilterSequenceBatches_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*bind.FilterOpts), args[1].([]uint64)) + }) + return _c +} + +func (_c *Etherman_FilterSequenceBatches_Call) Return(_a0 *cdkvalidium.CdkvalidiumSequenceBatchesIterator, _a1 error) *Etherman_FilterSequenceBatches_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Etherman_FilterSequenceBatches_Call) RunAndReturn(run func(*bind.FilterOpts, []uint64) (*cdkvalidium.CdkvalidiumSequenceBatchesIterator, error)) *Etherman_FilterSequenceBatches_Call { + _c.Call.Return(run) + return _c +} + // GetCurrentDataCommittee provides a mock function with given fields: func (_m *Etherman) GetCurrentDataCommittee() (*etherman.DataCommittee, error) { ret := _m.Called() @@ -86,6 +123,33 @@ func (_m *Etherman) GetCurrentDataCommittee() (*etherman.DataCommittee, error) { return r0, r1 } +// Etherman_GetCurrentDataCommittee_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetCurrentDataCommittee' +type Etherman_GetCurrentDataCommittee_Call struct { + *mock.Call +} + +// GetCurrentDataCommittee is a helper method to define mock.On call +func (_e *Etherman_Expecter) GetCurrentDataCommittee() *Etherman_GetCurrentDataCommittee_Call { + return &Etherman_GetCurrentDataCommittee_Call{Call: _e.mock.On("GetCurrentDataCommittee")} +} + +func (_c *Etherman_GetCurrentDataCommittee_Call) Run(run func()) *Etherman_GetCurrentDataCommittee_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Etherman_GetCurrentDataCommittee_Call) Return(_a0 *etherman.DataCommittee, _a1 error) *Etherman_GetCurrentDataCommittee_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Etherman_GetCurrentDataCommittee_Call) RunAndReturn(run func() (*etherman.DataCommittee, error)) *Etherman_GetCurrentDataCommittee_Call { + _c.Call.Return(run) + return _c +} + // GetCurrentDataCommitteeMembers provides a mock function with given fields: func (_m *Etherman) GetCurrentDataCommitteeMembers() ([]etherman.DataCommitteeMember, error) { ret := _m.Called() @@ -116,6 +180,33 @@ func (_m *Etherman) GetCurrentDataCommitteeMembers() ([]etherman.DataCommitteeMe return r0, r1 } +// Etherman_GetCurrentDataCommitteeMembers_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetCurrentDataCommitteeMembers' +type Etherman_GetCurrentDataCommitteeMembers_Call struct { + *mock.Call +} + +// GetCurrentDataCommitteeMembers is a helper method to define mock.On call +func (_e *Etherman_Expecter) GetCurrentDataCommitteeMembers() *Etherman_GetCurrentDataCommitteeMembers_Call { + return &Etherman_GetCurrentDataCommitteeMembers_Call{Call: _e.mock.On("GetCurrentDataCommitteeMembers")} +} + +func (_c *Etherman_GetCurrentDataCommitteeMembers_Call) Run(run func()) *Etherman_GetCurrentDataCommitteeMembers_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Etherman_GetCurrentDataCommitteeMembers_Call) Return(_a0 []etherman.DataCommitteeMember, _a1 error) *Etherman_GetCurrentDataCommitteeMembers_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Etherman_GetCurrentDataCommitteeMembers_Call) RunAndReturn(run func() ([]etherman.DataCommitteeMember, error)) *Etherman_GetCurrentDataCommitteeMembers_Call { + _c.Call.Return(run) + return _c +} + // GetTx provides a mock function with given fields: ctx, txHash func (_m *Etherman) GetTx(ctx context.Context, txHash common.Hash) (*types.Transaction, bool, error) { ret := _m.Called(ctx, txHash) @@ -153,6 +244,35 @@ func (_m *Etherman) GetTx(ctx context.Context, txHash common.Hash) (*types.Trans return r0, r1, r2 } +// Etherman_GetTx_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetTx' +type Etherman_GetTx_Call struct { + *mock.Call +} + +// GetTx is a helper method to define mock.On call +// - ctx context.Context +// - txHash common.Hash +func (_e *Etherman_Expecter) GetTx(ctx interface{}, txHash interface{}) *Etherman_GetTx_Call { + return &Etherman_GetTx_Call{Call: _e.mock.On("GetTx", ctx, txHash)} +} + +func (_c *Etherman_GetTx_Call) Run(run func(ctx context.Context, txHash common.Hash)) *Etherman_GetTx_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(common.Hash)) + }) + return _c +} + +func (_c *Etherman_GetTx_Call) Return(_a0 *types.Transaction, _a1 bool, _a2 error) *Etherman_GetTx_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *Etherman_GetTx_Call) RunAndReturn(run func(context.Context, common.Hash) (*types.Transaction, bool, error)) *Etherman_GetTx_Call { + _c.Call.Return(run) + return _c +} + // HeaderByNumber provides a mock function with given fields: ctx, number func (_m *Etherman) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) { ret := _m.Called(ctx, number) @@ -183,6 +303,35 @@ func (_m *Etherman) HeaderByNumber(ctx context.Context, number *big.Int) (*types return r0, r1 } +// Etherman_HeaderByNumber_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'HeaderByNumber' +type Etherman_HeaderByNumber_Call struct { + *mock.Call +} + +// HeaderByNumber is a helper method to define mock.On call +// - ctx context.Context +// - number *big.Int +func (_e *Etherman_Expecter) HeaderByNumber(ctx interface{}, number interface{}) *Etherman_HeaderByNumber_Call { + return &Etherman_HeaderByNumber_Call{Call: _e.mock.On("HeaderByNumber", ctx, number)} +} + +func (_c *Etherman_HeaderByNumber_Call) Run(run func(ctx context.Context, number *big.Int)) *Etherman_HeaderByNumber_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*big.Int)) + }) + return _c +} + +func (_c *Etherman_HeaderByNumber_Call) Return(_a0 *types.Header, _a1 error) *Etherman_HeaderByNumber_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Etherman_HeaderByNumber_Call) RunAndReturn(run func(context.Context, *big.Int) (*types.Header, error)) *Etherman_HeaderByNumber_Call { + _c.Call.Return(run) + return _c +} + // TrustedSequencer provides a mock function with given fields: func (_m *Etherman) TrustedSequencer() (common.Address, error) { ret := _m.Called() @@ -213,6 +362,33 @@ func (_m *Etherman) TrustedSequencer() (common.Address, error) { return r0, r1 } +// Etherman_TrustedSequencer_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'TrustedSequencer' +type Etherman_TrustedSequencer_Call struct { + *mock.Call +} + +// TrustedSequencer is a helper method to define mock.On call +func (_e *Etherman_Expecter) TrustedSequencer() *Etherman_TrustedSequencer_Call { + return &Etherman_TrustedSequencer_Call{Call: _e.mock.On("TrustedSequencer")} +} + +func (_c *Etherman_TrustedSequencer_Call) Run(run func()) *Etherman_TrustedSequencer_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Etherman_TrustedSequencer_Call) Return(_a0 common.Address, _a1 error) *Etherman_TrustedSequencer_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Etherman_TrustedSequencer_Call) RunAndReturn(run func() (common.Address, error)) *Etherman_TrustedSequencer_Call { + _c.Call.Return(run) + return _c +} + // TrustedSequencerURL provides a mock function with given fields: func (_m *Etherman) TrustedSequencerURL() (string, error) { ret := _m.Called() @@ -241,6 +417,33 @@ func (_m *Etherman) TrustedSequencerURL() (string, error) { return r0, r1 } +// Etherman_TrustedSequencerURL_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'TrustedSequencerURL' +type Etherman_TrustedSequencerURL_Call struct { + *mock.Call +} + +// TrustedSequencerURL is a helper method to define mock.On call +func (_e *Etherman_Expecter) TrustedSequencerURL() *Etherman_TrustedSequencerURL_Call { + return &Etherman_TrustedSequencerURL_Call{Call: _e.mock.On("TrustedSequencerURL")} +} + +func (_c *Etherman_TrustedSequencerURL_Call) Run(run func()) *Etherman_TrustedSequencerURL_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Etherman_TrustedSequencerURL_Call) Return(_a0 string, _a1 error) *Etherman_TrustedSequencerURL_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Etherman_TrustedSequencerURL_Call) RunAndReturn(run func() (string, error)) *Etherman_TrustedSequencerURL_Call { + _c.Call.Return(run) + return _c +} + // WatchSetTrustedSequencer provides a mock function with given fields: ctx, events func (_m *Etherman) WatchSetTrustedSequencer(ctx context.Context, events chan *cdkvalidium.CdkvalidiumSetTrustedSequencer) (event.Subscription, error) { ret := _m.Called(ctx, events) @@ -271,6 +474,35 @@ func (_m *Etherman) WatchSetTrustedSequencer(ctx context.Context, events chan *c return r0, r1 } +// Etherman_WatchSetTrustedSequencer_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WatchSetTrustedSequencer' +type Etherman_WatchSetTrustedSequencer_Call struct { + *mock.Call +} + +// WatchSetTrustedSequencer is a helper method to define mock.On call +// - ctx context.Context +// - events chan *cdkvalidium.CdkvalidiumSetTrustedSequencer +func (_e *Etherman_Expecter) WatchSetTrustedSequencer(ctx interface{}, events interface{}) *Etherman_WatchSetTrustedSequencer_Call { + return &Etherman_WatchSetTrustedSequencer_Call{Call: _e.mock.On("WatchSetTrustedSequencer", ctx, events)} +} + +func (_c *Etherman_WatchSetTrustedSequencer_Call) Run(run func(ctx context.Context, events chan *cdkvalidium.CdkvalidiumSetTrustedSequencer)) *Etherman_WatchSetTrustedSequencer_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(chan *cdkvalidium.CdkvalidiumSetTrustedSequencer)) + }) + return _c +} + +func (_c *Etherman_WatchSetTrustedSequencer_Call) Return(_a0 event.Subscription, _a1 error) *Etherman_WatchSetTrustedSequencer_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Etherman_WatchSetTrustedSequencer_Call) RunAndReturn(run func(context.Context, chan *cdkvalidium.CdkvalidiumSetTrustedSequencer) (event.Subscription, error)) *Etherman_WatchSetTrustedSequencer_Call { + _c.Call.Return(run) + return _c +} + // WatchSetTrustedSequencerURL provides a mock function with given fields: ctx, events func (_m *Etherman) WatchSetTrustedSequencerURL(ctx context.Context, events chan *cdkvalidium.CdkvalidiumSetTrustedSequencerURL) (event.Subscription, error) { ret := _m.Called(ctx, events) @@ -301,6 +533,35 @@ func (_m *Etherman) WatchSetTrustedSequencerURL(ctx context.Context, events chan return r0, r1 } +// Etherman_WatchSetTrustedSequencerURL_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WatchSetTrustedSequencerURL' +type Etherman_WatchSetTrustedSequencerURL_Call struct { + *mock.Call +} + +// WatchSetTrustedSequencerURL is a helper method to define mock.On call +// - ctx context.Context +// - events chan *cdkvalidium.CdkvalidiumSetTrustedSequencerURL +func (_e *Etherman_Expecter) WatchSetTrustedSequencerURL(ctx interface{}, events interface{}) *Etherman_WatchSetTrustedSequencerURL_Call { + return &Etherman_WatchSetTrustedSequencerURL_Call{Call: _e.mock.On("WatchSetTrustedSequencerURL", ctx, events)} +} + +func (_c *Etherman_WatchSetTrustedSequencerURL_Call) Run(run func(ctx context.Context, events chan *cdkvalidium.CdkvalidiumSetTrustedSequencerURL)) *Etherman_WatchSetTrustedSequencerURL_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(chan *cdkvalidium.CdkvalidiumSetTrustedSequencerURL)) + }) + return _c +} + +func (_c *Etherman_WatchSetTrustedSequencerURL_Call) Return(_a0 event.Subscription, _a1 error) *Etherman_WatchSetTrustedSequencerURL_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Etherman_WatchSetTrustedSequencerURL_Call) RunAndReturn(run func(context.Context, chan *cdkvalidium.CdkvalidiumSetTrustedSequencerURL) (event.Subscription, error)) *Etherman_WatchSetTrustedSequencerURL_Call { + _c.Call.Return(run) + return _c +} + // NewEtherman creates a new instance of Etherman. 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 NewEtherman(t interface { diff --git a/mocks/sequencer_tracker.generated.go b/mocks/sequencer_tracker.generated.go index daab5c7b..37df4cfd 100644 --- a/mocks/sequencer_tracker.generated.go +++ b/mocks/sequencer_tracker.generated.go @@ -12,6 +12,14 @@ type ISequencerTracker struct { mock.Mock } +type ISequencerTracker_Expecter struct { + mock *mock.Mock +} + +func (_m *ISequencerTracker) EXPECT() *ISequencerTracker_Expecter { + return &ISequencerTracker_Expecter{mock: &_m.Mock} +} + // GetSequenceBatch provides a mock function with given fields: batchNum func (_m *ISequencerTracker) GetSequenceBatch(batchNum uint64) (*sequencer.SeqBatch, error) { ret := _m.Called(batchNum) @@ -42,6 +50,34 @@ func (_m *ISequencerTracker) GetSequenceBatch(batchNum uint64) (*sequencer.SeqBa return r0, r1 } +// ISequencerTracker_GetSequenceBatch_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetSequenceBatch' +type ISequencerTracker_GetSequenceBatch_Call struct { + *mock.Call +} + +// GetSequenceBatch is a helper method to define mock.On call +// - batchNum uint64 +func (_e *ISequencerTracker_Expecter) GetSequenceBatch(batchNum interface{}) *ISequencerTracker_GetSequenceBatch_Call { + return &ISequencerTracker_GetSequenceBatch_Call{Call: _e.mock.On("GetSequenceBatch", batchNum)} +} + +func (_c *ISequencerTracker_GetSequenceBatch_Call) Run(run func(batchNum uint64)) *ISequencerTracker_GetSequenceBatch_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(uint64)) + }) + return _c +} + +func (_c *ISequencerTracker_GetSequenceBatch_Call) Return(_a0 *sequencer.SeqBatch, _a1 error) *ISequencerTracker_GetSequenceBatch_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ISequencerTracker_GetSequenceBatch_Call) RunAndReturn(run func(uint64) (*sequencer.SeqBatch, error)) *ISequencerTracker_GetSequenceBatch_Call { + _c.Call.Return(run) + return _c +} + // NewISequencerTracker creates a new instance of ISequencerTracker. 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 NewISequencerTracker(t interface { diff --git a/mocks/subscription.generated.go b/mocks/subscription.generated.go index 32db6dfa..547f5ca8 100644 --- a/mocks/subscription.generated.go +++ b/mocks/subscription.generated.go @@ -9,6 +9,14 @@ type Subscription struct { mock.Mock } +type Subscription_Expecter struct { + mock *mock.Mock +} + +func (_m *Subscription) EXPECT() *Subscription_Expecter { + return &Subscription_Expecter{mock: &_m.Mock} +} + // Err provides a mock function with given fields: func (_m *Subscription) Err() <-chan error { ret := _m.Called() @@ -29,11 +37,65 @@ func (_m *Subscription) Err() <-chan error { return r0 } +// Subscription_Err_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Err' +type Subscription_Err_Call struct { + *mock.Call +} + +// Err is a helper method to define mock.On call +func (_e *Subscription_Expecter) Err() *Subscription_Err_Call { + return &Subscription_Err_Call{Call: _e.mock.On("Err")} +} + +func (_c *Subscription_Err_Call) Run(run func()) *Subscription_Err_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Subscription_Err_Call) Return(_a0 <-chan error) *Subscription_Err_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Subscription_Err_Call) RunAndReturn(run func() <-chan error) *Subscription_Err_Call { + _c.Call.Return(run) + return _c +} + // Unsubscribe provides a mock function with given fields: func (_m *Subscription) Unsubscribe() { _m.Called() } +// Subscription_Unsubscribe_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Unsubscribe' +type Subscription_Unsubscribe_Call struct { + *mock.Call +} + +// Unsubscribe is a helper method to define mock.On call +func (_e *Subscription_Expecter) Unsubscribe() *Subscription_Unsubscribe_Call { + return &Subscription_Unsubscribe_Call{Call: _e.mock.On("Unsubscribe")} +} + +func (_c *Subscription_Unsubscribe_Call) Run(run func()) *Subscription_Unsubscribe_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Subscription_Unsubscribe_Call) Return() *Subscription_Unsubscribe_Call { + _c.Call.Return() + return _c +} + +func (_c *Subscription_Unsubscribe_Call) RunAndReturn(run func()) *Subscription_Unsubscribe_Call { + _c.Call.Return(run) + return _c +} + // NewSubscription creates a new instance of Subscription. 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 NewSubscription(t interface { diff --git a/mocks/tx.generated.go b/mocks/tx.generated.go index 2872f3a3..fddcf9ec 100644 --- a/mocks/tx.generated.go +++ b/mocks/tx.generated.go @@ -17,6 +17,14 @@ type Tx struct { mock.Mock } +type Tx_Expecter struct { + mock *mock.Mock +} + +func (_m *Tx) EXPECT() *Tx_Expecter { + return &Tx_Expecter{mock: &_m.Mock} +} + // Commit provides a mock function with given fields: func (_m *Tx) Commit() error { ret := _m.Called() @@ -35,6 +43,33 @@ func (_m *Tx) Commit() error { return r0 } +// Tx_Commit_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Commit' +type Tx_Commit_Call struct { + *mock.Call +} + +// Commit is a helper method to define mock.On call +func (_e *Tx_Expecter) Commit() *Tx_Commit_Call { + return &Tx_Commit_Call{Call: _e.mock.On("Commit")} +} + +func (_c *Tx_Commit_Call) Run(run func()) *Tx_Commit_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Tx_Commit_Call) Return(_a0 error) *Tx_Commit_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Tx_Commit_Call) RunAndReturn(run func() error) *Tx_Commit_Call { + _c.Call.Return(run) + return _c +} + // ExecContext provides a mock function with given fields: ctx, query, args func (_m *Tx) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) { var _ca []interface{} @@ -68,6 +103,43 @@ func (_m *Tx) ExecContext(ctx context.Context, query string, args ...interface{} return r0, r1 } +// Tx_ExecContext_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ExecContext' +type Tx_ExecContext_Call struct { + *mock.Call +} + +// ExecContext is a helper method to define mock.On call +// - ctx context.Context +// - query string +// - args ...interface{} +func (_e *Tx_Expecter) ExecContext(ctx interface{}, query interface{}, args ...interface{}) *Tx_ExecContext_Call { + return &Tx_ExecContext_Call{Call: _e.mock.On("ExecContext", + append([]interface{}{ctx, query}, args...)...)} +} + +func (_c *Tx_ExecContext_Call) Run(run func(ctx context.Context, query string, args ...interface{})) *Tx_ExecContext_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]interface{}, len(args)-2) + for i, a := range args[2:] { + if a != nil { + variadicArgs[i] = a.(interface{}) + } + } + run(args[0].(context.Context), args[1].(string), variadicArgs...) + }) + return _c +} + +func (_c *Tx_ExecContext_Call) Return(_a0 sql.Result, _a1 error) *Tx_ExecContext_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Tx_ExecContext_Call) RunAndReturn(run func(context.Context, string, ...interface{}) (sql.Result, error)) *Tx_ExecContext_Call { + _c.Call.Return(run) + return _c +} + // QueryContext provides a mock function with given fields: ctx, query, args func (_m *Tx) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) { var _ca []interface{} @@ -101,6 +173,43 @@ func (_m *Tx) QueryContext(ctx context.Context, query string, args ...interface{ return r0, r1 } +// Tx_QueryContext_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'QueryContext' +type Tx_QueryContext_Call struct { + *mock.Call +} + +// QueryContext is a helper method to define mock.On call +// - ctx context.Context +// - query string +// - args ...interface{} +func (_e *Tx_Expecter) QueryContext(ctx interface{}, query interface{}, args ...interface{}) *Tx_QueryContext_Call { + return &Tx_QueryContext_Call{Call: _e.mock.On("QueryContext", + append([]interface{}{ctx, query}, args...)...)} +} + +func (_c *Tx_QueryContext_Call) Run(run func(ctx context.Context, query string, args ...interface{})) *Tx_QueryContext_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]interface{}, len(args)-2) + for i, a := range args[2:] { + if a != nil { + variadicArgs[i] = a.(interface{}) + } + } + run(args[0].(context.Context), args[1].(string), variadicArgs...) + }) + return _c +} + +func (_c *Tx_QueryContext_Call) Return(_a0 *sql.Rows, _a1 error) *Tx_QueryContext_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Tx_QueryContext_Call) RunAndReturn(run func(context.Context, string, ...interface{}) (*sql.Rows, error)) *Tx_QueryContext_Call { + _c.Call.Return(run) + return _c +} + // QueryRowxContext provides a mock function with given fields: ctx, query, args func (_m *Tx) QueryRowxContext(ctx context.Context, query string, args ...interface{}) *sqlx.Row { var _ca []interface{} @@ -124,6 +233,43 @@ func (_m *Tx) QueryRowxContext(ctx context.Context, query string, args ...interf return r0 } +// Tx_QueryRowxContext_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'QueryRowxContext' +type Tx_QueryRowxContext_Call struct { + *mock.Call +} + +// QueryRowxContext is a helper method to define mock.On call +// - ctx context.Context +// - query string +// - args ...interface{} +func (_e *Tx_Expecter) QueryRowxContext(ctx interface{}, query interface{}, args ...interface{}) *Tx_QueryRowxContext_Call { + return &Tx_QueryRowxContext_Call{Call: _e.mock.On("QueryRowxContext", + append([]interface{}{ctx, query}, args...)...)} +} + +func (_c *Tx_QueryRowxContext_Call) Run(run func(ctx context.Context, query string, args ...interface{})) *Tx_QueryRowxContext_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]interface{}, len(args)-2) + for i, a := range args[2:] { + if a != nil { + variadicArgs[i] = a.(interface{}) + } + } + run(args[0].(context.Context), args[1].(string), variadicArgs...) + }) + return _c +} + +func (_c *Tx_QueryRowxContext_Call) Return(_a0 *sqlx.Row) *Tx_QueryRowxContext_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Tx_QueryRowxContext_Call) RunAndReturn(run func(context.Context, string, ...interface{}) *sqlx.Row) *Tx_QueryRowxContext_Call { + _c.Call.Return(run) + return _c +} + // QueryxContext provides a mock function with given fields: ctx, query, args func (_m *Tx) QueryxContext(ctx context.Context, query string, args ...interface{}) (*sqlx.Rows, error) { var _ca []interface{} @@ -157,6 +303,43 @@ func (_m *Tx) QueryxContext(ctx context.Context, query string, args ...interface return r0, r1 } +// Tx_QueryxContext_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'QueryxContext' +type Tx_QueryxContext_Call struct { + *mock.Call +} + +// QueryxContext is a helper method to define mock.On call +// - ctx context.Context +// - query string +// - args ...interface{} +func (_e *Tx_Expecter) QueryxContext(ctx interface{}, query interface{}, args ...interface{}) *Tx_QueryxContext_Call { + return &Tx_QueryxContext_Call{Call: _e.mock.On("QueryxContext", + append([]interface{}{ctx, query}, args...)...)} +} + +func (_c *Tx_QueryxContext_Call) Run(run func(ctx context.Context, query string, args ...interface{})) *Tx_QueryxContext_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]interface{}, len(args)-2) + for i, a := range args[2:] { + if a != nil { + variadicArgs[i] = a.(interface{}) + } + } + run(args[0].(context.Context), args[1].(string), variadicArgs...) + }) + return _c +} + +func (_c *Tx_QueryxContext_Call) Return(_a0 *sqlx.Rows, _a1 error) *Tx_QueryxContext_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Tx_QueryxContext_Call) RunAndReturn(run func(context.Context, string, ...interface{}) (*sqlx.Rows, error)) *Tx_QueryxContext_Call { + _c.Call.Return(run) + return _c +} + // Rollback provides a mock function with given fields: func (_m *Tx) Rollback() error { ret := _m.Called() @@ -175,6 +358,33 @@ func (_m *Tx) Rollback() error { return r0 } +// Tx_Rollback_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Rollback' +type Tx_Rollback_Call struct { + *mock.Call +} + +// Rollback is a helper method to define mock.On call +func (_e *Tx_Expecter) Rollback() *Tx_Rollback_Call { + return &Tx_Rollback_Call{Call: _e.mock.On("Rollback")} +} + +func (_c *Tx_Rollback_Call) Run(run func()) *Tx_Rollback_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Tx_Rollback_Call) Return(_a0 error) *Tx_Rollback_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Tx_Rollback_Call) RunAndReturn(run func() error) *Tx_Rollback_Call { + _c.Call.Return(run) + return _c +} + // NewTx creates a new instance of Tx. 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 NewTx(t interface { diff --git a/sequencer/tracker.go b/sequencer/tracker.go index b47e4375..2e23852a 100644 --- a/sequencer/tracker.go +++ b/sequencer/tracker.go @@ -13,8 +13,6 @@ import ( ) // ISequencerTracker is an interface that defines functions that a sequencer tracker must implement -// -//go:generate mockery --name ISequencerTracker --output ../mocks --case=underscore --filename sequencer_tracker.generated.go type ISequencerTracker interface { GetSequenceBatch(batchNum uint64) (*SeqBatch, error) } diff --git a/sequencer/tracker_test.go b/sequencer/tracker_test.go index 525ad6ed..40642b99 100644 --- a/sequencer/tracker_test.go +++ b/sequencer/tracker_test.go @@ -16,8 +16,6 @@ import ( "github.com/stretchr/testify/require" ) -//go:generate mockery --name Subscription --output ../mocks --case=underscore --srcpkg github.com/ethereum/go-ethereum/event --filename subscription.generated.go - func Test_NewTracker(t *testing.T) { testErr := errors.New("test error") diff --git a/synchronizer/batches.go b/synchronizer/batches.go index 3c176c16..18d777f9 100644 --- a/synchronizer/batches.go +++ b/synchronizer/batches.go @@ -37,7 +37,7 @@ type BatchSynchronizer struct { reorgs <-chan BlockReorg events chan *cdkvalidium.CdkvalidiumSequenceBatches sequencer sequencer.ISequencerTracker - rpcClientFactory client.IClientFactory + rpcClientFactory client.ClientFactory } // NewBatchSynchronizer creates the BatchSynchronizer @@ -48,7 +48,7 @@ func NewBatchSynchronizer( reorgs <-chan BlockReorg, ethClient etherman.Etherman, sequencer sequencer.ISequencerTracker, - rpcClientFactory client.IClientFactory, + rpcClientFactory client.ClientFactory, ) (*BatchSynchronizer, error) { if cfg.BlockBatchSize == 0 { log.Infof("block number size is not set, setting to default %d", defaultBlockBatchSize) diff --git a/synchronizer/batches_test.go b/synchronizer/batches_test.go index 9c0b3b16..8e089a6d 100644 --- a/synchronizer/batches_test.go +++ b/synchronizer/batches_test.go @@ -97,10 +97,10 @@ func TestBatchSynchronizer_Resolve(t *testing.T) { } testFn := func(config testConfig) { - clientMock := mocks.NewIClient(t) + clientMock := mocks.NewClient(t) ethermanMock := mocks.NewEtherman(t) sequencerMock := mocks.NewISequencerTracker(t) - clientFactoryMock := mocks.NewIClientFactory(t) + clientFactoryMock := mocks.NewClientFactory(t) if config.getSequenceBatchArgs != nil && config.getSequenceBatchReturns != nil { sequencerMock.On("GetSequenceBatch", config.getSequenceBatchArgs...).Return( diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index 352cc143..b1f8dc7c 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -115,7 +115,7 @@ type testClient struct { func newTestClient(url string, addr common.Address) *testClient { return &testClient{ - client: *client.New(url), + client: client.New(url), dacMemberAddr: addr, } } diff --git a/types/factories.go b/types/factories.go index 97da6530..a02350b1 100644 --- a/types/factories.go +++ b/types/factories.go @@ -10,16 +10,12 @@ import ( ) // IEthClient defines functions that an ethereum rpc client should implement -// -//go:generate mockery --name IEthClient --output ../mocks --case=underscore --filename eth_client.generated.go type IEthClient interface { BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error) } // IEthClientFactory defines functions for a EthClient factory -// -//go:generate mockery --name IEthClientFactory --output ../mocks --case=underscore --filename eth_client_factory.generated.go type IEthClientFactory interface { CreateEthClient(ctx context.Context, url string) (IEthClient, error) } From f0ca2c799dbd3e83a0a526f2f68b8e63c6ed35da Mon Sep 17 00:00:00 2001 From: begmaroman Date: Wed, 24 Jan 2024 11:03:09 +0100 Subject: [PATCH 2/2] Added mockery configuration --- .mockery.yaml | 12 +++-- client/client.go | 17 ++++--- cmd/main.go | 2 +- ...nerated.go => client_factory.generated.go} | 2 +- mocks/eth_client.generated.go | 50 +++++++++---------- mocks/eth_client_factory.generated.go | 42 ++++++++-------- mocks/sequencer_tracker.generated.go | 34 ++++++------- sequencer/tracker.go | 7 --- synchronizer/batches.go | 13 +++-- synchronizer/batches_test.go | 4 +- synchronizer/init.go | 8 +-- synchronizer/init_test.go | 4 +- types/factories.go | 14 +++--- 13 files changed, 107 insertions(+), 102 deletions(-) rename mocks/{clientfactory.generated.go => client_factory.generated.go} (96%) diff --git a/.mockery.yaml b/.mockery.yaml index ac8e3600..83b1530c 100644 --- a/.mockery.yaml +++ b/.mockery.yaml @@ -19,8 +19,10 @@ packages: github.com/0xPolygon/cdk-data-availability/client: config: interfaces: - ClientFactory: + Factory: config: + mockname: ClientFactory + filename: client_factory.generated.go Client: config: github.com/0xPolygon/cdk-data-availability/etherman: @@ -28,18 +30,18 @@ packages: interfaces: Etherman: config: - github.com/0xPolygon/cdk-data-availability/sequencer: + github.com/0xPolygon/cdk-data-availability/synchronizer: config: interfaces: - ISequencerTracker: + SequencerTracker: config: filename: sequencer_tracker.generated.go github.com/0xPolygon/cdk-data-availability/types: config: interfaces: - IEthClient: + EthClient: config: filename: eth_client.generated.go - IEthClientFactory: + EthClientFactory: config: filename: eth_client_factory.generated.go \ No newline at end of file diff --git a/client/client.go b/client/client.go index 8b8df0fc..fe26b194 100644 --- a/client/client.go +++ b/client/client.go @@ -10,8 +10,8 @@ import ( "github.com/ethereum/go-ethereum/common" ) -// ClientFactory interface for the client factory -type ClientFactory interface { +// Factory interface for the client factory +type Factory interface { New(url string) Client } @@ -21,11 +21,16 @@ type Client interface { SignSequence(signedSequence types.SignedSequence) ([]byte, error) } -// Factory is the implementation of the data committee client factory -type Factory struct{} +// factory is the implementation of the data committee client factory +type factory struct{} + +// NewFactory is the constructor of factory +func NewFactory() Factory { + return &factory{} +} // New returns an implementation of the data committee node client -func (f *Factory) New(url string) Client { +func (f *factory) New(url string) Client { return New(url) } @@ -35,7 +40,7 @@ type client struct { } // New returns a client ready to be used -func New(url string) *client { +func New(url string) Client { return &client{ url: url, } diff --git a/cmd/main.go b/cmd/main.go index 0e3ac156..70875a22 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -119,7 +119,7 @@ func start(cliCtx *cli.Context) error { cancelFuncs = append(cancelFuncs, detector.Stop) batchSynchronizer, err := synchronizer.NewBatchSynchronizer(c.L1, selfAddr, - storage, detector.Subscribe(), etherman, sequencerTracker, &client.Factory{}) + storage, detector.Subscribe(), etherman, sequencerTracker, client.NewFactory()) if err != nil { log.Fatal(err) } diff --git a/mocks/clientfactory.generated.go b/mocks/client_factory.generated.go similarity index 96% rename from mocks/clientfactory.generated.go rename to mocks/client_factory.generated.go index 64176b08..aff44994 100644 --- a/mocks/clientfactory.generated.go +++ b/mocks/client_factory.generated.go @@ -7,7 +7,7 @@ import ( mock "github.com/stretchr/testify/mock" ) -// ClientFactory is an autogenerated mock type for the ClientFactory type +// ClientFactory is an autogenerated mock type for the Factory type type ClientFactory struct { mock.Mock } diff --git a/mocks/eth_client.generated.go b/mocks/eth_client.generated.go index be264b67..fa905b6b 100644 --- a/mocks/eth_client.generated.go +++ b/mocks/eth_client.generated.go @@ -14,21 +14,21 @@ import ( types "github.com/ethereum/go-ethereum/core/types" ) -// IEthClient is an autogenerated mock type for the IEthClient type -type IEthClient struct { +// EthClient is an autogenerated mock type for the EthClient type +type EthClient struct { mock.Mock } -type IEthClient_Expecter struct { +type EthClient_Expecter struct { mock *mock.Mock } -func (_m *IEthClient) EXPECT() *IEthClient_Expecter { - return &IEthClient_Expecter{mock: &_m.Mock} +func (_m *EthClient) EXPECT() *EthClient_Expecter { + return &EthClient_Expecter{mock: &_m.Mock} } // BlockByNumber provides a mock function with given fields: ctx, number -func (_m *IEthClient) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) { +func (_m *EthClient) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) { ret := _m.Called(ctx, number) if len(ret) == 0 { @@ -57,37 +57,37 @@ func (_m *IEthClient) BlockByNumber(ctx context.Context, number *big.Int) (*type return r0, r1 } -// IEthClient_BlockByNumber_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'BlockByNumber' -type IEthClient_BlockByNumber_Call struct { +// EthClient_BlockByNumber_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'BlockByNumber' +type EthClient_BlockByNumber_Call struct { *mock.Call } // BlockByNumber is a helper method to define mock.On call // - ctx context.Context // - number *big.Int -func (_e *IEthClient_Expecter) BlockByNumber(ctx interface{}, number interface{}) *IEthClient_BlockByNumber_Call { - return &IEthClient_BlockByNumber_Call{Call: _e.mock.On("BlockByNumber", ctx, number)} +func (_e *EthClient_Expecter) BlockByNumber(ctx interface{}, number interface{}) *EthClient_BlockByNumber_Call { + return &EthClient_BlockByNumber_Call{Call: _e.mock.On("BlockByNumber", ctx, number)} } -func (_c *IEthClient_BlockByNumber_Call) Run(run func(ctx context.Context, number *big.Int)) *IEthClient_BlockByNumber_Call { +func (_c *EthClient_BlockByNumber_Call) Run(run func(ctx context.Context, number *big.Int)) *EthClient_BlockByNumber_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(context.Context), args[1].(*big.Int)) }) return _c } -func (_c *IEthClient_BlockByNumber_Call) Return(_a0 *types.Block, _a1 error) *IEthClient_BlockByNumber_Call { +func (_c *EthClient_BlockByNumber_Call) Return(_a0 *types.Block, _a1 error) *EthClient_BlockByNumber_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *IEthClient_BlockByNumber_Call) RunAndReturn(run func(context.Context, *big.Int) (*types.Block, error)) *IEthClient_BlockByNumber_Call { +func (_c *EthClient_BlockByNumber_Call) RunAndReturn(run func(context.Context, *big.Int) (*types.Block, error)) *EthClient_BlockByNumber_Call { _c.Call.Return(run) return _c } // CodeAt provides a mock function with given fields: ctx, account, blockNumber -func (_m *IEthClient) CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error) { +func (_m *EthClient) CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error) { ret := _m.Called(ctx, account, blockNumber) if len(ret) == 0 { @@ -116,8 +116,8 @@ func (_m *IEthClient) CodeAt(ctx context.Context, account common.Address, blockN return r0, r1 } -// IEthClient_CodeAt_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CodeAt' -type IEthClient_CodeAt_Call struct { +// EthClient_CodeAt_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CodeAt' +type EthClient_CodeAt_Call struct { *mock.Call } @@ -125,34 +125,34 @@ type IEthClient_CodeAt_Call struct { // - ctx context.Context // - account common.Address // - blockNumber *big.Int -func (_e *IEthClient_Expecter) CodeAt(ctx interface{}, account interface{}, blockNumber interface{}) *IEthClient_CodeAt_Call { - return &IEthClient_CodeAt_Call{Call: _e.mock.On("CodeAt", ctx, account, blockNumber)} +func (_e *EthClient_Expecter) CodeAt(ctx interface{}, account interface{}, blockNumber interface{}) *EthClient_CodeAt_Call { + return &EthClient_CodeAt_Call{Call: _e.mock.On("CodeAt", ctx, account, blockNumber)} } -func (_c *IEthClient_CodeAt_Call) Run(run func(ctx context.Context, account common.Address, blockNumber *big.Int)) *IEthClient_CodeAt_Call { +func (_c *EthClient_CodeAt_Call) Run(run func(ctx context.Context, account common.Address, blockNumber *big.Int)) *EthClient_CodeAt_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(context.Context), args[1].(common.Address), args[2].(*big.Int)) }) return _c } -func (_c *IEthClient_CodeAt_Call) Return(_a0 []byte, _a1 error) *IEthClient_CodeAt_Call { +func (_c *EthClient_CodeAt_Call) Return(_a0 []byte, _a1 error) *EthClient_CodeAt_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *IEthClient_CodeAt_Call) RunAndReturn(run func(context.Context, common.Address, *big.Int) ([]byte, error)) *IEthClient_CodeAt_Call { +func (_c *EthClient_CodeAt_Call) RunAndReturn(run func(context.Context, common.Address, *big.Int) ([]byte, error)) *EthClient_CodeAt_Call { _c.Call.Return(run) return _c } -// NewIEthClient creates a new instance of IEthClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// NewEthClient creates a new instance of EthClient. 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 NewIEthClient(t interface { +func NewEthClient(t interface { mock.TestingT Cleanup(func()) -}) *IEthClient { - mock := &IEthClient{} +}) *EthClient { + mock := &EthClient{} mock.Mock.Test(t) t.Cleanup(func() { mock.AssertExpectations(t) }) diff --git a/mocks/eth_client_factory.generated.go b/mocks/eth_client_factory.generated.go index e0857eae..aa47fed0 100644 --- a/mocks/eth_client_factory.generated.go +++ b/mocks/eth_client_factory.generated.go @@ -9,37 +9,37 @@ import ( mock "github.com/stretchr/testify/mock" ) -// IEthClientFactory is an autogenerated mock type for the IEthClientFactory type -type IEthClientFactory struct { +// EthClientFactory is an autogenerated mock type for the EthClientFactory type +type EthClientFactory struct { mock.Mock } -type IEthClientFactory_Expecter struct { +type EthClientFactory_Expecter struct { mock *mock.Mock } -func (_m *IEthClientFactory) EXPECT() *IEthClientFactory_Expecter { - return &IEthClientFactory_Expecter{mock: &_m.Mock} +func (_m *EthClientFactory) EXPECT() *EthClientFactory_Expecter { + return &EthClientFactory_Expecter{mock: &_m.Mock} } // CreateEthClient provides a mock function with given fields: ctx, url -func (_m *IEthClientFactory) CreateEthClient(ctx context.Context, url string) (types.IEthClient, error) { +func (_m *EthClientFactory) CreateEthClient(ctx context.Context, url string) (types.EthClient, error) { ret := _m.Called(ctx, url) if len(ret) == 0 { panic("no return value specified for CreateEthClient") } - var r0 types.IEthClient + var r0 types.EthClient var r1 error - if rf, ok := ret.Get(0).(func(context.Context, string) (types.IEthClient, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, string) (types.EthClient, error)); ok { return rf(ctx, url) } - if rf, ok := ret.Get(0).(func(context.Context, string) types.IEthClient); ok { + if rf, ok := ret.Get(0).(func(context.Context, string) types.EthClient); ok { r0 = rf(ctx, url) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(types.IEthClient) + r0 = ret.Get(0).(types.EthClient) } } @@ -52,42 +52,42 @@ func (_m *IEthClientFactory) CreateEthClient(ctx context.Context, url string) (t return r0, r1 } -// IEthClientFactory_CreateEthClient_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateEthClient' -type IEthClientFactory_CreateEthClient_Call struct { +// EthClientFactory_CreateEthClient_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateEthClient' +type EthClientFactory_CreateEthClient_Call struct { *mock.Call } // CreateEthClient is a helper method to define mock.On call // - ctx context.Context // - url string -func (_e *IEthClientFactory_Expecter) CreateEthClient(ctx interface{}, url interface{}) *IEthClientFactory_CreateEthClient_Call { - return &IEthClientFactory_CreateEthClient_Call{Call: _e.mock.On("CreateEthClient", ctx, url)} +func (_e *EthClientFactory_Expecter) CreateEthClient(ctx interface{}, url interface{}) *EthClientFactory_CreateEthClient_Call { + return &EthClientFactory_CreateEthClient_Call{Call: _e.mock.On("CreateEthClient", ctx, url)} } -func (_c *IEthClientFactory_CreateEthClient_Call) Run(run func(ctx context.Context, url string)) *IEthClientFactory_CreateEthClient_Call { +func (_c *EthClientFactory_CreateEthClient_Call) Run(run func(ctx context.Context, url string)) *EthClientFactory_CreateEthClient_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(context.Context), args[1].(string)) }) return _c } -func (_c *IEthClientFactory_CreateEthClient_Call) Return(_a0 types.IEthClient, _a1 error) *IEthClientFactory_CreateEthClient_Call { +func (_c *EthClientFactory_CreateEthClient_Call) Return(_a0 types.EthClient, _a1 error) *EthClientFactory_CreateEthClient_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *IEthClientFactory_CreateEthClient_Call) RunAndReturn(run func(context.Context, string) (types.IEthClient, error)) *IEthClientFactory_CreateEthClient_Call { +func (_c *EthClientFactory_CreateEthClient_Call) RunAndReturn(run func(context.Context, string) (types.EthClient, error)) *EthClientFactory_CreateEthClient_Call { _c.Call.Return(run) return _c } -// NewIEthClientFactory creates a new instance of IEthClientFactory. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// NewEthClientFactory creates a new instance of EthClientFactory. 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 NewIEthClientFactory(t interface { +func NewEthClientFactory(t interface { mock.TestingT Cleanup(func()) -}) *IEthClientFactory { - mock := &IEthClientFactory{} +}) *EthClientFactory { + mock := &EthClientFactory{} mock.Mock.Test(t) t.Cleanup(func() { mock.AssertExpectations(t) }) diff --git a/mocks/sequencer_tracker.generated.go b/mocks/sequencer_tracker.generated.go index 37df4cfd..2b9f73d2 100644 --- a/mocks/sequencer_tracker.generated.go +++ b/mocks/sequencer_tracker.generated.go @@ -7,21 +7,21 @@ import ( mock "github.com/stretchr/testify/mock" ) -// ISequencerTracker is an autogenerated mock type for the ISequencerTracker type -type ISequencerTracker struct { +// SequencerTracker is an autogenerated mock type for the SequencerTracker type +type SequencerTracker struct { mock.Mock } -type ISequencerTracker_Expecter struct { +type SequencerTracker_Expecter struct { mock *mock.Mock } -func (_m *ISequencerTracker) EXPECT() *ISequencerTracker_Expecter { - return &ISequencerTracker_Expecter{mock: &_m.Mock} +func (_m *SequencerTracker) EXPECT() *SequencerTracker_Expecter { + return &SequencerTracker_Expecter{mock: &_m.Mock} } // GetSequenceBatch provides a mock function with given fields: batchNum -func (_m *ISequencerTracker) GetSequenceBatch(batchNum uint64) (*sequencer.SeqBatch, error) { +func (_m *SequencerTracker) GetSequenceBatch(batchNum uint64) (*sequencer.SeqBatch, error) { ret := _m.Called(batchNum) if len(ret) == 0 { @@ -50,41 +50,41 @@ func (_m *ISequencerTracker) GetSequenceBatch(batchNum uint64) (*sequencer.SeqBa return r0, r1 } -// ISequencerTracker_GetSequenceBatch_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetSequenceBatch' -type ISequencerTracker_GetSequenceBatch_Call struct { +// SequencerTracker_GetSequenceBatch_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetSequenceBatch' +type SequencerTracker_GetSequenceBatch_Call struct { *mock.Call } // GetSequenceBatch is a helper method to define mock.On call // - batchNum uint64 -func (_e *ISequencerTracker_Expecter) GetSequenceBatch(batchNum interface{}) *ISequencerTracker_GetSequenceBatch_Call { - return &ISequencerTracker_GetSequenceBatch_Call{Call: _e.mock.On("GetSequenceBatch", batchNum)} +func (_e *SequencerTracker_Expecter) GetSequenceBatch(batchNum interface{}) *SequencerTracker_GetSequenceBatch_Call { + return &SequencerTracker_GetSequenceBatch_Call{Call: _e.mock.On("GetSequenceBatch", batchNum)} } -func (_c *ISequencerTracker_GetSequenceBatch_Call) Run(run func(batchNum uint64)) *ISequencerTracker_GetSequenceBatch_Call { +func (_c *SequencerTracker_GetSequenceBatch_Call) Run(run func(batchNum uint64)) *SequencerTracker_GetSequenceBatch_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(uint64)) }) return _c } -func (_c *ISequencerTracker_GetSequenceBatch_Call) Return(_a0 *sequencer.SeqBatch, _a1 error) *ISequencerTracker_GetSequenceBatch_Call { +func (_c *SequencerTracker_GetSequenceBatch_Call) Return(_a0 *sequencer.SeqBatch, _a1 error) *SequencerTracker_GetSequenceBatch_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *ISequencerTracker_GetSequenceBatch_Call) RunAndReturn(run func(uint64) (*sequencer.SeqBatch, error)) *ISequencerTracker_GetSequenceBatch_Call { +func (_c *SequencerTracker_GetSequenceBatch_Call) RunAndReturn(run func(uint64) (*sequencer.SeqBatch, error)) *SequencerTracker_GetSequenceBatch_Call { _c.Call.Return(run) return _c } -// NewISequencerTracker creates a new instance of ISequencerTracker. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// NewSequencerTracker creates a new instance of SequencerTracker. 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 NewISequencerTracker(t interface { +func NewSequencerTracker(t interface { mock.TestingT Cleanup(func()) -}) *ISequencerTracker { - mock := &ISequencerTracker{} +}) *SequencerTracker { + mock := &SequencerTracker{} mock.Mock.Test(t) t.Cleanup(func() { mock.AssertExpectations(t) }) diff --git a/sequencer/tracker.go b/sequencer/tracker.go index 2e23852a..53ffe21e 100644 --- a/sequencer/tracker.go +++ b/sequencer/tracker.go @@ -12,13 +12,6 @@ import ( "github.com/ethereum/go-ethereum/common" ) -// ISequencerTracker is an interface that defines functions that a sequencer tracker must implement -type ISequencerTracker interface { - GetSequenceBatch(batchNum uint64) (*SeqBatch, error) -} - -var _ ISequencerTracker = (*Tracker)(nil) - // Tracker watches the contract for relevant changes to the sequencer type Tracker struct { client etherman.Etherman diff --git a/synchronizer/batches.go b/synchronizer/batches.go index 18d777f9..7ba6abb4 100644 --- a/synchronizer/batches.go +++ b/synchronizer/batches.go @@ -23,6 +23,11 @@ import ( const defaultBlockBatchSize = 32 +// SequencerTracker is an interface that defines functions that a sequencer tracker must implement +type SequencerTracker interface { + GetSequenceBatch(batchNum uint64) (*sequencer.SeqBatch, error) +} + // BatchSynchronizer watches for number events, checks if they are "locally" stored, then retrieves and stores missing data type BatchSynchronizer struct { client etherman.Etherman @@ -36,8 +41,8 @@ type BatchSynchronizer struct { lock sync.Mutex reorgs <-chan BlockReorg events chan *cdkvalidium.CdkvalidiumSequenceBatches - sequencer sequencer.ISequencerTracker - rpcClientFactory client.ClientFactory + sequencer SequencerTracker + rpcClientFactory client.Factory } // NewBatchSynchronizer creates the BatchSynchronizer @@ -47,8 +52,8 @@ func NewBatchSynchronizer( db db.DB, reorgs <-chan BlockReorg, ethClient etherman.Etherman, - sequencer sequencer.ISequencerTracker, - rpcClientFactory client.ClientFactory, + sequencer SequencerTracker, + rpcClientFactory client.Factory, ) (*BatchSynchronizer, error) { if cfg.BlockBatchSize == 0 { log.Infof("block number size is not set, setting to default %d", defaultBlockBatchSize) diff --git a/synchronizer/batches_test.go b/synchronizer/batches_test.go index 8e089a6d..4bec3bcd 100644 --- a/synchronizer/batches_test.go +++ b/synchronizer/batches_test.go @@ -99,7 +99,7 @@ func TestBatchSynchronizer_Resolve(t *testing.T) { testFn := func(config testConfig) { clientMock := mocks.NewClient(t) ethermanMock := mocks.NewEtherman(t) - sequencerMock := mocks.NewISequencerTracker(t) + sequencerMock := mocks.NewSequencerTracker(t) clientFactoryMock := mocks.NewClientFactory(t) if config.getSequenceBatchArgs != nil && config.getSequenceBatchReturns != nil { @@ -325,7 +325,7 @@ func TestBatchSyncronizer_HandleEvent(t *testing.T) { dbMock := mocks.NewDB(t) txMock := mocks.NewTx(t) ethermanMock := mocks.NewEtherman(t) - sequencerMock := mocks.NewISequencerTracker(t) + sequencerMock := mocks.NewSequencerTracker(t) if config.getTxArgs != nil && config.getTxReturns != nil { ethermanMock.On("GetTx", config.getTxArgs...).Return( diff --git a/synchronizer/init.go b/synchronizer/init.go index 20aca06d..1f09f2c1 100644 --- a/synchronizer/init.go +++ b/synchronizer/init.go @@ -18,7 +18,7 @@ const ( ) // InitStartBlock initializes the L1 sync task by finding the inception block for the CDKValidium contract -func InitStartBlock(db db.DB, ethClientFactory types.IEthClientFactory, l1 config.L1Config) error { +func InitStartBlock(db db.DB, ethClientFactory types.EthClientFactory, l1 config.L1Config) error { ctx, cancel := context.WithTimeout(context.Background(), initBlockTimeout) defer cancel() @@ -45,7 +45,7 @@ func InitStartBlock(db db.DB, ethClientFactory types.IEthClientFactory, l1 confi return setStartBlock(db, startBlock.Uint64()) } -func findContractDeploymentBlock(ctx context.Context, eth types.IEthClient, contract common.Address) (*big.Int, error) { +func findContractDeploymentBlock(ctx context.Context, eth types.EthClient, contract common.Address) (*big.Int, error) { latestBlock, err := eth.BlockByNumber(ctx, nil) if err != nil { return nil, err @@ -55,7 +55,7 @@ func findContractDeploymentBlock(ctx context.Context, eth types.IEthClient, cont } // findCode is an O(log(n)) search for the inception block of a contract at the given address -func findCode(ctx context.Context, eth types.IEthClient, address common.Address, startBlock, endBlock int64) int64 { +func findCode(ctx context.Context, eth types.EthClient, address common.Address, startBlock, endBlock int64) int64 { if startBlock == endBlock { return startBlock } @@ -67,7 +67,7 @@ func findCode(ctx context.Context, eth types.IEthClient, address common.Address, } } -func codeLen(ctx context.Context, eth types.IEthClient, address common.Address, blockNumber int64) int64 { +func codeLen(ctx context.Context, eth types.EthClient, address common.Address, blockNumber int64) int64 { data, err := eth.CodeAt(ctx, address, big.NewInt(blockNumber)) if err != nil { return 0 diff --git a/synchronizer/init_test.go b/synchronizer/init_test.go index a6c6b414..3bc64e1b 100644 --- a/synchronizer/init_test.go +++ b/synchronizer/init_test.go @@ -52,8 +52,8 @@ func Test_InitStartBlock(t *testing.T) { testFn := func(config testConfig) { dbMock := mocks.NewDB(t) txMock := mocks.NewTx(t) - ethClientMock := mocks.NewIEthClient(t) - ethClientFactoryMock := mocks.NewIEthClientFactory(t) + ethClientMock := mocks.NewEthClient(t) + ethClientFactoryMock := mocks.NewEthClientFactory(t) if config.getLastProcessedBlockArgs != nil && config.getLastProcessedBlockReturns != nil { dbMock.On("GetLastProcessedBlock", config.getLastProcessedBlockArgs...).Return( diff --git a/types/factories.go b/types/factories.go index a02350b1..5faa7235 100644 --- a/types/factories.go +++ b/types/factories.go @@ -9,23 +9,23 @@ import ( "github.com/ethereum/go-ethereum/ethclient" ) -// IEthClient defines functions that an ethereum rpc client should implement -type IEthClient interface { +// EthClient defines functions that an ethereum rpc client should implement +type EthClient interface { BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error) } -// IEthClientFactory defines functions for a EthClient factory -type IEthClientFactory interface { - CreateEthClient(ctx context.Context, url string) (IEthClient, error) +// EthClientFactory defines functions for a EthClient factory +type EthClientFactory interface { + CreateEthClient(ctx context.Context, url string) (EthClient, error) } -var _ IEthClientFactory = (*EthClientFactoryImpl)(nil) +var _ EthClientFactory = (*EthClientFactoryImpl)(nil) // EthClientFactoryImpl is the implementation of EthClientFactory interface type EthClientFactoryImpl struct{} // CreateEthClient creates a new eth client -func (e *EthClientFactoryImpl) CreateEthClient(ctx context.Context, url string) (IEthClient, error) { +func (e *EthClientFactoryImpl) CreateEthClient(ctx context.Context, url string) (EthClient, error) { return ethclient.DialContext(ctx, url) }