From 838bbaf4c520697a122947465d581ee1172adc85 Mon Sep 17 00:00:00 2001 From: Goran Rojovic Date: Tue, 16 Jan 2024 12:09:06 +0100 Subject: [PATCH 1/2] Use mockery to auto generate mocks --- Makefile | 11 + etherman/etherman.go | 7 +- etherman/etherman_test.go | 61 +- etherman/interfaces.go | 3 +- interop/executor.go | 14 +- interop/executor_test.go | 32 +- mocks/db.generated.go | 59 ++ mocks/eth_tx_manager.generated.go | 116 ++++ mocks/ethclient_mock.go | 146 ----- mocks/etherman.generated.go | 125 +++++ mocks/etherman_client.generated.go | 682 +++++++++++++++++++++++ mocks/mocks.go | 124 ----- mocks/zk_evm_client.generated.go | 61 ++ mocks/zk_evm_client_creator.generated.go | 47 ++ rpc/rpc.go | 4 +- rpc/rpc_test.go | 28 +- types/interfaces.go | 18 +- 17 files changed, 1188 insertions(+), 350 deletions(-) create mode 100644 mocks/db.generated.go create mode 100644 mocks/eth_tx_manager.generated.go delete mode 100644 mocks/ethclient_mock.go create mode 100644 mocks/etherman.generated.go create mode 100644 mocks/etherman_client.generated.go delete mode 100644 mocks/mocks.go create mode 100644 mocks/zk_evm_client.generated.go create mode 100644 mocks/zk_evm_client_creator.generated.go diff --git a/Makefile b/Makefile index e1303d5..ca24997 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ include version.mk CHECK_GO := $(shell command -v go 2> /dev/null) CHECK_CURL := $(shell command -v curl 2> /dev/null) CHECK_DOCKER := $(shell command -v docker 2> /dev/null) +CHECK_MOCKERY := $(shell command -v mockery 2> /dev/null) check-go: ifndef CHECK_GO @@ -20,6 +21,11 @@ ifndef CHECK_DOCKER $(error "Docker is not installed. Please install Docker and retry.") endif +check-mockery: +ifndef CHECK_MOCKERY + $(error "Mockery is not installed. Please install Mockery and retry.") +endif + # Targets that require the checks build: check-go build-docker: check-docker @@ -32,6 +38,7 @@ install-linter: check-go check-curl lint: check-go unit-tests: check-go e2e-tests: check-go +generate-mocks: check-go check-mockery ARCH := $(shell uname -m) @@ -110,3 +117,7 @@ e2e-tests: ## Runs E2E tests .PHONY: unit-tests unit-tests: ## Runs unit tests go test -v -timeout=5m -race -shuffle=on -coverprofile coverage.out `go list ./... | grep -v test` + +.PHONY: generate-mocks +generate-mocks: ## Generates mocks and other autogenerated types + $(GOENVVARS) go generate ./... diff --git a/etherman/etherman.go b/etherman/etherman.go index 40e6c55..e6bedb5 100644 --- a/etherman/etherman.go +++ b/etherman/etherman.go @@ -4,10 +4,11 @@ import ( "context" "errors" "fmt" - "github.com/0xPolygon/beethoven/config" "math/big" "time" + "github.com/0xPolygon/beethoven/config" + "github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/polygonrollupmanager" "github.com/0xPolygonHermez/zkevm-node/etherman/smartcontracts/polygonzkevm" "github.com/0xPolygonHermez/zkevm-node/log" @@ -28,12 +29,12 @@ const ( ) type Etherman struct { - ethClient EthereumClient + ethClient IEthereumClient auth bind.TransactOpts config *config.Config } -func New(ethClient EthereumClient, auth bind.TransactOpts, cfg *config.Config) (Etherman, error) { +func New(ethClient IEthereumClient, auth bind.TransactOpts, cfg *config.Config) (Etherman, error) { return Etherman{ ethClient: ethClient, auth: auth, diff --git a/etherman/etherman_test.go b/etherman/etherman_test.go index 6944c81..1d04868 100644 --- a/etherman/etherman_test.go +++ b/etherman/etherman_test.go @@ -3,12 +3,13 @@ package etherman import ( "context" "errors" + "math/big" + "testing" + "github.com/0xPolygon/beethoven/config" cdkTypes "github.com/0xPolygon/beethoven/rpc/types" "github.com/0xPolygon/beethoven/tx" "github.com/ethereum/go-ethereum/crypto" - "math/big" - "testing" "github.com/0xPolygon/beethoven/mocks" "github.com/ethereum/go-ethereum" @@ -23,7 +24,7 @@ func signer(from common.Address, tx *types.Transaction) (*types.Transaction, err return tx, nil } -func getEtherman(ethClientMock EthereumClient) Etherman { +func getEtherman(ethClientMock IEthereumClient) Etherman { ethman, _ := New( ethClientMock, bind.TransactOpts{ @@ -50,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 := new(mocks.EthereumClientMock) + ethClient := mocks.NewIEthereumClient(t) ethman := getEtherman(ethClient) ethClient.On( @@ -100,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 := new(mocks.EthereumClientMock) + ethClient := mocks.NewIEthereumClient(t) ethman := getEtherman(ethClient) ethClient.On( @@ -131,7 +132,7 @@ func TestGetSequencerAddr(t *testing.T) { t.Run("Returns expected sequencer address", func(t *testing.T) { t.Parallel() - ethClient := new(mocks.EthereumClientMock) + ethClient := mocks.NewIEthereumClient(t) ethman := getEtherman(ethClient) ethClient.On( @@ -178,7 +179,7 @@ func TestGetSequencerAddr(t *testing.T) { func TestBuildTrustedVerifyBatches(t *testing.T) { t.Parallel() assert := assert.New(t) - ethman := getEtherman(new(mocks.EthereumClientMock)) + ethman := getEtherman(mocks.NewIEthereumClient(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. @@ -204,7 +205,7 @@ func TestCallContract(t *testing.T) { assert := assert.New(t) t.Run("Returns expected value", func(t *testing.T) { - ethClient := new(mocks.EthereumClientMock) + ethClient := mocks.NewIEthereumClient(t) ethman := getEtherman(ethClient) ethClient.On( @@ -247,7 +248,7 @@ func TestCallContract(t *testing.T) { }) t.Run("Returns expected error", func(t *testing.T) { - ethClient := new(mocks.EthereumClientMock) + ethClient := mocks.NewIEthereumClient(t) ethman := getEtherman(ethClient) ethClient.On( @@ -295,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 := new(mocks.EthereumClientMock) + ethClient := mocks.NewIEthereumClient(t) ethman := getEtherman(ethClient) ethClient.On( @@ -316,7 +317,7 @@ func TestCheckTxWasMined(t *testing.T) { }) t.Run("Returns expected error", func(t *testing.T) { - ethClient := new(mocks.EthereumClientMock) + ethClient := mocks.NewIEthereumClient(t) ethman := getEtherman(ethClient) ethClient.On( @@ -337,7 +338,7 @@ func TestCheckTxWasMined(t *testing.T) { }) t.Run("Returns the expected values", func(t *testing.T) { - ethClient := new(mocks.EthereumClientMock) + ethClient := mocks.NewIEthereumClient(t) ethman := getEtherman(ethClient) ethClient.On( @@ -363,7 +364,7 @@ func TestCurrentNonce(t *testing.T) { assert := assert.New(t) t.Run("Returns the expected nonce value", func(t *testing.T) { - ethClient := new(mocks.EthereumClientMock) + ethClient := mocks.NewIEthereumClient(t) ethman := getEtherman(ethClient) ethClient.On( @@ -384,7 +385,7 @@ func TestCurrentNonce(t *testing.T) { }) t.Run("Returns the expected error", func(t *testing.T) { - ethClient := new(mocks.EthereumClientMock) + ethClient := mocks.NewIEthereumClient(t) ethman := getEtherman(ethClient) ethClient.On( @@ -410,7 +411,7 @@ func TestGetTx(t *testing.T) { assert := assert.New(t) t.Run("Returns the expected transaction", func(t *testing.T) { - ethClient := new(mocks.EthereumClientMock) + ethClient := mocks.NewIEthereumClient(t) ethman := getEtherman(ethClient) ethClient.On( @@ -432,7 +433,7 @@ func TestGetTx(t *testing.T) { }) t.Run("Returns the expected error", func(t *testing.T) { - ethClient := new(mocks.EthereumClientMock) + ethClient := mocks.NewIEthereumClient(t) ethman := getEtherman(ethClient) ethClient.On( @@ -459,7 +460,7 @@ func TestGetTxReceipt(t *testing.T) { assert := assert.New(t) t.Run("Returns expected receipt", func(t *testing.T) { - ethClient := new(mocks.EthereumClientMock) + ethClient := mocks.NewIEthereumClient(t) ethman := getEtherman(ethClient) ethClient.On( @@ -479,7 +480,7 @@ func TestGetTxReceipt(t *testing.T) { }) t.Run("Returns expected error", func(t *testing.T) { - ethClient := new(mocks.EthereumClientMock) + ethClient := mocks.NewIEthereumClient(t) ethman := getEtherman(ethClient) ethClient.On( @@ -512,7 +513,7 @@ func TestSendTx(t *testing.T) { ) t.Run("Returns expected value", func(t *testing.T) { - ethClient := new(mocks.EthereumClientMock) + ethClient := mocks.NewIEthereumClient(t) ethman := getEtherman(ethClient) ethClient.On( @@ -530,7 +531,7 @@ func TestSendTx(t *testing.T) { }) t.Run("Returns expected error", func(t *testing.T) { - ethClient := new(mocks.EthereumClientMock) + ethClient := mocks.NewIEthereumClient(t) ethman := getEtherman(ethClient) ethClient.On( @@ -553,7 +554,7 @@ func TestSuggestedGasPrice(t *testing.T) { assert := assert.New(t) t.Run("Returns expected value", func(t *testing.T) { - ethClient := new(mocks.EthereumClientMock) + ethClient := mocks.NewIEthereumClient(t) ethman := getEtherman(ethClient) ethClient.On( @@ -572,7 +573,7 @@ func TestSuggestedGasPrice(t *testing.T) { }) t.Run("Returns expected error", func(t *testing.T) { - ethClient := new(mocks.EthereumClientMock) + ethClient := mocks.NewIEthereumClient(t) ethman := getEtherman(ethClient) ethClient.On( @@ -596,7 +597,7 @@ func TestEstimateGas(t *testing.T) { assert := assert.New(t) t.Run("Returns the expected value", func(t *testing.T) { - ethclient := new(mocks.EthereumClientMock) + ethclient := mocks.NewIEthereumClient(t) ethman := getEtherman(ethclient) ethclient.On( @@ -627,7 +628,7 @@ func TestEstimateGas(t *testing.T) { }) t.Run("Returns the expected error", func(t *testing.T) { - ethclient := new(mocks.EthereumClientMock) + ethclient := mocks.NewIEthereumClient(t) ethman := getEtherman(ethclient) ethclient.On( @@ -671,7 +672,7 @@ func TestSignTx(t *testing.T) { ) t.Run("Returns the expected value", func(t *testing.T) { - ethClient := new(mocks.EthereumClientMock) + ethClient := mocks.NewIEthereumClient(t) ethman := getEtherman(ethClient) transaction, err := ethman.SignTx(context.TODO(), common.Address{}, txData) @@ -694,7 +695,7 @@ func TestGetRevertMessage(t *testing.T) { ) t.Run("Returns an empty string and the expected error", func(t *testing.T) { - ethClient := new(mocks.EthereumClientMock) + ethClient := mocks.NewIEthereumClient(t) ethman := getEtherman(ethClient) ethClient.On( @@ -713,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 := new(mocks.EthereumClientMock) + ethClient := mocks.NewIEthereumClient(t) ethman := getEtherman(ethClient) ethClient.On( @@ -734,7 +735,7 @@ func TestGetRevertMessage(t *testing.T) { }) t.Run("Returns the expected revert reason string", func(t *testing.T) { - ethClient := new(mocks.EthereumClientMock) + ethClient := mocks.NewIEthereumClient(t) ethman := getEtherman(ethClient) key, _ := crypto.GenerateKey() @@ -784,7 +785,7 @@ func TestGetLastBlock(t *testing.T) { assert := assert.New(t) t.Run("Returns the expected values", func(t *testing.T) { - ethClient := new(mocks.EthereumClientMock) + ethClient := mocks.NewIEthereumClient(t) ethman := getEtherman(ethClient) ethClient.On( @@ -811,7 +812,7 @@ func TestGetLastBlock(t *testing.T) { }) t.Run("Returns the expected error", func(t *testing.T) { - ethClient := new(mocks.EthereumClientMock) + ethClient := mocks.NewIEthereumClient(t) ethman := getEtherman(ethClient) ethClient.On( diff --git a/etherman/interfaces.go b/etherman/interfaces.go index 9287bfb..3fdd8d5 100644 --- a/etherman/interfaces.go +++ b/etherman/interfaces.go @@ -5,7 +5,8 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi/bind" ) -type EthereumClient interface { +//go:generate mockery --name IEthereumClient --output ../mocks --case=underscore --filename etherman_client.generated.go +type IEthereumClient interface { ethereum.ChainReader ethereum.ChainStateReader ethereum.ContractCaller diff --git a/interop/executor.go b/interop/executor.go index 9c9d16c..67d6d13 100644 --- a/interop/executor.go +++ b/interop/executor.go @@ -18,11 +18,11 @@ import ( "github.com/jackc/pgx/v4" ) -var _ types.ZkEVMClientClientCreator = (*zkEVMClientCreator)(nil) +var _ types.IZkEVMClientClientCreator = (*zkEVMClientCreator)(nil) type zkEVMClientCreator struct{} -func (zc *zkEVMClientCreator) NewClient(rpc string) types.ZkEVMClientInterface { +func (zc *zkEVMClientCreator) NewClient(rpc string) types.IZkEVMClient { return client.NewClient(rpc) } @@ -30,15 +30,15 @@ type Executor struct { logger *log.Logger interopAdminAddr common.Address config *config.Config - ethTxMan types.EthTxManager - etherman types.EthermanInterface - ZkEVMClientCreator types.ZkEVMClientClientCreator + ethTxMan types.IEthTxManager + etherman types.IEtherman + ZkEVMClientCreator types.IZkEVMClientClientCreator } func New(logger *log.Logger, cfg *config.Config, interopAdminAddr common.Address, - etherman types.EthermanInterface, - ethTxManager types.EthTxManager, + etherman types.IEtherman, + ethTxManager types.IEthTxManager, ) *Executor { return &Executor{ logger: logger, diff --git a/interop/executor_test.go b/interop/executor_test.go index 63bbdb1..5bdb811 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.EthermanMock{} - ethTxManager := &mocks.EthTxManagerMock{} + etherman := mocks.NewIEtherman(t) + ethTxManager := mocks.NewIEthTxManager(t) executor := New(nil, cfg, interopAdminAddr, etherman, ethTxManager) @@ -43,8 +43,8 @@ func TestExecutor_CheckTx(t *testing.T) { }, } interopAdminAddr := common.HexToAddress("0x1234567890abcdef") - etherman := &mocks.EthermanMock{} - ethTxManager := &mocks.EthTxManagerMock{} + etherman := mocks.NewIEtherman(t) + ethTxManager := mocks.NewIEthTxManager(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.EthermanMock{} - ethTxManager := &mocks.EthTxManagerMock{} + etherman := mocks.NewIEtherman(t) + ethTxManager := mocks.NewIEthTxManager(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.EthermanMock{} - ethTxManager := &mocks.EthTxManagerMock{} + etherman := mocks.NewIEtherman(t) + ethTxManager := mocks.NewIEthTxManager(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.EthermanMock{} - ethTxManager := &mocks.EthTxManagerMock{} + etherman := mocks.NewIEtherman(t) + ethTxManager := mocks.NewIEthTxManager(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.ZkEVMClientCreatorMock{} - mockZkEVMClient := &mocks.ZkEVMClientMock{} + mockZkEVMClientCreator := mocks.NewIZkEVMClientClientCreator(t) + mockZkEVMClient := mocks.NewIZkEVMClient(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.EthermanMock{} - ethTxManager := &mocks.EthTxManagerMock{} + etherman := mocks.NewIEtherman(t) + ethTxManager := mocks.NewIEthTxManager(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.EthermanMock{} - ethTxManager := &mocks.EthTxManagerMock{} + etherman := mocks.NewIEtherman(t) + ethTxManager := mocks.NewIEthTxManager(t) dbTx := &mocks.TxMock{} executor := New(nil, cfg, interopAdminAddr, etherman, ethTxManager) diff --git a/mocks/db.generated.go b/mocks/db.generated.go new file mode 100644 index 0000000..ab1fc22 --- /dev/null +++ b/mocks/db.generated.go @@ -0,0 +1,59 @@ +// Code generated by mockery v2.38.0. DO NOT EDIT. + +package mocks + +import ( + context "context" + + pgx "github.com/jackc/pgx/v4" + mock "github.com/stretchr/testify/mock" +) + +// IDB is an autogenerated mock type for the IDB type +type IDB struct { + mock.Mock +} + +// BeginStateTransaction provides a mock function with given fields: ctx +func (_m *IDB) BeginStateTransaction(ctx context.Context) (pgx.Tx, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for BeginStateTransaction") + } + + var r0 pgx.Tx + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) (pgx.Tx, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) pgx.Tx); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(pgx.Tx) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + 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. +// The first argument is typically a *testing.T value. +func NewIDB(t interface { + mock.TestingT + Cleanup(func()) +}) *IDB { + mock := &IDB{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/eth_tx_manager.generated.go b/mocks/eth_tx_manager.generated.go new file mode 100644 index 0000000..04f37d2 --- /dev/null +++ b/mocks/eth_tx_manager.generated.go @@ -0,0 +1,116 @@ +// Code generated by mockery v2.38.0. DO NOT EDIT. + +package mocks + +import ( + context "context" + big "math/big" + + common "github.com/ethereum/go-ethereum/common" + + ethtxmanager "github.com/0xPolygonHermez/zkevm-node/ethtxmanager" + + mock "github.com/stretchr/testify/mock" + + pgx "github.com/jackc/pgx/v4" +) + +// IEthTxManager is an autogenerated mock type for the IEthTxManager type +type IEthTxManager 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 { + ret := _m.Called(ctx, owner, id, from, to, value, data, gasOffset, dbTx) + + if len(ret) == 0 { + panic("no return value specified for Add") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string, string, common.Address, *common.Address, *big.Int, []byte, uint64, pgx.Tx) error); ok { + r0 = rf(ctx, owner, id, from, to, value, data, gasOffset, dbTx) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// 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) { + _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) { + ret := _m.Called(ctx, owner, id, dbTx) + + if len(ret) == 0 { + panic("no return value specified for Result") + } + + var r0 ethtxmanager.MonitoredTxResult + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, string, pgx.Tx) (ethtxmanager.MonitoredTxResult, error)); ok { + return rf(ctx, owner, id, dbTx) + } + if rf, ok := ret.Get(0).(func(context.Context, string, string, pgx.Tx) ethtxmanager.MonitoredTxResult); ok { + r0 = rf(ctx, owner, id, dbTx) + } else { + r0 = ret.Get(0).(ethtxmanager.MonitoredTxResult) + } + + if rf, ok := ret.Get(1).(func(context.Context, string, string, pgx.Tx) error); ok { + r1 = rf(ctx, owner, id, dbTx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// 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) { + ret := _m.Called(ctx, owner, statuses, dbTx) + + if len(ret) == 0 { + panic("no return value specified for ResultsByStatus") + } + + var r0 []ethtxmanager.MonitoredTxResult + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, []ethtxmanager.MonitoredTxStatus, pgx.Tx) ([]ethtxmanager.MonitoredTxResult, error)); ok { + return rf(ctx, owner, statuses, dbTx) + } + if rf, ok := ret.Get(0).(func(context.Context, string, []ethtxmanager.MonitoredTxStatus, pgx.Tx) []ethtxmanager.MonitoredTxResult); ok { + r0 = rf(ctx, owner, statuses, dbTx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]ethtxmanager.MonitoredTxResult) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, string, []ethtxmanager.MonitoredTxStatus, pgx.Tx) error); ok { + r1 = rf(ctx, owner, statuses, dbTx) + } else { + r1 = ret.Error(1) + } + + 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. +// The first argument is typically a *testing.T value. +func NewIEthTxManager(t interface { + mock.TestingT + Cleanup(func()) +}) *IEthTxManager { + mock := &IEthTxManager{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/ethclient_mock.go b/mocks/ethclient_mock.go deleted file mode 100644 index 285108e..0000000 --- a/mocks/ethclient_mock.go +++ /dev/null @@ -1,146 +0,0 @@ -package mocks - -import ( - "context" - "github.com/ethereum/go-ethereum" - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/core/types" - "github.com/stretchr/testify/mock" - "math/big" -) - -type EthereumClientMock struct { - mock.Mock -} - -func (e *EthereumClientMock) BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error) { - args := e.Called(ctx, hash) - - return args.Get(0).(*types.Block), args.Error(1) -} - -func (e *EthereumClientMock) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) { - args := e.Called(ctx, hash) - - return args.Get(0).(*types.Header), args.Error(1) -} - -func (e *EthereumClientMock) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) { - args := e.Called(ctx, number) - - return args.Get(0).(*types.Header), args.Error(1) -} - -func (e *EthereumClientMock) TransactionCount(ctx context.Context, blockHash common.Hash) (uint, error) { - args := e.Called(ctx, blockHash) - - return args.Get(0).(uint), args.Error(1) -} - -func (e *EthereumClientMock) TransactionInBlock(ctx context.Context, blockHash common.Hash, index uint) (*types.Transaction, error) { - args := e.Called(ctx, blockHash) - - return args.Get(0).(*types.Transaction), args.Error(1) -} - -func (e *EthereumClientMock) SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (ethereum.Subscription, error) { - args := e.Called(ctx, ch) - - return args.Get(0).(ethereum.Subscription), args.Error(1) -} - -func (e *EthereumClientMock) BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error) { - args := e.Called(ctx, account, blockNumber) - - return args.Get(0).(*big.Int), args.Error(1) -} - -func (e *EthereumClientMock) StorageAt(ctx context.Context, account common.Address, key common.Hash, blockNumber *big.Int) ([]byte, error) { - args := e.Called(ctx, account, key, blockNumber) - - return args.Get(0).([]byte), args.Error(1) -} - -func (e *EthereumClientMock) CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error) { - args := e.Called(ctx, account, blockNumber) - - return args.Get(0).([]byte), args.Error(1) -} - -func (e *EthereumClientMock) FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error) { - args := e.Called(ctx, q) - - return args.Get(0).([]types.Log), args.Error(1) -} - -func (e *EthereumClientMock) SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error) { - args := e.Called(ctx, q, ch) - - return args.Get(0).(ethereum.Subscription), args.Error(1) -} - -func (e *EthereumClientMock) PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error) { - args := e.Called(ctx, account) - - return args.Get(0).([]byte), args.Error(1) -} - -func (e *EthereumClientMock) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error) { - args := e.Called(ctx, account) - - return args.Get(0).(uint64), args.Error(1) -} - -func (e *EthereumClientMock) SuggestGasTipCap(ctx context.Context) (*big.Int, error) { - args := e.Called(ctx) - - return args.Get(0).(*big.Int), args.Error(1) -} - -func (e *EthereumClientMock) CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error) { - args := e.Called(ctx, call, blockNumber) - - return args.Get(0).([]byte), args.Error(1) -} - -func (e *EthereumClientMock) TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) { - args := e.Called(ctx, txHash) - - return args.Get(0).(*types.Receipt), args.Error(1) -} - -func (e *EthereumClientMock) NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error) { - args := e.Called(ctx, account, blockNumber) - - return args.Get(0).(uint64), args.Error(1) -} - -func (e *EthereumClientMock) TransactionByHash(ctx context.Context, txHash common.Hash) (*types.Transaction, bool, error) { - args := e.Called(ctx, txHash) - - return args.Get(0).(*types.Transaction), args.Bool(1), args.Error(2) -} - -func (e *EthereumClientMock) SendTransaction(ctx context.Context, tx *types.Transaction) error { - args := e.Called(ctx, tx) - - return args.Error(0) -} - -func (e *EthereumClientMock) SuggestGasPrice(ctx context.Context) (*big.Int, error) { - args := e.Called(ctx) - - return args.Get(0).(*big.Int), args.Error(1) -} - -func (e *EthereumClientMock) EstimateGas(ctx context.Context, call ethereum.CallMsg) (uint64, error) { - args := e.Called(ctx, call) - - return args.Get(0).(uint64), args.Error(1) -} - -func (e *EthereumClientMock) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) { - args := e.Called(ctx, number) - - return args.Get(0).(*types.Block), args.Error(1) -} diff --git a/mocks/etherman.generated.go b/mocks/etherman.generated.go new file mode 100644 index 0000000..663e430 --- /dev/null +++ b/mocks/etherman.generated.go @@ -0,0 +1,125 @@ +// Code generated by mockery v2.38.0. DO NOT EDIT. + +package mocks + +import ( + context "context" + big "math/big" + + common "github.com/ethereum/go-ethereum/common" + + ethereum "github.com/ethereum/go-ethereum" + + mock "github.com/stretchr/testify/mock" + + tx "github.com/0xPolygon/beethoven/tx" +) + +// IEtherman is an autogenerated mock type for the IEtherman type +type IEtherman 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) { + ret := _m.Called(lastVerifiedBatch, newVerifiedBatch, proof, rollupId) + + if len(ret) == 0 { + panic("no return value specified for BuildTrustedVerifyBatchesTxData") + } + + var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func(uint64, uint64, tx.ZKP, uint32) ([]byte, error)); ok { + return rf(lastVerifiedBatch, newVerifiedBatch, proof, rollupId) + } + if rf, ok := ret.Get(0).(func(uint64, uint64, tx.ZKP, uint32) []byte); ok { + r0 = rf(lastVerifiedBatch, newVerifiedBatch, proof, rollupId) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } + } + + if rf, ok := ret.Get(1).(func(uint64, uint64, tx.ZKP, uint32) error); ok { + r1 = rf(lastVerifiedBatch, newVerifiedBatch, proof, rollupId) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// 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) { + ret := _m.Called(ctx, call, blockNumber) + + if len(ret) == 0 { + panic("no return value specified for CallContract") + } + + var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, ethereum.CallMsg, *big.Int) ([]byte, error)); ok { + return rf(ctx, call, blockNumber) + } + if rf, ok := ret.Get(0).(func(context.Context, ethereum.CallMsg, *big.Int) []byte); ok { + r0 = rf(ctx, call, blockNumber) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, ethereum.CallMsg, *big.Int) error); ok { + r1 = rf(ctx, call, blockNumber) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetSequencerAddr provides a mock function with given fields: rollupId +func (_m *IEtherman) GetSequencerAddr(rollupId uint32) (common.Address, error) { + ret := _m.Called(rollupId) + + if len(ret) == 0 { + panic("no return value specified for GetSequencerAddr") + } + + var r0 common.Address + var r1 error + if rf, ok := ret.Get(0).(func(uint32) (common.Address, error)); ok { + return rf(rollupId) + } + if rf, ok := ret.Get(0).(func(uint32) common.Address); ok { + r0 = rf(rollupId) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(common.Address) + } + } + + if rf, ok := ret.Get(1).(func(uint32) error); ok { + r1 = rf(rollupId) + } else { + r1 = ret.Error(1) + } + + 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. +// The first argument is typically a *testing.T value. +func NewIEtherman(t interface { + mock.TestingT + Cleanup(func()) +}) *IEtherman { + mock := &IEtherman{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/etherman_client.generated.go b/mocks/etherman_client.generated.go new file mode 100644 index 0000000..b420255 --- /dev/null +++ b/mocks/etherman_client.generated.go @@ -0,0 +1,682 @@ +// Code generated by mockery v2.38.0. DO NOT EDIT. + +package mocks + +import ( + context "context" + big "math/big" + + common "github.com/ethereum/go-ethereum/common" + + ethereum "github.com/ethereum/go-ethereum" + + mock "github.com/stretchr/testify/mock" + + types "github.com/ethereum/go-ethereum/core/types" +) + +// IEthereumClient is an autogenerated mock type for the IEthereumClient type +type IEthereumClient 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) { + ret := _m.Called(ctx, account, blockNumber) + + if len(ret) == 0 { + panic("no return value specified for BalanceAt") + } + + var r0 *big.Int + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, common.Address, *big.Int) (*big.Int, error)); ok { + return rf(ctx, account, blockNumber) + } + if rf, ok := ret.Get(0).(func(context.Context, common.Address, *big.Int) *big.Int); ok { + r0 = rf(ctx, account, blockNumber) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*big.Int) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, common.Address, *big.Int) error); ok { + r1 = rf(ctx, account, blockNumber) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// BlockByHash provides a mock function with given fields: ctx, hash +func (_m *IEthereumClient) BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error) { + ret := _m.Called(ctx, hash) + + if len(ret) == 0 { + panic("no return value specified for BlockByHash") + } + + var r0 *types.Block + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, common.Hash) (*types.Block, error)); ok { + return rf(ctx, hash) + } + if rf, ok := ret.Get(0).(func(context.Context, common.Hash) *types.Block); ok { + r0 = rf(ctx, hash) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.Block) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, common.Hash) error); ok { + r1 = rf(ctx, hash) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// BlockByNumber provides a mock function with given fields: ctx, number +func (_m *IEthereumClient) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) { + ret := _m.Called(ctx, number) + + if len(ret) == 0 { + panic("no return value specified for BlockByNumber") + } + + var r0 *types.Block + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *big.Int) (*types.Block, error)); ok { + return rf(ctx, number) + } + if rf, ok := ret.Get(0).(func(context.Context, *big.Int) *types.Block); ok { + r0 = rf(ctx, number) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.Block) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *big.Int) error); ok { + r1 = rf(ctx, number) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// 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) { + ret := _m.Called(ctx, call, blockNumber) + + if len(ret) == 0 { + panic("no return value specified for CallContract") + } + + var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, ethereum.CallMsg, *big.Int) ([]byte, error)); ok { + return rf(ctx, call, blockNumber) + } + if rf, ok := ret.Get(0).(func(context.Context, ethereum.CallMsg, *big.Int) []byte); ok { + r0 = rf(ctx, call, blockNumber) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, ethereum.CallMsg, *big.Int) error); ok { + r1 = rf(ctx, call, blockNumber) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// 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) { + ret := _m.Called(ctx, account, blockNumber) + + if len(ret) == 0 { + panic("no return value specified for CodeAt") + } + + var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, common.Address, *big.Int) ([]byte, error)); ok { + return rf(ctx, account, blockNumber) + } + if rf, ok := ret.Get(0).(func(context.Context, common.Address, *big.Int) []byte); ok { + r0 = rf(ctx, account, blockNumber) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, common.Address, *big.Int) error); ok { + r1 = rf(ctx, account, blockNumber) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// EstimateGas provides a mock function with given fields: ctx, call +func (_m *IEthereumClient) EstimateGas(ctx context.Context, call ethereum.CallMsg) (uint64, error) { + ret := _m.Called(ctx, call) + + if len(ret) == 0 { + panic("no return value specified for EstimateGas") + } + + var r0 uint64 + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, ethereum.CallMsg) (uint64, error)); ok { + return rf(ctx, call) + } + if rf, ok := ret.Get(0).(func(context.Context, ethereum.CallMsg) uint64); ok { + r0 = rf(ctx, call) + } else { + r0 = ret.Get(0).(uint64) + } + + if rf, ok := ret.Get(1).(func(context.Context, ethereum.CallMsg) error); ok { + r1 = rf(ctx, call) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// FilterLogs provides a mock function with given fields: ctx, q +func (_m *IEthereumClient) FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error) { + ret := _m.Called(ctx, q) + + if len(ret) == 0 { + panic("no return value specified for FilterLogs") + } + + var r0 []types.Log + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, ethereum.FilterQuery) ([]types.Log, error)); ok { + return rf(ctx, q) + } + if rf, ok := ret.Get(0).(func(context.Context, ethereum.FilterQuery) []types.Log); ok { + r0 = rf(ctx, q) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]types.Log) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, ethereum.FilterQuery) error); ok { + r1 = rf(ctx, q) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// HeaderByHash provides a mock function with given fields: ctx, hash +func (_m *IEthereumClient) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) { + ret := _m.Called(ctx, hash) + + if len(ret) == 0 { + panic("no return value specified for HeaderByHash") + } + + var r0 *types.Header + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, common.Hash) (*types.Header, error)); ok { + return rf(ctx, hash) + } + if rf, ok := ret.Get(0).(func(context.Context, common.Hash) *types.Header); ok { + r0 = rf(ctx, hash) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.Header) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, common.Hash) error); ok { + r1 = rf(ctx, hash) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// HeaderByNumber provides a mock function with given fields: ctx, number +func (_m *IEthereumClient) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) { + ret := _m.Called(ctx, number) + + if len(ret) == 0 { + panic("no return value specified for HeaderByNumber") + } + + var r0 *types.Header + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *big.Int) (*types.Header, error)); ok { + return rf(ctx, number) + } + if rf, ok := ret.Get(0).(func(context.Context, *big.Int) *types.Header); ok { + r0 = rf(ctx, number) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.Header) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *big.Int) error); ok { + r1 = rf(ctx, number) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// 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) { + ret := _m.Called(ctx, account, blockNumber) + + if len(ret) == 0 { + panic("no return value specified for NonceAt") + } + + var r0 uint64 + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, common.Address, *big.Int) (uint64, error)); ok { + return rf(ctx, account, blockNumber) + } + if rf, ok := ret.Get(0).(func(context.Context, common.Address, *big.Int) uint64); ok { + r0 = rf(ctx, account, blockNumber) + } else { + r0 = ret.Get(0).(uint64) + } + + if rf, ok := ret.Get(1).(func(context.Context, common.Address, *big.Int) error); ok { + r1 = rf(ctx, account, blockNumber) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// PendingCodeAt provides a mock function with given fields: ctx, account +func (_m *IEthereumClient) PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error) { + ret := _m.Called(ctx, account) + + if len(ret) == 0 { + panic("no return value specified for PendingCodeAt") + } + + var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, common.Address) ([]byte, error)); ok { + return rf(ctx, account) + } + if rf, ok := ret.Get(0).(func(context.Context, common.Address) []byte); ok { + r0 = rf(ctx, account) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, common.Address) error); ok { + r1 = rf(ctx, account) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// PendingNonceAt provides a mock function with given fields: ctx, account +func (_m *IEthereumClient) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error) { + ret := _m.Called(ctx, account) + + if len(ret) == 0 { + panic("no return value specified for PendingNonceAt") + } + + var r0 uint64 + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, common.Address) (uint64, error)); ok { + return rf(ctx, account) + } + if rf, ok := ret.Get(0).(func(context.Context, common.Address) uint64); ok { + r0 = rf(ctx, account) + } else { + r0 = ret.Get(0).(uint64) + } + + if rf, ok := ret.Get(1).(func(context.Context, common.Address) error); ok { + r1 = rf(ctx, account) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// SendTransaction provides a mock function with given fields: ctx, tx +func (_m *IEthereumClient) SendTransaction(ctx context.Context, tx *types.Transaction) error { + ret := _m.Called(ctx, tx) + + if len(ret) == 0 { + panic("no return value specified for SendTransaction") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *types.Transaction) error); ok { + r0 = rf(ctx, tx) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// 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) { + ret := _m.Called(ctx, account, key, blockNumber) + + if len(ret) == 0 { + panic("no return value specified for StorageAt") + } + + var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, common.Address, common.Hash, *big.Int) ([]byte, error)); ok { + return rf(ctx, account, key, blockNumber) + } + if rf, ok := ret.Get(0).(func(context.Context, common.Address, common.Hash, *big.Int) []byte); ok { + r0 = rf(ctx, account, key, blockNumber) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, common.Address, common.Hash, *big.Int) error); ok { + r1 = rf(ctx, account, key, blockNumber) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// 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) { + ret := _m.Called(ctx, q, ch) + + if len(ret) == 0 { + panic("no return value specified for SubscribeFilterLogs") + } + + var r0 ethereum.Subscription + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, ethereum.FilterQuery, chan<- types.Log) (ethereum.Subscription, error)); ok { + return rf(ctx, q, ch) + } + if rf, ok := ret.Get(0).(func(context.Context, ethereum.FilterQuery, chan<- types.Log) ethereum.Subscription); ok { + r0 = rf(ctx, q, ch) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(ethereum.Subscription) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, ethereum.FilterQuery, chan<- types.Log) error); ok { + r1 = rf(ctx, q, ch) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// SubscribeNewHead provides a mock function with given fields: ctx, ch +func (_m *IEthereumClient) SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (ethereum.Subscription, error) { + ret := _m.Called(ctx, ch) + + if len(ret) == 0 { + panic("no return value specified for SubscribeNewHead") + } + + var r0 ethereum.Subscription + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, chan<- *types.Header) (ethereum.Subscription, error)); ok { + return rf(ctx, ch) + } + if rf, ok := ret.Get(0).(func(context.Context, chan<- *types.Header) ethereum.Subscription); ok { + r0 = rf(ctx, ch) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(ethereum.Subscription) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, chan<- *types.Header) error); ok { + r1 = rf(ctx, ch) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// SuggestGasPrice provides a mock function with given fields: ctx +func (_m *IEthereumClient) SuggestGasPrice(ctx context.Context) (*big.Int, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for SuggestGasPrice") + } + + var r0 *big.Int + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) (*big.Int, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) *big.Int); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*big.Int) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// SuggestGasTipCap provides a mock function with given fields: ctx +func (_m *IEthereumClient) SuggestGasTipCap(ctx context.Context) (*big.Int, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for SuggestGasTipCap") + } + + var r0 *big.Int + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) (*big.Int, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) *big.Int); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*big.Int) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// TransactionByHash provides a mock function with given fields: ctx, txHash +func (_m *IEthereumClient) TransactionByHash(ctx context.Context, txHash common.Hash) (*types.Transaction, bool, error) { + ret := _m.Called(ctx, txHash) + + if len(ret) == 0 { + panic("no return value specified for TransactionByHash") + } + + var r0 *types.Transaction + var r1 bool + var r2 error + if rf, ok := ret.Get(0).(func(context.Context, common.Hash) (*types.Transaction, bool, error)); ok { + return rf(ctx, txHash) + } + if rf, ok := ret.Get(0).(func(context.Context, common.Hash) *types.Transaction); ok { + r0 = rf(ctx, txHash) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.Transaction) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, common.Hash) bool); ok { + r1 = rf(ctx, txHash) + } else { + r1 = ret.Get(1).(bool) + } + + if rf, ok := ret.Get(2).(func(context.Context, common.Hash) error); ok { + r2 = rf(ctx, txHash) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// TransactionCount provides a mock function with given fields: ctx, blockHash +func (_m *IEthereumClient) TransactionCount(ctx context.Context, blockHash common.Hash) (uint, error) { + ret := _m.Called(ctx, blockHash) + + if len(ret) == 0 { + panic("no return value specified for TransactionCount") + } + + var r0 uint + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, common.Hash) (uint, error)); ok { + return rf(ctx, blockHash) + } + if rf, ok := ret.Get(0).(func(context.Context, common.Hash) uint); ok { + r0 = rf(ctx, blockHash) + } else { + r0 = ret.Get(0).(uint) + } + + if rf, ok := ret.Get(1).(func(context.Context, common.Hash) error); ok { + r1 = rf(ctx, blockHash) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// 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) { + ret := _m.Called(ctx, blockHash, index) + + if len(ret) == 0 { + panic("no return value specified for TransactionInBlock") + } + + var r0 *types.Transaction + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, common.Hash, uint) (*types.Transaction, error)); ok { + return rf(ctx, blockHash, index) + } + if rf, ok := ret.Get(0).(func(context.Context, common.Hash, uint) *types.Transaction); ok { + r0 = rf(ctx, blockHash, index) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.Transaction) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, common.Hash, uint) error); ok { + r1 = rf(ctx, blockHash, index) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// TransactionReceipt provides a mock function with given fields: ctx, txHash +func (_m *IEthereumClient) TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) { + ret := _m.Called(ctx, txHash) + + if len(ret) == 0 { + panic("no return value specified for TransactionReceipt") + } + + var r0 *types.Receipt + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, common.Hash) (*types.Receipt, error)); ok { + return rf(ctx, txHash) + } + if rf, ok := ret.Get(0).(func(context.Context, common.Hash) *types.Receipt); ok { + r0 = rf(ctx, txHash) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.Receipt) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, common.Hash) error); ok { + r1 = rf(ctx, txHash) + } else { + r1 = ret.Error(1) + } + + 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. +// The first argument is typically a *testing.T value. +func NewIEthereumClient(t interface { + mock.TestingT + Cleanup(func()) +}) *IEthereumClient { + mock := &IEthereumClient{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/mocks.go b/mocks/mocks.go deleted file mode 100644 index dae56d9..0000000 --- a/mocks/mocks.go +++ /dev/null @@ -1,124 +0,0 @@ -package mocks - -import ( - "context" - "math/big" - - "github.com/0xPolygon/beethoven/tx" - "github.com/0xPolygon/beethoven/types" - - "github.com/0xPolygonHermez/zkevm-node/ethtxmanager" - validiumTypes "github.com/0xPolygonHermez/zkevm-node/jsonrpc/types" - "github.com/ethereum/go-ethereum" - "github.com/ethereum/go-ethereum/common" - "github.com/jackc/pgx/v4" - "github.com/stretchr/testify/mock" -) - -var _ types.EthermanInterface = (*EthermanMock)(nil) - -type EthermanMock struct { - mock.Mock -} - -func (e *EthermanMock) GetSequencerAddr(rollupId uint32) (common.Address, error) { - args := e.Called(rollupId) - - return args.Get(0).(common.Address), args.Error(1) //nolint:forcetypeassert -} - -func (e *EthermanMock) BuildTrustedVerifyBatchesTxData( - lastVerifiedBatch, - newVerifiedBatch uint64, - proof tx.ZKP, - rollupId uint32, -) (data []byte, err error) { - args := e.Called(lastVerifiedBatch, newVerifiedBatch, proof, rollupId) - - return args.Get(0).([]byte), args.Error(1) //nolint:forcetypeassert -} - -func (e *EthermanMock) CallContract(ctx context.Context, call ethereum.CallMsg, - blockNumber *big.Int) ([]byte, error) { - args := e.Called(ctx, call, blockNumber) - - return args.Get(0).([]byte), args.Error(1) //nolint:forcetypeassert -} - -var _ types.DBInterface = (*DbMock)(nil) - -type DbMock struct { - mock.Mock -} - -func (db *DbMock) BeginStateTransaction(ctx context.Context) (pgx.Tx, error) { - args := db.Called(ctx) - - tx, ok := args.Get(0).(pgx.Tx) - if !ok { - return nil, args.Error(1) - } - - return tx, args.Error(1) -} - -var _ types.EthTxManager = (*EthTxManagerMock)(nil) - -type EthTxManagerMock struct { - mock.Mock -} - -func (e *EthTxManagerMock) Add(ctx context.Context, owner, id string, - from common.Address, to *common.Address, value *big.Int, data []byte, gasOffset uint64, dbTx pgx.Tx) error { - args := e.Called(ctx, owner, id, from, to, value, data, gasOffset, dbTx) - - return args.Error(0) -} - -func (e *EthTxManagerMock) Result(ctx context.Context, owner, - id string, dbTx pgx.Tx) (ethtxmanager.MonitoredTxResult, error) { - args := e.Called(ctx, owner, id, dbTx) - - return args.Get(0).(ethtxmanager.MonitoredTxResult), args.Error(1) //nolint:forcetypeassert -} - -func (e *EthTxManagerMock) ResultsByStatus(ctx context.Context, owner string, - statuses []ethtxmanager.MonitoredTxStatus, dbTx pgx.Tx) ([]ethtxmanager.MonitoredTxResult, error) { - e.Called(ctx, owner, statuses, dbTx) - - return nil, nil -} - -func (e *EthTxManagerMock) ProcessPendingMonitoredTxs(ctx context.Context, owner string, - failedResultHandler ethtxmanager.ResultHandler, dbTx pgx.Tx) { - e.Called(ctx, owner, failedResultHandler, dbTx) -} - -var _ types.ZkEVMClientInterface = (*ZkEVMClientMock)(nil) - -type ZkEVMClientMock struct { - mock.Mock -} - -func (zkc *ZkEVMClientMock) BatchByNumber(ctx context.Context, number *big.Int) (*validiumTypes.Batch, error) { - args := zkc.Called(ctx, number) - - batch, ok := args.Get(0).(*validiumTypes.Batch) - if !ok { - return nil, args.Error(1) - } - - return batch, args.Error(1) -} - -var _ types.ZkEVMClientClientCreator = (*ZkEVMClientCreatorMock)(nil) - -type ZkEVMClientCreatorMock struct { - mock.Mock -} - -func (zc *ZkEVMClientCreatorMock) NewClient(rpc string) types.ZkEVMClientInterface { - args := zc.Called(rpc) - - return args.Get(0).(types.ZkEVMClientInterface) //nolint:forcetypeassert -} diff --git a/mocks/zk_evm_client.generated.go b/mocks/zk_evm_client.generated.go new file mode 100644 index 0000000..e4b0a1f --- /dev/null +++ b/mocks/zk_evm_client.generated.go @@ -0,0 +1,61 @@ +// Code generated by mockery v2.38.0. DO NOT EDIT. + +package mocks + +import ( + context "context" + big "math/big" + + mock "github.com/stretchr/testify/mock" + + types "github.com/0xPolygonHermez/zkevm-node/jsonrpc/types" +) + +// IZkEVMClient is an autogenerated mock type for the IZkEVMClient type +type IZkEVMClient 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) { + ret := _m.Called(ctx, number) + + if len(ret) == 0 { + panic("no return value specified for BatchByNumber") + } + + var r0 *types.Batch + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *big.Int) (*types.Batch, error)); ok { + return rf(ctx, number) + } + if rf, ok := ret.Get(0).(func(context.Context, *big.Int) *types.Batch); ok { + r0 = rf(ctx, number) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.Batch) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *big.Int) error); ok { + r1 = rf(ctx, number) + } else { + r1 = ret.Error(1) + } + + 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. +// The first argument is typically a *testing.T value. +func NewIZkEVMClient(t interface { + mock.TestingT + Cleanup(func()) +}) *IZkEVMClient { + mock := &IZkEVMClient{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/zk_evm_client_creator.generated.go b/mocks/zk_evm_client_creator.generated.go new file mode 100644 index 0000000..9606f73 --- /dev/null +++ b/mocks/zk_evm_client_creator.generated.go @@ -0,0 +1,47 @@ +// Code generated by mockery v2.38.0. DO NOT EDIT. + +package mocks + +import ( + types "github.com/0xPolygon/beethoven/types" + mock "github.com/stretchr/testify/mock" +) + +// IZkEVMClientClientCreator is an autogenerated mock type for the IZkEVMClientClientCreator type +type IZkEVMClientClientCreator struct { + mock.Mock +} + +// NewClient provides a mock function with given fields: rpc +func (_m *IZkEVMClientClientCreator) NewClient(rpc string) types.IZkEVMClient { + ret := _m.Called(rpc) + + if len(ret) == 0 { + panic("no return value specified for NewClient") + } + + var r0 types.IZkEVMClient + if rf, ok := ret.Get(0).(func(string) types.IZkEVMClient); ok { + r0 = rf(rpc) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(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. +// The first argument is typically a *testing.T value. +func NewIZkEVMClientClientCreator(t interface { + mock.TestingT + Cleanup(func()) +}) *IZkEVMClientClientCreator { + mock := &IZkEVMClientClientCreator{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/rpc/rpc.go b/rpc/rpc.go index b2bfe4e..266347b 100644 --- a/rpc/rpc.go +++ b/rpc/rpc.go @@ -24,14 +24,14 @@ const ( type InteropEndpoints struct { ctx context.Context executor *interop.Executor - db types.DBInterface + db types.IDB } // NewInteropEndpoints returns InteropEndpoints func NewInteropEndpoints( ctx context.Context, executor *interop.Executor, - db types.DBInterface, + db types.IDB, ) *InteropEndpoints { return &InteropEndpoints{ ctx: ctx, diff --git a/rpc/rpc_test.go b/rpc/rpc_test.go index 0b6fbb2..03d5ed7 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 := new(mocks.DbMock) + dbMock := mocks.NewIDB(t) dbMock.On("BeginStateTransaction", mock.Anything).Return(nil, errors.New("error")).Once() e := interop.New( log.WithFields("module", "test"), &config.Config{}, common.HexToAddress("0xadmin"), - new(mocks.EthermanMock), - new(mocks.EthTxManagerMock), + mocks.NewIEtherman(t), + mocks.NewIEthTxManager(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 := new(mocks.DbMock) + dbMock := mocks.NewIDB(t) dbMock.On("BeginStateTransaction", mock.Anything).Return(txMock, nil).Once() - txManagerMock := new(mocks.EthTxManagerMock) + txManagerMock := mocks.NewIEthTxManager(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"), - new(mocks.EthermanMock), + mocks.NewIEtherman(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 := new(mocks.DbMock) + dbMock := mocks.NewIDB(t) dbMock.On("BeginStateTransaction", mock.Anything).Return(txMock, nil).Once() - txManagerMock := new(mocks.EthTxManagerMock) + txManagerMock := mocks.NewIEthTxManager(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"), - new(mocks.EthermanMock), + mocks.NewIEtherman(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 := new(mocks.EthermanMock) - zkEVMClientCreatorMock := new(mocks.ZkEVMClientCreatorMock) - zkEVMClientMock := new(mocks.ZkEVMClientMock) - dbMock := new(mocks.DbMock) + ethermanMock := mocks.NewIEtherman(t) + zkEVMClientCreatorMock := mocks.NewIZkEVMClientClientCreator(t) + zkEVMClientMock := mocks.NewIZkEVMClient(t) + dbMock := mocks.NewIDB(t) txMock := new(mocks.TxMock) - ethTxManagerMock := new(mocks.EthTxManagerMock) + ethTxManagerMock := mocks.NewIEthTxManager(t) executeTestFn := func() { e := interop.New( diff --git a/types/interfaces.go b/types/interfaces.go index 2a198a6..6840646 100644 --- a/types/interfaces.go +++ b/types/interfaces.go @@ -12,28 +12,32 @@ import ( "github.com/jackc/pgx/v4" ) -type DBInterface interface { +//go:generate mockery --name IDB --output ../mocks --case=underscore --filename db.generated.go +type IDB interface { BeginStateTransaction(ctx context.Context) (pgx.Tx, error) } -type EthermanInterface interface { +//go:generate mockery --name IEtherman --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) } -// ethTxManager contains the methods required to send txs to ethereum. -type EthTxManager interface { +//go:generate mockery --name IEthTxManager --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) ResultsByStatus(ctx context.Context, owner string, statuses []ethtxmanager.MonitoredTxStatus, dbTx pgx.Tx) ([]ethtxmanager.MonitoredTxResult, error) ProcessPendingMonitoredTxs(ctx context.Context, owner string, failedResultHandler ethtxmanager.ResultHandler, dbTx pgx.Tx) } -type ZkEVMClientInterface interface { +//go:generate mockery --name IZkEVMClient --output ../mocks --case=underscore --filename zk_evm_client.generated.go +type IZkEVMClient interface { BatchByNumber(ctx context.Context, number *big.Int) (*types.Batch, error) } -type ZkEVMClientClientCreator interface { - NewClient(rpc string) ZkEVMClientInterface +//go:generate mockery --name IZkEVMClientClientCreator --output ../mocks --case=underscore --filename zk_evm_client_creator.generated.go +type IZkEVMClientClientCreator interface { + NewClient(rpc string) IZkEVMClient } From 3da4ae8a00bcc129f41b84729bb436c8c615f53a Mon Sep 17 00:00:00 2001 From: Goran Rojovic Date: Tue, 16 Jan 2024 16:03:18 +0100 Subject: [PATCH 2/2] 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 }