From 3da4ae8a00bcc129f41b84729bb436c8c615f53a Mon Sep 17 00:00:00 2001 From: Goran Rojovic Date: Tue, 16 Jan 2024 16:03:18 +0100 Subject: [PATCH] Comments fix --- etherman/etherman_test.go | 54 +++++++++++------------ etherman/interfaces.go | 2 +- interop/executor_test.go | 32 +++++++------- mocks/db.generated.go | 14 +++--- mocks/eth_tx_manager.generated.go | 20 ++++----- mocks/etherman.generated.go | 18 ++++---- mocks/etherman_client.generated.go | 56 ++++++++++++------------ mocks/zk_evm_client.generated.go | 14 +++--- mocks/zk_evm_client_creator.generated.go | 14 +++--- rpc/rpc_test.go | 28 ++++++------ types/interfaces.go | 10 ++--- 11 files changed, 131 insertions(+), 131 deletions(-) diff --git a/etherman/etherman_test.go b/etherman/etherman_test.go index 1d04868..777f19f 100644 --- a/etherman/etherman_test.go +++ b/etherman/etherman_test.go @@ -51,7 +51,7 @@ func TestGetSequencerAddr(t *testing.T) { t.Run("Returns expected error on 'TrustedSequencer' call (improperly formatted output)", func(t *testing.T) { t.Parallel() - ethClient := mocks.NewIEthereumClient(t) + ethClient := mocks.NewEthereumClientMock(t) ethman := getEtherman(ethClient) ethClient.On( @@ -101,7 +101,7 @@ func TestGetSequencerAddr(t *testing.T) { t.Run("Returns expected error on 'RollupIDToRollupData' call (improperly formatted output)", func(t *testing.T) { t.Parallel() - ethClient := mocks.NewIEthereumClient(t) + ethClient := mocks.NewEthereumClientMock(t) ethman := getEtherman(ethClient) ethClient.On( @@ -132,7 +132,7 @@ func TestGetSequencerAddr(t *testing.T) { t.Run("Returns expected sequencer address", func(t *testing.T) { t.Parallel() - ethClient := mocks.NewIEthereumClient(t) + ethClient := mocks.NewEthereumClientMock(t) ethman := getEtherman(ethClient) ethClient.On( @@ -179,7 +179,7 @@ func TestGetSequencerAddr(t *testing.T) { func TestBuildTrustedVerifyBatches(t *testing.T) { t.Parallel() assert := assert.New(t) - ethman := getEtherman(mocks.NewIEthereumClient(t)) + ethman := getEtherman(mocks.NewEthereumClientMock(t)) // Because we cant mock the ABI dependency is this the only test case that we somehow // can have here in a unit test. Further test coverage can get achieved with e2e or integration tests. @@ -205,7 +205,7 @@ func TestCallContract(t *testing.T) { assert := assert.New(t) t.Run("Returns expected value", func(t *testing.T) { - ethClient := mocks.NewIEthereumClient(t) + ethClient := mocks.NewEthereumClientMock(t) ethman := getEtherman(ethClient) ethClient.On( @@ -248,7 +248,7 @@ func TestCallContract(t *testing.T) { }) t.Run("Returns expected error", func(t *testing.T) { - ethClient := mocks.NewIEthereumClient(t) + ethClient := mocks.NewEthereumClientMock(t) ethman := getEtherman(ethClient) ethClient.On( @@ -296,7 +296,7 @@ func TestCheckTxWasMined(t *testing.T) { assert := assert.New(t) t.Run("Returns expected error on 'ethereum.NotFound'", func(t *testing.T) { - ethClient := mocks.NewIEthereumClient(t) + ethClient := mocks.NewEthereumClientMock(t) ethman := getEtherman(ethClient) ethClient.On( @@ -317,7 +317,7 @@ func TestCheckTxWasMined(t *testing.T) { }) t.Run("Returns expected error", func(t *testing.T) { - ethClient := mocks.NewIEthereumClient(t) + ethClient := mocks.NewEthereumClientMock(t) ethman := getEtherman(ethClient) ethClient.On( @@ -338,7 +338,7 @@ func TestCheckTxWasMined(t *testing.T) { }) t.Run("Returns the expected values", func(t *testing.T) { - ethClient := mocks.NewIEthereumClient(t) + ethClient := mocks.NewEthereumClientMock(t) ethman := getEtherman(ethClient) ethClient.On( @@ -364,7 +364,7 @@ func TestCurrentNonce(t *testing.T) { assert := assert.New(t) t.Run("Returns the expected nonce value", func(t *testing.T) { - ethClient := mocks.NewIEthereumClient(t) + ethClient := mocks.NewEthereumClientMock(t) ethman := getEtherman(ethClient) ethClient.On( @@ -385,7 +385,7 @@ func TestCurrentNonce(t *testing.T) { }) t.Run("Returns the expected error", func(t *testing.T) { - ethClient := mocks.NewIEthereumClient(t) + ethClient := mocks.NewEthereumClientMock(t) ethman := getEtherman(ethClient) ethClient.On( @@ -411,7 +411,7 @@ func TestGetTx(t *testing.T) { assert := assert.New(t) t.Run("Returns the expected transaction", func(t *testing.T) { - ethClient := mocks.NewIEthereumClient(t) + ethClient := mocks.NewEthereumClientMock(t) ethman := getEtherman(ethClient) ethClient.On( @@ -433,7 +433,7 @@ func TestGetTx(t *testing.T) { }) t.Run("Returns the expected error", func(t *testing.T) { - ethClient := mocks.NewIEthereumClient(t) + ethClient := mocks.NewEthereumClientMock(t) ethman := getEtherman(ethClient) ethClient.On( @@ -460,7 +460,7 @@ func TestGetTxReceipt(t *testing.T) { assert := assert.New(t) t.Run("Returns expected receipt", func(t *testing.T) { - ethClient := mocks.NewIEthereumClient(t) + ethClient := mocks.NewEthereumClientMock(t) ethman := getEtherman(ethClient) ethClient.On( @@ -480,7 +480,7 @@ func TestGetTxReceipt(t *testing.T) { }) t.Run("Returns expected error", func(t *testing.T) { - ethClient := mocks.NewIEthereumClient(t) + ethClient := mocks.NewEthereumClientMock(t) ethman := getEtherman(ethClient) ethClient.On( @@ -513,7 +513,7 @@ func TestSendTx(t *testing.T) { ) t.Run("Returns expected value", func(t *testing.T) { - ethClient := mocks.NewIEthereumClient(t) + ethClient := mocks.NewEthereumClientMock(t) ethman := getEtherman(ethClient) ethClient.On( @@ -531,7 +531,7 @@ func TestSendTx(t *testing.T) { }) t.Run("Returns expected error", func(t *testing.T) { - ethClient := mocks.NewIEthereumClient(t) + ethClient := mocks.NewEthereumClientMock(t) ethman := getEtherman(ethClient) ethClient.On( @@ -554,7 +554,7 @@ func TestSuggestedGasPrice(t *testing.T) { assert := assert.New(t) t.Run("Returns expected value", func(t *testing.T) { - ethClient := mocks.NewIEthereumClient(t) + ethClient := mocks.NewEthereumClientMock(t) ethman := getEtherman(ethClient) ethClient.On( @@ -573,7 +573,7 @@ func TestSuggestedGasPrice(t *testing.T) { }) t.Run("Returns expected error", func(t *testing.T) { - ethClient := mocks.NewIEthereumClient(t) + ethClient := mocks.NewEthereumClientMock(t) ethman := getEtherman(ethClient) ethClient.On( @@ -597,7 +597,7 @@ func TestEstimateGas(t *testing.T) { assert := assert.New(t) t.Run("Returns the expected value", func(t *testing.T) { - ethclient := mocks.NewIEthereumClient(t) + ethclient := mocks.NewEthereumClientMock(t) ethman := getEtherman(ethclient) ethclient.On( @@ -628,7 +628,7 @@ func TestEstimateGas(t *testing.T) { }) t.Run("Returns the expected error", func(t *testing.T) { - ethclient := mocks.NewIEthereumClient(t) + ethclient := mocks.NewEthereumClientMock(t) ethman := getEtherman(ethclient) ethclient.On( @@ -672,7 +672,7 @@ func TestSignTx(t *testing.T) { ) t.Run("Returns the expected value", func(t *testing.T) { - ethClient := mocks.NewIEthereumClient(t) + ethClient := mocks.NewEthereumClientMock(t) ethman := getEtherman(ethClient) transaction, err := ethman.SignTx(context.TODO(), common.Address{}, txData) @@ -695,7 +695,7 @@ func TestGetRevertMessage(t *testing.T) { ) t.Run("Returns an empty string and the expected error", func(t *testing.T) { - ethClient := mocks.NewIEthereumClient(t) + ethClient := mocks.NewEthereumClientMock(t) ethman := getEtherman(ethClient) ethClient.On( @@ -714,7 +714,7 @@ func TestGetRevertMessage(t *testing.T) { }) t.Run("Returns an empty string and the error set to nil", func(t *testing.T) { - ethClient := mocks.NewIEthereumClient(t) + ethClient := mocks.NewEthereumClientMock(t) ethman := getEtherman(ethClient) ethClient.On( @@ -735,7 +735,7 @@ func TestGetRevertMessage(t *testing.T) { }) t.Run("Returns the expected revert reason string", func(t *testing.T) { - ethClient := mocks.NewIEthereumClient(t) + ethClient := mocks.NewEthereumClientMock(t) ethman := getEtherman(ethClient) key, _ := crypto.GenerateKey() @@ -785,7 +785,7 @@ func TestGetLastBlock(t *testing.T) { assert := assert.New(t) t.Run("Returns the expected values", func(t *testing.T) { - ethClient := mocks.NewIEthereumClient(t) + ethClient := mocks.NewEthereumClientMock(t) ethman := getEtherman(ethClient) ethClient.On( @@ -812,7 +812,7 @@ func TestGetLastBlock(t *testing.T) { }) t.Run("Returns the expected error", func(t *testing.T) { - ethClient := mocks.NewIEthereumClient(t) + ethClient := mocks.NewEthereumClientMock(t) ethman := getEtherman(ethClient) ethClient.On( diff --git a/etherman/interfaces.go b/etherman/interfaces.go index 3fdd8d5..c926d90 100644 --- a/etherman/interfaces.go +++ b/etherman/interfaces.go @@ -5,7 +5,7 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi/bind" ) -//go:generate mockery --name IEthereumClient --output ../mocks --case=underscore --filename etherman_client.generated.go +//go:generate mockery --name IEthereumClient --structname EthereumClientMock --output ../mocks --case=underscore --filename etherman_client.generated.go type IEthereumClient interface { ethereum.ChainReader ethereum.ChainStateReader diff --git a/interop/executor_test.go b/interop/executor_test.go index 5bdb811..4ea0830 100644 --- a/interop/executor_test.go +++ b/interop/executor_test.go @@ -23,8 +23,8 @@ import ( func TestNewExecutor(t *testing.T) { cfg := &config.Config{} interopAdminAddr := common.HexToAddress("0x1234567890abcdef") - etherman := mocks.NewIEtherman(t) - ethTxManager := mocks.NewIEthTxManager(t) + etherman := mocks.NewEthermanMock(t) + ethTxManager := mocks.NewEthTxManagerMock(t) executor := New(nil, cfg, interopAdminAddr, etherman, ethTxManager) @@ -43,8 +43,8 @@ func TestExecutor_CheckTx(t *testing.T) { }, } interopAdminAddr := common.HexToAddress("0x1234567890abcdef") - etherman := mocks.NewIEtherman(t) - ethTxManager := mocks.NewIEthTxManager(t) + etherman := mocks.NewEthermanMock(t) + ethTxManager := mocks.NewEthTxManagerMock(t) executor := New(log.WithFields("test", "test"), cfg, interopAdminAddr, etherman, ethTxManager) @@ -81,8 +81,8 @@ func TestExecutor_CheckTx(t *testing.T) { func TestExecutor_VerifyZKP(t *testing.T) { cfg := &config.Config{} interopAdminAddr := common.HexToAddress("0x1234567890abcdef") - etherman := mocks.NewIEtherman(t) - ethTxManager := mocks.NewIEthTxManager(t) + etherman := mocks.NewEthermanMock(t) + ethTxManager := mocks.NewEthTxManagerMock(t) tnx := tx.Tx{ LastVerifiedBatch: 0, NewVerifiedBatch: 1, @@ -128,8 +128,8 @@ func TestExecutor_VerifyZKP(t *testing.T) { func TestExecutor_VerifySignature(t *testing.T) { cfg := &config.Config{} interopAdminAddr := common.HexToAddress("0x1234567890abcdef") - etherman := mocks.NewIEtherman(t) - ethTxManager := mocks.NewIEthTxManager(t) + etherman := mocks.NewEthermanMock(t) + ethTxManager := mocks.NewEthTxManagerMock(t) executor := New(nil, cfg, interopAdminAddr, etherman, ethTxManager) @@ -164,8 +164,8 @@ func TestExecutor_VerifySignature(t *testing.T) { func TestExecutor_Execute(t *testing.T) { cfg := &config.Config{} interopAdminAddr := common.HexToAddress("0x1234567890abcdef") - etherman := mocks.NewIEtherman(t) - ethTxManager := mocks.NewIEthTxManager(t) + etherman := mocks.NewEthermanMock(t) + ethTxManager := mocks.NewEthTxManagerMock(t) executor := New(log.WithFields("test", "test"), cfg, interopAdminAddr, etherman, ethTxManager) @@ -182,8 +182,8 @@ func TestExecutor_Execute(t *testing.T) { } // Mock the ZkEVMClientCreator.NewClient method - mockZkEVMClientCreator := mocks.NewIZkEVMClientClientCreator(t) - mockZkEVMClient := mocks.NewIZkEVMClient(t) + mockZkEVMClientCreator := mocks.NewZkEVMClientClientCreatorMock(t) + mockZkEVMClient := mocks.NewZkEVMClientMock(t) mockZkEVMClientCreator.On("NewClient", mock.Anything).Return(mockZkEVMClient).Once() mockZkEVMClient.On("BatchByNumber", mock.Anything, big.NewInt(int64(signedTx.Tx.NewVerifiedBatch))). @@ -205,8 +205,8 @@ func TestExecutor_Execute(t *testing.T) { func TestExecutor_Settle(t *testing.T) { cfg := &config.Config{} interopAdminAddr := common.HexToAddress("0x1234567890abcdef") - etherman := mocks.NewIEtherman(t) - ethTxManager := mocks.NewIEthTxManager(t) + etherman := mocks.NewEthermanMock(t) + ethTxManager := mocks.NewEthTxManagerMock(t) dbTx := &mocks.TxMock{} executor := New(nil, cfg, interopAdminAddr, etherman, ethTxManager) @@ -261,8 +261,8 @@ func TestExecutor_Settle(t *testing.T) { func TestExecutor_GetTxStatus(t *testing.T) { cfg := &config.Config{} interopAdminAddr := common.HexToAddress("0x1234567890abcdef") - etherman := mocks.NewIEtherman(t) - ethTxManager := mocks.NewIEthTxManager(t) + etherman := mocks.NewEthermanMock(t) + ethTxManager := mocks.NewEthTxManagerMock(t) dbTx := &mocks.TxMock{} executor := New(nil, cfg, interopAdminAddr, etherman, ethTxManager) diff --git a/mocks/db.generated.go b/mocks/db.generated.go index ab1fc22..e950eb1 100644 --- a/mocks/db.generated.go +++ b/mocks/db.generated.go @@ -9,13 +9,13 @@ import ( mock "github.com/stretchr/testify/mock" ) -// IDB is an autogenerated mock type for the IDB type -type IDB struct { +// DBMock is an autogenerated mock type for the IDB type +type DBMock struct { mock.Mock } // BeginStateTransaction provides a mock function with given fields: ctx -func (_m *IDB) BeginStateTransaction(ctx context.Context) (pgx.Tx, error) { +func (_m *DBMock) BeginStateTransaction(ctx context.Context) (pgx.Tx, error) { ret := _m.Called(ctx) if len(ret) == 0 { @@ -44,13 +44,13 @@ func (_m *IDB) BeginStateTransaction(ctx context.Context) (pgx.Tx, error) { return r0, r1 } -// NewIDB creates a new instance of IDB. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// NewDBMock creates a new instance of DBMock. 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 NewIDB(t interface { +func NewDBMock(t interface { mock.TestingT Cleanup(func()) -}) *IDB { - mock := &IDB{} +}) *DBMock { + mock := &DBMock{} mock.Mock.Test(t) t.Cleanup(func() { mock.AssertExpectations(t) }) diff --git a/mocks/eth_tx_manager.generated.go b/mocks/eth_tx_manager.generated.go index 04f37d2..d83c45e 100644 --- a/mocks/eth_tx_manager.generated.go +++ b/mocks/eth_tx_manager.generated.go @@ -15,13 +15,13 @@ import ( pgx "github.com/jackc/pgx/v4" ) -// IEthTxManager is an autogenerated mock type for the IEthTxManager type -type IEthTxManager struct { +// EthTxManagerMock is an autogenerated mock type for the IEthTxManager type +type EthTxManagerMock struct { mock.Mock } // Add provides a mock function with given fields: ctx, owner, id, from, to, value, data, gasOffset, dbTx -func (_m *IEthTxManager) Add(ctx context.Context, owner string, id string, from common.Address, to *common.Address, value *big.Int, data []byte, gasOffset uint64, dbTx pgx.Tx) error { +func (_m *EthTxManagerMock) Add(ctx context.Context, owner string, id string, from common.Address, to *common.Address, value *big.Int, data []byte, gasOffset uint64, dbTx pgx.Tx) error { ret := _m.Called(ctx, owner, id, from, to, value, data, gasOffset, dbTx) if len(ret) == 0 { @@ -39,12 +39,12 @@ func (_m *IEthTxManager) Add(ctx context.Context, owner string, id string, from } // ProcessPendingMonitoredTxs provides a mock function with given fields: ctx, owner, failedResultHandler, dbTx -func (_m *IEthTxManager) ProcessPendingMonitoredTxs(ctx context.Context, owner string, failedResultHandler ethtxmanager.ResultHandler, dbTx pgx.Tx) { +func (_m *EthTxManagerMock) ProcessPendingMonitoredTxs(ctx context.Context, owner string, failedResultHandler ethtxmanager.ResultHandler, dbTx pgx.Tx) { _m.Called(ctx, owner, failedResultHandler, dbTx) } // Result provides a mock function with given fields: ctx, owner, id, dbTx -func (_m *IEthTxManager) Result(ctx context.Context, owner string, id string, dbTx pgx.Tx) (ethtxmanager.MonitoredTxResult, error) { +func (_m *EthTxManagerMock) Result(ctx context.Context, owner string, id string, dbTx pgx.Tx) (ethtxmanager.MonitoredTxResult, error) { ret := _m.Called(ctx, owner, id, dbTx) if len(ret) == 0 { @@ -72,7 +72,7 @@ func (_m *IEthTxManager) Result(ctx context.Context, owner string, id string, db } // ResultsByStatus provides a mock function with given fields: ctx, owner, statuses, dbTx -func (_m *IEthTxManager) ResultsByStatus(ctx context.Context, owner string, statuses []ethtxmanager.MonitoredTxStatus, dbTx pgx.Tx) ([]ethtxmanager.MonitoredTxResult, error) { +func (_m *EthTxManagerMock) ResultsByStatus(ctx context.Context, owner string, statuses []ethtxmanager.MonitoredTxStatus, dbTx pgx.Tx) ([]ethtxmanager.MonitoredTxResult, error) { ret := _m.Called(ctx, owner, statuses, dbTx) if len(ret) == 0 { @@ -101,13 +101,13 @@ func (_m *IEthTxManager) ResultsByStatus(ctx context.Context, owner string, stat return r0, r1 } -// NewIEthTxManager creates a new instance of IEthTxManager. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// NewEthTxManagerMock creates a new instance of EthTxManagerMock. 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 NewIEthTxManager(t interface { +func NewEthTxManagerMock(t interface { mock.TestingT Cleanup(func()) -}) *IEthTxManager { - mock := &IEthTxManager{} +}) *EthTxManagerMock { + mock := &EthTxManagerMock{} mock.Mock.Test(t) t.Cleanup(func() { mock.AssertExpectations(t) }) diff --git a/mocks/etherman.generated.go b/mocks/etherman.generated.go index 663e430..ab0af5a 100644 --- a/mocks/etherman.generated.go +++ b/mocks/etherman.generated.go @@ -15,13 +15,13 @@ import ( tx "github.com/0xPolygon/beethoven/tx" ) -// IEtherman is an autogenerated mock type for the IEtherman type -type IEtherman struct { +// EthermanMock is an autogenerated mock type for the IEtherman type +type EthermanMock struct { mock.Mock } // BuildTrustedVerifyBatchesTxData provides a mock function with given fields: lastVerifiedBatch, newVerifiedBatch, proof, rollupId -func (_m *IEtherman) BuildTrustedVerifyBatchesTxData(lastVerifiedBatch uint64, newVerifiedBatch uint64, proof tx.ZKP, rollupId uint32) ([]byte, error) { +func (_m *EthermanMock) BuildTrustedVerifyBatchesTxData(lastVerifiedBatch uint64, newVerifiedBatch uint64, proof tx.ZKP, rollupId uint32) ([]byte, error) { ret := _m.Called(lastVerifiedBatch, newVerifiedBatch, proof, rollupId) if len(ret) == 0 { @@ -51,7 +51,7 @@ func (_m *IEtherman) BuildTrustedVerifyBatchesTxData(lastVerifiedBatch uint64, n } // CallContract provides a mock function with given fields: ctx, call, blockNumber -func (_m *IEtherman) CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error) { +func (_m *EthermanMock) CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error) { ret := _m.Called(ctx, call, blockNumber) if len(ret) == 0 { @@ -81,7 +81,7 @@ func (_m *IEtherman) CallContract(ctx context.Context, call ethereum.CallMsg, bl } // GetSequencerAddr provides a mock function with given fields: rollupId -func (_m *IEtherman) GetSequencerAddr(rollupId uint32) (common.Address, error) { +func (_m *EthermanMock) GetSequencerAddr(rollupId uint32) (common.Address, error) { ret := _m.Called(rollupId) if len(ret) == 0 { @@ -110,13 +110,13 @@ func (_m *IEtherman) GetSequencerAddr(rollupId uint32) (common.Address, error) { return r0, r1 } -// NewIEtherman creates a new instance of IEtherman. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// NewEthermanMock creates a new instance of EthermanMock. 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 NewIEtherman(t interface { +func NewEthermanMock(t interface { mock.TestingT Cleanup(func()) -}) *IEtherman { - mock := &IEtherman{} +}) *EthermanMock { + mock := &EthermanMock{} mock.Mock.Test(t) t.Cleanup(func() { mock.AssertExpectations(t) }) diff --git a/mocks/etherman_client.generated.go b/mocks/etherman_client.generated.go index b420255..3dfb2e6 100644 --- a/mocks/etherman_client.generated.go +++ b/mocks/etherman_client.generated.go @@ -15,13 +15,13 @@ import ( types "github.com/ethereum/go-ethereum/core/types" ) -// IEthereumClient is an autogenerated mock type for the IEthereumClient type -type IEthereumClient struct { +// EthereumClientMock is an autogenerated mock type for the IEthereumClient type +type EthereumClientMock struct { mock.Mock } // BalanceAt provides a mock function with given fields: ctx, account, blockNumber -func (_m *IEthereumClient) BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error) { +func (_m *EthereumClientMock) BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error) { ret := _m.Called(ctx, account, blockNumber) if len(ret) == 0 { @@ -51,7 +51,7 @@ func (_m *IEthereumClient) BalanceAt(ctx context.Context, account common.Address } // BlockByHash provides a mock function with given fields: ctx, hash -func (_m *IEthereumClient) BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error) { +func (_m *EthereumClientMock) BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error) { ret := _m.Called(ctx, hash) if len(ret) == 0 { @@ -81,7 +81,7 @@ func (_m *IEthereumClient) BlockByHash(ctx context.Context, hash common.Hash) (* } // BlockByNumber provides a mock function with given fields: ctx, number -func (_m *IEthereumClient) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) { +func (_m *EthereumClientMock) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) { ret := _m.Called(ctx, number) if len(ret) == 0 { @@ -111,7 +111,7 @@ func (_m *IEthereumClient) BlockByNumber(ctx context.Context, number *big.Int) ( } // CallContract provides a mock function with given fields: ctx, call, blockNumber -func (_m *IEthereumClient) CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error) { +func (_m *EthereumClientMock) CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error) { ret := _m.Called(ctx, call, blockNumber) if len(ret) == 0 { @@ -141,7 +141,7 @@ func (_m *IEthereumClient) CallContract(ctx context.Context, call ethereum.CallM } // CodeAt provides a mock function with given fields: ctx, account, blockNumber -func (_m *IEthereumClient) CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error) { +func (_m *EthereumClientMock) CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error) { ret := _m.Called(ctx, account, blockNumber) if len(ret) == 0 { @@ -171,7 +171,7 @@ func (_m *IEthereumClient) CodeAt(ctx context.Context, account common.Address, b } // EstimateGas provides a mock function with given fields: ctx, call -func (_m *IEthereumClient) EstimateGas(ctx context.Context, call ethereum.CallMsg) (uint64, error) { +func (_m *EthereumClientMock) EstimateGas(ctx context.Context, call ethereum.CallMsg) (uint64, error) { ret := _m.Called(ctx, call) if len(ret) == 0 { @@ -199,7 +199,7 @@ func (_m *IEthereumClient) EstimateGas(ctx context.Context, call ethereum.CallMs } // FilterLogs provides a mock function with given fields: ctx, q -func (_m *IEthereumClient) FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error) { +func (_m *EthereumClientMock) FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error) { ret := _m.Called(ctx, q) if len(ret) == 0 { @@ -229,7 +229,7 @@ func (_m *IEthereumClient) FilterLogs(ctx context.Context, q ethereum.FilterQuer } // HeaderByHash provides a mock function with given fields: ctx, hash -func (_m *IEthereumClient) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) { +func (_m *EthereumClientMock) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) { ret := _m.Called(ctx, hash) if len(ret) == 0 { @@ -259,7 +259,7 @@ func (_m *IEthereumClient) HeaderByHash(ctx context.Context, hash common.Hash) ( } // HeaderByNumber provides a mock function with given fields: ctx, number -func (_m *IEthereumClient) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) { +func (_m *EthereumClientMock) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) { ret := _m.Called(ctx, number) if len(ret) == 0 { @@ -289,7 +289,7 @@ func (_m *IEthereumClient) HeaderByNumber(ctx context.Context, number *big.Int) } // NonceAt provides a mock function with given fields: ctx, account, blockNumber -func (_m *IEthereumClient) NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error) { +func (_m *EthereumClientMock) NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error) { ret := _m.Called(ctx, account, blockNumber) if len(ret) == 0 { @@ -317,7 +317,7 @@ func (_m *IEthereumClient) NonceAt(ctx context.Context, account common.Address, } // PendingCodeAt provides a mock function with given fields: ctx, account -func (_m *IEthereumClient) PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error) { +func (_m *EthereumClientMock) PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error) { ret := _m.Called(ctx, account) if len(ret) == 0 { @@ -347,7 +347,7 @@ func (_m *IEthereumClient) PendingCodeAt(ctx context.Context, account common.Add } // PendingNonceAt provides a mock function with given fields: ctx, account -func (_m *IEthereumClient) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error) { +func (_m *EthereumClientMock) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error) { ret := _m.Called(ctx, account) if len(ret) == 0 { @@ -375,7 +375,7 @@ func (_m *IEthereumClient) PendingNonceAt(ctx context.Context, account common.Ad } // SendTransaction provides a mock function with given fields: ctx, tx -func (_m *IEthereumClient) SendTransaction(ctx context.Context, tx *types.Transaction) error { +func (_m *EthereumClientMock) SendTransaction(ctx context.Context, tx *types.Transaction) error { ret := _m.Called(ctx, tx) if len(ret) == 0 { @@ -393,7 +393,7 @@ func (_m *IEthereumClient) SendTransaction(ctx context.Context, tx *types.Transa } // StorageAt provides a mock function with given fields: ctx, account, key, blockNumber -func (_m *IEthereumClient) StorageAt(ctx context.Context, account common.Address, key common.Hash, blockNumber *big.Int) ([]byte, error) { +func (_m *EthereumClientMock) StorageAt(ctx context.Context, account common.Address, key common.Hash, blockNumber *big.Int) ([]byte, error) { ret := _m.Called(ctx, account, key, blockNumber) if len(ret) == 0 { @@ -423,7 +423,7 @@ func (_m *IEthereumClient) StorageAt(ctx context.Context, account common.Address } // SubscribeFilterLogs provides a mock function with given fields: ctx, q, ch -func (_m *IEthereumClient) SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error) { +func (_m *EthereumClientMock) SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error) { ret := _m.Called(ctx, q, ch) if len(ret) == 0 { @@ -453,7 +453,7 @@ func (_m *IEthereumClient) SubscribeFilterLogs(ctx context.Context, q ethereum.F } // SubscribeNewHead provides a mock function with given fields: ctx, ch -func (_m *IEthereumClient) SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (ethereum.Subscription, error) { +func (_m *EthereumClientMock) SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (ethereum.Subscription, error) { ret := _m.Called(ctx, ch) if len(ret) == 0 { @@ -483,7 +483,7 @@ func (_m *IEthereumClient) SubscribeNewHead(ctx context.Context, ch chan<- *type } // SuggestGasPrice provides a mock function with given fields: ctx -func (_m *IEthereumClient) SuggestGasPrice(ctx context.Context) (*big.Int, error) { +func (_m *EthereumClientMock) SuggestGasPrice(ctx context.Context) (*big.Int, error) { ret := _m.Called(ctx) if len(ret) == 0 { @@ -513,7 +513,7 @@ func (_m *IEthereumClient) SuggestGasPrice(ctx context.Context) (*big.Int, error } // SuggestGasTipCap provides a mock function with given fields: ctx -func (_m *IEthereumClient) SuggestGasTipCap(ctx context.Context) (*big.Int, error) { +func (_m *EthereumClientMock) SuggestGasTipCap(ctx context.Context) (*big.Int, error) { ret := _m.Called(ctx) if len(ret) == 0 { @@ -543,7 +543,7 @@ func (_m *IEthereumClient) SuggestGasTipCap(ctx context.Context) (*big.Int, erro } // TransactionByHash provides a mock function with given fields: ctx, txHash -func (_m *IEthereumClient) TransactionByHash(ctx context.Context, txHash common.Hash) (*types.Transaction, bool, error) { +func (_m *EthereumClientMock) TransactionByHash(ctx context.Context, txHash common.Hash) (*types.Transaction, bool, error) { ret := _m.Called(ctx, txHash) if len(ret) == 0 { @@ -580,7 +580,7 @@ func (_m *IEthereumClient) TransactionByHash(ctx context.Context, txHash common. } // TransactionCount provides a mock function with given fields: ctx, blockHash -func (_m *IEthereumClient) TransactionCount(ctx context.Context, blockHash common.Hash) (uint, error) { +func (_m *EthereumClientMock) TransactionCount(ctx context.Context, blockHash common.Hash) (uint, error) { ret := _m.Called(ctx, blockHash) if len(ret) == 0 { @@ -608,7 +608,7 @@ func (_m *IEthereumClient) TransactionCount(ctx context.Context, blockHash commo } // TransactionInBlock provides a mock function with given fields: ctx, blockHash, index -func (_m *IEthereumClient) TransactionInBlock(ctx context.Context, blockHash common.Hash, index uint) (*types.Transaction, error) { +func (_m *EthereumClientMock) TransactionInBlock(ctx context.Context, blockHash common.Hash, index uint) (*types.Transaction, error) { ret := _m.Called(ctx, blockHash, index) if len(ret) == 0 { @@ -638,7 +638,7 @@ func (_m *IEthereumClient) TransactionInBlock(ctx context.Context, blockHash com } // TransactionReceipt provides a mock function with given fields: ctx, txHash -func (_m *IEthereumClient) TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) { +func (_m *EthereumClientMock) TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) { ret := _m.Called(ctx, txHash) if len(ret) == 0 { @@ -667,13 +667,13 @@ func (_m *IEthereumClient) TransactionReceipt(ctx context.Context, txHash common return r0, r1 } -// NewIEthereumClient creates a new instance of IEthereumClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// NewEthereumClientMock creates a new instance of EthereumClientMock. 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 NewIEthereumClient(t interface { +func NewEthereumClientMock(t interface { mock.TestingT Cleanup(func()) -}) *IEthereumClient { - mock := &IEthereumClient{} +}) *EthereumClientMock { + mock := &EthereumClientMock{} mock.Mock.Test(t) t.Cleanup(func() { mock.AssertExpectations(t) }) diff --git a/mocks/zk_evm_client.generated.go b/mocks/zk_evm_client.generated.go index e4b0a1f..4cac43e 100644 --- a/mocks/zk_evm_client.generated.go +++ b/mocks/zk_evm_client.generated.go @@ -11,13 +11,13 @@ import ( types "github.com/0xPolygonHermez/zkevm-node/jsonrpc/types" ) -// IZkEVMClient is an autogenerated mock type for the IZkEVMClient type -type IZkEVMClient struct { +// ZkEVMClientMock is an autogenerated mock type for the IZkEVMClient type +type ZkEVMClientMock struct { mock.Mock } // BatchByNumber provides a mock function with given fields: ctx, number -func (_m *IZkEVMClient) BatchByNumber(ctx context.Context, number *big.Int) (*types.Batch, error) { +func (_m *ZkEVMClientMock) BatchByNumber(ctx context.Context, number *big.Int) (*types.Batch, error) { ret := _m.Called(ctx, number) if len(ret) == 0 { @@ -46,13 +46,13 @@ func (_m *IZkEVMClient) BatchByNumber(ctx context.Context, number *big.Int) (*ty return r0, r1 } -// NewIZkEVMClient creates a new instance of IZkEVMClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// NewZkEVMClientMock creates a new instance of ZkEVMClientMock. 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 NewIZkEVMClient(t interface { +func NewZkEVMClientMock(t interface { mock.TestingT Cleanup(func()) -}) *IZkEVMClient { - mock := &IZkEVMClient{} +}) *ZkEVMClientMock { + mock := &ZkEVMClientMock{} mock.Mock.Test(t) t.Cleanup(func() { mock.AssertExpectations(t) }) diff --git a/mocks/zk_evm_client_creator.generated.go b/mocks/zk_evm_client_creator.generated.go index 9606f73..dfa6dc8 100644 --- a/mocks/zk_evm_client_creator.generated.go +++ b/mocks/zk_evm_client_creator.generated.go @@ -7,13 +7,13 @@ import ( mock "github.com/stretchr/testify/mock" ) -// IZkEVMClientClientCreator is an autogenerated mock type for the IZkEVMClientClientCreator type -type IZkEVMClientClientCreator struct { +// ZkEVMClientClientCreatorMock is an autogenerated mock type for the IZkEVMClientClientCreator type +type ZkEVMClientClientCreatorMock struct { mock.Mock } // NewClient provides a mock function with given fields: rpc -func (_m *IZkEVMClientClientCreator) NewClient(rpc string) types.IZkEVMClient { +func (_m *ZkEVMClientClientCreatorMock) NewClient(rpc string) types.IZkEVMClient { ret := _m.Called(rpc) if len(ret) == 0 { @@ -32,13 +32,13 @@ func (_m *IZkEVMClientClientCreator) NewClient(rpc string) types.IZkEVMClient { return r0 } -// NewIZkEVMClientClientCreator creates a new instance of IZkEVMClientClientCreator. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// NewZkEVMClientClientCreatorMock creates a new instance of ZkEVMClientClientCreatorMock. 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 NewIZkEVMClientClientCreator(t interface { +func NewZkEVMClientClientCreatorMock(t interface { mock.TestingT Cleanup(func()) -}) *IZkEVMClientClientCreator { - mock := &IZkEVMClientClientCreator{} +}) *ZkEVMClientClientCreatorMock { + mock := &ZkEVMClientClientCreatorMock{} mock.Mock.Test(t) t.Cleanup(func() { mock.AssertExpectations(t) }) diff --git a/rpc/rpc_test.go b/rpc/rpc_test.go index 03d5ed7..21da4f7 100644 --- a/rpc/rpc_test.go +++ b/rpc/rpc_test.go @@ -29,15 +29,15 @@ func TestInteropEndpointsGetTxStatus(t *testing.T) { t.Run("BeginStateTransaction returns an error", func(t *testing.T) { t.Parallel() - dbMock := mocks.NewIDB(t) + dbMock := mocks.NewDBMock(t) dbMock.On("BeginStateTransaction", mock.Anything).Return(nil, errors.New("error")).Once() e := interop.New( log.WithFields("module", "test"), &config.Config{}, common.HexToAddress("0xadmin"), - mocks.NewIEtherman(t), - mocks.NewIEthTxManager(t), + mocks.NewEthermanMock(t), + mocks.NewEthTxManagerMock(t), ) i := NewInteropEndpoints(context.Background(), e, dbMock) @@ -57,10 +57,10 @@ func TestInteropEndpointsGetTxStatus(t *testing.T) { txMock := new(mocks.TxMock) txMock.On("Rollback", mock.Anything).Return(nil).Once() - dbMock := mocks.NewIDB(t) + dbMock := mocks.NewDBMock(t) dbMock.On("BeginStateTransaction", mock.Anything).Return(txMock, nil).Once() - txManagerMock := mocks.NewIEthTxManager(t) + txManagerMock := mocks.NewEthTxManagerMock(t) txManagerMock.On("Result", mock.Anything, ethTxManOwner, txHash.Hex(), txMock). Return(ethtxmanager.MonitoredTxResult{}, errors.New("error")).Once() @@ -68,7 +68,7 @@ func TestInteropEndpointsGetTxStatus(t *testing.T) { log.WithFields("module", "test"), &config.Config{}, common.HexToAddress("0xadmin"), - mocks.NewIEtherman(t), + mocks.NewEthermanMock(t), txManagerMock, ) i := NewInteropEndpoints(context.Background(), e, dbMock) @@ -101,10 +101,10 @@ func TestInteropEndpointsGetTxStatus(t *testing.T) { txMock := new(mocks.TxMock) txMock.On("Rollback", mock.Anything).Return(nil).Once() - dbMock := mocks.NewIDB(t) + dbMock := mocks.NewDBMock(t) dbMock.On("BeginStateTransaction", mock.Anything).Return(txMock, nil).Once() - txManagerMock := mocks.NewIEthTxManager(t) + txManagerMock := mocks.NewEthTxManagerMock(t) txManagerMock.On("Result", mock.Anything, ethTxManOwner, txHash.Hex(), txMock). Return(result, nil).Once() @@ -112,7 +112,7 @@ func TestInteropEndpointsGetTxStatus(t *testing.T) { log.WithFields("module", "test"), &config.Config{}, common.HexToAddress("0xadmin"), - mocks.NewIEtherman(t), + mocks.NewEthermanMock(t), txManagerMock, ) i := NewInteropEndpoints(context.Background(), e, dbMock) @@ -161,12 +161,12 @@ func TestInteropEndpointsSendTx(t *testing.T) { RollupID: 1, } signedTx := &tx.SignedTx{Tx: tnx} - ethermanMock := mocks.NewIEtherman(t) - zkEVMClientCreatorMock := mocks.NewIZkEVMClientClientCreator(t) - zkEVMClientMock := mocks.NewIZkEVMClient(t) - dbMock := mocks.NewIDB(t) + ethermanMock := mocks.NewEthermanMock(t) + zkEVMClientCreatorMock := mocks.NewZkEVMClientClientCreatorMock(t) + zkEVMClientMock := mocks.NewZkEVMClientMock(t) + dbMock := mocks.NewDBMock(t) txMock := new(mocks.TxMock) - ethTxManagerMock := mocks.NewIEthTxManager(t) + ethTxManagerMock := mocks.NewEthTxManagerMock(t) executeTestFn := func() { e := interop.New( diff --git a/types/interfaces.go b/types/interfaces.go index 6840646..1d4e003 100644 --- a/types/interfaces.go +++ b/types/interfaces.go @@ -12,19 +12,19 @@ import ( "github.com/jackc/pgx/v4" ) -//go:generate mockery --name IDB --output ../mocks --case=underscore --filename db.generated.go +//go:generate mockery --name IDB --structname DBMock --output ../mocks --case=underscore --filename db.generated.go type IDB interface { BeginStateTransaction(ctx context.Context) (pgx.Tx, error) } -//go:generate mockery --name IEtherman --output ../mocks --case=underscore --filename etherman.generated.go +//go:generate mockery --name IEtherman --structname EthermanMock --output ../mocks --case=underscore --filename etherman.generated.go type IEtherman interface { GetSequencerAddr(rollupId uint32) (common.Address, error) BuildTrustedVerifyBatchesTxData(lastVerifiedBatch, newVerifiedBatch uint64, proof tx.ZKP, rollupId uint32) (data []byte, err error) CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error) } -//go:generate mockery --name IEthTxManager --output ../mocks --case=underscore --filename eth_tx_manager.generated.go +//go:generate mockery --name IEthTxManager --structname EthTxManagerMock --output ../mocks --case=underscore --filename eth_tx_manager.generated.go type IEthTxManager interface { Add(ctx context.Context, owner, id string, from common.Address, to *common.Address, value *big.Int, data []byte, gasOffset uint64, dbTx pgx.Tx) error Result(ctx context.Context, owner, id string, dbTx pgx.Tx) (ethtxmanager.MonitoredTxResult, error) @@ -32,12 +32,12 @@ type IEthTxManager interface { ProcessPendingMonitoredTxs(ctx context.Context, owner string, failedResultHandler ethtxmanager.ResultHandler, dbTx pgx.Tx) } -//go:generate mockery --name IZkEVMClient --output ../mocks --case=underscore --filename zk_evm_client.generated.go +//go:generate mockery --name IZkEVMClient --structname ZkEVMClientMock --output ../mocks --case=underscore --filename zk_evm_client.generated.go type IZkEVMClient interface { BatchByNumber(ctx context.Context, number *big.Int) (*types.Batch, error) } -//go:generate mockery --name IZkEVMClientClientCreator --output ../mocks --case=underscore --filename zk_evm_client_creator.generated.go +//go:generate mockery --name IZkEVMClientClientCreator --structname ZkEVMClientClientCreatorMock --output ../mocks --case=underscore --filename zk_evm_client_creator.generated.go type IZkEVMClientClientCreator interface { NewClient(rpc string) IZkEVMClient }