From 069ef90407a1ad1ac9152f91a38ca0fad464293e Mon Sep 17 00:00:00 2001 From: joanestebanr <129153821+joanestebanr@users.noreply.github.com> Date: Tue, 30 Jul 2024 09:20:53 +0200 Subject: [PATCH 01/10] add tests for elderberry --- Makefile | 5 + .../mocks_da/batch_data_provider.go | 96 ++++++ dataavailability/mocks_da/da_backender.go | 263 +++++++++++++++ dataavailability/mocks_da/data_manager.go | 218 ++++++++++++ dataavailability/mocks_da/func_sign_type.go | 94 ++++++ .../mocks_da/sequence_retriever.go | 98 ++++++ dataavailability/mocks_da/sequence_sender.go | 156 +++++++++ .../mocks_da/sequence_sender_elderberry.go | 95 ++++++ localbridgesync/mock_downloader_test.go | 27 +- localbridgesync/mock_l2_test.go | 83 ++++- localbridgesync/mock_processor_test.go | 23 +- localbridgesync/mock_reorgdetector_test.go | 19 +- reorgdetector/mock_eth_client.go | 2 +- sequencesender/txbuilder/banana_validium.go | 4 +- sequencesender/txbuilder/banana_zkevm.go | 4 +- sequencesender/txbuilder/elderberry_base.go | 8 + .../txbuilder/elderberry_base_test.go | 101 ++++++ sequencesender/txbuilder/elderberry_types.go | 7 + .../txbuilder/elderberry_validium.go | 14 +- .../txbuilder/elderberry_validium_test.go | 109 ++++++ sequencesender/txbuilder/elderberry_zkevm.go | 16 +- .../txbuilder/elderberry_zkevm_test.go | 119 +++++++ sequencesender/txbuilder/interface.go | 3 +- .../mocks_txbuilder/cond_new_sequence.go | 104 ++++++ .../txbuilder/mocks_txbuilder/tx_builder.go | 317 ++++++++++++++++++ .../txbuilder/validium_cond_num_batches.go | 10 +- .../validium_cond_num_batches_test.go | 45 +++ .../txbuilder/zkevm_cond_max_size.go | 59 +++- .../txbuilder/zkevm_cond_max_size_test.go | 95 ++++++ test/Makefile | 17 +- 30 files changed, 2150 insertions(+), 61 deletions(-) create mode 100644 dataavailability/mocks_da/batch_data_provider.go create mode 100644 dataavailability/mocks_da/da_backender.go create mode 100644 dataavailability/mocks_da/data_manager.go create mode 100644 dataavailability/mocks_da/func_sign_type.go create mode 100644 dataavailability/mocks_da/sequence_retriever.go create mode 100644 dataavailability/mocks_da/sequence_sender.go create mode 100644 dataavailability/mocks_da/sequence_sender_elderberry.go create mode 100644 sequencesender/txbuilder/elderberry_base_test.go create mode 100644 sequencesender/txbuilder/elderberry_validium_test.go create mode 100644 sequencesender/txbuilder/elderberry_zkevm_test.go create mode 100644 sequencesender/txbuilder/mocks_txbuilder/cond_new_sequence.go create mode 100644 sequencesender/txbuilder/mocks_txbuilder/tx_builder.go create mode 100644 sequencesender/txbuilder/validium_cond_num_batches_test.go create mode 100644 sequencesender/txbuilder/zkevm_cond_max_size_test.go diff --git a/Makefile b/Makefile index d092a0f3..90da419b 100644 --- a/Makefile +++ b/Makefile @@ -83,7 +83,12 @@ stop: ## Stops all services .PHONY: test test: trap '$(STOP)' EXIT; MallocNanoZone=0 go test -count=1 -short -race -p 1 -covermode=atomic -coverprofile=../coverage.out -coverpkg ./... -timeout 200s ./... + +.PHONY: test-seq_sender +test-seq_sender: + trap '$(STOP)' EXIT; MallocNanoZone=0 go test -count=1 -short -race -p 1 -covermode=atomic -coverprofile=../coverage.out -coverpkg ./sequencesender/... -timeout 200s ./sequencesender/... + .PHONY: install-linter install-linter: ## Installs the linter curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin v1.54.2 diff --git a/dataavailability/mocks_da/batch_data_provider.go b/dataavailability/mocks_da/batch_data_provider.go new file mode 100644 index 00000000..36e782ac --- /dev/null +++ b/dataavailability/mocks_da/batch_data_provider.go @@ -0,0 +1,96 @@ +// Code generated by mockery. DO NOT EDIT. + +package mocks_da + +import ( + common "github.com/ethereum/go-ethereum/common" + + mock "github.com/stretchr/testify/mock" +) + +// BatchDataProvider is an autogenerated mock type for the BatchDataProvider type +type BatchDataProvider struct { + mock.Mock +} + +type BatchDataProvider_Expecter struct { + mock *mock.Mock +} + +func (_m *BatchDataProvider) EXPECT() *BatchDataProvider_Expecter { + return &BatchDataProvider_Expecter{mock: &_m.Mock} +} + +// GetBatchL2Data provides a mock function with given fields: batchNum, batchHashes, dataAvailabilityMessage +func (_m *BatchDataProvider) GetBatchL2Data(batchNum []uint64, batchHashes []common.Hash, dataAvailabilityMessage []byte) ([][]byte, error) { + ret := _m.Called(batchNum, batchHashes, dataAvailabilityMessage) + + if len(ret) == 0 { + panic("no return value specified for GetBatchL2Data") + } + + var r0 [][]byte + var r1 error + if rf, ok := ret.Get(0).(func([]uint64, []common.Hash, []byte) ([][]byte, error)); ok { + return rf(batchNum, batchHashes, dataAvailabilityMessage) + } + if rf, ok := ret.Get(0).(func([]uint64, []common.Hash, []byte) [][]byte); ok { + r0 = rf(batchNum, batchHashes, dataAvailabilityMessage) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([][]byte) + } + } + + if rf, ok := ret.Get(1).(func([]uint64, []common.Hash, []byte) error); ok { + r1 = rf(batchNum, batchHashes, dataAvailabilityMessage) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// BatchDataProvider_GetBatchL2Data_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetBatchL2Data' +type BatchDataProvider_GetBatchL2Data_Call struct { + *mock.Call +} + +// GetBatchL2Data is a helper method to define mock.On call +// - batchNum []uint64 +// - batchHashes []common.Hash +// - dataAvailabilityMessage []byte +func (_e *BatchDataProvider_Expecter) GetBatchL2Data(batchNum interface{}, batchHashes interface{}, dataAvailabilityMessage interface{}) *BatchDataProvider_GetBatchL2Data_Call { + return &BatchDataProvider_GetBatchL2Data_Call{Call: _e.mock.On("GetBatchL2Data", batchNum, batchHashes, dataAvailabilityMessage)} +} + +func (_c *BatchDataProvider_GetBatchL2Data_Call) Run(run func(batchNum []uint64, batchHashes []common.Hash, dataAvailabilityMessage []byte)) *BatchDataProvider_GetBatchL2Data_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].([]uint64), args[1].([]common.Hash), args[2].([]byte)) + }) + return _c +} + +func (_c *BatchDataProvider_GetBatchL2Data_Call) Return(_a0 [][]byte, _a1 error) *BatchDataProvider_GetBatchL2Data_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *BatchDataProvider_GetBatchL2Data_Call) RunAndReturn(run func([]uint64, []common.Hash, []byte) ([][]byte, error)) *BatchDataProvider_GetBatchL2Data_Call { + _c.Call.Return(run) + return _c +} + +// NewBatchDataProvider creates a new instance of BatchDataProvider. 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 NewBatchDataProvider(t interface { + mock.TestingT + Cleanup(func()) +}) *BatchDataProvider { + mock := &BatchDataProvider{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/dataavailability/mocks_da/da_backender.go b/dataavailability/mocks_da/da_backender.go new file mode 100644 index 00000000..398356e5 --- /dev/null +++ b/dataavailability/mocks_da/da_backender.go @@ -0,0 +1,263 @@ +// Code generated by mockery. DO NOT EDIT. + +package mocks_da + +import ( + context "context" + + common "github.com/ethereum/go-ethereum/common" + + etherman "github.com/0xPolygon/cdk/etherman" + + mock "github.com/stretchr/testify/mock" +) + +// DABackender is an autogenerated mock type for the DABackender type +type DABackender struct { + mock.Mock +} + +type DABackender_Expecter struct { + mock *mock.Mock +} + +func (_m *DABackender) EXPECT() *DABackender_Expecter { + return &DABackender_Expecter{mock: &_m.Mock} +} + +// GetSequence provides a mock function with given fields: ctx, batchHashes, dataAvailabilityMessage +func (_m *DABackender) GetSequence(ctx context.Context, batchHashes []common.Hash, dataAvailabilityMessage []byte) ([][]byte, error) { + ret := _m.Called(ctx, batchHashes, dataAvailabilityMessage) + + if len(ret) == 0 { + panic("no return value specified for GetSequence") + } + + var r0 [][]byte + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, []common.Hash, []byte) ([][]byte, error)); ok { + return rf(ctx, batchHashes, dataAvailabilityMessage) + } + if rf, ok := ret.Get(0).(func(context.Context, []common.Hash, []byte) [][]byte); ok { + r0 = rf(ctx, batchHashes, dataAvailabilityMessage) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([][]byte) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, []common.Hash, []byte) error); ok { + r1 = rf(ctx, batchHashes, dataAvailabilityMessage) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// DABackender_GetSequence_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetSequence' +type DABackender_GetSequence_Call struct { + *mock.Call +} + +// GetSequence is a helper method to define mock.On call +// - ctx context.Context +// - batchHashes []common.Hash +// - dataAvailabilityMessage []byte +func (_e *DABackender_Expecter) GetSequence(ctx interface{}, batchHashes interface{}, dataAvailabilityMessage interface{}) *DABackender_GetSequence_Call { + return &DABackender_GetSequence_Call{Call: _e.mock.On("GetSequence", ctx, batchHashes, dataAvailabilityMessage)} +} + +func (_c *DABackender_GetSequence_Call) Run(run func(ctx context.Context, batchHashes []common.Hash, dataAvailabilityMessage []byte)) *DABackender_GetSequence_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]common.Hash), args[2].([]byte)) + }) + return _c +} + +func (_c *DABackender_GetSequence_Call) Return(_a0 [][]byte, _a1 error) *DABackender_GetSequence_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *DABackender_GetSequence_Call) RunAndReturn(run func(context.Context, []common.Hash, []byte) ([][]byte, error)) *DABackender_GetSequence_Call { + _c.Call.Return(run) + return _c +} + +// Init provides a mock function with given fields: +func (_m *DABackender) Init() error { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Init") + } + + var r0 error + if rf, ok := ret.Get(0).(func() error); ok { + r0 = rf() + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// DABackender_Init_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Init' +type DABackender_Init_Call struct { + *mock.Call +} + +// Init is a helper method to define mock.On call +func (_e *DABackender_Expecter) Init() *DABackender_Init_Call { + return &DABackender_Init_Call{Call: _e.mock.On("Init")} +} + +func (_c *DABackender_Init_Call) Run(run func()) *DABackender_Init_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *DABackender_Init_Call) Return(_a0 error) *DABackender_Init_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *DABackender_Init_Call) RunAndReturn(run func() error) *DABackender_Init_Call { + _c.Call.Return(run) + return _c +} + +// PostSequence provides a mock function with given fields: ctx, sequence +func (_m *DABackender) PostSequence(ctx context.Context, sequence etherman.SequenceBanana) ([]byte, error) { + ret := _m.Called(ctx, sequence) + + if len(ret) == 0 { + panic("no return value specified for PostSequence") + } + + var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, etherman.SequenceBanana) ([]byte, error)); ok { + return rf(ctx, sequence) + } + if rf, ok := ret.Get(0).(func(context.Context, etherman.SequenceBanana) []byte); ok { + r0 = rf(ctx, sequence) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, etherman.SequenceBanana) error); ok { + r1 = rf(ctx, sequence) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// DABackender_PostSequence_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PostSequence' +type DABackender_PostSequence_Call struct { + *mock.Call +} + +// PostSequence is a helper method to define mock.On call +// - ctx context.Context +// - sequence etherman.SequenceBanana +func (_e *DABackender_Expecter) PostSequence(ctx interface{}, sequence interface{}) *DABackender_PostSequence_Call { + return &DABackender_PostSequence_Call{Call: _e.mock.On("PostSequence", ctx, sequence)} +} + +func (_c *DABackender_PostSequence_Call) Run(run func(ctx context.Context, sequence etherman.SequenceBanana)) *DABackender_PostSequence_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(etherman.SequenceBanana)) + }) + return _c +} + +func (_c *DABackender_PostSequence_Call) Return(_a0 []byte, _a1 error) *DABackender_PostSequence_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *DABackender_PostSequence_Call) RunAndReturn(run func(context.Context, etherman.SequenceBanana) ([]byte, error)) *DABackender_PostSequence_Call { + _c.Call.Return(run) + return _c +} + +// PostSequenceElderberry provides a mock function with given fields: ctx, batchesData +func (_m *DABackender) PostSequenceElderberry(ctx context.Context, batchesData [][]byte) ([]byte, error) { + ret := _m.Called(ctx, batchesData) + + if len(ret) == 0 { + panic("no return value specified for PostSequenceElderberry") + } + + var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, [][]byte) ([]byte, error)); ok { + return rf(ctx, batchesData) + } + if rf, ok := ret.Get(0).(func(context.Context, [][]byte) []byte); ok { + r0 = rf(ctx, batchesData) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, [][]byte) error); ok { + r1 = rf(ctx, batchesData) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// DABackender_PostSequenceElderberry_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PostSequenceElderberry' +type DABackender_PostSequenceElderberry_Call struct { + *mock.Call +} + +// PostSequenceElderberry is a helper method to define mock.On call +// - ctx context.Context +// - batchesData [][]byte +func (_e *DABackender_Expecter) PostSequenceElderberry(ctx interface{}, batchesData interface{}) *DABackender_PostSequenceElderberry_Call { + return &DABackender_PostSequenceElderberry_Call{Call: _e.mock.On("PostSequenceElderberry", ctx, batchesData)} +} + +func (_c *DABackender_PostSequenceElderberry_Call) Run(run func(ctx context.Context, batchesData [][]byte)) *DABackender_PostSequenceElderberry_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([][]byte)) + }) + return _c +} + +func (_c *DABackender_PostSequenceElderberry_Call) Return(_a0 []byte, _a1 error) *DABackender_PostSequenceElderberry_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *DABackender_PostSequenceElderberry_Call) RunAndReturn(run func(context.Context, [][]byte) ([]byte, error)) *DABackender_PostSequenceElderberry_Call { + _c.Call.Return(run) + return _c +} + +// NewDABackender creates a new instance of DABackender. 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 NewDABackender(t interface { + mock.TestingT + Cleanup(func()) +}) *DABackender { + mock := &DABackender{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/dataavailability/mocks_da/data_manager.go b/dataavailability/mocks_da/data_manager.go new file mode 100644 index 00000000..4b4e300f --- /dev/null +++ b/dataavailability/mocks_da/data_manager.go @@ -0,0 +1,218 @@ +// Code generated by mockery. DO NOT EDIT. + +package mocks_da + +import ( + context "context" + + common "github.com/ethereum/go-ethereum/common" + + etherman "github.com/0xPolygon/cdk/etherman" + + mock "github.com/stretchr/testify/mock" +) + +// DataManager is an autogenerated mock type for the DataManager type +type DataManager struct { + mock.Mock +} + +type DataManager_Expecter struct { + mock *mock.Mock +} + +func (_m *DataManager) EXPECT() *DataManager_Expecter { + return &DataManager_Expecter{mock: &_m.Mock} +} + +// GetBatchL2Data provides a mock function with given fields: batchNum, batchHashes, dataAvailabilityMessage +func (_m *DataManager) GetBatchL2Data(batchNum []uint64, batchHashes []common.Hash, dataAvailabilityMessage []byte) ([][]byte, error) { + ret := _m.Called(batchNum, batchHashes, dataAvailabilityMessage) + + if len(ret) == 0 { + panic("no return value specified for GetBatchL2Data") + } + + var r0 [][]byte + var r1 error + if rf, ok := ret.Get(0).(func([]uint64, []common.Hash, []byte) ([][]byte, error)); ok { + return rf(batchNum, batchHashes, dataAvailabilityMessage) + } + if rf, ok := ret.Get(0).(func([]uint64, []common.Hash, []byte) [][]byte); ok { + r0 = rf(batchNum, batchHashes, dataAvailabilityMessage) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([][]byte) + } + } + + if rf, ok := ret.Get(1).(func([]uint64, []common.Hash, []byte) error); ok { + r1 = rf(batchNum, batchHashes, dataAvailabilityMessage) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// DataManager_GetBatchL2Data_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetBatchL2Data' +type DataManager_GetBatchL2Data_Call struct { + *mock.Call +} + +// GetBatchL2Data is a helper method to define mock.On call +// - batchNum []uint64 +// - batchHashes []common.Hash +// - dataAvailabilityMessage []byte +func (_e *DataManager_Expecter) GetBatchL2Data(batchNum interface{}, batchHashes interface{}, dataAvailabilityMessage interface{}) *DataManager_GetBatchL2Data_Call { + return &DataManager_GetBatchL2Data_Call{Call: _e.mock.On("GetBatchL2Data", batchNum, batchHashes, dataAvailabilityMessage)} +} + +func (_c *DataManager_GetBatchL2Data_Call) Run(run func(batchNum []uint64, batchHashes []common.Hash, dataAvailabilityMessage []byte)) *DataManager_GetBatchL2Data_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].([]uint64), args[1].([]common.Hash), args[2].([]byte)) + }) + return _c +} + +func (_c *DataManager_GetBatchL2Data_Call) Return(_a0 [][]byte, _a1 error) *DataManager_GetBatchL2Data_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *DataManager_GetBatchL2Data_Call) RunAndReturn(run func([]uint64, []common.Hash, []byte) ([][]byte, error)) *DataManager_GetBatchL2Data_Call { + _c.Call.Return(run) + return _c +} + +// PostSequence provides a mock function with given fields: ctx, sequence +func (_m *DataManager) PostSequence(ctx context.Context, sequence etherman.SequenceBanana) ([]byte, error) { + ret := _m.Called(ctx, sequence) + + if len(ret) == 0 { + panic("no return value specified for PostSequence") + } + + var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, etherman.SequenceBanana) ([]byte, error)); ok { + return rf(ctx, sequence) + } + if rf, ok := ret.Get(0).(func(context.Context, etherman.SequenceBanana) []byte); ok { + r0 = rf(ctx, sequence) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, etherman.SequenceBanana) error); ok { + r1 = rf(ctx, sequence) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// DataManager_PostSequence_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PostSequence' +type DataManager_PostSequence_Call struct { + *mock.Call +} + +// PostSequence is a helper method to define mock.On call +// - ctx context.Context +// - sequence etherman.SequenceBanana +func (_e *DataManager_Expecter) PostSequence(ctx interface{}, sequence interface{}) *DataManager_PostSequence_Call { + return &DataManager_PostSequence_Call{Call: _e.mock.On("PostSequence", ctx, sequence)} +} + +func (_c *DataManager_PostSequence_Call) Run(run func(ctx context.Context, sequence etherman.SequenceBanana)) *DataManager_PostSequence_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(etherman.SequenceBanana)) + }) + return _c +} + +func (_c *DataManager_PostSequence_Call) Return(_a0 []byte, _a1 error) *DataManager_PostSequence_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *DataManager_PostSequence_Call) RunAndReturn(run func(context.Context, etherman.SequenceBanana) ([]byte, error)) *DataManager_PostSequence_Call { + _c.Call.Return(run) + return _c +} + +// PostSequenceElderberry provides a mock function with given fields: ctx, batchesData +func (_m *DataManager) PostSequenceElderberry(ctx context.Context, batchesData [][]byte) ([]byte, error) { + ret := _m.Called(ctx, batchesData) + + if len(ret) == 0 { + panic("no return value specified for PostSequenceElderberry") + } + + var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, [][]byte) ([]byte, error)); ok { + return rf(ctx, batchesData) + } + if rf, ok := ret.Get(0).(func(context.Context, [][]byte) []byte); ok { + r0 = rf(ctx, batchesData) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, [][]byte) error); ok { + r1 = rf(ctx, batchesData) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// DataManager_PostSequenceElderberry_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PostSequenceElderberry' +type DataManager_PostSequenceElderberry_Call struct { + *mock.Call +} + +// PostSequenceElderberry is a helper method to define mock.On call +// - ctx context.Context +// - batchesData [][]byte +func (_e *DataManager_Expecter) PostSequenceElderberry(ctx interface{}, batchesData interface{}) *DataManager_PostSequenceElderberry_Call { + return &DataManager_PostSequenceElderberry_Call{Call: _e.mock.On("PostSequenceElderberry", ctx, batchesData)} +} + +func (_c *DataManager_PostSequenceElderberry_Call) Run(run func(ctx context.Context, batchesData [][]byte)) *DataManager_PostSequenceElderberry_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([][]byte)) + }) + return _c +} + +func (_c *DataManager_PostSequenceElderberry_Call) Return(_a0 []byte, _a1 error) *DataManager_PostSequenceElderberry_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *DataManager_PostSequenceElderberry_Call) RunAndReturn(run func(context.Context, [][]byte) ([]byte, error)) *DataManager_PostSequenceElderberry_Call { + _c.Call.Return(run) + return _c +} + +// NewDataManager creates a new instance of DataManager. 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 NewDataManager(t interface { + mock.TestingT + Cleanup(func()) +}) *DataManager { + mock := &DataManager{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/dataavailability/mocks_da/func_sign_type.go b/dataavailability/mocks_da/func_sign_type.go new file mode 100644 index 00000000..3efa4e42 --- /dev/null +++ b/dataavailability/mocks_da/func_sign_type.go @@ -0,0 +1,94 @@ +// Code generated by mockery. DO NOT EDIT. + +package mocks_da + +import ( + client "github.com/0xPolygon/cdk-data-availability/client" + + mock "github.com/stretchr/testify/mock" +) + +// funcSignType is an autogenerated mock type for the funcSignType type +type funcSignType struct { + mock.Mock +} + +type funcSignType_Expecter struct { + mock *mock.Mock +} + +func (_m *funcSignType) EXPECT() *funcSignType_Expecter { + return &funcSignType_Expecter{mock: &_m.Mock} +} + +// Execute provides a mock function with given fields: c +func (_m *funcSignType) Execute(c client.Client) ([]byte, error) { + ret := _m.Called(c) + + if len(ret) == 0 { + panic("no return value specified for Execute") + } + + var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func(client.Client) ([]byte, error)); ok { + return rf(c) + } + if rf, ok := ret.Get(0).(func(client.Client) []byte); ok { + r0 = rf(c) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } + } + + if rf, ok := ret.Get(1).(func(client.Client) error); ok { + r1 = rf(c) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// funcSignType_Execute_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Execute' +type funcSignType_Execute_Call struct { + *mock.Call +} + +// Execute is a helper method to define mock.On call +// - c client.Client +func (_e *funcSignType_Expecter) Execute(c interface{}) *funcSignType_Execute_Call { + return &funcSignType_Execute_Call{Call: _e.mock.On("Execute", c)} +} + +func (_c *funcSignType_Execute_Call) Run(run func(c client.Client)) *funcSignType_Execute_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(client.Client)) + }) + return _c +} + +func (_c *funcSignType_Execute_Call) Return(_a0 []byte, _a1 error) *funcSignType_Execute_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *funcSignType_Execute_Call) RunAndReturn(run func(client.Client) ([]byte, error)) *funcSignType_Execute_Call { + _c.Call.Return(run) + return _c +} + +// newFuncSignType creates a new instance of funcSignType. 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 newFuncSignType(t interface { + mock.TestingT + Cleanup(func()) +}) *funcSignType { + mock := &funcSignType{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/dataavailability/mocks_da/sequence_retriever.go b/dataavailability/mocks_da/sequence_retriever.go new file mode 100644 index 00000000..f82d9a70 --- /dev/null +++ b/dataavailability/mocks_da/sequence_retriever.go @@ -0,0 +1,98 @@ +// Code generated by mockery. DO NOT EDIT. + +package mocks_da + +import ( + context "context" + + common "github.com/ethereum/go-ethereum/common" + + mock "github.com/stretchr/testify/mock" +) + +// SequenceRetriever is an autogenerated mock type for the SequenceRetriever type +type SequenceRetriever struct { + mock.Mock +} + +type SequenceRetriever_Expecter struct { + mock *mock.Mock +} + +func (_m *SequenceRetriever) EXPECT() *SequenceRetriever_Expecter { + return &SequenceRetriever_Expecter{mock: &_m.Mock} +} + +// GetSequence provides a mock function with given fields: ctx, batchHashes, dataAvailabilityMessage +func (_m *SequenceRetriever) GetSequence(ctx context.Context, batchHashes []common.Hash, dataAvailabilityMessage []byte) ([][]byte, error) { + ret := _m.Called(ctx, batchHashes, dataAvailabilityMessage) + + if len(ret) == 0 { + panic("no return value specified for GetSequence") + } + + var r0 [][]byte + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, []common.Hash, []byte) ([][]byte, error)); ok { + return rf(ctx, batchHashes, dataAvailabilityMessage) + } + if rf, ok := ret.Get(0).(func(context.Context, []common.Hash, []byte) [][]byte); ok { + r0 = rf(ctx, batchHashes, dataAvailabilityMessage) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([][]byte) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, []common.Hash, []byte) error); ok { + r1 = rf(ctx, batchHashes, dataAvailabilityMessage) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// SequenceRetriever_GetSequence_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetSequence' +type SequenceRetriever_GetSequence_Call struct { + *mock.Call +} + +// GetSequence is a helper method to define mock.On call +// - ctx context.Context +// - batchHashes []common.Hash +// - dataAvailabilityMessage []byte +func (_e *SequenceRetriever_Expecter) GetSequence(ctx interface{}, batchHashes interface{}, dataAvailabilityMessage interface{}) *SequenceRetriever_GetSequence_Call { + return &SequenceRetriever_GetSequence_Call{Call: _e.mock.On("GetSequence", ctx, batchHashes, dataAvailabilityMessage)} +} + +func (_c *SequenceRetriever_GetSequence_Call) Run(run func(ctx context.Context, batchHashes []common.Hash, dataAvailabilityMessage []byte)) *SequenceRetriever_GetSequence_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]common.Hash), args[2].([]byte)) + }) + return _c +} + +func (_c *SequenceRetriever_GetSequence_Call) Return(_a0 [][]byte, _a1 error) *SequenceRetriever_GetSequence_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *SequenceRetriever_GetSequence_Call) RunAndReturn(run func(context.Context, []common.Hash, []byte) ([][]byte, error)) *SequenceRetriever_GetSequence_Call { + _c.Call.Return(run) + return _c +} + +// NewSequenceRetriever creates a new instance of SequenceRetriever. 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 NewSequenceRetriever(t interface { + mock.TestingT + Cleanup(func()) +}) *SequenceRetriever { + mock := &SequenceRetriever{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/dataavailability/mocks_da/sequence_sender.go b/dataavailability/mocks_da/sequence_sender.go new file mode 100644 index 00000000..fc05dbfe --- /dev/null +++ b/dataavailability/mocks_da/sequence_sender.go @@ -0,0 +1,156 @@ +// Code generated by mockery. DO NOT EDIT. + +package mocks_da + +import ( + context "context" + + etherman "github.com/0xPolygon/cdk/etherman" + + mock "github.com/stretchr/testify/mock" +) + +// SequenceSender is an autogenerated mock type for the SequenceSender type +type SequenceSender struct { + mock.Mock +} + +type SequenceSender_Expecter struct { + mock *mock.Mock +} + +func (_m *SequenceSender) EXPECT() *SequenceSender_Expecter { + return &SequenceSender_Expecter{mock: &_m.Mock} +} + +// PostSequence provides a mock function with given fields: ctx, sequence +func (_m *SequenceSender) PostSequence(ctx context.Context, sequence etherman.SequenceBanana) ([]byte, error) { + ret := _m.Called(ctx, sequence) + + if len(ret) == 0 { + panic("no return value specified for PostSequence") + } + + var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, etherman.SequenceBanana) ([]byte, error)); ok { + return rf(ctx, sequence) + } + if rf, ok := ret.Get(0).(func(context.Context, etherman.SequenceBanana) []byte); ok { + r0 = rf(ctx, sequence) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, etherman.SequenceBanana) error); ok { + r1 = rf(ctx, sequence) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// SequenceSender_PostSequence_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PostSequence' +type SequenceSender_PostSequence_Call struct { + *mock.Call +} + +// PostSequence is a helper method to define mock.On call +// - ctx context.Context +// - sequence etherman.SequenceBanana +func (_e *SequenceSender_Expecter) PostSequence(ctx interface{}, sequence interface{}) *SequenceSender_PostSequence_Call { + return &SequenceSender_PostSequence_Call{Call: _e.mock.On("PostSequence", ctx, sequence)} +} + +func (_c *SequenceSender_PostSequence_Call) Run(run func(ctx context.Context, sequence etherman.SequenceBanana)) *SequenceSender_PostSequence_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(etherman.SequenceBanana)) + }) + return _c +} + +func (_c *SequenceSender_PostSequence_Call) Return(_a0 []byte, _a1 error) *SequenceSender_PostSequence_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *SequenceSender_PostSequence_Call) RunAndReturn(run func(context.Context, etherman.SequenceBanana) ([]byte, error)) *SequenceSender_PostSequence_Call { + _c.Call.Return(run) + return _c +} + +// PostSequenceElderberry provides a mock function with given fields: ctx, batchesData +func (_m *SequenceSender) PostSequenceElderberry(ctx context.Context, batchesData [][]byte) ([]byte, error) { + ret := _m.Called(ctx, batchesData) + + if len(ret) == 0 { + panic("no return value specified for PostSequenceElderberry") + } + + var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, [][]byte) ([]byte, error)); ok { + return rf(ctx, batchesData) + } + if rf, ok := ret.Get(0).(func(context.Context, [][]byte) []byte); ok { + r0 = rf(ctx, batchesData) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, [][]byte) error); ok { + r1 = rf(ctx, batchesData) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// SequenceSender_PostSequenceElderberry_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PostSequenceElderberry' +type SequenceSender_PostSequenceElderberry_Call struct { + *mock.Call +} + +// PostSequenceElderberry is a helper method to define mock.On call +// - ctx context.Context +// - batchesData [][]byte +func (_e *SequenceSender_Expecter) PostSequenceElderberry(ctx interface{}, batchesData interface{}) *SequenceSender_PostSequenceElderberry_Call { + return &SequenceSender_PostSequenceElderberry_Call{Call: _e.mock.On("PostSequenceElderberry", ctx, batchesData)} +} + +func (_c *SequenceSender_PostSequenceElderberry_Call) Run(run func(ctx context.Context, batchesData [][]byte)) *SequenceSender_PostSequenceElderberry_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([][]byte)) + }) + return _c +} + +func (_c *SequenceSender_PostSequenceElderberry_Call) Return(_a0 []byte, _a1 error) *SequenceSender_PostSequenceElderberry_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *SequenceSender_PostSequenceElderberry_Call) RunAndReturn(run func(context.Context, [][]byte) ([]byte, error)) *SequenceSender_PostSequenceElderberry_Call { + _c.Call.Return(run) + return _c +} + +// NewSequenceSender creates a new instance of SequenceSender. 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 NewSequenceSender(t interface { + mock.TestingT + Cleanup(func()) +}) *SequenceSender { + mock := &SequenceSender{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/dataavailability/mocks_da/sequence_sender_elderberry.go b/dataavailability/mocks_da/sequence_sender_elderberry.go new file mode 100644 index 00000000..3816fa1b --- /dev/null +++ b/dataavailability/mocks_da/sequence_sender_elderberry.go @@ -0,0 +1,95 @@ +// Code generated by mockery. DO NOT EDIT. + +package mocks_da + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" +) + +// SequenceSenderElderberry is an autogenerated mock type for the SequenceSenderElderberry type +type SequenceSenderElderberry struct { + mock.Mock +} + +type SequenceSenderElderberry_Expecter struct { + mock *mock.Mock +} + +func (_m *SequenceSenderElderberry) EXPECT() *SequenceSenderElderberry_Expecter { + return &SequenceSenderElderberry_Expecter{mock: &_m.Mock} +} + +// PostSequenceElderberry provides a mock function with given fields: ctx, batchesData +func (_m *SequenceSenderElderberry) PostSequenceElderberry(ctx context.Context, batchesData [][]byte) ([]byte, error) { + ret := _m.Called(ctx, batchesData) + + if len(ret) == 0 { + panic("no return value specified for PostSequenceElderberry") + } + + var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, [][]byte) ([]byte, error)); ok { + return rf(ctx, batchesData) + } + if rf, ok := ret.Get(0).(func(context.Context, [][]byte) []byte); ok { + r0 = rf(ctx, batchesData) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, [][]byte) error); ok { + r1 = rf(ctx, batchesData) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// SequenceSenderElderberry_PostSequenceElderberry_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PostSequenceElderberry' +type SequenceSenderElderberry_PostSequenceElderberry_Call struct { + *mock.Call +} + +// PostSequenceElderberry is a helper method to define mock.On call +// - ctx context.Context +// - batchesData [][]byte +func (_e *SequenceSenderElderberry_Expecter) PostSequenceElderberry(ctx interface{}, batchesData interface{}) *SequenceSenderElderberry_PostSequenceElderberry_Call { + return &SequenceSenderElderberry_PostSequenceElderberry_Call{Call: _e.mock.On("PostSequenceElderberry", ctx, batchesData)} +} + +func (_c *SequenceSenderElderberry_PostSequenceElderberry_Call) Run(run func(ctx context.Context, batchesData [][]byte)) *SequenceSenderElderberry_PostSequenceElderberry_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([][]byte)) + }) + return _c +} + +func (_c *SequenceSenderElderberry_PostSequenceElderberry_Call) Return(_a0 []byte, _a1 error) *SequenceSenderElderberry_PostSequenceElderberry_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *SequenceSenderElderberry_PostSequenceElderberry_Call) RunAndReturn(run func(context.Context, [][]byte) ([]byte, error)) *SequenceSenderElderberry_PostSequenceElderberry_Call { + _c.Call.Return(run) + return _c +} + +// NewSequenceSenderElderberry creates a new instance of SequenceSenderElderberry. 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 NewSequenceSenderElderberry(t interface { + mock.TestingT + Cleanup(func()) +}) *SequenceSenderElderberry { + mock := &SequenceSenderElderberry{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/localbridgesync/mock_downloader_test.go b/localbridgesync/mock_downloader_test.go index f2df97d0..b3f2ad08 100644 --- a/localbridgesync/mock_downloader_test.go +++ b/localbridgesync/mock_downloader_test.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.22.1. DO NOT EDIT. +// Code generated by mockery v2.39.0. DO NOT EDIT. package localbridgesync @@ -28,6 +28,10 @@ func (_m *DownloaderMock) download(ctx context.Context, fromBlock uint64, downlo func (_m *DownloaderMock) getBlockHeader(ctx context.Context, blockNum uint64) blockHeader { ret := _m.Called(ctx, blockNum) + if len(ret) == 0 { + panic("no return value specified for getBlockHeader") + } + var r0 blockHeader if rf, ok := ret.Get(0).(func(context.Context, uint64) blockHeader); ok { r0 = rf(ctx, blockNum) @@ -42,6 +46,10 @@ func (_m *DownloaderMock) getBlockHeader(ctx context.Context, blockNum uint64) b func (_m *DownloaderMock) getEventsByBlockRange(ctx context.Context, fromBlock uint64, toBlock uint64) []block { ret := _m.Called(ctx, fromBlock, toBlock) + if len(ret) == 0 { + panic("no return value specified for getEventsByBlockRange") + } + var r0 []block if rf, ok := ret.Get(0).(func(context.Context, uint64, uint64) []block); ok { r0 = rf(ctx, fromBlock, toBlock) @@ -58,6 +66,10 @@ func (_m *DownloaderMock) getEventsByBlockRange(ctx context.Context, fromBlock u func (_m *DownloaderMock) getLogs(ctx context.Context, fromBlock uint64, toBlock uint64) []types.Log { ret := _m.Called(ctx, fromBlock, toBlock) + if len(ret) == 0 { + panic("no return value specified for getLogs") + } + var r0 []types.Log if rf, ok := ret.Get(0).(func(context.Context, uint64, uint64) []types.Log); ok { r0 = rf(ctx, fromBlock, toBlock) @@ -74,6 +86,10 @@ func (_m *DownloaderMock) getLogs(ctx context.Context, fromBlock uint64, toBlock func (_m *DownloaderMock) waitForNewBlocks(ctx context.Context, lastBlockSeen uint64) uint64 { ret := _m.Called(ctx, lastBlockSeen) + if len(ret) == 0 { + panic("no return value specified for waitForNewBlocks") + } + var r0 uint64 if rf, ok := ret.Get(0).(func(context.Context, uint64) uint64); ok { r0 = rf(ctx, lastBlockSeen) @@ -84,13 +100,12 @@ func (_m *DownloaderMock) waitForNewBlocks(ctx context.Context, lastBlockSeen ui return r0 } -type mockConstructorTestingTNewDownloaderMock interface { +// NewDownloaderMock creates a new instance of DownloaderMock. 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 NewDownloaderMock(t interface { mock.TestingT Cleanup(func()) -} - -// NewDownloaderMock creates a new instance of DownloaderMock. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewDownloaderMock(t mockConstructorTestingTNewDownloaderMock) *DownloaderMock { +}) *DownloaderMock { mock := &DownloaderMock{} mock.Mock.Test(t) diff --git a/localbridgesync/mock_l2_test.go b/localbridgesync/mock_l2_test.go index 78baa614..22432fd1 100644 --- a/localbridgesync/mock_l2_test.go +++ b/localbridgesync/mock_l2_test.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.22.1. DO NOT EDIT. +// Code generated by mockery v2.39.0. DO NOT EDIT. package localbridgesync @@ -24,6 +24,10 @@ type L2Mock struct { func (_m *L2Mock) 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 { @@ -50,6 +54,10 @@ func (_m *L2Mock) BlockByHash(ctx context.Context, hash common.Hash) (*types.Blo func (_m *L2Mock) 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 { @@ -76,6 +84,10 @@ func (_m *L2Mock) BlockByNumber(ctx context.Context, number *big.Int) (*types.Bl func (_m *L2Mock) BlockNumber(ctx context.Context) (uint64, error) { ret := _m.Called(ctx) + if len(ret) == 0 { + panic("no return value specified for BlockNumber") + } + var r0 uint64 var r1 error if rf, ok := ret.Get(0).(func(context.Context) (uint64, error)); ok { @@ -100,6 +112,10 @@ func (_m *L2Mock) BlockNumber(ctx context.Context) (uint64, error) { func (_m *L2Mock) 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 { @@ -126,6 +142,10 @@ func (_m *L2Mock) CallContract(ctx context.Context, call ethereum.CallMsg, block func (_m *L2Mock) CodeAt(ctx context.Context, contract common.Address, blockNumber *big.Int) ([]byte, error) { ret := _m.Called(ctx, contract, 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 { @@ -152,6 +172,10 @@ func (_m *L2Mock) CodeAt(ctx context.Context, contract common.Address, blockNumb func (_m *L2Mock) 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 { @@ -176,6 +200,10 @@ func (_m *L2Mock) EstimateGas(ctx context.Context, call ethereum.CallMsg) (uint6 func (_m *L2Mock) 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 { @@ -202,6 +230,10 @@ func (_m *L2Mock) FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]typ func (_m *L2Mock) 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 { @@ -228,6 +260,10 @@ func (_m *L2Mock) HeaderByHash(ctx context.Context, hash common.Hash) (*types.He func (_m *L2Mock) 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 { @@ -254,6 +290,10 @@ func (_m *L2Mock) HeaderByNumber(ctx context.Context, number *big.Int) (*types.H func (_m *L2Mock) 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 { @@ -280,6 +320,10 @@ func (_m *L2Mock) PendingCodeAt(ctx context.Context, account common.Address) ([] func (_m *L2Mock) 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 { @@ -304,6 +348,10 @@ func (_m *L2Mock) PendingNonceAt(ctx context.Context, account common.Address) (u func (_m *L2Mock) 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) @@ -318,6 +366,10 @@ func (_m *L2Mock) SendTransaction(ctx context.Context, tx *types.Transaction) er func (_m *L2Mock) 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 { @@ -344,6 +396,10 @@ func (_m *L2Mock) SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuer func (_m *L2Mock) 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 { @@ -370,6 +426,10 @@ func (_m *L2Mock) SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) func (_m *L2Mock) 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 { @@ -396,6 +456,10 @@ func (_m *L2Mock) SuggestGasPrice(ctx context.Context) (*big.Int, error) { func (_m *L2Mock) 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 { @@ -422,6 +486,10 @@ func (_m *L2Mock) SuggestGasTipCap(ctx context.Context) (*big.Int, error) { func (_m *L2Mock) 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 { @@ -446,6 +514,10 @@ func (_m *L2Mock) TransactionCount(ctx context.Context, blockHash common.Hash) ( func (_m *L2Mock) 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 { @@ -468,13 +540,12 @@ func (_m *L2Mock) TransactionInBlock(ctx context.Context, blockHash common.Hash, return r0, r1 } -type mockConstructorTestingTNewL2Mock interface { +// NewL2Mock creates a new instance of L2Mock. 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 NewL2Mock(t interface { mock.TestingT Cleanup(func()) -} - -// NewL2Mock creates a new instance of L2Mock. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewL2Mock(t mockConstructorTestingTNewL2Mock) *L2Mock { +}) *L2Mock { mock := &L2Mock{} mock.Mock.Test(t) diff --git a/localbridgesync/mock_processor_test.go b/localbridgesync/mock_processor_test.go index 4a629f5c..431c6201 100644 --- a/localbridgesync/mock_processor_test.go +++ b/localbridgesync/mock_processor_test.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.22.1. DO NOT EDIT. +// Code generated by mockery v2.39.0. DO NOT EDIT. package localbridgesync @@ -17,6 +17,10 @@ type ProcessorMock struct { func (_m *ProcessorMock) getLastProcessedBlock(ctx context.Context) (uint64, error) { ret := _m.Called(ctx) + if len(ret) == 0 { + panic("no return value specified for getLastProcessedBlock") + } + var r0 uint64 var r1 error if rf, ok := ret.Get(0).(func(context.Context) (uint64, error)); ok { @@ -41,6 +45,10 @@ func (_m *ProcessorMock) getLastProcessedBlock(ctx context.Context) (uint64, err func (_m *ProcessorMock) reorg(firstReorgedBlock uint64) error { ret := _m.Called(firstReorgedBlock) + if len(ret) == 0 { + panic("no return value specified for reorg") + } + var r0 error if rf, ok := ret.Get(0).(func(uint64) error); ok { r0 = rf(firstReorgedBlock) @@ -55,6 +63,10 @@ func (_m *ProcessorMock) reorg(firstReorgedBlock uint64) error { func (_m *ProcessorMock) storeBridgeEvents(blockNum uint64, events []BridgeEvent) error { ret := _m.Called(blockNum, events) + if len(ret) == 0 { + panic("no return value specified for storeBridgeEvents") + } + var r0 error if rf, ok := ret.Get(0).(func(uint64, []BridgeEvent) error); ok { r0 = rf(blockNum, events) @@ -65,13 +77,12 @@ func (_m *ProcessorMock) storeBridgeEvents(blockNum uint64, events []BridgeEvent return r0 } -type mockConstructorTestingTNewProcessorMock interface { +// NewProcessorMock creates a new instance of ProcessorMock. 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 NewProcessorMock(t interface { mock.TestingT Cleanup(func()) -} - -// NewProcessorMock creates a new instance of ProcessorMock. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewProcessorMock(t mockConstructorTestingTNewProcessorMock) *ProcessorMock { +}) *ProcessorMock { mock := &ProcessorMock{} mock.Mock.Test(t) diff --git a/localbridgesync/mock_reorgdetector_test.go b/localbridgesync/mock_reorgdetector_test.go index d11434a1..9d076315 100644 --- a/localbridgesync/mock_reorgdetector_test.go +++ b/localbridgesync/mock_reorgdetector_test.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.22.1. DO NOT EDIT. +// Code generated by mockery v2.39.0. DO NOT EDIT. package localbridgesync @@ -21,6 +21,10 @@ type ReorgDetectorMock struct { func (_m *ReorgDetectorMock) AddBlockToTrack(ctx context.Context, id string, blockNum uint64, blockHash common.Hash) error { ret := _m.Called(ctx, id, blockNum, blockHash) + if len(ret) == 0 { + panic("no return value specified for AddBlockToTrack") + } + var r0 error if rf, ok := ret.Get(0).(func(context.Context, string, uint64, common.Hash) error); ok { r0 = rf(ctx, id, blockNum, blockHash) @@ -35,6 +39,10 @@ func (_m *ReorgDetectorMock) AddBlockToTrack(ctx context.Context, id string, blo func (_m *ReorgDetectorMock) Subscribe(id string) *reorgdetector.Subscription { ret := _m.Called(id) + if len(ret) == 0 { + panic("no return value specified for Subscribe") + } + var r0 *reorgdetector.Subscription if rf, ok := ret.Get(0).(func(string) *reorgdetector.Subscription); ok { r0 = rf(id) @@ -47,13 +55,12 @@ func (_m *ReorgDetectorMock) Subscribe(id string) *reorgdetector.Subscription { return r0 } -type mockConstructorTestingTNewReorgDetectorMock interface { +// NewReorgDetectorMock creates a new instance of ReorgDetectorMock. 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 NewReorgDetectorMock(t interface { mock.TestingT Cleanup(func()) -} - -// NewReorgDetectorMock creates a new instance of ReorgDetectorMock. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewReorgDetectorMock(t mockConstructorTestingTNewReorgDetectorMock) *ReorgDetectorMock { +}) *ReorgDetectorMock { mock := &ReorgDetectorMock{} mock.Mock.Test(t) diff --git a/reorgdetector/mock_eth_client.go b/reorgdetector/mock_eth_client.go index add883f6..e0eef607 100644 --- a/reorgdetector/mock_eth_client.go +++ b/reorgdetector/mock_eth_client.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.42.1. DO NOT EDIT. +// Code generated by mockery v2.39.0. DO NOT EDIT. package reorgdetector diff --git a/sequencesender/txbuilder/banana_validium.go b/sequencesender/txbuilder/banana_validium.go index d926143a..e518d107 100644 --- a/sequencesender/txbuilder/banana_validium.go +++ b/sequencesender/txbuilder/banana_validium.go @@ -28,14 +28,14 @@ func NewTxBuilderBananaValidium(rollupContract contracts.RollupBananaType, return &TxBuilderBananaValidium{ TxBuilderBananaBase: *NewTxBuilderBananaBase(rollupContract, gerContract, opts, sender), da: da, - condNewSeq: &NewSequenceConditionalNumBatches{ + condNewSeq: &ConditionalNewSequenceNumBatches{ maxBatchesForL1: maxBatchesForL1, }, } } func (t *TxBuilderBananaValidium) NewSequenceIfWorthToSend(ctx context.Context, sequenceBatches []seqsendertypes.Batch, l2Coinbase common.Address, batchNumber uint64) (seqsendertypes.Sequence, error) { - return t.condNewSeq.NewSequenceIfWorthToSend(ctx, t, sequenceBatches, t.SenderAddress, l2Coinbase, batchNumber) + return t.condNewSeq.NewSequenceIfWorthToSend(ctx, t, sequenceBatches, t.SenderAddress, l2Coinbase) } func (t *TxBuilderBananaValidium) BuildSequenceBatchesTx(ctx context.Context, sender common.Address, sequences seqsendertypes.Sequence) (*ethtypes.Transaction, error) { diff --git a/sequencesender/txbuilder/banana_zkevm.go b/sequencesender/txbuilder/banana_zkevm.go index dbb679fb..e2a2e1aa 100644 --- a/sequencesender/txbuilder/banana_zkevm.go +++ b/sequencesender/txbuilder/banana_zkevm.go @@ -22,14 +22,14 @@ type TxBuilderBananaZKEVM struct { func NewTxBuilderBananaZKEVM(rollupContract contracts.RollupBananaType, gerContract contracts.GlobalExitRootBananaType, opts bind.TransactOpts, sender common.Address, maxTxSizeForL1 uint64) *TxBuilderBananaZKEVM { return &TxBuilderBananaZKEVM{ TxBuilderBananaBase: *NewTxBuilderBananaBase(rollupContract, gerContract, opts, sender), - condNewSeq: &NewSequenceConditionalMaxSize{ + condNewSeq: &ConditionalNewSequenceMaxSize{ maxTxSizeForL1: maxTxSizeForL1, }, } } func (t *TxBuilderBananaZKEVM) NewSequenceIfWorthToSend(ctx context.Context, sequenceBatches []seqsendertypes.Batch, l2Coinbase common.Address, batchNumber uint64) (seqsendertypes.Sequence, error) { - return t.condNewSeq.NewSequenceIfWorthToSend(ctx, t, sequenceBatches, t.SenderAddress, l2Coinbase, batchNumber) + return t.condNewSeq.NewSequenceIfWorthToSend(ctx, t, sequenceBatches, t.SenderAddress, l2Coinbase) } func (t *TxBuilderBananaZKEVM) BuildSequenceBatchesTx(ctx context.Context, sender common.Address, sequences seqsendertypes.Sequence) (*ethtypes.Transaction, error) { diff --git a/sequencesender/txbuilder/elderberry_base.go b/sequencesender/txbuilder/elderberry_base.go index f643a96c..8343eecf 100644 --- a/sequencesender/txbuilder/elderberry_base.go +++ b/sequencesender/txbuilder/elderberry_base.go @@ -21,6 +21,11 @@ func NewTxBuilderElderberryBase(rollupContract contracts.RollupElderberryType, o } } +// SetAuth sets the auth for the tx builder +func (t *TxBuilderElderberryBase) SetAuth(auth *bind.TransactOpts) { + t.opts = *auth +} + func (t *TxBuilderElderberryBase) NewSequence(batches []seqsendertypes.Batch, coinbase common.Address) (seqsendertypes.Sequence, error) { seq := ElderberrySequence{ l2Coinbase: coinbase, @@ -44,5 +49,8 @@ func getLastSequencedBatchNumber(sequences seqsendertypes.Sequence) uint64 { if sequences.Len() == 0 { return 0 } + if sequences.FirstBatch().BatchNumber() == 0 { + panic("First batch number is 0, that is not allowed!") + } return sequences.FirstBatch().BatchNumber() - 1 } diff --git a/sequencesender/txbuilder/elderberry_base_test.go b/sequencesender/txbuilder/elderberry_base_test.go new file mode 100644 index 00000000..619ce1da --- /dev/null +++ b/sequencesender/txbuilder/elderberry_base_test.go @@ -0,0 +1,101 @@ +package txbuilder + +import ( + "testing" + + "github.com/0xPolygon/cdk/etherman/contracts" + "github.com/0xPolygon/cdk/sequencesender/seqsendertypes" + "github.com/0xPolygon/cdk/state/datastream" + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + "github.com/stretchr/testify/require" +) + +func TestElderberryBaseNewSequence(t *testing.T) { + zkevmContract := contracts.RollupElderberryType{} + opts := bind.TransactOpts{} + sut := NewTxBuilderElderberryBase(zkevmContract, opts) + require.NotNil(t, sut) + seq, err := sut.NewSequence(nil, common.Address{}) + require.NotNil(t, seq) + require.NoError(t, err) +} + +func TestElderberryBaseNewBatchFromL2Block(t *testing.T) { + sut := newElderberryBaseSUT(t) + l2Block := &datastream.L2Block{ + Timestamp: 1, + BatchNumber: 2, + L1InfotreeIndex: 3, + Coinbase: []byte{1, 2, 3}, + GlobalExitRoot: []byte{4, 5, 6}, + } + batch := sut.NewBatchFromL2Block(l2Block) + require.NotNil(t, batch) + require.Equal(t, l2Block.Timestamp, batch.LastL2BLockTimestamp()) + require.Equal(t, l2Block.BatchNumber, batch.BatchNumber()) + require.Equal(t, l2Block.L1InfotreeIndex, batch.L1InfoTreeIndex()) + require.Equal(t, common.BytesToAddress(l2Block.Coinbase), batch.LastCoinbase()) + require.Equal(t, common.BytesToHash(l2Block.GlobalExitRoot), batch.GlobalExitRoot()) + +} + +func TestElderberryBasegetLastSequencedBatchNumberEmpty(t *testing.T) { + sut := newElderberryBaseSUT(t) + seq, err := sut.NewSequence(nil, common.Address{}) + require.NoError(t, err) + + require.Equal(t, uint64(0), getLastSequencedBatchNumber(seq)) +} + +func TestElderberryBasegetLastSequencedBatch1Batch(t *testing.T) { + sut := newElderberryBaseSUT(t) + l2Block := &datastream.L2Block{ + Timestamp: 1, + BatchNumber: 2, + L1InfotreeIndex: 3, + Coinbase: []byte{1, 2, 3}, + GlobalExitRoot: []byte{4, 5, 6}, + } + batchElder := sut.NewBatchFromL2Block(l2Block) + batches := []seqsendertypes.Batch{ + batchElder, + } + + seq, err := sut.NewSequence(batches, common.Address{}) + require.NoError(t, err) + + require.Equal(t, l2Block.BatchNumber-1, getLastSequencedBatchNumber(seq)) +} + +func TestElderberryBaseGetLastSequencedBatchFirstBatchIsZeroThrowAPanic(t *testing.T) { + sut := newElderberryBaseSUT(t) + l2Block := &datastream.L2Block{ + Timestamp: 1, + BatchNumber: 0, + L1InfotreeIndex: 3, + Coinbase: []byte{1, 2, 3}, + GlobalExitRoot: []byte{4, 5, 6}, + } + batchElder := sut.NewBatchFromL2Block(l2Block) + batches := []seqsendertypes.Batch{ + batchElder, + } + + seq, err := sut.NewSequence(batches, common.Address{}) + require.NoError(t, err) + defer func() { + if r := recover(); r == nil { + t.Errorf("The code did not panic") + } + }() + getLastSequencedBatchNumber(seq) +} + +func newElderberryBaseSUT(t *testing.T) *TxBuilderElderberryBase { + zkevmContract := contracts.RollupElderberryType{} + opts := bind.TransactOpts{} + sut := NewTxBuilderElderberryBase(zkevmContract, opts) + require.NotNil(t, sut) + return sut +} diff --git a/sequencesender/txbuilder/elderberry_types.go b/sequencesender/txbuilder/elderberry_types.go index fc57bc18..bbc7d56a 100644 --- a/sequencesender/txbuilder/elderberry_types.go +++ b/sequencesender/txbuilder/elderberry_types.go @@ -13,6 +13,13 @@ type ElderberrySequence struct { batches []seqsendertypes.Batch } +func NewElderberrySequence(batches []seqsendertypes.Batch, l2Coinbase common.Address) *ElderberrySequence { + return &ElderberrySequence{ + l2Coinbase: l2Coinbase, + batches: batches, + } +} + func (b *ElderberrySequence) IndexL1InfoRoot() uint32 { log.Fatal("Elderberry Sequence does not have IndexL1InfoRoot") return 0 diff --git a/sequencesender/txbuilder/elderberry_validium.go b/sequencesender/txbuilder/elderberry_validium.go index a0369191..2a223878 100644 --- a/sequencesender/txbuilder/elderberry_validium.go +++ b/sequencesender/txbuilder/elderberry_validium.go @@ -3,6 +3,7 @@ package txbuilder import ( "context" "encoding/hex" + "fmt" "math/big" "github.com/0xPolygon/cdk-contracts-tooling/contracts/elderberry/polygonvalidiumetrog" @@ -32,23 +33,26 @@ func NewTxBuilderElderberryValidium(zkevm contracts.RollupElderberryType, TxBuilderElderberryBase: *NewTxBuilderElderberryBase( zkevm, opts, ), - condNewSeq: &NewSequenceConditionalNumBatches{ - maxBatchesForL1: maxBatchesForL1, - }, + condNewSeq: NewConditionalNewSequenceNumBatches(maxBatchesForL1), } } func (t *TxBuilderElderberryValidium) NewSequenceIfWorthToSend(ctx context.Context, sequenceBatches []seqsendertypes.Batch, l2Coinbase common.Address, batchNumber uint64) (seqsendertypes.Sequence, error) { - return t.condNewSeq.NewSequenceIfWorthToSend(ctx, t, sequenceBatches, t.opts.From, l2Coinbase, batchNumber) + return t.condNewSeq.NewSequenceIfWorthToSend(ctx, t, sequenceBatches, t.opts.From, l2Coinbase) } func (t *TxBuilderElderberryValidium) BuildSequenceBatchesTx(ctx context.Context, sender common.Address, sequences seqsendertypes.Sequence) (*ethtypes.Transaction, error) { - + if sequences == nil || sequences.Len() == 0 { + return nil, fmt.Errorf("can't sequence an empty sequence") + } batchesData := convertToBatchesData(sequences) dataAvailabilityMessage, err := t.da.PostSequenceElderberry(ctx, batchesData) if err != nil { log.Error("error posting sequences to the data availability protocol: ", err) return nil, err } + if dataAvailabilityMessage == nil { + return nil, fmt.Errorf("data availability message is nil") + } newopts := t.opts newopts.NoSend = true diff --git a/sequencesender/txbuilder/elderberry_validium_test.go b/sequencesender/txbuilder/elderberry_validium_test.go new file mode 100644 index 00000000..68f5e303 --- /dev/null +++ b/sequencesender/txbuilder/elderberry_validium_test.go @@ -0,0 +1,109 @@ +package txbuilder_test + +import ( + "context" + "fmt" + "math/big" + "strings" + "testing" + + "github.com/0xPolygon/cdk-contracts-tooling/contracts/elderberry/polygonvalidiumetrog" + "github.com/0xPolygon/cdk/dataavailability/mocks_da" + "github.com/0xPolygon/cdk/etherman/contracts" + "github.com/0xPolygon/cdk/sequencesender/seqsendertypes" + "github.com/0xPolygon/cdk/sequencesender/txbuilder" + "github.com/0xPolygon/cdk/state/datastream" + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/crypto" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" +) + +func TestElderberryValidiumName(t *testing.T) { + testData := newElderberryValidiumSUT(t) + require.NotNil(t, testData.sut) + require.True(t, strings.Contains(testData.sut.String(), "Elderberry")) + require.True(t, strings.Contains(testData.sut.String(), "Validium")) +} + +func TestElderberryValidiumBuildSequenceBatchesTxEmtpySequence(t *testing.T) { + testData := newElderberryValidiumSUT(t) + ctx := context.TODO() + _, err := testData.sut.BuildSequenceBatchesTx(ctx, common.Address{}, nil) + require.Error(t, err) + + seq, err := testData.sut.NewSequence(nil, common.Address{}) + require.NoError(t, err) + _, err = testData.sut.BuildSequenceBatchesTx(ctx, common.Address{}, seq) + require.Error(t, err) +} + +func TestElderberryValidiumBuildSequenceBatchesTxSequenceErrorsFromDA(t *testing.T) { + testData := newElderberryValidiumSUT(t) + ctx := context.TODO() + l2Block := &datastream.L2Block{ + Timestamp: 1, + BatchNumber: 1, + L1InfotreeIndex: 3, + Coinbase: []byte{1, 2, 3}, + GlobalExitRoot: []byte{4, 5, 6}, + } + batchElder := testData.sut.NewBatchFromL2Block(l2Block) + batches := []seqsendertypes.Batch{ + batchElder, + } + seq, err := testData.sut.NewSequence(batches, common.Address{}) + require.NoError(t, err) + testData.mockDA.EXPECT().PostSequenceElderberry(ctx, mock.Anything).Return(nil, nil) + _, err = testData.sut.BuildSequenceBatchesTx(ctx, common.Address{}, seq) + require.Error(t, err, "data availability message is nil") + testData.mockDA.EXPECT().PostSequenceElderberry(ctx, mock.Anything).Return(nil, fmt.Errorf("test error")) + _, err = testData.sut.BuildSequenceBatchesTx(ctx, common.Address{}, seq) + require.Error(t, err, "error posting sequences to the data availability protocol: test error") +} + +func TestElderberryValidiumBuildSequenceBatchesTxSequenceDAOk(t *testing.T) { + testData := newElderberryValidiumSUT(t) + ctx := context.TODO() + l2Block := &datastream.L2Block{ + Timestamp: 1, + BatchNumber: 1, + L1InfotreeIndex: 3, + Coinbase: []byte{1, 2, 3}, + GlobalExitRoot: []byte{4, 5, 6}, + } + batchElder := testData.sut.NewBatchFromL2Block(l2Block) + batches := []seqsendertypes.Batch{ + batchElder, + } + seq, err := testData.sut.NewSequence(batches, common.Address{}) + require.NoError(t, err) + testData.mockDA.EXPECT().PostSequenceElderberry(ctx, mock.Anything).Return([]byte{1}, nil) + tx, err := testData.sut.BuildSequenceBatchesTx(ctx, common.Address{}, seq) + require.NoError(t, err) + require.NotNil(t, tx) +} + +type testDataElderberryValidium struct { + mockDA *mocks_da.SequenceSenderElderberry + sut *txbuilder.TxBuilderElderberryValidium +} + +func newElderberryValidiumSUT(t *testing.T) *testDataElderberryValidium { + zkevmContract, err := contracts.NewContractBase(polygonvalidiumetrog.NewPolygonvalidiumetrog, common.Address{}, nil, contracts.ContractNameRollup, contracts.VersionElderberry) + require.NoError(t, err) + privateKey, err := crypto.HexToECDSA("64e679029f5032046955d41713dcc4b565de77ab891748d31bcf38864b54c175") + require.NoError(t, err) + opts, err := bind.NewKeyedTransactorWithChainID(privateKey, big.NewInt(1)) + require.NoError(t, err) + sender := common.Address{} + da := mocks_da.NewSequenceSenderElderberry(t) + + sut := txbuilder.NewTxBuilderElderberryValidium(*zkevmContract, da, *opts, sender, uint64(100)) + require.NotNil(t, sut) + return &testDataElderberryValidium{ + mockDA: da, + sut: sut, + } +} diff --git a/sequencesender/txbuilder/elderberry_zkevm.go b/sequencesender/txbuilder/elderberry_zkevm.go index 39979375..46df1f57 100644 --- a/sequencesender/txbuilder/elderberry_zkevm.go +++ b/sequencesender/txbuilder/elderberry_zkevm.go @@ -2,6 +2,7 @@ package txbuilder import ( "context" + "fmt" "math/big" "github.com/0xPolygon/cdk-contracts-tooling/contracts/elderberry/polygonvalidiumetrog" @@ -25,18 +26,20 @@ func NewTxBuilderElderberryZKEVM(zkevm contracts.RollupElderberryType, opts bind TxBuilderElderberryBase: *NewTxBuilderElderberryBase( zkevm, opts, ), - condNewSeq: &NewSequenceConditionalMaxSize{ - maxTxSizeForL1: maxTxSizeForL1, - }, + condNewSeq: NewConditionalNewSequenceMaxSize(maxTxSizeForL1), } } func (t *TxBuilderElderberryZKEVM) NewSequenceIfWorthToSend(ctx context.Context, sequenceBatches []seqsendertypes.Batch, l2Coinbase common.Address, batchNumber uint64) (seqsendertypes.Sequence, error) { - return t.condNewSeq.NewSequenceIfWorthToSend(ctx, t, sequenceBatches, t.opts.From, l2Coinbase, batchNumber) + return t.condNewSeq.NewSequenceIfWorthToSend(ctx, t, sequenceBatches, t.opts.From, l2Coinbase) } -func (t *TxBuilderElderberryZKEVM) BuildSequenceBatchesTx(ctx context.Context, sender common.Address, sequences seqsendertypes.Sequence) (*ethtypes.Transaction, error) { +// SetCondNewSeq allow to override the default conditional for new sequence +func (t *TxBuilderElderberryZKEVM) SetCondNewSeq(cond CondNewSequence) { + t.condNewSeq = cond +} +func (t *TxBuilderElderberryZKEVM) BuildSequenceBatchesTx(ctx context.Context, sender common.Address, sequences seqsendertypes.Sequence) (*ethtypes.Transaction, error) { newopts := t.opts newopts.NoSend = true @@ -49,6 +52,9 @@ func (t *TxBuilderElderberryZKEVM) BuildSequenceBatchesTx(ctx context.Context, s } func (t *TxBuilderElderberryZKEVM) sequenceBatchesRollup(opts bind.TransactOpts, sequences seqsendertypes.Sequence) (*types.Transaction, error) { + if sequences == nil || sequences.Len() == 0 { + return nil, fmt.Errorf("can't sequence an empty sequence") + } batches := make([]polygonvalidiumetrog.PolygonRollupBaseEtrogBatchData, sequences.Len()) for i, seq := range sequences.Batches() { var ger common.Hash diff --git a/sequencesender/txbuilder/elderberry_zkevm_test.go b/sequencesender/txbuilder/elderberry_zkevm_test.go new file mode 100644 index 00000000..6ae3b6eb --- /dev/null +++ b/sequencesender/txbuilder/elderberry_zkevm_test.go @@ -0,0 +1,119 @@ +package txbuilder_test + +import ( + "context" + "math/big" + "strings" + "testing" + + "github.com/0xPolygon/cdk-contracts-tooling/contracts/elderberry/polygonvalidiumetrog" + "github.com/0xPolygon/cdk/etherman/contracts" + "github.com/0xPolygon/cdk/sequencesender/seqsendertypes" + "github.com/0xPolygon/cdk/sequencesender/txbuilder" + "github.com/0xPolygon/cdk/sequencesender/txbuilder/mocks_txbuilder" + "github.com/0xPolygon/cdk/state/datastream" + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/crypto" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" +) + +func TestElderberryZkevmName(t *testing.T) { + zkevmContract := contracts.RollupElderberryType{} + opts := bind.TransactOpts{} + sender := common.Address{} + sut := txbuilder.NewTxBuilderElderberryZKEVM(zkevmContract, opts, sender, 100) + require.NotNil(t, sut) + require.True(t, strings.Contains(sut.String(), "Elderberry")) + require.True(t, strings.Contains(sut.String(), "ZKEVM")) +} + +func TestElderberryZkevmNewSequence(t *testing.T) { + zkevmContract := contracts.RollupElderberryType{} + opts := bind.TransactOpts{} + sender := common.Address{} + sut := txbuilder.NewTxBuilderElderberryZKEVM(zkevmContract, opts, sender, 100) + require.NotNil(t, sut) + seq, err := sut.NewSequence(nil, common.Address{}) + require.NoError(t, err) + require.NotNil(t, seq) +} + +func TestElderberryZkevmBuildSequenceBatchesTxEmtpySequence(t *testing.T) { + sut := newElderberryZkevmSUT(t) + ctx := context.TODO() + _, err := sut.BuildSequenceBatchesTx(ctx, common.Address{}, nil) + require.Error(t, err) + + seq, err := sut.NewSequence(nil, common.Address{}) + require.NoError(t, err) + _, err = sut.BuildSequenceBatchesTx(ctx, common.Address{}, seq) + require.Error(t, err) +} + +func TestElderberryZkevmBuildSequenceBatchesTxSequence1Batch(t *testing.T) { + sut := newElderberryZkevmSUT(t) + ctx := context.TODO() + l2Block := &datastream.L2Block{ + Timestamp: 1, + BatchNumber: 1, + L1InfotreeIndex: 3, + Coinbase: []byte{1, 2, 3}, + GlobalExitRoot: []byte{4, 5, 6}, + } + batchElder := sut.NewBatchFromL2Block(l2Block) + batches := []seqsendertypes.Batch{ + batchElder, + } + seq, err := sut.NewSequence(batches, common.Address{}) + require.NoError(t, err) + _, err = sut.BuildSequenceBatchesTx(ctx, common.Address{}, seq) + require.NoError(t, err) +} + +// This have to signer so produce an error +func TestElderberryZkevmBuildSequenceBatchesTxSequence1BatchError(t *testing.T) { + sut := newElderberryZkevmSUT(t) + sut.SetAuth(&bind.TransactOpts{}) + ctx := context.TODO() + l2Block := &datastream.L2Block{ + Timestamp: 1, + BatchNumber: 1, + L1InfotreeIndex: 3, + Coinbase: []byte{1, 2, 3}, + GlobalExitRoot: []byte{4, 5, 6}, + } + batchElder := sut.NewBatchFromL2Block(l2Block) + batches := []seqsendertypes.Batch{ + batchElder, + } + seq, err := sut.NewSequence(batches, common.Address{}) + require.NoError(t, err) + _, err = sut.BuildSequenceBatchesTx(ctx, common.Address{}, seq) + require.Error(t, err) +} + +func TestElderberryZkevmNewSequenceIfWorthToSend(t *testing.T) { + sut := newElderberryZkevmSUT(t) + mockCond := mocks_txbuilder.NewCondNewSequence(t) + sut.SetCondNewSeq(mockCond) + // Returns that is not work to be send + mockCond.EXPECT().NewSequenceIfWorthToSend(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, nil) + seq, err := sut.NewSequenceIfWorthToSend(context.TODO(), nil, common.Address{}, 0) + require.NoError(t, err) + require.Nil(t, seq) +} + +func newElderberryZkevmSUT(t *testing.T) *txbuilder.TxBuilderElderberryZKEVM { + zkevmContract, err := contracts.NewContractBase(polygonvalidiumetrog.NewPolygonvalidiumetrog, common.Address{}, nil, contracts.ContractNameRollup, contracts.VersionElderberry) + require.NoError(t, err) + privateKey, err := crypto.HexToECDSA("64e679029f5032046955d41713dcc4b565de77ab891748d31bcf38864b54c175") + require.NoError(t, err) + opts, err := bind.NewKeyedTransactorWithChainID(privateKey, big.NewInt(1)) + require.NoError(t, err) + sender := common.Address{} + sut := txbuilder.NewTxBuilderElderberryZKEVM(*zkevmContract, *opts, sender, 100) + require.NotNil(t, sut) + return sut +} diff --git a/sequencesender/txbuilder/interface.go b/sequencesender/txbuilder/interface.go index 8f3b4661..ea6e8770 100644 --- a/sequencesender/txbuilder/interface.go +++ b/sequencesender/txbuilder/interface.go @@ -18,5 +18,6 @@ type TxBuilder interface { } type CondNewSequence interface { - NewSequenceIfWorthToSend(ctx context.Context, txBuilder TxBuilder, sequenceBatches []seqsendertypes.Batch, senderAddress, l2Coinbase common.Address, batchNumber uint64) (seqsendertypes.Sequence, error) + //NewSequenceIfWorthToSend Return nil, nil if the sequence is not worth sending + NewSequenceIfWorthToSend(ctx context.Context, txBuilder TxBuilder, sequenceBatches []seqsendertypes.Batch, senderAddress, l2Coinbase common.Address) (seqsendertypes.Sequence, error) } diff --git a/sequencesender/txbuilder/mocks_txbuilder/cond_new_sequence.go b/sequencesender/txbuilder/mocks_txbuilder/cond_new_sequence.go new file mode 100644 index 00000000..2600af02 --- /dev/null +++ b/sequencesender/txbuilder/mocks_txbuilder/cond_new_sequence.go @@ -0,0 +1,104 @@ +// Code generated by mockery. DO NOT EDIT. + +package mocks_txbuilder + +import ( + context "context" + + common "github.com/ethereum/go-ethereum/common" + + mock "github.com/stretchr/testify/mock" + + seqsendertypes "github.com/0xPolygon/cdk/sequencesender/seqsendertypes" + + txbuilder "github.com/0xPolygon/cdk/sequencesender/txbuilder" +) + +// CondNewSequence is an autogenerated mock type for the CondNewSequence type +type CondNewSequence struct { + mock.Mock +} + +type CondNewSequence_Expecter struct { + mock *mock.Mock +} + +func (_m *CondNewSequence) EXPECT() *CondNewSequence_Expecter { + return &CondNewSequence_Expecter{mock: &_m.Mock} +} + +// NewSequenceIfWorthToSend provides a mock function with given fields: ctx, txBuilder, sequenceBatches, senderAddress, l2Coinbase +func (_m *CondNewSequence) NewSequenceIfWorthToSend(ctx context.Context, txBuilder txbuilder.TxBuilder, sequenceBatches []seqsendertypes.Batch, senderAddress common.Address, l2Coinbase common.Address) (seqsendertypes.Sequence, error) { + ret := _m.Called(ctx, txBuilder, sequenceBatches, senderAddress, l2Coinbase) + + if len(ret) == 0 { + panic("no return value specified for NewSequenceIfWorthToSend") + } + + var r0 seqsendertypes.Sequence + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, txbuilder.TxBuilder, []seqsendertypes.Batch, common.Address, common.Address) (seqsendertypes.Sequence, error)); ok { + return rf(ctx, txBuilder, sequenceBatches, senderAddress, l2Coinbase) + } + if rf, ok := ret.Get(0).(func(context.Context, txbuilder.TxBuilder, []seqsendertypes.Batch, common.Address, common.Address) seqsendertypes.Sequence); ok { + r0 = rf(ctx, txBuilder, sequenceBatches, senderAddress, l2Coinbase) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(seqsendertypes.Sequence) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, txbuilder.TxBuilder, []seqsendertypes.Batch, common.Address, common.Address) error); ok { + r1 = rf(ctx, txBuilder, sequenceBatches, senderAddress, l2Coinbase) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// CondNewSequence_NewSequenceIfWorthToSend_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NewSequenceIfWorthToSend' +type CondNewSequence_NewSequenceIfWorthToSend_Call struct { + *mock.Call +} + +// NewSequenceIfWorthToSend is a helper method to define mock.On call +// - ctx context.Context +// - txBuilder txbuilder.TxBuilder +// - sequenceBatches []seqsendertypes.Batch +// - senderAddress common.Address +// - l2Coinbase common.Address +func (_e *CondNewSequence_Expecter) NewSequenceIfWorthToSend(ctx interface{}, txBuilder interface{}, sequenceBatches interface{}, senderAddress interface{}, l2Coinbase interface{}) *CondNewSequence_NewSequenceIfWorthToSend_Call { + return &CondNewSequence_NewSequenceIfWorthToSend_Call{Call: _e.mock.On("NewSequenceIfWorthToSend", ctx, txBuilder, sequenceBatches, senderAddress, l2Coinbase)} +} + +func (_c *CondNewSequence_NewSequenceIfWorthToSend_Call) Run(run func(ctx context.Context, txBuilder txbuilder.TxBuilder, sequenceBatches []seqsendertypes.Batch, senderAddress common.Address, l2Coinbase common.Address)) *CondNewSequence_NewSequenceIfWorthToSend_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(txbuilder.TxBuilder), args[2].([]seqsendertypes.Batch), args[3].(common.Address), args[4].(common.Address)) + }) + return _c +} + +func (_c *CondNewSequence_NewSequenceIfWorthToSend_Call) Return(_a0 seqsendertypes.Sequence, _a1 error) *CondNewSequence_NewSequenceIfWorthToSend_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *CondNewSequence_NewSequenceIfWorthToSend_Call) RunAndReturn(run func(context.Context, txbuilder.TxBuilder, []seqsendertypes.Batch, common.Address, common.Address) (seqsendertypes.Sequence, error)) *CondNewSequence_NewSequenceIfWorthToSend_Call { + _c.Call.Return(run) + return _c +} + +// NewCondNewSequence creates a new instance of CondNewSequence. 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 NewCondNewSequence(t interface { + mock.TestingT + Cleanup(func()) +}) *CondNewSequence { + mock := &CondNewSequence{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/sequencesender/txbuilder/mocks_txbuilder/tx_builder.go b/sequencesender/txbuilder/mocks_txbuilder/tx_builder.go new file mode 100644 index 00000000..e9aa9127 --- /dev/null +++ b/sequencesender/txbuilder/mocks_txbuilder/tx_builder.go @@ -0,0 +1,317 @@ +// Code generated by mockery. DO NOT EDIT. + +package mocks_txbuilder + +import ( + context "context" + + common "github.com/ethereum/go-ethereum/common" + + datastream "github.com/0xPolygon/cdk/state/datastream" + + mock "github.com/stretchr/testify/mock" + + seqsendertypes "github.com/0xPolygon/cdk/sequencesender/seqsendertypes" + + types "github.com/ethereum/go-ethereum/core/types" +) + +// TxBuilder is an autogenerated mock type for the TxBuilder type +type TxBuilder struct { + mock.Mock +} + +type TxBuilder_Expecter struct { + mock *mock.Mock +} + +func (_m *TxBuilder) EXPECT() *TxBuilder_Expecter { + return &TxBuilder_Expecter{mock: &_m.Mock} +} + +// BuildSequenceBatchesTx provides a mock function with given fields: ctx, sender, sequences +func (_m *TxBuilder) BuildSequenceBatchesTx(ctx context.Context, sender common.Address, sequences seqsendertypes.Sequence) (*types.Transaction, error) { + ret := _m.Called(ctx, sender, sequences) + + if len(ret) == 0 { + panic("no return value specified for BuildSequenceBatchesTx") + } + + var r0 *types.Transaction + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, common.Address, seqsendertypes.Sequence) (*types.Transaction, error)); ok { + return rf(ctx, sender, sequences) + } + if rf, ok := ret.Get(0).(func(context.Context, common.Address, seqsendertypes.Sequence) *types.Transaction); ok { + r0 = rf(ctx, sender, sequences) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.Transaction) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, common.Address, seqsendertypes.Sequence) error); ok { + r1 = rf(ctx, sender, sequences) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// TxBuilder_BuildSequenceBatchesTx_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'BuildSequenceBatchesTx' +type TxBuilder_BuildSequenceBatchesTx_Call struct { + *mock.Call +} + +// BuildSequenceBatchesTx is a helper method to define mock.On call +// - ctx context.Context +// - sender common.Address +// - sequences seqsendertypes.Sequence +func (_e *TxBuilder_Expecter) BuildSequenceBatchesTx(ctx interface{}, sender interface{}, sequences interface{}) *TxBuilder_BuildSequenceBatchesTx_Call { + return &TxBuilder_BuildSequenceBatchesTx_Call{Call: _e.mock.On("BuildSequenceBatchesTx", ctx, sender, sequences)} +} + +func (_c *TxBuilder_BuildSequenceBatchesTx_Call) Run(run func(ctx context.Context, sender common.Address, sequences seqsendertypes.Sequence)) *TxBuilder_BuildSequenceBatchesTx_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(common.Address), args[2].(seqsendertypes.Sequence)) + }) + return _c +} + +func (_c *TxBuilder_BuildSequenceBatchesTx_Call) Return(_a0 *types.Transaction, _a1 error) *TxBuilder_BuildSequenceBatchesTx_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *TxBuilder_BuildSequenceBatchesTx_Call) RunAndReturn(run func(context.Context, common.Address, seqsendertypes.Sequence) (*types.Transaction, error)) *TxBuilder_BuildSequenceBatchesTx_Call { + _c.Call.Return(run) + return _c +} + +// NewBatchFromL2Block provides a mock function with given fields: l2Block +func (_m *TxBuilder) NewBatchFromL2Block(l2Block *datastream.L2Block) seqsendertypes.Batch { + ret := _m.Called(l2Block) + + if len(ret) == 0 { + panic("no return value specified for NewBatchFromL2Block") + } + + var r0 seqsendertypes.Batch + if rf, ok := ret.Get(0).(func(*datastream.L2Block) seqsendertypes.Batch); ok { + r0 = rf(l2Block) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(seqsendertypes.Batch) + } + } + + return r0 +} + +// TxBuilder_NewBatchFromL2Block_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NewBatchFromL2Block' +type TxBuilder_NewBatchFromL2Block_Call struct { + *mock.Call +} + +// NewBatchFromL2Block is a helper method to define mock.On call +// - l2Block *datastream.L2Block +func (_e *TxBuilder_Expecter) NewBatchFromL2Block(l2Block interface{}) *TxBuilder_NewBatchFromL2Block_Call { + return &TxBuilder_NewBatchFromL2Block_Call{Call: _e.mock.On("NewBatchFromL2Block", l2Block)} +} + +func (_c *TxBuilder_NewBatchFromL2Block_Call) Run(run func(l2Block *datastream.L2Block)) *TxBuilder_NewBatchFromL2Block_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*datastream.L2Block)) + }) + return _c +} + +func (_c *TxBuilder_NewBatchFromL2Block_Call) Return(_a0 seqsendertypes.Batch) *TxBuilder_NewBatchFromL2Block_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *TxBuilder_NewBatchFromL2Block_Call) RunAndReturn(run func(*datastream.L2Block) seqsendertypes.Batch) *TxBuilder_NewBatchFromL2Block_Call { + _c.Call.Return(run) + return _c +} + +// NewSequence provides a mock function with given fields: batches, coinbase +func (_m *TxBuilder) NewSequence(batches []seqsendertypes.Batch, coinbase common.Address) (seqsendertypes.Sequence, error) { + ret := _m.Called(batches, coinbase) + + if len(ret) == 0 { + panic("no return value specified for NewSequence") + } + + var r0 seqsendertypes.Sequence + var r1 error + if rf, ok := ret.Get(0).(func([]seqsendertypes.Batch, common.Address) (seqsendertypes.Sequence, error)); ok { + return rf(batches, coinbase) + } + if rf, ok := ret.Get(0).(func([]seqsendertypes.Batch, common.Address) seqsendertypes.Sequence); ok { + r0 = rf(batches, coinbase) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(seqsendertypes.Sequence) + } + } + + if rf, ok := ret.Get(1).(func([]seqsendertypes.Batch, common.Address) error); ok { + r1 = rf(batches, coinbase) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// TxBuilder_NewSequence_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NewSequence' +type TxBuilder_NewSequence_Call struct { + *mock.Call +} + +// NewSequence is a helper method to define mock.On call +// - batches []seqsendertypes.Batch +// - coinbase common.Address +func (_e *TxBuilder_Expecter) NewSequence(batches interface{}, coinbase interface{}) *TxBuilder_NewSequence_Call { + return &TxBuilder_NewSequence_Call{Call: _e.mock.On("NewSequence", batches, coinbase)} +} + +func (_c *TxBuilder_NewSequence_Call) Run(run func(batches []seqsendertypes.Batch, coinbase common.Address)) *TxBuilder_NewSequence_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].([]seqsendertypes.Batch), args[1].(common.Address)) + }) + return _c +} + +func (_c *TxBuilder_NewSequence_Call) Return(_a0 seqsendertypes.Sequence, _a1 error) *TxBuilder_NewSequence_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *TxBuilder_NewSequence_Call) RunAndReturn(run func([]seqsendertypes.Batch, common.Address) (seqsendertypes.Sequence, error)) *TxBuilder_NewSequence_Call { + _c.Call.Return(run) + return _c +} + +// NewSequenceIfWorthToSend provides a mock function with given fields: ctx, sequenceBatches, l2Coinbase, batchNumber +func (_m *TxBuilder) NewSequenceIfWorthToSend(ctx context.Context, sequenceBatches []seqsendertypes.Batch, l2Coinbase common.Address, batchNumber uint64) (seqsendertypes.Sequence, error) { + ret := _m.Called(ctx, sequenceBatches, l2Coinbase, batchNumber) + + if len(ret) == 0 { + panic("no return value specified for NewSequenceIfWorthToSend") + } + + var r0 seqsendertypes.Sequence + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, []seqsendertypes.Batch, common.Address, uint64) (seqsendertypes.Sequence, error)); ok { + return rf(ctx, sequenceBatches, l2Coinbase, batchNumber) + } + if rf, ok := ret.Get(0).(func(context.Context, []seqsendertypes.Batch, common.Address, uint64) seqsendertypes.Sequence); ok { + r0 = rf(ctx, sequenceBatches, l2Coinbase, batchNumber) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(seqsendertypes.Sequence) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, []seqsendertypes.Batch, common.Address, uint64) error); ok { + r1 = rf(ctx, sequenceBatches, l2Coinbase, batchNumber) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// TxBuilder_NewSequenceIfWorthToSend_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NewSequenceIfWorthToSend' +type TxBuilder_NewSequenceIfWorthToSend_Call struct { + *mock.Call +} + +// NewSequenceIfWorthToSend is a helper method to define mock.On call +// - ctx context.Context +// - sequenceBatches []seqsendertypes.Batch +// - l2Coinbase common.Address +// - batchNumber uint64 +func (_e *TxBuilder_Expecter) NewSequenceIfWorthToSend(ctx interface{}, sequenceBatches interface{}, l2Coinbase interface{}, batchNumber interface{}) *TxBuilder_NewSequenceIfWorthToSend_Call { + return &TxBuilder_NewSequenceIfWorthToSend_Call{Call: _e.mock.On("NewSequenceIfWorthToSend", ctx, sequenceBatches, l2Coinbase, batchNumber)} +} + +func (_c *TxBuilder_NewSequenceIfWorthToSend_Call) Run(run func(ctx context.Context, sequenceBatches []seqsendertypes.Batch, l2Coinbase common.Address, batchNumber uint64)) *TxBuilder_NewSequenceIfWorthToSend_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]seqsendertypes.Batch), args[2].(common.Address), args[3].(uint64)) + }) + return _c +} + +func (_c *TxBuilder_NewSequenceIfWorthToSend_Call) Return(_a0 seqsendertypes.Sequence, _a1 error) *TxBuilder_NewSequenceIfWorthToSend_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *TxBuilder_NewSequenceIfWorthToSend_Call) RunAndReturn(run func(context.Context, []seqsendertypes.Batch, common.Address, uint64) (seqsendertypes.Sequence, error)) *TxBuilder_NewSequenceIfWorthToSend_Call { + _c.Call.Return(run) + return _c +} + +// String provides a mock function with given fields: +func (_m *TxBuilder) String() string { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for String") + } + + var r0 string + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// TxBuilder_String_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'String' +type TxBuilder_String_Call struct { + *mock.Call +} + +// String is a helper method to define mock.On call +func (_e *TxBuilder_Expecter) String() *TxBuilder_String_Call { + return &TxBuilder_String_Call{Call: _e.mock.On("String")} +} + +func (_c *TxBuilder_String_Call) Run(run func()) *TxBuilder_String_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *TxBuilder_String_Call) Return(_a0 string) *TxBuilder_String_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *TxBuilder_String_Call) RunAndReturn(run func() string) *TxBuilder_String_Call { + _c.Call.Return(run) + return _c +} + +// NewTxBuilder creates a new instance of TxBuilder. 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 NewTxBuilder(t interface { + mock.TestingT + Cleanup(func()) +}) *TxBuilder { + mock := &TxBuilder{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/sequencesender/txbuilder/validium_cond_num_batches.go b/sequencesender/txbuilder/validium_cond_num_batches.go index da663063..66c7c905 100644 --- a/sequencesender/txbuilder/validium_cond_num_batches.go +++ b/sequencesender/txbuilder/validium_cond_num_batches.go @@ -8,11 +8,17 @@ import ( "github.com/ethereum/go-ethereum/common" ) -type NewSequenceConditionalNumBatches struct { +type ConditionalNewSequenceNumBatches struct { maxBatchesForL1 uint64 // cfg.MaxBatchesForL1 } -func (c *NewSequenceConditionalNumBatches) NewSequenceIfWorthToSend(ctx context.Context, txBuilder TxBuilder, sequenceBatches []seqsendertypes.Batch, senderAddress, l2Coinbase common.Address, batchNumber uint64) (seqsendertypes.Sequence, error) { +func NewConditionalNewSequenceNumBatches(maxBatchesForL1 uint64) *ConditionalNewSequenceNumBatches { + return &ConditionalNewSequenceNumBatches{ + maxBatchesForL1: maxBatchesForL1, + } +} + +func (c *ConditionalNewSequenceNumBatches) NewSequenceIfWorthToSend(ctx context.Context, txBuilder TxBuilder, sequenceBatches []seqsendertypes.Batch, senderAddress, l2Coinbase common.Address) (seqsendertypes.Sequence, error) { if c.maxBatchesForL1 > 0 && len(sequenceBatches) >= int(c.maxBatchesForL1) { log.Infof( "[SeqSender] sequence should be sent to L1, because MaxBatchesForL1 (%d) has been reached", diff --git a/sequencesender/txbuilder/validium_cond_num_batches_test.go b/sequencesender/txbuilder/validium_cond_num_batches_test.go new file mode 100644 index 00000000..5375b4fd --- /dev/null +++ b/sequencesender/txbuilder/validium_cond_num_batches_test.go @@ -0,0 +1,45 @@ +package txbuilder_test + +import ( + "testing" + + "github.com/0xPolygon/cdk/sequencesender/seqsendertypes" + "github.com/0xPolygon/cdk/sequencesender/txbuilder" + "github.com/0xPolygon/cdk/sequencesender/txbuilder/mocks_txbuilder" + "github.com/ethereum/go-ethereum/common" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" +) + +func TestConditionalNumBatchesDisabled(t *testing.T) { + mockTxBuilder := mocks_txbuilder.NewTxBuilder(t) + sut := txbuilder.NewConditionalNewSequenceNumBatches(0) + + tx, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, nil, common.Address{}, common.Address{}) + require.NoError(t, err) + require.Nil(t, tx) +} + +// It have 1 batch and minium are 2, so no new sequence +func TestConditionalNumBatchesDontFulfillCondition(t *testing.T) { + mockTxBuilder := mocks_txbuilder.NewTxBuilder(t) + sut := txbuilder.NewConditionalNewSequenceNumBatches(2) + var sequenceBatches []seqsendertypes.Batch + sequenceBatches = append(sequenceBatches, &txbuilder.BananaBatch{}) + tx, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, sequenceBatches, common.Address{}, common.Address{}) + require.NoError(t, err) + require.Nil(t, tx) +} + +// It have 2 batch and minium are 2, so new sequence +func TestConditionalNumBatchesFulfillCondition(t *testing.T) { + mockTxBuilder := mocks_txbuilder.NewTxBuilder(t) + sut := txbuilder.NewConditionalNewSequenceNumBatches(2) + var sequenceBatches []seqsendertypes.Batch + sequenceBatches = append(sequenceBatches, &txbuilder.BananaBatch{}) + sequenceBatches = append(sequenceBatches, &txbuilder.BananaBatch{}) + mockTxBuilder.EXPECT().NewSequence(mock.Anything, mock.Anything).Return(nil, nil) + tx, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, sequenceBatches, common.Address{}, common.Address{}) + require.NoError(t, err) + require.Nil(t, tx) +} diff --git a/sequencesender/txbuilder/zkevm_cond_max_size.go b/sequencesender/txbuilder/zkevm_cond_max_size.go index 3218d015..5280b71f 100644 --- a/sequencesender/txbuilder/zkevm_cond_max_size.go +++ b/sequencesender/txbuilder/zkevm_cond_max_size.go @@ -3,6 +3,7 @@ package txbuilder import ( "context" "errors" + "fmt" "github.com/0xPolygon/cdk/etherman" "github.com/0xPolygon/cdk/log" @@ -15,26 +16,46 @@ var ( ErrOversizedData = errors.New("oversized data") ) -type NewSequenceConditionalMaxSize struct { +type ConditionalNewSequenceMaxSize struct { maxTxSizeForL1 uint64 // cfg.MaxTxSizeForL1 } -func (c *NewSequenceConditionalMaxSize) NewSequenceIfWorthToSend(ctx context.Context, txBuilder TxBuilder, sequenceBatches []seqsendertypes.Batch, senderAddress, l2Coinbase common.Address, batchNumber uint64) (seqsendertypes.Sequence, error) { +func NewConditionalNewSequenceMaxSize(maxTxSizeForL1 uint64) *ConditionalNewSequenceMaxSize { + return &ConditionalNewSequenceMaxSize{ + maxTxSizeForL1: maxTxSizeForL1, + } +} + +func (c *ConditionalNewSequenceMaxSize) NewSequenceIfWorthToSend(ctx context.Context, txBuilder TxBuilder, sequenceBatches []seqsendertypes.Batch, senderAddress, l2Coinbase common.Address) (seqsendertypes.Sequence, error) { + if c.maxTxSizeForL1 == 0 { + log.Debug("maxTxSizeForL1 is 0, so is disabled") + return nil, nil + } sequence, err := txBuilder.NewSequence(sequenceBatches, l2Coinbase) if err != nil { return nil, err } + if sequence == nil { + err = fmt.Errorf("error txBuilder.NewSequence, returns sequence=nil and err==nil, is not expected") + log.Errorf(err.Error()) + return nil, err + } // Check if can be sent tx, err := txBuilder.BuildSequenceBatchesTx(ctx, senderAddress, sequence) - if err == nil && tx.Size() > c.maxTxSizeForL1 { - log.Infof("[SeqSender] oversized Data on TX oldHash %s (txSize %d > %d)", tx.Hash(), tx.Size(), c.maxTxSizeForL1) + if tx == nil && err == nil { + err = fmt.Errorf("error txBuilder.BuildSequenceBatchesTx, returns tx=nil and err==nil, is not expected") + log.Errorf(err.Error()) + return nil, err + } + if err == nil && tx != nil && tx.Size() > c.maxTxSizeForL1 { + log.Infof("Oversized Data on TX oldHash %s (txSize %d > %d)", tx.Hash(), tx.Size(), c.maxTxSizeForL1) err = ErrOversizedData } if err != nil { - log.Infof("[SeqSender] handling estimate gas send sequence error: %v", err) - sequenceBatches, err = handleEstimateGasSendSequenceErr(sequence.Batches(), batchNumber, err) + log.Debugf("Handling estimate gas send sequence error: %v", err) + sequenceBatches, err = handleEstimateGasSendSequenceErr(sequence.Batches(), err) if sequenceBatches != nil { // Handling the error gracefully, re-processing the sequence as a sanity check //sequence, err = s.newSequenceBanana(sequenceBatches, s.cfg.L2Coinbase) @@ -43,36 +64,42 @@ func (c *NewSequenceConditionalMaxSize) NewSequenceIfWorthToSend(ctx context.Con return nil, err } - _, err = txBuilder.BuildSequenceBatchesTx(ctx, senderAddress, sequence) + txReduced, err := txBuilder.BuildSequenceBatchesTx(ctx, senderAddress, sequence) + log.Debugf("After reducing batches: (txSize %d -> %d)", tx.Size(), txReduced.Size()) + if err == nil && txReduced != nil && txReduced.Size() > c.maxTxSizeForL1 { + log.Warnf("After reducing batches: (txSize %d -> %d) is still too big > %d", tx.Size(), txReduced.Size(), c.maxTxSizeForL1) + } return sequence, err } return sequence, err } - log.Infof("[SeqSender] [MaxSize] current size:%d max_size:%d num_batches: %d", tx.Size(), c.maxTxSizeForL1, sequence.Len()) + log.Debugf("Current size:%d < max_size:%d num_batches: %d, no sequence promoted yet", tx.Size(), c.maxTxSizeForL1, sequence.Len()) return nil, nil } // handleEstimateGasSendSequenceErr handles an error on the estimate gas. Results: (nil,nil)=requires waiting, (nil,error)=no handled gracefully, (seq,nil) handled gracefully -func handleEstimateGasSendSequenceErr(sequenceBatches []seqsendertypes.Batch, currentBatchNumToSequence uint64, err error) ([]seqsendertypes.Batch, error) { +func handleEstimateGasSendSequenceErr(sequenceBatches []seqsendertypes.Batch, err error) ([]seqsendertypes.Batch, error) { // Insufficient allowance if errors.Is(err, etherman.ErrInsufficientAllowance) { return nil, err } + errMsg := fmt.Sprintf("due to unknown error: %v", err) if isDataForEthTxTooBig(err) { - // Remove the latest item and send the sequences - log.Infof("Done building sequences, selected batches to %d. Batch %d caused the L1 tx to be too big: %v", currentBatchNumToSequence-1, currentBatchNumToSequence, err) - } else { - // Remove the latest item and send the sequences - log.Infof("Done building sequences, selected batches to %d. Batch %d excluded due to unknown error: %v", currentBatchNumToSequence, currentBatchNumToSequence+1, err) + errMsg = fmt.Sprintf("caused the L1 tx to be too big: %v", err) } - + adjustMsg := "" if len(sequenceBatches) > 1 { + lastPrevious := sequenceBatches[len(sequenceBatches)-1].BatchNumber() sequenceBatches = sequenceBatches[:len(sequenceBatches)-1] + lastCurrent := sequenceBatches[len(sequenceBatches)-1].BatchNumber() + adjustMsg = fmt.Sprintf("removing last batch: old BatchNumber:%d -> %d, new length: %d", lastPrevious, lastCurrent, len(sequenceBatches)) } else { sequenceBatches = nil + adjustMsg = "removing all batches" + log.Warnf("No more batches to remove, sequence is empty... it could be a deadlock situation") } - + log.Infof("Adjusted sequence, %s, because %s", adjustMsg, errMsg) return sequenceBatches, nil } diff --git a/sequencesender/txbuilder/zkevm_cond_max_size_test.go b/sequencesender/txbuilder/zkevm_cond_max_size_test.go new file mode 100644 index 00000000..0f87e78c --- /dev/null +++ b/sequencesender/txbuilder/zkevm_cond_max_size_test.go @@ -0,0 +1,95 @@ +package txbuilder_test + +import ( + "context" + "testing" + + "github.com/0xPolygon/cdk/etherman" + "github.com/0xPolygon/cdk/sequencesender/seqsendertypes" + "github.com/0xPolygon/cdk/sequencesender/txbuilder" + "github.com/0xPolygon/cdk/sequencesender/txbuilder/mocks_txbuilder" + "github.com/ethereum/go-ethereum/common" + ethtypes "github.com/ethereum/go-ethereum/core/types" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" +) + +func TestConditionalMaxSizeDisabled(t *testing.T) { + mockTxBuilder := mocks_txbuilder.NewTxBuilder(t) + sut := txbuilder.NewConditionalNewSequenceMaxSize(0) + + tx, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, nil, common.Address{}, common.Address{}) + require.NoError(t, err) + require.Nil(t, tx) +} + +func TestConditionalMaxSizeTxBuilderNewSequenceReturnsNil(t *testing.T) { + mockTxBuilder := mocks_txbuilder.NewTxBuilder(t) + sut := txbuilder.NewConditionalNewSequenceMaxSize(1024) + var sequenceBatches []seqsendertypes.Batch + sequenceBatches = append(sequenceBatches, &txbuilder.BananaBatch{}) + mockTxBuilder.EXPECT().NewSequence(sequenceBatches, common.Address{}).Return(nil, nil) + _, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, sequenceBatches, common.Address{}, common.Address{}) + require.Error(t, err) +} + +func TestConditionalMaxSizeTxBuilderBuildSequenceBatchesTxReturnsNil(t *testing.T) { + mockTxBuilder := mocks_txbuilder.NewTxBuilder(t) + sut := txbuilder.NewConditionalNewSequenceMaxSize(1024) + var sequenceBatches []seqsendertypes.Batch + sequenceBatches = append(sequenceBatches, &txbuilder.BananaBatch{}) + seq := &txbuilder.ElderberrySequence{} + mockTxBuilder.EXPECT().NewSequence(sequenceBatches, common.Address{}).Return(seq, nil) + mockTxBuilder.EXPECT().BuildSequenceBatchesTx(mock.Anything, mock.Anything, mock.Anything).Return(nil, nil) + _, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, sequenceBatches, common.Address{}, common.Address{}) + require.Error(t, err) +} + +func TestConditionalMaxSizeTxBuilderDontFulFill(t *testing.T) { + mockTxBuilder := mocks_txbuilder.NewTxBuilder(t) + sut := txbuilder.NewConditionalNewSequenceMaxSize(1024) + var sequenceBatches []seqsendertypes.Batch + sequenceBatches = append(sequenceBatches, &txbuilder.BananaBatch{}) + seq := &txbuilder.ElderberrySequence{} + mockTxBuilder.EXPECT().NewSequence(sequenceBatches, common.Address{}).Return(seq, nil) + inner := ðtypes.LegacyTx{} + tx := ethtypes.NewTx(inner) + mockTxBuilder.EXPECT().BuildSequenceBatchesTx(mock.Anything, mock.Anything, mock.Anything).Return(tx, nil) + + res, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, sequenceBatches, common.Address{}, common.Address{}) + + require.NoError(t, err) + require.Nil(t, res) +} + +func TestConditionalMaxSizeTxBuilderFulFill(t *testing.T) { + mockTxBuilder := mocks_txbuilder.NewTxBuilder(t) + sut := txbuilder.NewConditionalNewSequenceMaxSize(10) + l2coinbase := common.Address{} + ctx := context.TODO() + + newSeq := newTestSeq(3, 100, l2coinbase) + mockTxBuilder.EXPECT().NewSequence(newSeq.Batches(), l2coinbase).Return(newSeq, nil) + inner := ðtypes.LegacyTx{ + Data: []byte{0x01, 0x02, 0x03, 0x04}, + } + tx := ethtypes.NewTx(inner) + mockTxBuilder.EXPECT().BuildSequenceBatchesTx(ctx, mock.Anything, newSeq).Return(tx, nil) + // The size of result Tx is 14 that is > 10, so it reduce 1 batch + newSeqReduced := newTestSeq(2, 100, l2coinbase) + mockTxBuilder.EXPECT().NewSequence(newSeqReduced.Batches(), l2coinbase).Return(newSeqReduced, nil) + mockTxBuilder.EXPECT().BuildSequenceBatchesTx(ctx, mock.Anything, newSeqReduced).Return(tx, nil) + + res, err := sut.NewSequenceIfWorthToSend(ctx, mockTxBuilder, newSeq.Batches(), common.Address{}, l2coinbase) + + require.NoError(t, err) + require.NotNil(t, res) +} + +func newTestSeq(numBatches int, firstBatch uint64, l2coinbase common.Address) *txbuilder.ElderberrySequence { + var sequenceBatches []seqsendertypes.Batch + for i := 0; i < numBatches; i++ { + sequenceBatches = append(sequenceBatches, txbuilder.NewBananaBatch(ðerman.Batch{BatchNumber: firstBatch + uint64(i)})) + } + return txbuilder.NewElderberrySequence(sequenceBatches, l2coinbase) +} diff --git a/test/Makefile b/test/Makefile index 3511b4f7..7a53df8c 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,7 +1,6 @@ .PHONY: generate-mocks -generate-mocks: - $(MAKE) generate-mocks-localbridgesync - $(MAKE) generate-mocks-reorgdetector +generate-mocks: generate-mocks-localbridgesync generate-mocks-reorgdetector generate-mocks-sequencesender generate-mocks-da + .PHONY: generate-mocks-localbridgesync generate-mocks-localbridgesync: ## Generates mocks for localbridgesync, using mockery tool @@ -14,6 +13,18 @@ generate-mocks-localbridgesync: ## Generates mocks for localbridgesync, using mo generate-mocks-reorgdetector: ## Generates mocks for reorgdetector, using mockery tool export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/mockery --name=EthClient --dir=../reorgdetector --output=../reorgdetector --outpkg=reorgdetector --inpackage --structname=EthClientMock --filename=mock_eth_client.go +COMMON_MOCKERY_PARAMS=--disable-version-string --with-expecter +.PHONY: generate-mocks-sequencesender +generate-mocks-sequencesender: ## Generates mocks for sequencesender, using mockery tool + rm -Rf ../sequencesender/txbuilder/mocks_txbuilder + export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/mockery --all --case snake --dir ../sequencesender/txbuilder --output ../sequencesender/txbuilder/mocks_txbuilder --outpkg mocks_txbuilder ${COMMON_MOCKERY_PARAMS} + +.PHONY: generate-mocks-da +generate-mocks-da: ## Generates mocks for dataavailability, using mockery tool + rm -Rf ../dataavailability/mocks_da + export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/mockery --all --case snake --dir ../dataavailability --output ../dataavailability/mocks_da --outpkg mocks_da ${COMMON_MOCKERY_PARAMS} + + .PHONY: test-e2e-elderberry-validium test-e2e-elderberry-validium: stop ## Runs e2e tests checking elderberry/validium ./run-e2e-seq_sender.sh cdk-validium From 9c0aaa203ea5f5216615995c9b10014828ad506f Mon Sep 17 00:00:00 2001 From: joanestebanr <129153821+joanestebanr@users.noreply.github.com> Date: Tue, 30 Jul 2024 12:15:08 +0200 Subject: [PATCH 02/10] removed sender from txbuilder because is already in opts (auth) --- cmd/run.go | 8 ++--- sequencesender/sequencesender.go | 2 +- sequencesender/txbuilder/banana_base.go | 7 ++--- sequencesender/txbuilder/banana_validium.go | 16 +++++----- sequencesender/txbuilder/banana_zkevm.go | 12 ++++---- .../txbuilder/elderberry_validium.go | 6 ++-- .../txbuilder/elderberry_validium_test.go | 14 ++++----- sequencesender/txbuilder/elderberry_zkevm.go | 6 ++-- .../txbuilder/elderberry_zkevm_test.go | 19 +++++------- sequencesender/txbuilder/interface.go | 4 +-- .../mocks_txbuilder/cond_new_sequence.go | 29 +++++++++---------- .../txbuilder/mocks_txbuilder/tx_builder.go | 29 +++++++++---------- .../txbuilder/validium_cond_num_batches.go | 2 +- .../validium_cond_num_batches_test.go | 6 ++-- .../txbuilder/zkevm_cond_max_size.go | 6 ++-- .../txbuilder/zkevm_cond_max_size_test.go | 18 ++++++------ 16 files changed, 86 insertions(+), 98 deletions(-) diff --git a/cmd/run.go b/cmd/run.go index 15d24c29..33a40a9b 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -163,15 +163,15 @@ func newTxBuilder(cfg config.Config, ethman *etherman.Client) (txbuilder.TxBuild switch contracts.VersionType(cfg.Common.ContractVersions) { case contracts.VersionBanana: if cfg.Common.IsValidiumMode { - txBuilder = txbuilder.NewTxBuilderBananaValidium(ethman.Contracts.Banana.Rollup, ethman.Contracts.Banana.GlobalExitRoot, da, *auth, auth.From, cfg.SequenceSender.MaxBatchesForL1) + txBuilder = txbuilder.NewTxBuilderBananaValidium(ethman.Contracts.Banana.Rollup, ethman.Contracts.Banana.GlobalExitRoot, da, *auth, cfg.SequenceSender.MaxBatchesForL1) } else { - txBuilder = txbuilder.NewTxBuilderBananaZKEVM(ethman.Contracts.Banana.Rollup, ethman.Contracts.Banana.GlobalExitRoot, *auth, auth.From, cfg.SequenceSender.MaxTxSizeForL1) + txBuilder = txbuilder.NewTxBuilderBananaZKEVM(ethman.Contracts.Banana.Rollup, ethman.Contracts.Banana.GlobalExitRoot, *auth, cfg.SequenceSender.MaxTxSizeForL1) } case contracts.VersionElderberry: if cfg.Common.IsValidiumMode { - txBuilder = txbuilder.NewTxBuilderElderberryValidium(ethman.Contracts.Elderberry.Rollup, da, *auth, auth.From, cfg.SequenceSender.MaxBatchesForL1) + txBuilder = txbuilder.NewTxBuilderElderberryValidium(ethman.Contracts.Elderberry.Rollup, da, *auth, cfg.SequenceSender.MaxBatchesForL1) } else { - txBuilder = txbuilder.NewTxBuilderElderberryZKEVM(ethman.Contracts.Elderberry.Rollup, *auth, auth.From, cfg.SequenceSender.MaxTxSizeForL1) + txBuilder = txbuilder.NewTxBuilderElderberryZKEVM(ethman.Contracts.Elderberry.Rollup, *auth, cfg.SequenceSender.MaxTxSizeForL1) } default: err = fmt.Errorf("unknown contract version: %s", cfg.Common.ContractVersions) diff --git a/sequencesender/sequencesender.go b/sequencesender/sequencesender.go index 961b6f75..941e6db6 100644 --- a/sequencesender/sequencesender.go +++ b/sequencesender/sequencesender.go @@ -520,7 +520,7 @@ func (s *SequenceSender) tryToSendSequence(ctx context.Context) { log.Infof("[SeqSender] sending sequences to L1. From batch %d to batch %d", firstSequence.BatchNumber(), lastSequence.BatchNumber()) log.Infof(sequence.String()) - tx, err := s.TxBuilder.BuildSequenceBatchesTx(ctx, s.cfg.SenderAddress, sequence) + tx, err := s.TxBuilder.BuildSequenceBatchesTx(ctx, sequence) if err != nil { log.Errorf("[SeqSender] error building sequenceBatches tx: %v", err) return diff --git a/sequencesender/txbuilder/banana_base.go b/sequencesender/txbuilder/banana_base.go index 60c6c4a7..6d36e33b 100644 --- a/sequencesender/txbuilder/banana_base.go +++ b/sequencesender/txbuilder/banana_base.go @@ -17,19 +17,16 @@ type TxBuilderBananaBase struct { rollupContract contracts.RollupBananaType globalExitRootContract contracts.GlobalExitRootBananaType - opts bind.TransactOpts - SenderAddress common.Address + opts bind.TransactOpts } func NewTxBuilderBananaBase(rollupContract contracts.RollupBananaType, gerContract contracts.GlobalExitRootBananaType, - opts bind.TransactOpts, - sender common.Address) *TxBuilderBananaBase { + opts bind.TransactOpts) *TxBuilderBananaBase { return &TxBuilderBananaBase{ rollupContract: rollupContract, globalExitRootContract: gerContract, opts: opts, - SenderAddress: sender, } } diff --git a/sequencesender/txbuilder/banana_validium.go b/sequencesender/txbuilder/banana_validium.go index e518d107..7abaae17 100644 --- a/sequencesender/txbuilder/banana_validium.go +++ b/sequencesender/txbuilder/banana_validium.go @@ -24,21 +24,19 @@ type TxBuilderBananaValidium struct { func NewTxBuilderBananaValidium(rollupContract contracts.RollupBananaType, gerContract contracts.GlobalExitRootBananaType, - da dataavailability.SequenceSender, opts bind.TransactOpts, sender common.Address, maxBatchesForL1 uint64) *TxBuilderBananaValidium { + da dataavailability.SequenceSender, opts bind.TransactOpts, maxBatchesForL1 uint64) *TxBuilderBananaValidium { return &TxBuilderBananaValidium{ - TxBuilderBananaBase: *NewTxBuilderBananaBase(rollupContract, gerContract, opts, sender), + TxBuilderBananaBase: *NewTxBuilderBananaBase(rollupContract, gerContract, opts), da: da, - condNewSeq: &ConditionalNewSequenceNumBatches{ - maxBatchesForL1: maxBatchesForL1, - }, + condNewSeq: NewConditionalNewSequenceNumBatches(maxBatchesForL1), } } func (t *TxBuilderBananaValidium) NewSequenceIfWorthToSend(ctx context.Context, sequenceBatches []seqsendertypes.Batch, l2Coinbase common.Address, batchNumber uint64) (seqsendertypes.Sequence, error) { - return t.condNewSeq.NewSequenceIfWorthToSend(ctx, t, sequenceBatches, t.SenderAddress, l2Coinbase) + return t.condNewSeq.NewSequenceIfWorthToSend(ctx, t, sequenceBatches, l2Coinbase) } -func (t *TxBuilderBananaValidium) BuildSequenceBatchesTx(ctx context.Context, sender common.Address, sequences seqsendertypes.Sequence) (*ethtypes.Transaction, error) { +func (t *TxBuilderBananaValidium) BuildSequenceBatchesTx(ctx context.Context, sequences seqsendertypes.Sequence) (*ethtypes.Transaction, error) { // TODO: param sender // Post sequences to DA backend var dataAvailabilityMessage []byte @@ -56,7 +54,7 @@ func (t *TxBuilderBananaValidium) BuildSequenceBatchesTx(ctx context.Context, se } // Build sequence data - tx, err := t.internalBuildSequenceBatchesTx(t.SenderAddress, ethseq, dataAvailabilityMessage) + tx, err := t.internalBuildSequenceBatchesTx(ethseq, dataAvailabilityMessage) if err != nil { log.Errorf("[SeqSender] error estimating new sequenceBatches to add to ethtxmanager: ", err) return nil, err @@ -65,7 +63,7 @@ func (t *TxBuilderBananaValidium) BuildSequenceBatchesTx(ctx context.Context, se } // BuildSequenceBatchesTx builds a tx to be sent to the PoE SC method SequenceBatches. -func (t *TxBuilderBananaValidium) internalBuildSequenceBatchesTx(sender common.Address, sequence etherman.SequenceBanana, +func (t *TxBuilderBananaValidium) internalBuildSequenceBatchesTx(sequence etherman.SequenceBanana, dataAvailabilityMessage []byte) (*ethtypes.Transaction, error) { newopts := t.opts newopts.NoSend = true diff --git a/sequencesender/txbuilder/banana_zkevm.go b/sequencesender/txbuilder/banana_zkevm.go index e2a2e1aa..28cdcdd2 100644 --- a/sequencesender/txbuilder/banana_zkevm.go +++ b/sequencesender/txbuilder/banana_zkevm.go @@ -19,20 +19,18 @@ type TxBuilderBananaZKEVM struct { condNewSeq CondNewSequence } -func NewTxBuilderBananaZKEVM(rollupContract contracts.RollupBananaType, gerContract contracts.GlobalExitRootBananaType, opts bind.TransactOpts, sender common.Address, maxTxSizeForL1 uint64) *TxBuilderBananaZKEVM { +func NewTxBuilderBananaZKEVM(rollupContract contracts.RollupBananaType, gerContract contracts.GlobalExitRootBananaType, opts bind.TransactOpts, maxTxSizeForL1 uint64) *TxBuilderBananaZKEVM { return &TxBuilderBananaZKEVM{ - TxBuilderBananaBase: *NewTxBuilderBananaBase(rollupContract, gerContract, opts, sender), - condNewSeq: &ConditionalNewSequenceMaxSize{ - maxTxSizeForL1: maxTxSizeForL1, - }, + TxBuilderBananaBase: *NewTxBuilderBananaBase(rollupContract, gerContract, opts), + condNewSeq: NewConditionalNewSequenceMaxSize(maxTxSizeForL1), } } func (t *TxBuilderBananaZKEVM) NewSequenceIfWorthToSend(ctx context.Context, sequenceBatches []seqsendertypes.Batch, l2Coinbase common.Address, batchNumber uint64) (seqsendertypes.Sequence, error) { - return t.condNewSeq.NewSequenceIfWorthToSend(ctx, t, sequenceBatches, t.SenderAddress, l2Coinbase) + return t.condNewSeq.NewSequenceIfWorthToSend(ctx, t, sequenceBatches, l2Coinbase) } -func (t *TxBuilderBananaZKEVM) BuildSequenceBatchesTx(ctx context.Context, sender common.Address, sequences seqsendertypes.Sequence) (*ethtypes.Transaction, error) { +func (t *TxBuilderBananaZKEVM) BuildSequenceBatchesTx(ctx context.Context, sequences seqsendertypes.Sequence) (*ethtypes.Transaction, error) { var err error ethseq, err := convertToSequenceBanana(sequences) if err != nil { diff --git a/sequencesender/txbuilder/elderberry_validium.go b/sequencesender/txbuilder/elderberry_validium.go index 2a223878..d6dde1d5 100644 --- a/sequencesender/txbuilder/elderberry_validium.go +++ b/sequencesender/txbuilder/elderberry_validium.go @@ -27,7 +27,7 @@ type TxBuilderElderberryValidium struct { func NewTxBuilderElderberryValidium(zkevm contracts.RollupElderberryType, da dataavailability.SequenceSenderElderberry, - opts bind.TransactOpts, sender common.Address, maxBatchesForL1 uint64) *TxBuilderElderberryValidium { + opts bind.TransactOpts, maxBatchesForL1 uint64) *TxBuilderElderberryValidium { return &TxBuilderElderberryValidium{ da: da, TxBuilderElderberryBase: *NewTxBuilderElderberryBase( @@ -37,10 +37,10 @@ func NewTxBuilderElderberryValidium(zkevm contracts.RollupElderberryType, } } func (t *TxBuilderElderberryValidium) NewSequenceIfWorthToSend(ctx context.Context, sequenceBatches []seqsendertypes.Batch, l2Coinbase common.Address, batchNumber uint64) (seqsendertypes.Sequence, error) { - return t.condNewSeq.NewSequenceIfWorthToSend(ctx, t, sequenceBatches, t.opts.From, l2Coinbase) + return t.condNewSeq.NewSequenceIfWorthToSend(ctx, t, sequenceBatches, l2Coinbase) } -func (t *TxBuilderElderberryValidium) BuildSequenceBatchesTx(ctx context.Context, sender common.Address, sequences seqsendertypes.Sequence) (*ethtypes.Transaction, error) { +func (t *TxBuilderElderberryValidium) BuildSequenceBatchesTx(ctx context.Context, sequences seqsendertypes.Sequence) (*ethtypes.Transaction, error) { if sequences == nil || sequences.Len() == 0 { return nil, fmt.Errorf("can't sequence an empty sequence") } diff --git a/sequencesender/txbuilder/elderberry_validium_test.go b/sequencesender/txbuilder/elderberry_validium_test.go index 68f5e303..a5bfb818 100644 --- a/sequencesender/txbuilder/elderberry_validium_test.go +++ b/sequencesender/txbuilder/elderberry_validium_test.go @@ -30,12 +30,12 @@ func TestElderberryValidiumName(t *testing.T) { func TestElderberryValidiumBuildSequenceBatchesTxEmtpySequence(t *testing.T) { testData := newElderberryValidiumSUT(t) ctx := context.TODO() - _, err := testData.sut.BuildSequenceBatchesTx(ctx, common.Address{}, nil) + _, err := testData.sut.BuildSequenceBatchesTx(ctx, nil) require.Error(t, err) seq, err := testData.sut.NewSequence(nil, common.Address{}) require.NoError(t, err) - _, err = testData.sut.BuildSequenceBatchesTx(ctx, common.Address{}, seq) + _, err = testData.sut.BuildSequenceBatchesTx(ctx, seq) require.Error(t, err) } @@ -56,10 +56,10 @@ func TestElderberryValidiumBuildSequenceBatchesTxSequenceErrorsFromDA(t *testing seq, err := testData.sut.NewSequence(batches, common.Address{}) require.NoError(t, err) testData.mockDA.EXPECT().PostSequenceElderberry(ctx, mock.Anything).Return(nil, nil) - _, err = testData.sut.BuildSequenceBatchesTx(ctx, common.Address{}, seq) + _, err = testData.sut.BuildSequenceBatchesTx(ctx, seq) require.Error(t, err, "data availability message is nil") testData.mockDA.EXPECT().PostSequenceElderberry(ctx, mock.Anything).Return(nil, fmt.Errorf("test error")) - _, err = testData.sut.BuildSequenceBatchesTx(ctx, common.Address{}, seq) + _, err = testData.sut.BuildSequenceBatchesTx(ctx, seq) require.Error(t, err, "error posting sequences to the data availability protocol: test error") } @@ -80,7 +80,7 @@ func TestElderberryValidiumBuildSequenceBatchesTxSequenceDAOk(t *testing.T) { seq, err := testData.sut.NewSequence(batches, common.Address{}) require.NoError(t, err) testData.mockDA.EXPECT().PostSequenceElderberry(ctx, mock.Anything).Return([]byte{1}, nil) - tx, err := testData.sut.BuildSequenceBatchesTx(ctx, common.Address{}, seq) + tx, err := testData.sut.BuildSequenceBatchesTx(ctx, seq) require.NoError(t, err) require.NotNil(t, tx) } @@ -97,10 +97,10 @@ func newElderberryValidiumSUT(t *testing.T) *testDataElderberryValidium { require.NoError(t, err) opts, err := bind.NewKeyedTransactorWithChainID(privateKey, big.NewInt(1)) require.NoError(t, err) - sender := common.Address{} + da := mocks_da.NewSequenceSenderElderberry(t) - sut := txbuilder.NewTxBuilderElderberryValidium(*zkevmContract, da, *opts, sender, uint64(100)) + sut := txbuilder.NewTxBuilderElderberryValidium(*zkevmContract, da, *opts, uint64(100)) require.NotNil(t, sut) return &testDataElderberryValidium{ mockDA: da, diff --git a/sequencesender/txbuilder/elderberry_zkevm.go b/sequencesender/txbuilder/elderberry_zkevm.go index 46df1f57..0db8b6e3 100644 --- a/sequencesender/txbuilder/elderberry_zkevm.go +++ b/sequencesender/txbuilder/elderberry_zkevm.go @@ -21,7 +21,7 @@ type TxBuilderElderberryZKEVM struct { condNewSeq CondNewSequence } -func NewTxBuilderElderberryZKEVM(zkevm contracts.RollupElderberryType, opts bind.TransactOpts, sender common.Address, maxTxSizeForL1 uint64) *TxBuilderElderberryZKEVM { +func NewTxBuilderElderberryZKEVM(zkevm contracts.RollupElderberryType, opts bind.TransactOpts, maxTxSizeForL1 uint64) *TxBuilderElderberryZKEVM { return &TxBuilderElderberryZKEVM{ TxBuilderElderberryBase: *NewTxBuilderElderberryBase( zkevm, opts, @@ -31,7 +31,7 @@ func NewTxBuilderElderberryZKEVM(zkevm contracts.RollupElderberryType, opts bind } func (t *TxBuilderElderberryZKEVM) NewSequenceIfWorthToSend(ctx context.Context, sequenceBatches []seqsendertypes.Batch, l2Coinbase common.Address, batchNumber uint64) (seqsendertypes.Sequence, error) { - return t.condNewSeq.NewSequenceIfWorthToSend(ctx, t, sequenceBatches, t.opts.From, l2Coinbase) + return t.condNewSeq.NewSequenceIfWorthToSend(ctx, t, sequenceBatches, l2Coinbase) } // SetCondNewSeq allow to override the default conditional for new sequence @@ -39,7 +39,7 @@ func (t *TxBuilderElderberryZKEVM) SetCondNewSeq(cond CondNewSequence) { t.condNewSeq = cond } -func (t *TxBuilderElderberryZKEVM) BuildSequenceBatchesTx(ctx context.Context, sender common.Address, sequences seqsendertypes.Sequence) (*ethtypes.Transaction, error) { +func (t *TxBuilderElderberryZKEVM) BuildSequenceBatchesTx(ctx context.Context, sequences seqsendertypes.Sequence) (*ethtypes.Transaction, error) { newopts := t.opts newopts.NoSend = true diff --git a/sequencesender/txbuilder/elderberry_zkevm_test.go b/sequencesender/txbuilder/elderberry_zkevm_test.go index 6ae3b6eb..1819bbe2 100644 --- a/sequencesender/txbuilder/elderberry_zkevm_test.go +++ b/sequencesender/txbuilder/elderberry_zkevm_test.go @@ -22,8 +22,7 @@ import ( func TestElderberryZkevmName(t *testing.T) { zkevmContract := contracts.RollupElderberryType{} opts := bind.TransactOpts{} - sender := common.Address{} - sut := txbuilder.NewTxBuilderElderberryZKEVM(zkevmContract, opts, sender, 100) + sut := txbuilder.NewTxBuilderElderberryZKEVM(zkevmContract, opts, 100) require.NotNil(t, sut) require.True(t, strings.Contains(sut.String(), "Elderberry")) require.True(t, strings.Contains(sut.String(), "ZKEVM")) @@ -32,8 +31,7 @@ func TestElderberryZkevmName(t *testing.T) { func TestElderberryZkevmNewSequence(t *testing.T) { zkevmContract := contracts.RollupElderberryType{} opts := bind.TransactOpts{} - sender := common.Address{} - sut := txbuilder.NewTxBuilderElderberryZKEVM(zkevmContract, opts, sender, 100) + sut := txbuilder.NewTxBuilderElderberryZKEVM(zkevmContract, opts, 100) require.NotNil(t, sut) seq, err := sut.NewSequence(nil, common.Address{}) require.NoError(t, err) @@ -43,12 +41,12 @@ func TestElderberryZkevmNewSequence(t *testing.T) { func TestElderberryZkevmBuildSequenceBatchesTxEmtpySequence(t *testing.T) { sut := newElderberryZkevmSUT(t) ctx := context.TODO() - _, err := sut.BuildSequenceBatchesTx(ctx, common.Address{}, nil) + _, err := sut.BuildSequenceBatchesTx(ctx, nil) require.Error(t, err) seq, err := sut.NewSequence(nil, common.Address{}) require.NoError(t, err) - _, err = sut.BuildSequenceBatchesTx(ctx, common.Address{}, seq) + _, err = sut.BuildSequenceBatchesTx(ctx, seq) require.Error(t, err) } @@ -68,7 +66,7 @@ func TestElderberryZkevmBuildSequenceBatchesTxSequence1Batch(t *testing.T) { } seq, err := sut.NewSequence(batches, common.Address{}) require.NoError(t, err) - _, err = sut.BuildSequenceBatchesTx(ctx, common.Address{}, seq) + _, err = sut.BuildSequenceBatchesTx(ctx, seq) require.NoError(t, err) } @@ -90,7 +88,7 @@ func TestElderberryZkevmBuildSequenceBatchesTxSequence1BatchError(t *testing.T) } seq, err := sut.NewSequence(batches, common.Address{}) require.NoError(t, err) - _, err = sut.BuildSequenceBatchesTx(ctx, common.Address{}, seq) + _, err = sut.BuildSequenceBatchesTx(ctx, seq) require.Error(t, err) } @@ -99,7 +97,7 @@ func TestElderberryZkevmNewSequenceIfWorthToSend(t *testing.T) { mockCond := mocks_txbuilder.NewCondNewSequence(t) sut.SetCondNewSeq(mockCond) // Returns that is not work to be send - mockCond.EXPECT().NewSequenceIfWorthToSend(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, nil) + mockCond.EXPECT().NewSequenceIfWorthToSend(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, nil) seq, err := sut.NewSequenceIfWorthToSend(context.TODO(), nil, common.Address{}, 0) require.NoError(t, err) require.Nil(t, seq) @@ -112,8 +110,7 @@ func newElderberryZkevmSUT(t *testing.T) *txbuilder.TxBuilderElderberryZKEVM { require.NoError(t, err) opts, err := bind.NewKeyedTransactorWithChainID(privateKey, big.NewInt(1)) require.NoError(t, err) - sender := common.Address{} - sut := txbuilder.NewTxBuilderElderberryZKEVM(*zkevmContract, *opts, sender, 100) + sut := txbuilder.NewTxBuilderElderberryZKEVM(*zkevmContract, *opts, 100) require.NotNil(t, sut) return sut } diff --git a/sequencesender/txbuilder/interface.go b/sequencesender/txbuilder/interface.go index ea6e8770..ddcd5105 100644 --- a/sequencesender/txbuilder/interface.go +++ b/sequencesender/txbuilder/interface.go @@ -10,7 +10,7 @@ import ( ) type TxBuilder interface { - BuildSequenceBatchesTx(ctx context.Context, sender common.Address, sequences seqsendertypes.Sequence) (*ethtypes.Transaction, error) + BuildSequenceBatchesTx(ctx context.Context, sequences seqsendertypes.Sequence) (*ethtypes.Transaction, error) NewSequence(batches []seqsendertypes.Batch, coinbase common.Address) (seqsendertypes.Sequence, error) NewSequenceIfWorthToSend(ctx context.Context, sequenceBatches []seqsendertypes.Batch, l2Coinbase common.Address, batchNumber uint64) (seqsendertypes.Sequence, error) NewBatchFromL2Block(l2Block *datastream.L2Block) seqsendertypes.Batch @@ -19,5 +19,5 @@ type TxBuilder interface { type CondNewSequence interface { //NewSequenceIfWorthToSend Return nil, nil if the sequence is not worth sending - NewSequenceIfWorthToSend(ctx context.Context, txBuilder TxBuilder, sequenceBatches []seqsendertypes.Batch, senderAddress, l2Coinbase common.Address) (seqsendertypes.Sequence, error) + NewSequenceIfWorthToSend(ctx context.Context, txBuilder TxBuilder, sequenceBatches []seqsendertypes.Batch, l2Coinbase common.Address) (seqsendertypes.Sequence, error) } diff --git a/sequencesender/txbuilder/mocks_txbuilder/cond_new_sequence.go b/sequencesender/txbuilder/mocks_txbuilder/cond_new_sequence.go index 2600af02..ae818ce9 100644 --- a/sequencesender/txbuilder/mocks_txbuilder/cond_new_sequence.go +++ b/sequencesender/txbuilder/mocks_txbuilder/cond_new_sequence.go @@ -27,9 +27,9 @@ func (_m *CondNewSequence) EXPECT() *CondNewSequence_Expecter { return &CondNewSequence_Expecter{mock: &_m.Mock} } -// NewSequenceIfWorthToSend provides a mock function with given fields: ctx, txBuilder, sequenceBatches, senderAddress, l2Coinbase -func (_m *CondNewSequence) NewSequenceIfWorthToSend(ctx context.Context, txBuilder txbuilder.TxBuilder, sequenceBatches []seqsendertypes.Batch, senderAddress common.Address, l2Coinbase common.Address) (seqsendertypes.Sequence, error) { - ret := _m.Called(ctx, txBuilder, sequenceBatches, senderAddress, l2Coinbase) +// NewSequenceIfWorthToSend provides a mock function with given fields: ctx, txBuilder, sequenceBatches, l2Coinbase +func (_m *CondNewSequence) NewSequenceIfWorthToSend(ctx context.Context, txBuilder txbuilder.TxBuilder, sequenceBatches []seqsendertypes.Batch, l2Coinbase common.Address) (seqsendertypes.Sequence, error) { + ret := _m.Called(ctx, txBuilder, sequenceBatches, l2Coinbase) if len(ret) == 0 { panic("no return value specified for NewSequenceIfWorthToSend") @@ -37,19 +37,19 @@ func (_m *CondNewSequence) NewSequenceIfWorthToSend(ctx context.Context, txBuild var r0 seqsendertypes.Sequence var r1 error - if rf, ok := ret.Get(0).(func(context.Context, txbuilder.TxBuilder, []seqsendertypes.Batch, common.Address, common.Address) (seqsendertypes.Sequence, error)); ok { - return rf(ctx, txBuilder, sequenceBatches, senderAddress, l2Coinbase) + if rf, ok := ret.Get(0).(func(context.Context, txbuilder.TxBuilder, []seqsendertypes.Batch, common.Address) (seqsendertypes.Sequence, error)); ok { + return rf(ctx, txBuilder, sequenceBatches, l2Coinbase) } - if rf, ok := ret.Get(0).(func(context.Context, txbuilder.TxBuilder, []seqsendertypes.Batch, common.Address, common.Address) seqsendertypes.Sequence); ok { - r0 = rf(ctx, txBuilder, sequenceBatches, senderAddress, l2Coinbase) + if rf, ok := ret.Get(0).(func(context.Context, txbuilder.TxBuilder, []seqsendertypes.Batch, common.Address) seqsendertypes.Sequence); ok { + r0 = rf(ctx, txBuilder, sequenceBatches, l2Coinbase) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(seqsendertypes.Sequence) } } - if rf, ok := ret.Get(1).(func(context.Context, txbuilder.TxBuilder, []seqsendertypes.Batch, common.Address, common.Address) error); ok { - r1 = rf(ctx, txBuilder, sequenceBatches, senderAddress, l2Coinbase) + if rf, ok := ret.Get(1).(func(context.Context, txbuilder.TxBuilder, []seqsendertypes.Batch, common.Address) error); ok { + r1 = rf(ctx, txBuilder, sequenceBatches, l2Coinbase) } else { r1 = ret.Error(1) } @@ -66,15 +66,14 @@ type CondNewSequence_NewSequenceIfWorthToSend_Call struct { // - ctx context.Context // - txBuilder txbuilder.TxBuilder // - sequenceBatches []seqsendertypes.Batch -// - senderAddress common.Address // - l2Coinbase common.Address -func (_e *CondNewSequence_Expecter) NewSequenceIfWorthToSend(ctx interface{}, txBuilder interface{}, sequenceBatches interface{}, senderAddress interface{}, l2Coinbase interface{}) *CondNewSequence_NewSequenceIfWorthToSend_Call { - return &CondNewSequence_NewSequenceIfWorthToSend_Call{Call: _e.mock.On("NewSequenceIfWorthToSend", ctx, txBuilder, sequenceBatches, senderAddress, l2Coinbase)} +func (_e *CondNewSequence_Expecter) NewSequenceIfWorthToSend(ctx interface{}, txBuilder interface{}, sequenceBatches interface{}, l2Coinbase interface{}) *CondNewSequence_NewSequenceIfWorthToSend_Call { + return &CondNewSequence_NewSequenceIfWorthToSend_Call{Call: _e.mock.On("NewSequenceIfWorthToSend", ctx, txBuilder, sequenceBatches, l2Coinbase)} } -func (_c *CondNewSequence_NewSequenceIfWorthToSend_Call) Run(run func(ctx context.Context, txBuilder txbuilder.TxBuilder, sequenceBatches []seqsendertypes.Batch, senderAddress common.Address, l2Coinbase common.Address)) *CondNewSequence_NewSequenceIfWorthToSend_Call { +func (_c *CondNewSequence_NewSequenceIfWorthToSend_Call) Run(run func(ctx context.Context, txBuilder txbuilder.TxBuilder, sequenceBatches []seqsendertypes.Batch, l2Coinbase common.Address)) *CondNewSequence_NewSequenceIfWorthToSend_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(txbuilder.TxBuilder), args[2].([]seqsendertypes.Batch), args[3].(common.Address), args[4].(common.Address)) + run(args[0].(context.Context), args[1].(txbuilder.TxBuilder), args[2].([]seqsendertypes.Batch), args[3].(common.Address)) }) return _c } @@ -84,7 +83,7 @@ func (_c *CondNewSequence_NewSequenceIfWorthToSend_Call) Return(_a0 seqsendertyp return _c } -func (_c *CondNewSequence_NewSequenceIfWorthToSend_Call) RunAndReturn(run func(context.Context, txbuilder.TxBuilder, []seqsendertypes.Batch, common.Address, common.Address) (seqsendertypes.Sequence, error)) *CondNewSequence_NewSequenceIfWorthToSend_Call { +func (_c *CondNewSequence_NewSequenceIfWorthToSend_Call) RunAndReturn(run func(context.Context, txbuilder.TxBuilder, []seqsendertypes.Batch, common.Address) (seqsendertypes.Sequence, error)) *CondNewSequence_NewSequenceIfWorthToSend_Call { _c.Call.Return(run) return _c } diff --git a/sequencesender/txbuilder/mocks_txbuilder/tx_builder.go b/sequencesender/txbuilder/mocks_txbuilder/tx_builder.go index e9aa9127..4b713efa 100644 --- a/sequencesender/txbuilder/mocks_txbuilder/tx_builder.go +++ b/sequencesender/txbuilder/mocks_txbuilder/tx_builder.go @@ -29,9 +29,9 @@ func (_m *TxBuilder) EXPECT() *TxBuilder_Expecter { return &TxBuilder_Expecter{mock: &_m.Mock} } -// BuildSequenceBatchesTx provides a mock function with given fields: ctx, sender, sequences -func (_m *TxBuilder) BuildSequenceBatchesTx(ctx context.Context, sender common.Address, sequences seqsendertypes.Sequence) (*types.Transaction, error) { - ret := _m.Called(ctx, sender, sequences) +// BuildSequenceBatchesTx provides a mock function with given fields: ctx, sequences +func (_m *TxBuilder) BuildSequenceBatchesTx(ctx context.Context, sequences seqsendertypes.Sequence) (*types.Transaction, error) { + ret := _m.Called(ctx, sequences) if len(ret) == 0 { panic("no return value specified for BuildSequenceBatchesTx") @@ -39,19 +39,19 @@ func (_m *TxBuilder) BuildSequenceBatchesTx(ctx context.Context, sender common.A var r0 *types.Transaction var r1 error - if rf, ok := ret.Get(0).(func(context.Context, common.Address, seqsendertypes.Sequence) (*types.Transaction, error)); ok { - return rf(ctx, sender, sequences) + if rf, ok := ret.Get(0).(func(context.Context, seqsendertypes.Sequence) (*types.Transaction, error)); ok { + return rf(ctx, sequences) } - if rf, ok := ret.Get(0).(func(context.Context, common.Address, seqsendertypes.Sequence) *types.Transaction); ok { - r0 = rf(ctx, sender, sequences) + if rf, ok := ret.Get(0).(func(context.Context, seqsendertypes.Sequence) *types.Transaction); ok { + r0 = rf(ctx, sequences) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*types.Transaction) } } - if rf, ok := ret.Get(1).(func(context.Context, common.Address, seqsendertypes.Sequence) error); ok { - r1 = rf(ctx, sender, sequences) + if rf, ok := ret.Get(1).(func(context.Context, seqsendertypes.Sequence) error); ok { + r1 = rf(ctx, sequences) } else { r1 = ret.Error(1) } @@ -66,15 +66,14 @@ type TxBuilder_BuildSequenceBatchesTx_Call struct { // BuildSequenceBatchesTx is a helper method to define mock.On call // - ctx context.Context -// - sender common.Address // - sequences seqsendertypes.Sequence -func (_e *TxBuilder_Expecter) BuildSequenceBatchesTx(ctx interface{}, sender interface{}, sequences interface{}) *TxBuilder_BuildSequenceBatchesTx_Call { - return &TxBuilder_BuildSequenceBatchesTx_Call{Call: _e.mock.On("BuildSequenceBatchesTx", ctx, sender, sequences)} +func (_e *TxBuilder_Expecter) BuildSequenceBatchesTx(ctx interface{}, sequences interface{}) *TxBuilder_BuildSequenceBatchesTx_Call { + return &TxBuilder_BuildSequenceBatchesTx_Call{Call: _e.mock.On("BuildSequenceBatchesTx", ctx, sequences)} } -func (_c *TxBuilder_BuildSequenceBatchesTx_Call) Run(run func(ctx context.Context, sender common.Address, sequences seqsendertypes.Sequence)) *TxBuilder_BuildSequenceBatchesTx_Call { +func (_c *TxBuilder_BuildSequenceBatchesTx_Call) Run(run func(ctx context.Context, sequences seqsendertypes.Sequence)) *TxBuilder_BuildSequenceBatchesTx_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(common.Address), args[2].(seqsendertypes.Sequence)) + run(args[0].(context.Context), args[1].(seqsendertypes.Sequence)) }) return _c } @@ -84,7 +83,7 @@ func (_c *TxBuilder_BuildSequenceBatchesTx_Call) Return(_a0 *types.Transaction, return _c } -func (_c *TxBuilder_BuildSequenceBatchesTx_Call) RunAndReturn(run func(context.Context, common.Address, seqsendertypes.Sequence) (*types.Transaction, error)) *TxBuilder_BuildSequenceBatchesTx_Call { +func (_c *TxBuilder_BuildSequenceBatchesTx_Call) RunAndReturn(run func(context.Context, seqsendertypes.Sequence) (*types.Transaction, error)) *TxBuilder_BuildSequenceBatchesTx_Call { _c.Call.Return(run) return _c } diff --git a/sequencesender/txbuilder/validium_cond_num_batches.go b/sequencesender/txbuilder/validium_cond_num_batches.go index 66c7c905..1b85582b 100644 --- a/sequencesender/txbuilder/validium_cond_num_batches.go +++ b/sequencesender/txbuilder/validium_cond_num_batches.go @@ -18,7 +18,7 @@ func NewConditionalNewSequenceNumBatches(maxBatchesForL1 uint64) *ConditionalNew } } -func (c *ConditionalNewSequenceNumBatches) NewSequenceIfWorthToSend(ctx context.Context, txBuilder TxBuilder, sequenceBatches []seqsendertypes.Batch, senderAddress, l2Coinbase common.Address) (seqsendertypes.Sequence, error) { +func (c *ConditionalNewSequenceNumBatches) NewSequenceIfWorthToSend(ctx context.Context, txBuilder TxBuilder, sequenceBatches []seqsendertypes.Batch, l2Coinbase common.Address) (seqsendertypes.Sequence, error) { if c.maxBatchesForL1 > 0 && len(sequenceBatches) >= int(c.maxBatchesForL1) { log.Infof( "[SeqSender] sequence should be sent to L1, because MaxBatchesForL1 (%d) has been reached", diff --git a/sequencesender/txbuilder/validium_cond_num_batches_test.go b/sequencesender/txbuilder/validium_cond_num_batches_test.go index 5375b4fd..c449f161 100644 --- a/sequencesender/txbuilder/validium_cond_num_batches_test.go +++ b/sequencesender/txbuilder/validium_cond_num_batches_test.go @@ -15,7 +15,7 @@ func TestConditionalNumBatchesDisabled(t *testing.T) { mockTxBuilder := mocks_txbuilder.NewTxBuilder(t) sut := txbuilder.NewConditionalNewSequenceNumBatches(0) - tx, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, nil, common.Address{}, common.Address{}) + tx, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, nil, common.Address{}) require.NoError(t, err) require.Nil(t, tx) } @@ -26,7 +26,7 @@ func TestConditionalNumBatchesDontFulfillCondition(t *testing.T) { sut := txbuilder.NewConditionalNewSequenceNumBatches(2) var sequenceBatches []seqsendertypes.Batch sequenceBatches = append(sequenceBatches, &txbuilder.BananaBatch{}) - tx, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, sequenceBatches, common.Address{}, common.Address{}) + tx, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, sequenceBatches, common.Address{}) require.NoError(t, err) require.Nil(t, tx) } @@ -39,7 +39,7 @@ func TestConditionalNumBatchesFulfillCondition(t *testing.T) { sequenceBatches = append(sequenceBatches, &txbuilder.BananaBatch{}) sequenceBatches = append(sequenceBatches, &txbuilder.BananaBatch{}) mockTxBuilder.EXPECT().NewSequence(mock.Anything, mock.Anything).Return(nil, nil) - tx, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, sequenceBatches, common.Address{}, common.Address{}) + tx, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, sequenceBatches, common.Address{}) require.NoError(t, err) require.Nil(t, tx) } diff --git a/sequencesender/txbuilder/zkevm_cond_max_size.go b/sequencesender/txbuilder/zkevm_cond_max_size.go index 5280b71f..805014fe 100644 --- a/sequencesender/txbuilder/zkevm_cond_max_size.go +++ b/sequencesender/txbuilder/zkevm_cond_max_size.go @@ -26,7 +26,7 @@ func NewConditionalNewSequenceMaxSize(maxTxSizeForL1 uint64) *ConditionalNewSequ } } -func (c *ConditionalNewSequenceMaxSize) NewSequenceIfWorthToSend(ctx context.Context, txBuilder TxBuilder, sequenceBatches []seqsendertypes.Batch, senderAddress, l2Coinbase common.Address) (seqsendertypes.Sequence, error) { +func (c *ConditionalNewSequenceMaxSize) NewSequenceIfWorthToSend(ctx context.Context, txBuilder TxBuilder, sequenceBatches []seqsendertypes.Batch, l2Coinbase common.Address) (seqsendertypes.Sequence, error) { if c.maxTxSizeForL1 == 0 { log.Debug("maxTxSizeForL1 is 0, so is disabled") return nil, nil @@ -42,7 +42,7 @@ func (c *ConditionalNewSequenceMaxSize) NewSequenceIfWorthToSend(ctx context.Con } // Check if can be sent - tx, err := txBuilder.BuildSequenceBatchesTx(ctx, senderAddress, sequence) + tx, err := txBuilder.BuildSequenceBatchesTx(ctx, sequence) if tx == nil && err == nil { err = fmt.Errorf("error txBuilder.BuildSequenceBatchesTx, returns tx=nil and err==nil, is not expected") log.Errorf(err.Error()) @@ -64,7 +64,7 @@ func (c *ConditionalNewSequenceMaxSize) NewSequenceIfWorthToSend(ctx context.Con return nil, err } - txReduced, err := txBuilder.BuildSequenceBatchesTx(ctx, senderAddress, sequence) + txReduced, err := txBuilder.BuildSequenceBatchesTx(ctx, sequence) log.Debugf("After reducing batches: (txSize %d -> %d)", tx.Size(), txReduced.Size()) if err == nil && txReduced != nil && txReduced.Size() > c.maxTxSizeForL1 { log.Warnf("After reducing batches: (txSize %d -> %d) is still too big > %d", tx.Size(), txReduced.Size(), c.maxTxSizeForL1) diff --git a/sequencesender/txbuilder/zkevm_cond_max_size_test.go b/sequencesender/txbuilder/zkevm_cond_max_size_test.go index 0f87e78c..a65cdc44 100644 --- a/sequencesender/txbuilder/zkevm_cond_max_size_test.go +++ b/sequencesender/txbuilder/zkevm_cond_max_size_test.go @@ -18,7 +18,7 @@ func TestConditionalMaxSizeDisabled(t *testing.T) { mockTxBuilder := mocks_txbuilder.NewTxBuilder(t) sut := txbuilder.NewConditionalNewSequenceMaxSize(0) - tx, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, nil, common.Address{}, common.Address{}) + tx, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, nil, common.Address{}) require.NoError(t, err) require.Nil(t, tx) } @@ -29,7 +29,7 @@ func TestConditionalMaxSizeTxBuilderNewSequenceReturnsNil(t *testing.T) { var sequenceBatches []seqsendertypes.Batch sequenceBatches = append(sequenceBatches, &txbuilder.BananaBatch{}) mockTxBuilder.EXPECT().NewSequence(sequenceBatches, common.Address{}).Return(nil, nil) - _, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, sequenceBatches, common.Address{}, common.Address{}) + _, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, sequenceBatches, common.Address{}) require.Error(t, err) } @@ -40,8 +40,8 @@ func TestConditionalMaxSizeTxBuilderBuildSequenceBatchesTxReturnsNil(t *testing. sequenceBatches = append(sequenceBatches, &txbuilder.BananaBatch{}) seq := &txbuilder.ElderberrySequence{} mockTxBuilder.EXPECT().NewSequence(sequenceBatches, common.Address{}).Return(seq, nil) - mockTxBuilder.EXPECT().BuildSequenceBatchesTx(mock.Anything, mock.Anything, mock.Anything).Return(nil, nil) - _, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, sequenceBatches, common.Address{}, common.Address{}) + mockTxBuilder.EXPECT().BuildSequenceBatchesTx(mock.Anything, mock.Anything).Return(nil, nil) + _, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, sequenceBatches, common.Address{}) require.Error(t, err) } @@ -54,9 +54,9 @@ func TestConditionalMaxSizeTxBuilderDontFulFill(t *testing.T) { mockTxBuilder.EXPECT().NewSequence(sequenceBatches, common.Address{}).Return(seq, nil) inner := ðtypes.LegacyTx{} tx := ethtypes.NewTx(inner) - mockTxBuilder.EXPECT().BuildSequenceBatchesTx(mock.Anything, mock.Anything, mock.Anything).Return(tx, nil) + mockTxBuilder.EXPECT().BuildSequenceBatchesTx(mock.Anything, mock.Anything).Return(tx, nil) - res, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, sequenceBatches, common.Address{}, common.Address{}) + res, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, sequenceBatches, common.Address{}) require.NoError(t, err) require.Nil(t, res) @@ -74,13 +74,13 @@ func TestConditionalMaxSizeTxBuilderFulFill(t *testing.T) { Data: []byte{0x01, 0x02, 0x03, 0x04}, } tx := ethtypes.NewTx(inner) - mockTxBuilder.EXPECT().BuildSequenceBatchesTx(ctx, mock.Anything, newSeq).Return(tx, nil) + mockTxBuilder.EXPECT().BuildSequenceBatchesTx(ctx, newSeq).Return(tx, nil) // The size of result Tx is 14 that is > 10, so it reduce 1 batch newSeqReduced := newTestSeq(2, 100, l2coinbase) mockTxBuilder.EXPECT().NewSequence(newSeqReduced.Batches(), l2coinbase).Return(newSeqReduced, nil) - mockTxBuilder.EXPECT().BuildSequenceBatchesTx(ctx, mock.Anything, newSeqReduced).Return(tx, nil) + mockTxBuilder.EXPECT().BuildSequenceBatchesTx(ctx, newSeqReduced).Return(tx, nil) - res, err := sut.NewSequenceIfWorthToSend(ctx, mockTxBuilder, newSeq.Batches(), common.Address{}, l2coinbase) + res, err := sut.NewSequenceIfWorthToSend(ctx, mockTxBuilder, newSeq.Batches(), l2coinbase) require.NoError(t, err) require.NotNil(t, res) From f187b473fa94a01f16a071f5ee1289a556069ac2 Mon Sep 17 00:00:00 2001 From: joanestebanr <129153821+joanestebanr@users.noreply.github.com> Date: Tue, 30 Jul 2024 18:50:11 +0200 Subject: [PATCH 03/10] refactor of contractBase to expose the contrac interface directly and be able to create mocks --- etherman/aggregator.go | 4 +- etherman/contracts/base.go | 47 ++--- etherman/contracts/base_test.go | 16 ++ etherman/contracts/contracts_banana.go | 24 ++- etherman/contracts/contracts_elderberry.go | 23 ++- etherman/etherman.go | 22 +-- sequencesender/txbuilder/banana_base.go | 27 +-- sequencesender/txbuilder/banana_validium.go | 16 +- sequencesender/txbuilder/banana_zkevm.go | 19 +- sequencesender/txbuilder/elderberry_base.go | 9 +- .../txbuilder/elderberry_base_test.go | 7 +- .../txbuilder/elderberry_validium.go | 21 ++- .../txbuilder/elderberry_validium_test.go | 2 +- sequencesender/txbuilder/elderberry_zkevm.go | 20 ++- .../txbuilder/elderberry_zkevm_test.go | 2 +- .../global_exit_root_banana_contractor.go | 139 +++++++++++++++ ...lobal_exit_root_banana_zkevm_contractor.go | 139 +++++++++++++++ .../rollup_banana_base_contractor.go | 93 ++++++++++ .../rollup_banana_validium_contractor.go | 163 ++++++++++++++++++ .../rollup_banana_zkevm_contractor.go | 162 +++++++++++++++++ .../rollup_elderberry_validium_contractor.go | 104 +++++++++++ .../rollup_elderberry_zkevm_contractor.go | 103 +++++++++++ 22 files changed, 1066 insertions(+), 96 deletions(-) create mode 100644 etherman/contracts/base_test.go create mode 100644 sequencesender/txbuilder/mocks_txbuilder/global_exit_root_banana_contractor.go create mode 100644 sequencesender/txbuilder/mocks_txbuilder/global_exit_root_banana_zkevm_contractor.go create mode 100644 sequencesender/txbuilder/mocks_txbuilder/rollup_banana_base_contractor.go create mode 100644 sequencesender/txbuilder/mocks_txbuilder/rollup_banana_validium_contractor.go create mode 100644 sequencesender/txbuilder/mocks_txbuilder/rollup_banana_zkevm_contractor.go create mode 100644 sequencesender/txbuilder/mocks_txbuilder/rollup_elderberry_validium_contractor.go create mode 100644 sequencesender/txbuilder/mocks_txbuilder/rollup_elderberry_zkevm_contractor.go diff --git a/etherman/aggregator.go b/etherman/aggregator.go index ed8d3575..87384a95 100644 --- a/etherman/aggregator.go +++ b/etherman/aggregator.go @@ -41,7 +41,7 @@ func (etherMan *Client) BuildTrustedVerifyBatchesTxData(lastVerifiedBatch, newVe const pendStateNum = 0 // TODO hardcoded for now until we implement the pending state feature - tx, err := etherMan.Contracts.Banana.RollupManager.Contract().VerifyBatchesTrustedAggregator( + tx, err := etherMan.Contracts.Banana.RollupManager.VerifyBatchesTrustedAggregator( &opts, etherMan.RollupID, pendStateNum, @@ -64,7 +64,7 @@ func (etherMan *Client) BuildTrustedVerifyBatchesTxData(lastVerifiedBatch, newVe // GetBatchAccInputHash gets the batch accumulated input hash from the ethereum func (etherman *Client) GetBatchAccInputHash(ctx context.Context, batchNumber uint64) (common.Hash, error) { - rollupData, err := etherman.Contracts.Banana.RollupManager.Contract().GetRollupSequencedBatches(&bind.CallOpts{Pending: false}, etherman.RollupID, batchNumber) + rollupData, err := etherman.Contracts.Banana.RollupManager.GetRollupSequencedBatches(&bind.CallOpts{Pending: false}, etherman.RollupID, batchNumber) if err != nil { return common.Hash{}, err } diff --git a/etherman/contracts/base.go b/etherman/contracts/base.go index ebe17711..c2aabd02 100644 --- a/etherman/contracts/base.go +++ b/etherman/contracts/base.go @@ -1,52 +1,55 @@ package contracts import ( + "reflect" + "github.com/0xPolygon/cdk/log" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" ) -type ContractBase[T any] struct { - contract *T +type ContractBase struct { address common.Address contractName NameType version VersionType } -type contractConstructorFunc[T any] func(address common.Address, backend bind.ContractBackend) (*T, error) +type contractConstructorFunc[T any] func(address common.Address, backend bind.ContractBackend) (T, error) -func NewContractBase[T any](constructor contractConstructorFunc[T], address common.Address, backend bind.ContractBackend, - name NameType, version VersionType) (*ContractBase[T], error) { - contractBind, err := constructor(address, backend) - if err != nil { - log.Errorf("failed to bind contract %s at address %s. Err:%w", name, address.String(), err) - return nil, err - } - - return &ContractBase[T]{ - contract: contractBind, +func NewContractBase(address common.Address, backend bind.ContractBackend, + name NameType, version VersionType) *ContractBase { + return &ContractBase{ address: address, contractName: name, version: version, - }, nil -} - -func (e *ContractBase[T]) Contract() *T { - return e.contract + } } -func (e *ContractBase[T]) Address() common.Address { +func (e *ContractBase) Address() common.Address { return e.address } -func (e *ContractBase[T]) Name() string { +func (e *ContractBase) Name() string { return string(e.contractName) } -func (e *ContractBase[T]) Version() string { +func (e *ContractBase) Version() string { return string(e.version) } -func (e *ContractBase[T]) String() string { +func (e *ContractBase) String() string { return e.Version() + "/" + e.Name() + "@" + e.Address().String() } + +func NewContractMagic[C any, T any](constructor contractConstructorFunc[T], address common.Address, backend bind.ContractBackend, name NameType, version VersionType) (*C, error) { + contractBind, err := constructor(address, backend) + if err != nil { + log.Errorf("failed to bind contract %s at address %s. Err:%w", name, address.String(), err) + return nil, err + } + tmp := new(C) + values := reflect.ValueOf(tmp).Elem() + values.FieldByIndex([]int{0}).Set(reflect.ValueOf(contractBind)) + values.FieldByIndex([]int{1}).Set(reflect.ValueOf(NewContractBase(address, backend, name, version))) + return tmp, nil +} diff --git a/etherman/contracts/base_test.go b/etherman/contracts/base_test.go new file mode 100644 index 00000000..2261220a --- /dev/null +++ b/etherman/contracts/base_test.go @@ -0,0 +1,16 @@ +package contracts_test + +import ( + "testing" + + "github.com/0xPolygon/cdk-contracts-tooling/contracts/banana/polygonzkevmglobalexitrootv2" + "github.com/0xPolygon/cdk/etherman/contracts" + "github.com/ethereum/go-ethereum/common" + "github.com/stretchr/testify/require" +) + +func TestNewContractMagic(t *testing.T) { + ger, err := contracts.NewContractMagic[contracts.GlobalExitRootBananaType](polygonzkevmglobalexitrootv2.NewPolygonzkevmglobalexitrootv2, common.Address{}, nil, contracts.ContractNameGlobalExitRoot, contracts.VersionBanana) + require.NoError(t, err) + require.NotNil(t, ger) +} diff --git a/etherman/contracts/contracts_banana.go b/etherman/contracts/contracts_banana.go index d01e9782..39e3eb12 100644 --- a/etherman/contracts/contracts_banana.go +++ b/etherman/contracts/contracts_banana.go @@ -8,9 +8,20 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi/bind" ) -type GlobalExitRootBananaType = ContractBase[polygonzkevmglobalexitrootv2.Polygonzkevmglobalexitrootv2] -type RollupBananaType = ContractBase[polygonvalidiumetrog.Polygonvalidiumetrog] -type RollupManagerBananaType = ContractBase[polygonrollupmanager.Polygonrollupmanager] +type GlobalExitRootBananaType struct { + *polygonzkevmglobalexitrootv2.Polygonzkevmglobalexitrootv2 + *ContractBase +} + +type RollupManagerBananaType struct { + *polygonrollupmanager.Polygonrollupmanager + *ContractBase +} + +type RollupBananaType struct { + *polygonvalidiumetrog.Polygonvalidiumetrog + *ContractBase +} type ContractsBanana struct { GlobalExitRoot GlobalExitRootBananaType @@ -19,16 +30,17 @@ type ContractsBanana struct { } func NewContractsBanana(cfg config.L1Config, backend bind.ContractBackend) (*ContractsBanana, error) { - ger, err := NewContractBase(polygonzkevmglobalexitrootv2.NewPolygonzkevmglobalexitrootv2, cfg.GlobalExitRootManagerAddr, backend, ContractNameGlobalExitRoot, VersionBanana) + + ger, err := NewContractMagic[GlobalExitRootBananaType](polygonzkevmglobalexitrootv2.NewPolygonzkevmglobalexitrootv2, cfg.GlobalExitRootManagerAddr, backend, ContractNameGlobalExitRoot, VersionBanana) if err != nil { return nil, err } - rollup, err := NewContractBase(polygonvalidiumetrog.NewPolygonvalidiumetrog, cfg.ZkEVMAddr, backend, ContractNameRollup, VersionBanana) + rollup, err := NewContractMagic[RollupBananaType](polygonvalidiumetrog.NewPolygonvalidiumetrog, cfg.ZkEVMAddr, backend, ContractNameRollup, VersionBanana) if err != nil { return nil, err } - rollupManager, err := NewContractBase(polygonrollupmanager.NewPolygonrollupmanager, cfg.RollupManagerAddr, backend, ContractNameRollupManager, VersionBanana) + rollupManager, err := NewContractMagic[RollupManagerBananaType](polygonrollupmanager.NewPolygonrollupmanager, cfg.RollupManagerAddr, backend, ContractNameRollupManager, VersionBanana) if err != nil { return nil, err } diff --git a/etherman/contracts/contracts_elderberry.go b/etherman/contracts/contracts_elderberry.go index 4127ff11..45f53d14 100644 --- a/etherman/contracts/contracts_elderberry.go +++ b/etherman/contracts/contracts_elderberry.go @@ -8,9 +8,20 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi/bind" ) -type GlobalExitRootElderberryType = ContractBase[polygonzkevmglobalexitrootv2.Polygonzkevmglobalexitrootv2] -type RollupElderberryType = ContractBase[polygonvalidiumetrog.Polygonvalidiumetrog] -type RollupManagerElderberryType = ContractBase[polygonrollupmanager.Polygonrollupmanager] +type GlobalExitRootElderberryType struct { + *polygonzkevmglobalexitrootv2.Polygonzkevmglobalexitrootv2 + *ContractBase +} + +type RollupElderberryType struct { + *polygonvalidiumetrog.Polygonvalidiumetrog + *ContractBase +} + +type RollupManagerElderberryType struct { + *polygonrollupmanager.Polygonrollupmanager + *ContractBase +} type ContractsElderberry struct { GlobalExitRoot GlobalExitRootElderberryType @@ -19,16 +30,16 @@ type ContractsElderberry struct { } func NewContractsElderberry(cfg config.L1Config, backend bind.ContractBackend) (*ContractsElderberry, error) { - ger, err := NewContractBase(polygonzkevmglobalexitrootv2.NewPolygonzkevmglobalexitrootv2, cfg.GlobalExitRootManagerAddr, backend, ContractNameGlobalExitRoot, VersionElderberry) + ger, err := NewContractMagic[GlobalExitRootElderberryType](polygonzkevmglobalexitrootv2.NewPolygonzkevmglobalexitrootv2, cfg.GlobalExitRootManagerAddr, backend, ContractNameGlobalExitRoot, VersionElderberry) if err != nil { return nil, err } - rollup, err := NewContractBase(polygonvalidiumetrog.NewPolygonvalidiumetrog, cfg.ZkEVMAddr, backend, ContractNameRollup, VersionElderberry) + rollup, err := NewContractMagic[RollupElderberryType](polygonvalidiumetrog.NewPolygonvalidiumetrog, cfg.ZkEVMAddr, backend, ContractNameRollup, VersionElderberry) if err != nil { return nil, err } - rollupManager, err := NewContractBase(polygonrollupmanager.NewPolygonrollupmanager, cfg.RollupManagerAddr, backend, ContractNameRollupManager, VersionElderberry) + rollupManager, err := NewContractMagic[RollupManagerElderberryType](polygonrollupmanager.NewPolygonrollupmanager, cfg.RollupManagerAddr, backend, ContractNameRollupManager, VersionElderberry) if err != nil { return nil, err } diff --git a/etherman/etherman.go b/etherman/etherman.go index e47477c8..dc639ff4 100644 --- a/etherman/etherman.go +++ b/etherman/etherman.go @@ -93,7 +93,7 @@ func NewClient(cfg config.Config, l1Config config.L1Config, commonConfig cdkcomm } log.Info(contracts.String()) // Get RollupID - rollupID, err := contracts.Banana.RollupManager.Contract().RollupAddressToID(&bind.CallOpts{Pending: false}, l1Config.ZkEVMAddr) + rollupID, err := contracts.Banana.RollupManager.RollupAddressToID(&bind.CallOpts{Pending: false}, l1Config.ZkEVMAddr) if err != nil { log.Errorf("error getting rollupID from %s : %+v", contracts.Banana.RollupManager.String(), err) return nil, err @@ -114,7 +114,7 @@ func NewClient(cfg config.Config, l1Config config.L1Config, commonConfig cdkcomm } if commonConfig.IsValidiumMode { - dapAddr, err := contracts.Banana.Rollup.Contract().DataAvailabilityProtocol(&bind.CallOpts{Pending: false}) + dapAddr, err := contracts.Banana.Rollup.DataAvailabilityProtocol(&bind.CallOpts{Pending: false}) if err != nil { return nil, err } @@ -148,7 +148,7 @@ func (etherMan *Client) WaitTxToBeMined(ctx context.Context, tx *types.Transacti // GetSendSequenceFee get super/trusted sequencer fee func (etherMan *Client) GetSendSequenceFee(numBatches uint64) (*big.Int, error) { - f, err := etherMan.Contracts.Banana.RollupManager.Contract().GetBatchFee(&bind.CallOpts{Pending: false}) + f, err := etherMan.Contracts.Banana.RollupManager.GetBatchFee(&bind.CallOpts{Pending: false}) if err != nil { return nil, err } @@ -158,7 +158,7 @@ func (etherMan *Client) GetSendSequenceFee(numBatches uint64) (*big.Int, error) // TrustedSequencer gets trusted sequencer address func (etherMan *Client) TrustedSequencer() (common.Address, error) { - return etherMan.Contracts.Banana.Rollup.Contract().TrustedSequencer(&bind.CallOpts{Pending: false}) + return etherMan.Contracts.Banana.Rollup.TrustedSequencer(&bind.CallOpts{Pending: false}) } // HeaderByNumber returns a block header from the current canonical chain. If number is @@ -181,7 +181,7 @@ func (etherMan *Client) EthBlockByNumber(ctx context.Context, blockNumber uint64 // GetLatestBatchNumber function allows to retrieve the latest proposed batch in the smc func (etherMan *Client) GetLatestBatchNumber() (uint64, error) { - rollupData, err := etherMan.Contracts.Banana.RollupManager.Contract().RollupIDToRollupData(&bind.CallOpts{Pending: false}, etherMan.RollupID) + rollupData, err := etherMan.Contracts.Banana.RollupManager.RollupIDToRollupData(&bind.CallOpts{Pending: false}, etherMan.RollupID) if err != nil { return 0, err } @@ -223,7 +223,7 @@ func (etherMan *Client) GetLatestBlockTimestamp(ctx context.Context) (uint64, er // GetLatestVerifiedBatchNum gets latest verified batch from ethereum func (etherMan *Client) GetLatestVerifiedBatchNum() (uint64, error) { - rollupData, err := etherMan.Contracts.Banana.RollupManager.Contract().RollupIDToRollupData(&bind.CallOpts{Pending: false}, etherMan.RollupID) + rollupData, err := etherMan.Contracts.Banana.RollupManager.RollupIDToRollupData(&bind.CallOpts{Pending: false}, etherMan.RollupID) if err != nil { return 0, err } @@ -242,12 +242,12 @@ func (etherMan *Client) GetTxReceipt(ctx context.Context, txHash common.Hash) (* // GetTrustedSequencerURL Gets the trusted sequencer url from rollup smc func (etherMan *Client) GetTrustedSequencerURL() (string, error) { - return etherMan.Contracts.Banana.Rollup.Contract().TrustedSequencerURL(&bind.CallOpts{Pending: false}) + return etherMan.Contracts.Banana.Rollup.TrustedSequencerURL(&bind.CallOpts{Pending: false}) } // GetL2ChainID returns L2 Chain ID func (etherMan *Client) GetL2ChainID() (uint64, error) { - rollupData, err := etherMan.Contracts.Banana.RollupManager.Contract().RollupIDToRollupData(&bind.CallOpts{Pending: false}, etherMan.RollupID) + rollupData, err := etherMan.Contracts.Banana.RollupManager.RollupIDToRollupData(&bind.CallOpts{Pending: false}, etherMan.RollupID) log.Debug("chainID read from rollupManager: ", rollupData.ChainID) if err != nil { log.Debug("error from rollupManager: ", err) @@ -397,7 +397,7 @@ func (etherMan *Client) GetLatestBlockHeader(ctx context.Context) (*types.Header // GetDAProtocolAddr returns the address of the data availability protocol func (etherMan *Client) GetDAProtocolAddr() (common.Address, error) { - return etherMan.Contracts.Banana.Rollup.Contract().DataAvailabilityProtocol(&bind.CallOpts{Pending: false}) + return etherMan.Contracts.Banana.Rollup.DataAvailabilityProtocol(&bind.CallOpts{Pending: false}) } // GetDAProtocolName returns the name of the data availability protocol @@ -407,7 +407,7 @@ func (etherMan *Client) GetDAProtocolName() (string, error) { // LastAccInputHash gets the last acc input hash from the SC func (etherMan *Client) LastAccInputHash() (common.Hash, error) { - return etherMan.Contracts.Banana.Rollup.Contract().LastAccInputHash(&bind.CallOpts{Pending: false}) + return etherMan.Contracts.Banana.Rollup.LastAccInputHash(&bind.CallOpts{Pending: false}) } // GetL1InfoRoot gets the L1 info root from the SC @@ -419,7 +419,7 @@ func (etherMan *Client) GetL1InfoRoot(indexL1InfoRoot uint32) (common.Hash, erro ) if indexL1InfoRoot > 0 { - lastL1InfoTreeRoot, err = etherMan.Contracts.Banana.GlobalExitRoot.Contract().L1InfoRootMap(&bind.CallOpts{Pending: false}, indexL1InfoRoot) + lastL1InfoTreeRoot, err = etherMan.Contracts.Banana.GlobalExitRoot.L1InfoRootMap(&bind.CallOpts{Pending: false}, indexL1InfoRoot) if err != nil { log.Errorf("error calling SC globalexitroot L1InfoLeafMap: %v", err) } diff --git a/sequencesender/txbuilder/banana_base.go b/sequencesender/txbuilder/banana_base.go index 6d36e33b..071444c1 100644 --- a/sequencesender/txbuilder/banana_base.go +++ b/sequencesender/txbuilder/banana_base.go @@ -5,7 +5,6 @@ import ( cdkcommon "github.com/0xPolygon/cdk/common" "github.com/0xPolygon/cdk/etherman" - "github.com/0xPolygon/cdk/etherman/contracts" "github.com/0xPolygon/cdk/log" "github.com/0xPolygon/cdk/sequencesender/seqsendertypes" "github.com/0xPolygon/cdk/state/datastream" @@ -13,15 +12,23 @@ import ( "github.com/ethereum/go-ethereum/common" ) -type TxBuilderBananaBase struct { - rollupContract contracts.RollupBananaType - globalExitRootContract contracts.GlobalExitRootBananaType +type rollupBananaBaseContractor interface { + LastAccInputHash(opts *bind.CallOpts) ([32]byte, error) +} - opts bind.TransactOpts +type globalExitRootBananaContractor interface { + L1InfoRootMap(opts *bind.CallOpts, index uint32) ([32]byte, error) + String() string +} + +type TxBuilderBananaBase struct { + rollupContract rollupBananaBaseContractor + globalExitRootContract globalExitRootBananaContractor + opts bind.TransactOpts } -func NewTxBuilderBananaBase(rollupContract contracts.RollupBananaType, - gerContract contracts.GlobalExitRootBananaType, +func NewTxBuilderBananaBase(rollupContract rollupBananaBaseContractor, + gerContract globalExitRootBananaContractor, opts bind.TransactOpts) *TxBuilderBananaBase { return &TxBuilderBananaBase{ rollupContract: rollupContract, @@ -100,7 +107,7 @@ func (t *TxBuilderBananaBase) NewSequence(batches []seqsendertypes.Batch, coinba sequence.L1InfoRoot = l1InfoRoot - accInputHash, err := t.rollupContract.Contract().LastAccInputHash(&bind.CallOpts{Pending: false}) + accInputHash, err := t.rollupContract.LastAccInputHash(&bind.CallOpts{Pending: false}) if err != nil { return nil, err } @@ -138,9 +145,9 @@ func (t *TxBuilderBananaBase) getL1InfoRoot(indexL1InfoRoot uint32) (common.Hash ) if indexL1InfoRoot > 0 { - lastL1InfoTreeRoot, err = t.globalExitRootContract.Contract().L1InfoRootMap(&bind.CallOpts{Pending: false}, indexL1InfoRoot) + lastL1InfoTreeRoot, err = t.globalExitRootContract.L1InfoRootMap(&bind.CallOpts{Pending: false}, indexL1InfoRoot) if err != nil { - log.Errorf("error calling SC globalexitroot L1InfoLeafMap: %v", err) + log.Errorf("error calling SC globalexitroot L1InfoLeafMap (%s) Err: %w", t.globalExitRootContract.String(), err) } } diff --git a/sequencesender/txbuilder/banana_validium.go b/sequencesender/txbuilder/banana_validium.go index 7abaae17..2cc553ad 100644 --- a/sequencesender/txbuilder/banana_validium.go +++ b/sequencesender/txbuilder/banana_validium.go @@ -12,23 +12,31 @@ import ( "github.com/0xPolygon/cdk/sequencesender/seqsendertypes" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" ) type TxBuilderBananaValidium struct { TxBuilderBananaBase - da dataavailability.SequenceSender - condNewSeq CondNewSequence + da dataavailability.SequenceSender + condNewSeq CondNewSequence + rollupContract rollupBananaValidiumContractor } -func NewTxBuilderBananaValidium(rollupContract contracts.RollupBananaType, +type rollupBananaValidiumContractor interface { + rollupBananaBaseContractor + SequenceBatchesValidium(opts *bind.TransactOpts, batches []polygonvalidiumetrog.PolygonValidiumEtrogValidiumBatchData, indexL1InfoRoot uint32, maxSequenceTimestamp uint64, expectedFinalAccInputHash [32]byte, l2Coinbase common.Address, dataAvailabilityMessage []byte) (*types.Transaction, error) +} + +func NewTxBuilderBananaValidium(rollupContract rollupBananaValidiumContractor, gerContract contracts.GlobalExitRootBananaType, da dataavailability.SequenceSender, opts bind.TransactOpts, maxBatchesForL1 uint64) *TxBuilderBananaValidium { return &TxBuilderBananaValidium{ TxBuilderBananaBase: *NewTxBuilderBananaBase(rollupContract, gerContract, opts), da: da, condNewSeq: NewConditionalNewSequenceNumBatches(maxBatchesForL1), + rollupContract: rollupContract, } } @@ -92,7 +100,7 @@ func (t *TxBuilderBananaValidium) sequenceBatchesValidium(opts bind.TransactOpts } } - tx, err := t.rollupContract.Contract().SequenceBatchesValidium(&opts, batches, sequence.IndexL1InfoRoot, sequence.MaxSequenceTimestamp, sequence.AccInputHash, sequence.L2Coinbase, dataAvailabilityMessage) + tx, err := t.rollupContract.SequenceBatchesValidium(&opts, batches, sequence.IndexL1InfoRoot, sequence.MaxSequenceTimestamp, sequence.AccInputHash, sequence.L2Coinbase, dataAvailabilityMessage) if err != nil { log.Debugf("Batches to send: %+v", batches) log.Debug("l2CoinBase: ", sequence.L2Coinbase) diff --git a/sequencesender/txbuilder/banana_zkevm.go b/sequencesender/txbuilder/banana_zkevm.go index 28cdcdd2..5bbcbf73 100644 --- a/sequencesender/txbuilder/banana_zkevm.go +++ b/sequencesender/txbuilder/banana_zkevm.go @@ -6,23 +6,34 @@ import ( "github.com/0xPolygon/cdk-contracts-tooling/contracts/banana/polygonvalidiumetrog" "github.com/0xPolygon/cdk/etherman" - "github.com/0xPolygon/cdk/etherman/contracts" "github.com/0xPolygon/cdk/log" "github.com/0xPolygon/cdk/sequencesender/seqsendertypes" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" ethtypes "github.com/ethereum/go-ethereum/core/types" ) type TxBuilderBananaZKEVM struct { TxBuilderBananaBase - condNewSeq CondNewSequence + condNewSeq CondNewSequence + rollupContract rollupBananaZKEVMContractor } -func NewTxBuilderBananaZKEVM(rollupContract contracts.RollupBananaType, gerContract contracts.GlobalExitRootBananaType, opts bind.TransactOpts, maxTxSizeForL1 uint64) *TxBuilderBananaZKEVM { +type rollupBananaZKEVMContractor interface { + rollupBananaBaseContractor + SequenceBatches(opts *bind.TransactOpts, batches []polygonvalidiumetrog.PolygonRollupBaseEtrogBatchData, indexL1InfoRoot uint32, maxSequenceTimestamp uint64, expectedFinalAccInputHash [32]byte, l2Coinbase common.Address) (*types.Transaction, error) +} + +type globalExitRootBananaZKEVMContractor interface { + globalExitRootBananaContractor +} + +func NewTxBuilderBananaZKEVM(rollupContract rollupBananaZKEVMContractor, gerContract globalExitRootBananaZKEVMContractor, opts bind.TransactOpts, maxTxSizeForL1 uint64) *TxBuilderBananaZKEVM { return &TxBuilderBananaZKEVM{ TxBuilderBananaBase: *NewTxBuilderBananaBase(rollupContract, gerContract, opts), condNewSeq: NewConditionalNewSequenceMaxSize(maxTxSizeForL1), + rollupContract: rollupContract, } } @@ -69,7 +80,7 @@ func (t *TxBuilderBananaZKEVM) sequenceBatchesRollup(opts bind.TransactOpts, seq } } - tx, err := t.rollupContract.Contract().SequenceBatches(&opts, batches, sequence.IndexL1InfoRoot, sequence.MaxSequenceTimestamp, sequence.AccInputHash, sequence.L2Coinbase) + tx, err := t.rollupContract.SequenceBatches(&opts, batches, sequence.IndexL1InfoRoot, sequence.MaxSequenceTimestamp, sequence.AccInputHash, sequence.L2Coinbase) if err != nil { log.Debugf("Batches to send: %+v", batches) log.Debug("l2CoinBase: ", sequence.L2Coinbase) diff --git a/sequencesender/txbuilder/elderberry_base.go b/sequencesender/txbuilder/elderberry_base.go index 8343eecf..64971e9c 100644 --- a/sequencesender/txbuilder/elderberry_base.go +++ b/sequencesender/txbuilder/elderberry_base.go @@ -2,7 +2,6 @@ package txbuilder import ( "github.com/0xPolygon/cdk/etherman" - "github.com/0xPolygon/cdk/etherman/contracts" "github.com/0xPolygon/cdk/sequencesender/seqsendertypes" "github.com/0xPolygon/cdk/state/datastream" "github.com/ethereum/go-ethereum/accounts/abi/bind" @@ -10,14 +9,12 @@ import ( ) type TxBuilderElderberryBase struct { - rollupContract contracts.RollupElderberryType - opts bind.TransactOpts + opts bind.TransactOpts } -func NewTxBuilderElderberryBase(rollupContract contracts.RollupElderberryType, opts bind.TransactOpts) *TxBuilderElderberryBase { +func NewTxBuilderElderberryBase(opts bind.TransactOpts) *TxBuilderElderberryBase { return &TxBuilderElderberryBase{ - rollupContract: rollupContract, - opts: opts, + opts: opts, } } diff --git a/sequencesender/txbuilder/elderberry_base_test.go b/sequencesender/txbuilder/elderberry_base_test.go index 619ce1da..43141f22 100644 --- a/sequencesender/txbuilder/elderberry_base_test.go +++ b/sequencesender/txbuilder/elderberry_base_test.go @@ -3,7 +3,6 @@ package txbuilder import ( "testing" - "github.com/0xPolygon/cdk/etherman/contracts" "github.com/0xPolygon/cdk/sequencesender/seqsendertypes" "github.com/0xPolygon/cdk/state/datastream" "github.com/ethereum/go-ethereum/accounts/abi/bind" @@ -12,9 +11,8 @@ import ( ) func TestElderberryBaseNewSequence(t *testing.T) { - zkevmContract := contracts.RollupElderberryType{} opts := bind.TransactOpts{} - sut := NewTxBuilderElderberryBase(zkevmContract, opts) + sut := NewTxBuilderElderberryBase(opts) require.NotNil(t, sut) seq, err := sut.NewSequence(nil, common.Address{}) require.NotNil(t, seq) @@ -93,9 +91,8 @@ func TestElderberryBaseGetLastSequencedBatchFirstBatchIsZeroThrowAPanic(t *testi } func newElderberryBaseSUT(t *testing.T) *TxBuilderElderberryBase { - zkevmContract := contracts.RollupElderberryType{} opts := bind.TransactOpts{} - sut := NewTxBuilderElderberryBase(zkevmContract, opts) + sut := NewTxBuilderElderberryBase(opts) require.NotNil(t, sut) return sut } diff --git a/sequencesender/txbuilder/elderberry_validium.go b/sequencesender/txbuilder/elderberry_validium.go index d6dde1d5..ec5c8dbc 100644 --- a/sequencesender/txbuilder/elderberry_validium.go +++ b/sequencesender/txbuilder/elderberry_validium.go @@ -21,19 +21,23 @@ import ( type TxBuilderElderberryValidium struct { TxBuilderElderberryBase - da dataavailability.SequenceSenderElderberry - condNewSeq CondNewSequence + da dataavailability.SequenceSenderElderberry + condNewSeq CondNewSequence + rollupContract rollupElderberryValidiumContractor +} + +type rollupElderberryValidiumContractor interface { + SequenceBatchesValidium(opts *bind.TransactOpts, batches []polygonvalidiumetrog.PolygonValidiumEtrogValidiumBatchData, maxSequenceTimestamp uint64, initSequencedBatch uint64, l2Coinbase common.Address, dataAvailabilityMessage []byte) (*types.Transaction, error) } func NewTxBuilderElderberryValidium(zkevm contracts.RollupElderberryType, da dataavailability.SequenceSenderElderberry, opts bind.TransactOpts, maxBatchesForL1 uint64) *TxBuilderElderberryValidium { return &TxBuilderElderberryValidium{ - da: da, - TxBuilderElderberryBase: *NewTxBuilderElderberryBase( - zkevm, opts, - ), - condNewSeq: NewConditionalNewSequenceNumBatches(maxBatchesForL1), + da: da, + TxBuilderElderberryBase: *NewTxBuilderElderberryBase(opts), + condNewSeq: NewConditionalNewSequenceNumBatches(maxBatchesForL1), + rollupContract: zkevm, } } func (t *TxBuilderElderberryValidium) NewSequenceIfWorthToSend(ctx context.Context, sequenceBatches []seqsendertypes.Batch, l2Coinbase common.Address, batchNumber uint64) (seqsendertypes.Sequence, error) { @@ -80,10 +84,9 @@ func (t *TxBuilderElderberryValidium) buildSequenceBatchesTxValidium(opts *bind. } } lastSequencedBatchNumber := getLastSequencedBatchNumber(sequences) - ZkEVM := t.rollupContract.Contract() log.Infof("SequenceBatchesValidium(from=%s, len(batches)=%d, MaxSequenceTimestamp=%d, lastSequencedBatchNumber=%d, L2Coinbase=%s, dataAvailabilityMessage=%s)", t.opts.From.String(), len(batches), sequences.MaxSequenceTimestamp(), lastSequencedBatchNumber, sequences.L2Coinbase().String(), hex.EncodeToString(dataAvailabilityMessage)) - tx, err := ZkEVM.SequenceBatchesValidium(opts, batches, sequences.MaxSequenceTimestamp(), + tx, err := t.rollupContract.SequenceBatchesValidium(opts, batches, sequences.MaxSequenceTimestamp(), lastSequencedBatchNumber, sequences.L2Coinbase(), dataAvailabilityMessage) if err != nil { if parsedErr, ok := etherman.TryParseError(err); ok { diff --git a/sequencesender/txbuilder/elderberry_validium_test.go b/sequencesender/txbuilder/elderberry_validium_test.go index a5bfb818..2d57d0e7 100644 --- a/sequencesender/txbuilder/elderberry_validium_test.go +++ b/sequencesender/txbuilder/elderberry_validium_test.go @@ -91,7 +91,7 @@ type testDataElderberryValidium struct { } func newElderberryValidiumSUT(t *testing.T) *testDataElderberryValidium { - zkevmContract, err := contracts.NewContractBase(polygonvalidiumetrog.NewPolygonvalidiumetrog, common.Address{}, nil, contracts.ContractNameRollup, contracts.VersionElderberry) + zkevmContract, err := contracts.NewContractMagic[contracts.RollupElderberryType](polygonvalidiumetrog.NewPolygonvalidiumetrog, common.Address{}, nil, contracts.ContractNameRollup, contracts.VersionElderberry) require.NoError(t, err) privateKey, err := crypto.HexToECDSA("64e679029f5032046955d41713dcc4b565de77ab891748d31bcf38864b54c175") require.NoError(t, err) diff --git a/sequencesender/txbuilder/elderberry_zkevm.go b/sequencesender/txbuilder/elderberry_zkevm.go index 0db8b6e3..baf3d5ae 100644 --- a/sequencesender/txbuilder/elderberry_zkevm.go +++ b/sequencesender/txbuilder/elderberry_zkevm.go @@ -7,7 +7,6 @@ import ( "github.com/0xPolygon/cdk-contracts-tooling/contracts/elderberry/polygonvalidiumetrog" "github.com/0xPolygon/cdk/etherman" - "github.com/0xPolygon/cdk/etherman/contracts" "github.com/0xPolygon/cdk/log" "github.com/0xPolygon/cdk/sequencesender/seqsendertypes" "github.com/ethereum/go-ethereum/accounts/abi/bind" @@ -18,15 +17,19 @@ import ( type TxBuilderElderberryZKEVM struct { TxBuilderElderberryBase - condNewSeq CondNewSequence + condNewSeq CondNewSequence + rollupContract rollupElderberryZKEVMContractor } -func NewTxBuilderElderberryZKEVM(zkevm contracts.RollupElderberryType, opts bind.TransactOpts, maxTxSizeForL1 uint64) *TxBuilderElderberryZKEVM { +type rollupElderberryZKEVMContractor interface { + SequenceBatches(opts *bind.TransactOpts, batches []polygonvalidiumetrog.PolygonRollupBaseEtrogBatchData, maxSequenceTimestamp uint64, initSequencedBatch uint64, l2Coinbase common.Address) (*types.Transaction, error) +} + +func NewTxBuilderElderberryZKEVM(zkevm rollupElderberryZKEVMContractor, opts bind.TransactOpts, maxTxSizeForL1 uint64) *TxBuilderElderberryZKEVM { return &TxBuilderElderberryZKEVM{ - TxBuilderElderberryBase: *NewTxBuilderElderberryBase( - zkevm, opts, - ), - condNewSeq: NewConditionalNewSequenceMaxSize(maxTxSizeForL1), + TxBuilderElderberryBase: *NewTxBuilderElderberryBase(opts), + condNewSeq: NewConditionalNewSequenceMaxSize(maxTxSizeForL1), + rollupContract: zkevm, } } @@ -71,8 +74,7 @@ func (t *TxBuilderElderberryZKEVM) sequenceBatchesRollup(opts bind.TransactOpts, } } lastSequencedBatchNumber := getLastSequencedBatchNumber(sequences) - ZkEVM := t.rollupContract.Contract() - tx, err := ZkEVM.SequenceBatches(&opts, batches, sequences.MaxSequenceTimestamp(), lastSequencedBatchNumber, sequences.L2Coinbase()) + tx, err := t.rollupContract.SequenceBatches(&opts, batches, sequences.MaxSequenceTimestamp(), lastSequencedBatchNumber, sequences.L2Coinbase()) if err != nil { t.warningMessage(batches, sequences.L2Coinbase(), &opts) if parsedErr, ok := etherman.TryParseError(err); ok { diff --git a/sequencesender/txbuilder/elderberry_zkevm_test.go b/sequencesender/txbuilder/elderberry_zkevm_test.go index 1819bbe2..67f9bda4 100644 --- a/sequencesender/txbuilder/elderberry_zkevm_test.go +++ b/sequencesender/txbuilder/elderberry_zkevm_test.go @@ -104,7 +104,7 @@ func TestElderberryZkevmNewSequenceIfWorthToSend(t *testing.T) { } func newElderberryZkevmSUT(t *testing.T) *txbuilder.TxBuilderElderberryZKEVM { - zkevmContract, err := contracts.NewContractBase(polygonvalidiumetrog.NewPolygonvalidiumetrog, common.Address{}, nil, contracts.ContractNameRollup, contracts.VersionElderberry) + zkevmContract, err := contracts.NewContractMagic[contracts.RollupElderberryType](polygonvalidiumetrog.NewPolygonvalidiumetrog, common.Address{}, nil, contracts.ContractNameRollup, contracts.VersionElderberry) require.NoError(t, err) privateKey, err := crypto.HexToECDSA("64e679029f5032046955d41713dcc4b565de77ab891748d31bcf38864b54c175") require.NoError(t, err) diff --git a/sequencesender/txbuilder/mocks_txbuilder/global_exit_root_banana_contractor.go b/sequencesender/txbuilder/mocks_txbuilder/global_exit_root_banana_contractor.go new file mode 100644 index 00000000..b6be951b --- /dev/null +++ b/sequencesender/txbuilder/mocks_txbuilder/global_exit_root_banana_contractor.go @@ -0,0 +1,139 @@ +// Code generated by mockery. DO NOT EDIT. + +package mocks_txbuilder + +import ( + bind "github.com/ethereum/go-ethereum/accounts/abi/bind" + mock "github.com/stretchr/testify/mock" +) + +// globalExitRootBananaContractor is an autogenerated mock type for the globalExitRootBananaContractor type +type globalExitRootBananaContractor struct { + mock.Mock +} + +type globalExitRootBananaContractor_Expecter struct { + mock *mock.Mock +} + +func (_m *globalExitRootBananaContractor) EXPECT() *globalExitRootBananaContractor_Expecter { + return &globalExitRootBananaContractor_Expecter{mock: &_m.Mock} +} + +// L1InfoRootMap provides a mock function with given fields: opts, index +func (_m *globalExitRootBananaContractor) L1InfoRootMap(opts *bind.CallOpts, index uint32) ([32]byte, error) { + ret := _m.Called(opts, index) + + if len(ret) == 0 { + panic("no return value specified for L1InfoRootMap") + } + + var r0 [32]byte + var r1 error + if rf, ok := ret.Get(0).(func(*bind.CallOpts, uint32) ([32]byte, error)); ok { + return rf(opts, index) + } + if rf, ok := ret.Get(0).(func(*bind.CallOpts, uint32) [32]byte); ok { + r0 = rf(opts, index) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([32]byte) + } + } + + if rf, ok := ret.Get(1).(func(*bind.CallOpts, uint32) error); ok { + r1 = rf(opts, index) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// globalExitRootBananaContractor_L1InfoRootMap_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'L1InfoRootMap' +type globalExitRootBananaContractor_L1InfoRootMap_Call struct { + *mock.Call +} + +// L1InfoRootMap is a helper method to define mock.On call +// - opts *bind.CallOpts +// - index uint32 +func (_e *globalExitRootBananaContractor_Expecter) L1InfoRootMap(opts interface{}, index interface{}) *globalExitRootBananaContractor_L1InfoRootMap_Call { + return &globalExitRootBananaContractor_L1InfoRootMap_Call{Call: _e.mock.On("L1InfoRootMap", opts, index)} +} + +func (_c *globalExitRootBananaContractor_L1InfoRootMap_Call) Run(run func(opts *bind.CallOpts, index uint32)) *globalExitRootBananaContractor_L1InfoRootMap_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*bind.CallOpts), args[1].(uint32)) + }) + return _c +} + +func (_c *globalExitRootBananaContractor_L1InfoRootMap_Call) Return(_a0 [32]byte, _a1 error) *globalExitRootBananaContractor_L1InfoRootMap_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *globalExitRootBananaContractor_L1InfoRootMap_Call) RunAndReturn(run func(*bind.CallOpts, uint32) ([32]byte, error)) *globalExitRootBananaContractor_L1InfoRootMap_Call { + _c.Call.Return(run) + return _c +} + +// String provides a mock function with given fields: +func (_m *globalExitRootBananaContractor) String() string { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for String") + } + + var r0 string + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// globalExitRootBananaContractor_String_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'String' +type globalExitRootBananaContractor_String_Call struct { + *mock.Call +} + +// String is a helper method to define mock.On call +func (_e *globalExitRootBananaContractor_Expecter) String() *globalExitRootBananaContractor_String_Call { + return &globalExitRootBananaContractor_String_Call{Call: _e.mock.On("String")} +} + +func (_c *globalExitRootBananaContractor_String_Call) Run(run func()) *globalExitRootBananaContractor_String_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *globalExitRootBananaContractor_String_Call) Return(_a0 string) *globalExitRootBananaContractor_String_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *globalExitRootBananaContractor_String_Call) RunAndReturn(run func() string) *globalExitRootBananaContractor_String_Call { + _c.Call.Return(run) + return _c +} + +// newGlobalExitRootBananaContractor creates a new instance of globalExitRootBananaContractor. 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 newGlobalExitRootBananaContractor(t interface { + mock.TestingT + Cleanup(func()) +}) *globalExitRootBananaContractor { + mock := &globalExitRootBananaContractor{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/sequencesender/txbuilder/mocks_txbuilder/global_exit_root_banana_zkevm_contractor.go b/sequencesender/txbuilder/mocks_txbuilder/global_exit_root_banana_zkevm_contractor.go new file mode 100644 index 00000000..0f979cb4 --- /dev/null +++ b/sequencesender/txbuilder/mocks_txbuilder/global_exit_root_banana_zkevm_contractor.go @@ -0,0 +1,139 @@ +// Code generated by mockery. DO NOT EDIT. + +package mocks_txbuilder + +import ( + bind "github.com/ethereum/go-ethereum/accounts/abi/bind" + mock "github.com/stretchr/testify/mock" +) + +// globalExitRootBananaZKEVMContractor is an autogenerated mock type for the globalExitRootBananaZKEVMContractor type +type globalExitRootBananaZKEVMContractor struct { + mock.Mock +} + +type globalExitRootBananaZKEVMContractor_Expecter struct { + mock *mock.Mock +} + +func (_m *globalExitRootBananaZKEVMContractor) EXPECT() *globalExitRootBananaZKEVMContractor_Expecter { + return &globalExitRootBananaZKEVMContractor_Expecter{mock: &_m.Mock} +} + +// L1InfoRootMap provides a mock function with given fields: opts, index +func (_m *globalExitRootBananaZKEVMContractor) L1InfoRootMap(opts *bind.CallOpts, index uint32) ([32]byte, error) { + ret := _m.Called(opts, index) + + if len(ret) == 0 { + panic("no return value specified for L1InfoRootMap") + } + + var r0 [32]byte + var r1 error + if rf, ok := ret.Get(0).(func(*bind.CallOpts, uint32) ([32]byte, error)); ok { + return rf(opts, index) + } + if rf, ok := ret.Get(0).(func(*bind.CallOpts, uint32) [32]byte); ok { + r0 = rf(opts, index) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([32]byte) + } + } + + if rf, ok := ret.Get(1).(func(*bind.CallOpts, uint32) error); ok { + r1 = rf(opts, index) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// globalExitRootBananaZKEVMContractor_L1InfoRootMap_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'L1InfoRootMap' +type globalExitRootBananaZKEVMContractor_L1InfoRootMap_Call struct { + *mock.Call +} + +// L1InfoRootMap is a helper method to define mock.On call +// - opts *bind.CallOpts +// - index uint32 +func (_e *globalExitRootBananaZKEVMContractor_Expecter) L1InfoRootMap(opts interface{}, index interface{}) *globalExitRootBananaZKEVMContractor_L1InfoRootMap_Call { + return &globalExitRootBananaZKEVMContractor_L1InfoRootMap_Call{Call: _e.mock.On("L1InfoRootMap", opts, index)} +} + +func (_c *globalExitRootBananaZKEVMContractor_L1InfoRootMap_Call) Run(run func(opts *bind.CallOpts, index uint32)) *globalExitRootBananaZKEVMContractor_L1InfoRootMap_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*bind.CallOpts), args[1].(uint32)) + }) + return _c +} + +func (_c *globalExitRootBananaZKEVMContractor_L1InfoRootMap_Call) Return(_a0 [32]byte, _a1 error) *globalExitRootBananaZKEVMContractor_L1InfoRootMap_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *globalExitRootBananaZKEVMContractor_L1InfoRootMap_Call) RunAndReturn(run func(*bind.CallOpts, uint32) ([32]byte, error)) *globalExitRootBananaZKEVMContractor_L1InfoRootMap_Call { + _c.Call.Return(run) + return _c +} + +// String provides a mock function with given fields: +func (_m *globalExitRootBananaZKEVMContractor) String() string { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for String") + } + + var r0 string + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// globalExitRootBananaZKEVMContractor_String_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'String' +type globalExitRootBananaZKEVMContractor_String_Call struct { + *mock.Call +} + +// String is a helper method to define mock.On call +func (_e *globalExitRootBananaZKEVMContractor_Expecter) String() *globalExitRootBananaZKEVMContractor_String_Call { + return &globalExitRootBananaZKEVMContractor_String_Call{Call: _e.mock.On("String")} +} + +func (_c *globalExitRootBananaZKEVMContractor_String_Call) Run(run func()) *globalExitRootBananaZKEVMContractor_String_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *globalExitRootBananaZKEVMContractor_String_Call) Return(_a0 string) *globalExitRootBananaZKEVMContractor_String_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *globalExitRootBananaZKEVMContractor_String_Call) RunAndReturn(run func() string) *globalExitRootBananaZKEVMContractor_String_Call { + _c.Call.Return(run) + return _c +} + +// newGlobalExitRootBananaZKEVMContractor creates a new instance of globalExitRootBananaZKEVMContractor. 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 newGlobalExitRootBananaZKEVMContractor(t interface { + mock.TestingT + Cleanup(func()) +}) *globalExitRootBananaZKEVMContractor { + mock := &globalExitRootBananaZKEVMContractor{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/sequencesender/txbuilder/mocks_txbuilder/rollup_banana_base_contractor.go b/sequencesender/txbuilder/mocks_txbuilder/rollup_banana_base_contractor.go new file mode 100644 index 00000000..85e82206 --- /dev/null +++ b/sequencesender/txbuilder/mocks_txbuilder/rollup_banana_base_contractor.go @@ -0,0 +1,93 @@ +// Code generated by mockery. DO NOT EDIT. + +package mocks_txbuilder + +import ( + bind "github.com/ethereum/go-ethereum/accounts/abi/bind" + mock "github.com/stretchr/testify/mock" +) + +// rollupBananaBaseContractor is an autogenerated mock type for the rollupBananaBaseContractor type +type rollupBananaBaseContractor struct { + mock.Mock +} + +type rollupBananaBaseContractor_Expecter struct { + mock *mock.Mock +} + +func (_m *rollupBananaBaseContractor) EXPECT() *rollupBananaBaseContractor_Expecter { + return &rollupBananaBaseContractor_Expecter{mock: &_m.Mock} +} + +// LastAccInputHash provides a mock function with given fields: opts +func (_m *rollupBananaBaseContractor) LastAccInputHash(opts *bind.CallOpts) ([32]byte, error) { + ret := _m.Called(opts) + + if len(ret) == 0 { + panic("no return value specified for LastAccInputHash") + } + + var r0 [32]byte + var r1 error + if rf, ok := ret.Get(0).(func(*bind.CallOpts) ([32]byte, error)); ok { + return rf(opts) + } + if rf, ok := ret.Get(0).(func(*bind.CallOpts) [32]byte); ok { + r0 = rf(opts) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([32]byte) + } + } + + if rf, ok := ret.Get(1).(func(*bind.CallOpts) error); ok { + r1 = rf(opts) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// rollupBananaBaseContractor_LastAccInputHash_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LastAccInputHash' +type rollupBananaBaseContractor_LastAccInputHash_Call struct { + *mock.Call +} + +// LastAccInputHash is a helper method to define mock.On call +// - opts *bind.CallOpts +func (_e *rollupBananaBaseContractor_Expecter) LastAccInputHash(opts interface{}) *rollupBananaBaseContractor_LastAccInputHash_Call { + return &rollupBananaBaseContractor_LastAccInputHash_Call{Call: _e.mock.On("LastAccInputHash", opts)} +} + +func (_c *rollupBananaBaseContractor_LastAccInputHash_Call) Run(run func(opts *bind.CallOpts)) *rollupBananaBaseContractor_LastAccInputHash_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*bind.CallOpts)) + }) + return _c +} + +func (_c *rollupBananaBaseContractor_LastAccInputHash_Call) Return(_a0 [32]byte, _a1 error) *rollupBananaBaseContractor_LastAccInputHash_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *rollupBananaBaseContractor_LastAccInputHash_Call) RunAndReturn(run func(*bind.CallOpts) ([32]byte, error)) *rollupBananaBaseContractor_LastAccInputHash_Call { + _c.Call.Return(run) + return _c +} + +// newRollupBananaBaseContractor creates a new instance of rollupBananaBaseContractor. 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 newRollupBananaBaseContractor(t interface { + mock.TestingT + Cleanup(func()) +}) *rollupBananaBaseContractor { + mock := &rollupBananaBaseContractor{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/sequencesender/txbuilder/mocks_txbuilder/rollup_banana_validium_contractor.go b/sequencesender/txbuilder/mocks_txbuilder/rollup_banana_validium_contractor.go new file mode 100644 index 00000000..430a45b8 --- /dev/null +++ b/sequencesender/txbuilder/mocks_txbuilder/rollup_banana_validium_contractor.go @@ -0,0 +1,163 @@ +// Code generated by mockery. DO NOT EDIT. + +package mocks_txbuilder + +import ( + bind "github.com/ethereum/go-ethereum/accounts/abi/bind" + common "github.com/ethereum/go-ethereum/common" + + mock "github.com/stretchr/testify/mock" + + polygonvalidiumetrog "github.com/0xPolygon/cdk-contracts-tooling/contracts/banana/polygonvalidiumetrog" + + types "github.com/ethereum/go-ethereum/core/types" +) + +// rollupBananaValidiumContractor is an autogenerated mock type for the rollupBananaValidiumContractor type +type rollupBananaValidiumContractor struct { + mock.Mock +} + +type rollupBananaValidiumContractor_Expecter struct { + mock *mock.Mock +} + +func (_m *rollupBananaValidiumContractor) EXPECT() *rollupBananaValidiumContractor_Expecter { + return &rollupBananaValidiumContractor_Expecter{mock: &_m.Mock} +} + +// LastAccInputHash provides a mock function with given fields: opts +func (_m *rollupBananaValidiumContractor) LastAccInputHash(opts *bind.CallOpts) ([32]byte, error) { + ret := _m.Called(opts) + + if len(ret) == 0 { + panic("no return value specified for LastAccInputHash") + } + + var r0 [32]byte + var r1 error + if rf, ok := ret.Get(0).(func(*bind.CallOpts) ([32]byte, error)); ok { + return rf(opts) + } + if rf, ok := ret.Get(0).(func(*bind.CallOpts) [32]byte); ok { + r0 = rf(opts) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([32]byte) + } + } + + if rf, ok := ret.Get(1).(func(*bind.CallOpts) error); ok { + r1 = rf(opts) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// rollupBananaValidiumContractor_LastAccInputHash_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LastAccInputHash' +type rollupBananaValidiumContractor_LastAccInputHash_Call struct { + *mock.Call +} + +// LastAccInputHash is a helper method to define mock.On call +// - opts *bind.CallOpts +func (_e *rollupBananaValidiumContractor_Expecter) LastAccInputHash(opts interface{}) *rollupBananaValidiumContractor_LastAccInputHash_Call { + return &rollupBananaValidiumContractor_LastAccInputHash_Call{Call: _e.mock.On("LastAccInputHash", opts)} +} + +func (_c *rollupBananaValidiumContractor_LastAccInputHash_Call) Run(run func(opts *bind.CallOpts)) *rollupBananaValidiumContractor_LastAccInputHash_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*bind.CallOpts)) + }) + return _c +} + +func (_c *rollupBananaValidiumContractor_LastAccInputHash_Call) Return(_a0 [32]byte, _a1 error) *rollupBananaValidiumContractor_LastAccInputHash_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *rollupBananaValidiumContractor_LastAccInputHash_Call) RunAndReturn(run func(*bind.CallOpts) ([32]byte, error)) *rollupBananaValidiumContractor_LastAccInputHash_Call { + _c.Call.Return(run) + return _c +} + +// SequenceBatchesValidium provides a mock function with given fields: opts, batches, indexL1InfoRoot, maxSequenceTimestamp, expectedFinalAccInputHash, l2Coinbase, dataAvailabilityMessage +func (_m *rollupBananaValidiumContractor) SequenceBatchesValidium(opts *bind.TransactOpts, batches []polygonvalidiumetrog.PolygonValidiumEtrogValidiumBatchData, indexL1InfoRoot uint32, maxSequenceTimestamp uint64, expectedFinalAccInputHash [32]byte, l2Coinbase common.Address, dataAvailabilityMessage []byte) (*types.Transaction, error) { + ret := _m.Called(opts, batches, indexL1InfoRoot, maxSequenceTimestamp, expectedFinalAccInputHash, l2Coinbase, dataAvailabilityMessage) + + if len(ret) == 0 { + panic("no return value specified for SequenceBatchesValidium") + } + + var r0 *types.Transaction + var r1 error + if rf, ok := ret.Get(0).(func(*bind.TransactOpts, []polygonvalidiumetrog.PolygonValidiumEtrogValidiumBatchData, uint32, uint64, [32]byte, common.Address, []byte) (*types.Transaction, error)); ok { + return rf(opts, batches, indexL1InfoRoot, maxSequenceTimestamp, expectedFinalAccInputHash, l2Coinbase, dataAvailabilityMessage) + } + if rf, ok := ret.Get(0).(func(*bind.TransactOpts, []polygonvalidiumetrog.PolygonValidiumEtrogValidiumBatchData, uint32, uint64, [32]byte, common.Address, []byte) *types.Transaction); ok { + r0 = rf(opts, batches, indexL1InfoRoot, maxSequenceTimestamp, expectedFinalAccInputHash, l2Coinbase, dataAvailabilityMessage) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.Transaction) + } + } + + if rf, ok := ret.Get(1).(func(*bind.TransactOpts, []polygonvalidiumetrog.PolygonValidiumEtrogValidiumBatchData, uint32, uint64, [32]byte, common.Address, []byte) error); ok { + r1 = rf(opts, batches, indexL1InfoRoot, maxSequenceTimestamp, expectedFinalAccInputHash, l2Coinbase, dataAvailabilityMessage) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// rollupBananaValidiumContractor_SequenceBatchesValidium_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SequenceBatchesValidium' +type rollupBananaValidiumContractor_SequenceBatchesValidium_Call struct { + *mock.Call +} + +// SequenceBatchesValidium is a helper method to define mock.On call +// - opts *bind.TransactOpts +// - batches []polygonvalidiumetrog.PolygonValidiumEtrogValidiumBatchData +// - indexL1InfoRoot uint32 +// - maxSequenceTimestamp uint64 +// - expectedFinalAccInputHash [32]byte +// - l2Coinbase common.Address +// - dataAvailabilityMessage []byte +func (_e *rollupBananaValidiumContractor_Expecter) SequenceBatchesValidium(opts interface{}, batches interface{}, indexL1InfoRoot interface{}, maxSequenceTimestamp interface{}, expectedFinalAccInputHash interface{}, l2Coinbase interface{}, dataAvailabilityMessage interface{}) *rollupBananaValidiumContractor_SequenceBatchesValidium_Call { + return &rollupBananaValidiumContractor_SequenceBatchesValidium_Call{Call: _e.mock.On("SequenceBatchesValidium", opts, batches, indexL1InfoRoot, maxSequenceTimestamp, expectedFinalAccInputHash, l2Coinbase, dataAvailabilityMessage)} +} + +func (_c *rollupBananaValidiumContractor_SequenceBatchesValidium_Call) Run(run func(opts *bind.TransactOpts, batches []polygonvalidiumetrog.PolygonValidiumEtrogValidiumBatchData, indexL1InfoRoot uint32, maxSequenceTimestamp uint64, expectedFinalAccInputHash [32]byte, l2Coinbase common.Address, dataAvailabilityMessage []byte)) *rollupBananaValidiumContractor_SequenceBatchesValidium_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*bind.TransactOpts), args[1].([]polygonvalidiumetrog.PolygonValidiumEtrogValidiumBatchData), args[2].(uint32), args[3].(uint64), args[4].([32]byte), args[5].(common.Address), args[6].([]byte)) + }) + return _c +} + +func (_c *rollupBananaValidiumContractor_SequenceBatchesValidium_Call) Return(_a0 *types.Transaction, _a1 error) *rollupBananaValidiumContractor_SequenceBatchesValidium_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *rollupBananaValidiumContractor_SequenceBatchesValidium_Call) RunAndReturn(run func(*bind.TransactOpts, []polygonvalidiumetrog.PolygonValidiumEtrogValidiumBatchData, uint32, uint64, [32]byte, common.Address, []byte) (*types.Transaction, error)) *rollupBananaValidiumContractor_SequenceBatchesValidium_Call { + _c.Call.Return(run) + return _c +} + +// newRollupBananaValidiumContractor creates a new instance of rollupBananaValidiumContractor. 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 newRollupBananaValidiumContractor(t interface { + mock.TestingT + Cleanup(func()) +}) *rollupBananaValidiumContractor { + mock := &rollupBananaValidiumContractor{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/sequencesender/txbuilder/mocks_txbuilder/rollup_banana_zkevm_contractor.go b/sequencesender/txbuilder/mocks_txbuilder/rollup_banana_zkevm_contractor.go new file mode 100644 index 00000000..4576a0de --- /dev/null +++ b/sequencesender/txbuilder/mocks_txbuilder/rollup_banana_zkevm_contractor.go @@ -0,0 +1,162 @@ +// Code generated by mockery. DO NOT EDIT. + +package mocks_txbuilder + +import ( + bind "github.com/ethereum/go-ethereum/accounts/abi/bind" + common "github.com/ethereum/go-ethereum/common" + + mock "github.com/stretchr/testify/mock" + + polygonvalidiumetrog "github.com/0xPolygon/cdk-contracts-tooling/contracts/banana/polygonvalidiumetrog" + + types "github.com/ethereum/go-ethereum/core/types" +) + +// rollupBananaZKEVMContractor is an autogenerated mock type for the rollupBananaZKEVMContractor type +type rollupBananaZKEVMContractor struct { + mock.Mock +} + +type rollupBananaZKEVMContractor_Expecter struct { + mock *mock.Mock +} + +func (_m *rollupBananaZKEVMContractor) EXPECT() *rollupBananaZKEVMContractor_Expecter { + return &rollupBananaZKEVMContractor_Expecter{mock: &_m.Mock} +} + +// LastAccInputHash provides a mock function with given fields: opts +func (_m *rollupBananaZKEVMContractor) LastAccInputHash(opts *bind.CallOpts) ([32]byte, error) { + ret := _m.Called(opts) + + if len(ret) == 0 { + panic("no return value specified for LastAccInputHash") + } + + var r0 [32]byte + var r1 error + if rf, ok := ret.Get(0).(func(*bind.CallOpts) ([32]byte, error)); ok { + return rf(opts) + } + if rf, ok := ret.Get(0).(func(*bind.CallOpts) [32]byte); ok { + r0 = rf(opts) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([32]byte) + } + } + + if rf, ok := ret.Get(1).(func(*bind.CallOpts) error); ok { + r1 = rf(opts) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// rollupBananaZKEVMContractor_LastAccInputHash_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LastAccInputHash' +type rollupBananaZKEVMContractor_LastAccInputHash_Call struct { + *mock.Call +} + +// LastAccInputHash is a helper method to define mock.On call +// - opts *bind.CallOpts +func (_e *rollupBananaZKEVMContractor_Expecter) LastAccInputHash(opts interface{}) *rollupBananaZKEVMContractor_LastAccInputHash_Call { + return &rollupBananaZKEVMContractor_LastAccInputHash_Call{Call: _e.mock.On("LastAccInputHash", opts)} +} + +func (_c *rollupBananaZKEVMContractor_LastAccInputHash_Call) Run(run func(opts *bind.CallOpts)) *rollupBananaZKEVMContractor_LastAccInputHash_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*bind.CallOpts)) + }) + return _c +} + +func (_c *rollupBananaZKEVMContractor_LastAccInputHash_Call) Return(_a0 [32]byte, _a1 error) *rollupBananaZKEVMContractor_LastAccInputHash_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *rollupBananaZKEVMContractor_LastAccInputHash_Call) RunAndReturn(run func(*bind.CallOpts) ([32]byte, error)) *rollupBananaZKEVMContractor_LastAccInputHash_Call { + _c.Call.Return(run) + return _c +} + +// SequenceBatches provides a mock function with given fields: opts, batches, indexL1InfoRoot, maxSequenceTimestamp, expectedFinalAccInputHash, l2Coinbase +func (_m *rollupBananaZKEVMContractor) SequenceBatches(opts *bind.TransactOpts, batches []polygonvalidiumetrog.PolygonRollupBaseEtrogBatchData, indexL1InfoRoot uint32, maxSequenceTimestamp uint64, expectedFinalAccInputHash [32]byte, l2Coinbase common.Address) (*types.Transaction, error) { + ret := _m.Called(opts, batches, indexL1InfoRoot, maxSequenceTimestamp, expectedFinalAccInputHash, l2Coinbase) + + if len(ret) == 0 { + panic("no return value specified for SequenceBatches") + } + + var r0 *types.Transaction + var r1 error + if rf, ok := ret.Get(0).(func(*bind.TransactOpts, []polygonvalidiumetrog.PolygonRollupBaseEtrogBatchData, uint32, uint64, [32]byte, common.Address) (*types.Transaction, error)); ok { + return rf(opts, batches, indexL1InfoRoot, maxSequenceTimestamp, expectedFinalAccInputHash, l2Coinbase) + } + if rf, ok := ret.Get(0).(func(*bind.TransactOpts, []polygonvalidiumetrog.PolygonRollupBaseEtrogBatchData, uint32, uint64, [32]byte, common.Address) *types.Transaction); ok { + r0 = rf(opts, batches, indexL1InfoRoot, maxSequenceTimestamp, expectedFinalAccInputHash, l2Coinbase) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.Transaction) + } + } + + if rf, ok := ret.Get(1).(func(*bind.TransactOpts, []polygonvalidiumetrog.PolygonRollupBaseEtrogBatchData, uint32, uint64, [32]byte, common.Address) error); ok { + r1 = rf(opts, batches, indexL1InfoRoot, maxSequenceTimestamp, expectedFinalAccInputHash, l2Coinbase) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// rollupBananaZKEVMContractor_SequenceBatches_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SequenceBatches' +type rollupBananaZKEVMContractor_SequenceBatches_Call struct { + *mock.Call +} + +// SequenceBatches is a helper method to define mock.On call +// - opts *bind.TransactOpts +// - batches []polygonvalidiumetrog.PolygonRollupBaseEtrogBatchData +// - indexL1InfoRoot uint32 +// - maxSequenceTimestamp uint64 +// - expectedFinalAccInputHash [32]byte +// - l2Coinbase common.Address +func (_e *rollupBananaZKEVMContractor_Expecter) SequenceBatches(opts interface{}, batches interface{}, indexL1InfoRoot interface{}, maxSequenceTimestamp interface{}, expectedFinalAccInputHash interface{}, l2Coinbase interface{}) *rollupBananaZKEVMContractor_SequenceBatches_Call { + return &rollupBananaZKEVMContractor_SequenceBatches_Call{Call: _e.mock.On("SequenceBatches", opts, batches, indexL1InfoRoot, maxSequenceTimestamp, expectedFinalAccInputHash, l2Coinbase)} +} + +func (_c *rollupBananaZKEVMContractor_SequenceBatches_Call) Run(run func(opts *bind.TransactOpts, batches []polygonvalidiumetrog.PolygonRollupBaseEtrogBatchData, indexL1InfoRoot uint32, maxSequenceTimestamp uint64, expectedFinalAccInputHash [32]byte, l2Coinbase common.Address)) *rollupBananaZKEVMContractor_SequenceBatches_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*bind.TransactOpts), args[1].([]polygonvalidiumetrog.PolygonRollupBaseEtrogBatchData), args[2].(uint32), args[3].(uint64), args[4].([32]byte), args[5].(common.Address)) + }) + return _c +} + +func (_c *rollupBananaZKEVMContractor_SequenceBatches_Call) Return(_a0 *types.Transaction, _a1 error) *rollupBananaZKEVMContractor_SequenceBatches_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *rollupBananaZKEVMContractor_SequenceBatches_Call) RunAndReturn(run func(*bind.TransactOpts, []polygonvalidiumetrog.PolygonRollupBaseEtrogBatchData, uint32, uint64, [32]byte, common.Address) (*types.Transaction, error)) *rollupBananaZKEVMContractor_SequenceBatches_Call { + _c.Call.Return(run) + return _c +} + +// newRollupBananaZKEVMContractor creates a new instance of rollupBananaZKEVMContractor. 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 newRollupBananaZKEVMContractor(t interface { + mock.TestingT + Cleanup(func()) +}) *rollupBananaZKEVMContractor { + mock := &rollupBananaZKEVMContractor{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/sequencesender/txbuilder/mocks_txbuilder/rollup_elderberry_validium_contractor.go b/sequencesender/txbuilder/mocks_txbuilder/rollup_elderberry_validium_contractor.go new file mode 100644 index 00000000..8560234f --- /dev/null +++ b/sequencesender/txbuilder/mocks_txbuilder/rollup_elderberry_validium_contractor.go @@ -0,0 +1,104 @@ +// Code generated by mockery. DO NOT EDIT. + +package mocks_txbuilder + +import ( + bind "github.com/ethereum/go-ethereum/accounts/abi/bind" + common "github.com/ethereum/go-ethereum/common" + + mock "github.com/stretchr/testify/mock" + + polygonvalidiumetrog "github.com/0xPolygon/cdk-contracts-tooling/contracts/elderberry/polygonvalidiumetrog" + + types "github.com/ethereum/go-ethereum/core/types" +) + +// rollupElderberryValidiumContractor is an autogenerated mock type for the rollupElderberryValidiumContractor type +type rollupElderberryValidiumContractor struct { + mock.Mock +} + +type rollupElderberryValidiumContractor_Expecter struct { + mock *mock.Mock +} + +func (_m *rollupElderberryValidiumContractor) EXPECT() *rollupElderberryValidiumContractor_Expecter { + return &rollupElderberryValidiumContractor_Expecter{mock: &_m.Mock} +} + +// SequenceBatchesValidium provides a mock function with given fields: opts, batches, maxSequenceTimestamp, initSequencedBatch, l2Coinbase, dataAvailabilityMessage +func (_m *rollupElderberryValidiumContractor) SequenceBatchesValidium(opts *bind.TransactOpts, batches []polygonvalidiumetrog.PolygonValidiumEtrogValidiumBatchData, maxSequenceTimestamp uint64, initSequencedBatch uint64, l2Coinbase common.Address, dataAvailabilityMessage []byte) (*types.Transaction, error) { + ret := _m.Called(opts, batches, maxSequenceTimestamp, initSequencedBatch, l2Coinbase, dataAvailabilityMessage) + + if len(ret) == 0 { + panic("no return value specified for SequenceBatchesValidium") + } + + var r0 *types.Transaction + var r1 error + if rf, ok := ret.Get(0).(func(*bind.TransactOpts, []polygonvalidiumetrog.PolygonValidiumEtrogValidiumBatchData, uint64, uint64, common.Address, []byte) (*types.Transaction, error)); ok { + return rf(opts, batches, maxSequenceTimestamp, initSequencedBatch, l2Coinbase, dataAvailabilityMessage) + } + if rf, ok := ret.Get(0).(func(*bind.TransactOpts, []polygonvalidiumetrog.PolygonValidiumEtrogValidiumBatchData, uint64, uint64, common.Address, []byte) *types.Transaction); ok { + r0 = rf(opts, batches, maxSequenceTimestamp, initSequencedBatch, l2Coinbase, dataAvailabilityMessage) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.Transaction) + } + } + + if rf, ok := ret.Get(1).(func(*bind.TransactOpts, []polygonvalidiumetrog.PolygonValidiumEtrogValidiumBatchData, uint64, uint64, common.Address, []byte) error); ok { + r1 = rf(opts, batches, maxSequenceTimestamp, initSequencedBatch, l2Coinbase, dataAvailabilityMessage) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// rollupElderberryValidiumContractor_SequenceBatchesValidium_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SequenceBatchesValidium' +type rollupElderberryValidiumContractor_SequenceBatchesValidium_Call struct { + *mock.Call +} + +// SequenceBatchesValidium is a helper method to define mock.On call +// - opts *bind.TransactOpts +// - batches []polygonvalidiumetrog.PolygonValidiumEtrogValidiumBatchData +// - maxSequenceTimestamp uint64 +// - initSequencedBatch uint64 +// - l2Coinbase common.Address +// - dataAvailabilityMessage []byte +func (_e *rollupElderberryValidiumContractor_Expecter) SequenceBatchesValidium(opts interface{}, batches interface{}, maxSequenceTimestamp interface{}, initSequencedBatch interface{}, l2Coinbase interface{}, dataAvailabilityMessage interface{}) *rollupElderberryValidiumContractor_SequenceBatchesValidium_Call { + return &rollupElderberryValidiumContractor_SequenceBatchesValidium_Call{Call: _e.mock.On("SequenceBatchesValidium", opts, batches, maxSequenceTimestamp, initSequencedBatch, l2Coinbase, dataAvailabilityMessage)} +} + +func (_c *rollupElderberryValidiumContractor_SequenceBatchesValidium_Call) Run(run func(opts *bind.TransactOpts, batches []polygonvalidiumetrog.PolygonValidiumEtrogValidiumBatchData, maxSequenceTimestamp uint64, initSequencedBatch uint64, l2Coinbase common.Address, dataAvailabilityMessage []byte)) *rollupElderberryValidiumContractor_SequenceBatchesValidium_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*bind.TransactOpts), args[1].([]polygonvalidiumetrog.PolygonValidiumEtrogValidiumBatchData), args[2].(uint64), args[3].(uint64), args[4].(common.Address), args[5].([]byte)) + }) + return _c +} + +func (_c *rollupElderberryValidiumContractor_SequenceBatchesValidium_Call) Return(_a0 *types.Transaction, _a1 error) *rollupElderberryValidiumContractor_SequenceBatchesValidium_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *rollupElderberryValidiumContractor_SequenceBatchesValidium_Call) RunAndReturn(run func(*bind.TransactOpts, []polygonvalidiumetrog.PolygonValidiumEtrogValidiumBatchData, uint64, uint64, common.Address, []byte) (*types.Transaction, error)) *rollupElderberryValidiumContractor_SequenceBatchesValidium_Call { + _c.Call.Return(run) + return _c +} + +// newRollupElderberryValidiumContractor creates a new instance of rollupElderberryValidiumContractor. 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 newRollupElderberryValidiumContractor(t interface { + mock.TestingT + Cleanup(func()) +}) *rollupElderberryValidiumContractor { + mock := &rollupElderberryValidiumContractor{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/sequencesender/txbuilder/mocks_txbuilder/rollup_elderberry_zkevm_contractor.go b/sequencesender/txbuilder/mocks_txbuilder/rollup_elderberry_zkevm_contractor.go new file mode 100644 index 00000000..aa662419 --- /dev/null +++ b/sequencesender/txbuilder/mocks_txbuilder/rollup_elderberry_zkevm_contractor.go @@ -0,0 +1,103 @@ +// Code generated by mockery. DO NOT EDIT. + +package mocks_txbuilder + +import ( + bind "github.com/ethereum/go-ethereum/accounts/abi/bind" + common "github.com/ethereum/go-ethereum/common" + + mock "github.com/stretchr/testify/mock" + + polygonvalidiumetrog "github.com/0xPolygon/cdk-contracts-tooling/contracts/elderberry/polygonvalidiumetrog" + + types "github.com/ethereum/go-ethereum/core/types" +) + +// rollupElderberryZKEVMContractor is an autogenerated mock type for the rollupElderberryZKEVMContractor type +type rollupElderberryZKEVMContractor struct { + mock.Mock +} + +type rollupElderberryZKEVMContractor_Expecter struct { + mock *mock.Mock +} + +func (_m *rollupElderberryZKEVMContractor) EXPECT() *rollupElderberryZKEVMContractor_Expecter { + return &rollupElderberryZKEVMContractor_Expecter{mock: &_m.Mock} +} + +// SequenceBatches provides a mock function with given fields: opts, batches, maxSequenceTimestamp, initSequencedBatch, l2Coinbase +func (_m *rollupElderberryZKEVMContractor) SequenceBatches(opts *bind.TransactOpts, batches []polygonvalidiumetrog.PolygonRollupBaseEtrogBatchData, maxSequenceTimestamp uint64, initSequencedBatch uint64, l2Coinbase common.Address) (*types.Transaction, error) { + ret := _m.Called(opts, batches, maxSequenceTimestamp, initSequencedBatch, l2Coinbase) + + if len(ret) == 0 { + panic("no return value specified for SequenceBatches") + } + + var r0 *types.Transaction + var r1 error + if rf, ok := ret.Get(0).(func(*bind.TransactOpts, []polygonvalidiumetrog.PolygonRollupBaseEtrogBatchData, uint64, uint64, common.Address) (*types.Transaction, error)); ok { + return rf(opts, batches, maxSequenceTimestamp, initSequencedBatch, l2Coinbase) + } + if rf, ok := ret.Get(0).(func(*bind.TransactOpts, []polygonvalidiumetrog.PolygonRollupBaseEtrogBatchData, uint64, uint64, common.Address) *types.Transaction); ok { + r0 = rf(opts, batches, maxSequenceTimestamp, initSequencedBatch, l2Coinbase) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*types.Transaction) + } + } + + if rf, ok := ret.Get(1).(func(*bind.TransactOpts, []polygonvalidiumetrog.PolygonRollupBaseEtrogBatchData, uint64, uint64, common.Address) error); ok { + r1 = rf(opts, batches, maxSequenceTimestamp, initSequencedBatch, l2Coinbase) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// rollupElderberryZKEVMContractor_SequenceBatches_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SequenceBatches' +type rollupElderberryZKEVMContractor_SequenceBatches_Call struct { + *mock.Call +} + +// SequenceBatches is a helper method to define mock.On call +// - opts *bind.TransactOpts +// - batches []polygonvalidiumetrog.PolygonRollupBaseEtrogBatchData +// - maxSequenceTimestamp uint64 +// - initSequencedBatch uint64 +// - l2Coinbase common.Address +func (_e *rollupElderberryZKEVMContractor_Expecter) SequenceBatches(opts interface{}, batches interface{}, maxSequenceTimestamp interface{}, initSequencedBatch interface{}, l2Coinbase interface{}) *rollupElderberryZKEVMContractor_SequenceBatches_Call { + return &rollupElderberryZKEVMContractor_SequenceBatches_Call{Call: _e.mock.On("SequenceBatches", opts, batches, maxSequenceTimestamp, initSequencedBatch, l2Coinbase)} +} + +func (_c *rollupElderberryZKEVMContractor_SequenceBatches_Call) Run(run func(opts *bind.TransactOpts, batches []polygonvalidiumetrog.PolygonRollupBaseEtrogBatchData, maxSequenceTimestamp uint64, initSequencedBatch uint64, l2Coinbase common.Address)) *rollupElderberryZKEVMContractor_SequenceBatches_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*bind.TransactOpts), args[1].([]polygonvalidiumetrog.PolygonRollupBaseEtrogBatchData), args[2].(uint64), args[3].(uint64), args[4].(common.Address)) + }) + return _c +} + +func (_c *rollupElderberryZKEVMContractor_SequenceBatches_Call) Return(_a0 *types.Transaction, _a1 error) *rollupElderberryZKEVMContractor_SequenceBatches_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *rollupElderberryZKEVMContractor_SequenceBatches_Call) RunAndReturn(run func(*bind.TransactOpts, []polygonvalidiumetrog.PolygonRollupBaseEtrogBatchData, uint64, uint64, common.Address) (*types.Transaction, error)) *rollupElderberryZKEVMContractor_SequenceBatches_Call { + _c.Call.Return(run) + return _c +} + +// newRollupElderberryZKEVMContractor creates a new instance of rollupElderberryZKEVMContractor. 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 newRollupElderberryZKEVMContractor(t interface { + mock.TestingT + Cleanup(func()) +}) *rollupElderberryZKEVMContractor { + mock := &rollupElderberryZKEVMContractor{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} From 4bbe28955f4fc28813f2ebae9bc958edce23d591 Mon Sep 17 00:00:00 2001 From: joanestebanr <129153821+joanestebanr@users.noreply.github.com> Date: Tue, 30 Jul 2024 21:49:03 +0200 Subject: [PATCH 04/10] generate puiblic mocks for private interfaces --- dataavailability/mocks_da/func_sign_type.go | 34 ++++++------- .../global_exit_root_banana_contractor.go | 50 +++++++++---------- ...lobal_exit_root_banana_zkevm_contractor.go | 50 +++++++++---------- .../rollup_banana_base_contractor.go | 34 ++++++------- .../rollup_banana_validium_contractor.go | 50 +++++++++---------- .../rollup_banana_zkevm_contractor.go | 50 +++++++++---------- .../rollup_elderberry_validium_contractor.go | 34 ++++++------- .../rollup_elderberry_zkevm_contractor.go | 34 ++++++------- test/Makefile | 2 +- 9 files changed, 169 insertions(+), 169 deletions(-) diff --git a/dataavailability/mocks_da/func_sign_type.go b/dataavailability/mocks_da/func_sign_type.go index 3efa4e42..6a343269 100644 --- a/dataavailability/mocks_da/func_sign_type.go +++ b/dataavailability/mocks_da/func_sign_type.go @@ -8,21 +8,21 @@ import ( mock "github.com/stretchr/testify/mock" ) -// funcSignType is an autogenerated mock type for the funcSignType type -type funcSignType struct { +// FuncSignType is an autogenerated mock type for the funcSignType type +type FuncSignType struct { mock.Mock } -type funcSignType_Expecter struct { +type FuncSignType_Expecter struct { mock *mock.Mock } -func (_m *funcSignType) EXPECT() *funcSignType_Expecter { - return &funcSignType_Expecter{mock: &_m.Mock} +func (_m *FuncSignType) EXPECT() *FuncSignType_Expecter { + return &FuncSignType_Expecter{mock: &_m.Mock} } // Execute provides a mock function with given fields: c -func (_m *funcSignType) Execute(c client.Client) ([]byte, error) { +func (_m *FuncSignType) Execute(c client.Client) ([]byte, error) { ret := _m.Called(c) if len(ret) == 0 { @@ -51,41 +51,41 @@ func (_m *funcSignType) Execute(c client.Client) ([]byte, error) { return r0, r1 } -// funcSignType_Execute_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Execute' -type funcSignType_Execute_Call struct { +// FuncSignType_Execute_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Execute' +type FuncSignType_Execute_Call struct { *mock.Call } // Execute is a helper method to define mock.On call // - c client.Client -func (_e *funcSignType_Expecter) Execute(c interface{}) *funcSignType_Execute_Call { - return &funcSignType_Execute_Call{Call: _e.mock.On("Execute", c)} +func (_e *FuncSignType_Expecter) Execute(c interface{}) *FuncSignType_Execute_Call { + return &FuncSignType_Execute_Call{Call: _e.mock.On("Execute", c)} } -func (_c *funcSignType_Execute_Call) Run(run func(c client.Client)) *funcSignType_Execute_Call { +func (_c *FuncSignType_Execute_Call) Run(run func(c client.Client)) *FuncSignType_Execute_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(client.Client)) }) return _c } -func (_c *funcSignType_Execute_Call) Return(_a0 []byte, _a1 error) *funcSignType_Execute_Call { +func (_c *FuncSignType_Execute_Call) Return(_a0 []byte, _a1 error) *FuncSignType_Execute_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *funcSignType_Execute_Call) RunAndReturn(run func(client.Client) ([]byte, error)) *funcSignType_Execute_Call { +func (_c *FuncSignType_Execute_Call) RunAndReturn(run func(client.Client) ([]byte, error)) *FuncSignType_Execute_Call { _c.Call.Return(run) return _c } -// newFuncSignType creates a new instance of funcSignType. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// NewFuncSignType creates a new instance of FuncSignType. 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 newFuncSignType(t interface { +func NewFuncSignType(t interface { mock.TestingT Cleanup(func()) -}) *funcSignType { - mock := &funcSignType{} +}) *FuncSignType { + mock := &FuncSignType{} mock.Mock.Test(t) t.Cleanup(func() { mock.AssertExpectations(t) }) diff --git a/sequencesender/txbuilder/mocks_txbuilder/global_exit_root_banana_contractor.go b/sequencesender/txbuilder/mocks_txbuilder/global_exit_root_banana_contractor.go index b6be951b..93dadeef 100644 --- a/sequencesender/txbuilder/mocks_txbuilder/global_exit_root_banana_contractor.go +++ b/sequencesender/txbuilder/mocks_txbuilder/global_exit_root_banana_contractor.go @@ -7,21 +7,21 @@ import ( mock "github.com/stretchr/testify/mock" ) -// globalExitRootBananaContractor is an autogenerated mock type for the globalExitRootBananaContractor type -type globalExitRootBananaContractor struct { +// GlobalExitRootBananaContractor is an autogenerated mock type for the globalExitRootBananaContractor type +type GlobalExitRootBananaContractor struct { mock.Mock } -type globalExitRootBananaContractor_Expecter struct { +type GlobalExitRootBananaContractor_Expecter struct { mock *mock.Mock } -func (_m *globalExitRootBananaContractor) EXPECT() *globalExitRootBananaContractor_Expecter { - return &globalExitRootBananaContractor_Expecter{mock: &_m.Mock} +func (_m *GlobalExitRootBananaContractor) EXPECT() *GlobalExitRootBananaContractor_Expecter { + return &GlobalExitRootBananaContractor_Expecter{mock: &_m.Mock} } // L1InfoRootMap provides a mock function with given fields: opts, index -func (_m *globalExitRootBananaContractor) L1InfoRootMap(opts *bind.CallOpts, index uint32) ([32]byte, error) { +func (_m *GlobalExitRootBananaContractor) L1InfoRootMap(opts *bind.CallOpts, index uint32) ([32]byte, error) { ret := _m.Called(opts, index) if len(ret) == 0 { @@ -50,37 +50,37 @@ func (_m *globalExitRootBananaContractor) L1InfoRootMap(opts *bind.CallOpts, ind return r0, r1 } -// globalExitRootBananaContractor_L1InfoRootMap_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'L1InfoRootMap' -type globalExitRootBananaContractor_L1InfoRootMap_Call struct { +// GlobalExitRootBananaContractor_L1InfoRootMap_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'L1InfoRootMap' +type GlobalExitRootBananaContractor_L1InfoRootMap_Call struct { *mock.Call } // L1InfoRootMap is a helper method to define mock.On call // - opts *bind.CallOpts // - index uint32 -func (_e *globalExitRootBananaContractor_Expecter) L1InfoRootMap(opts interface{}, index interface{}) *globalExitRootBananaContractor_L1InfoRootMap_Call { - return &globalExitRootBananaContractor_L1InfoRootMap_Call{Call: _e.mock.On("L1InfoRootMap", opts, index)} +func (_e *GlobalExitRootBananaContractor_Expecter) L1InfoRootMap(opts interface{}, index interface{}) *GlobalExitRootBananaContractor_L1InfoRootMap_Call { + return &GlobalExitRootBananaContractor_L1InfoRootMap_Call{Call: _e.mock.On("L1InfoRootMap", opts, index)} } -func (_c *globalExitRootBananaContractor_L1InfoRootMap_Call) Run(run func(opts *bind.CallOpts, index uint32)) *globalExitRootBananaContractor_L1InfoRootMap_Call { +func (_c *GlobalExitRootBananaContractor_L1InfoRootMap_Call) Run(run func(opts *bind.CallOpts, index uint32)) *GlobalExitRootBananaContractor_L1InfoRootMap_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(*bind.CallOpts), args[1].(uint32)) }) return _c } -func (_c *globalExitRootBananaContractor_L1InfoRootMap_Call) Return(_a0 [32]byte, _a1 error) *globalExitRootBananaContractor_L1InfoRootMap_Call { +func (_c *GlobalExitRootBananaContractor_L1InfoRootMap_Call) Return(_a0 [32]byte, _a1 error) *GlobalExitRootBananaContractor_L1InfoRootMap_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *globalExitRootBananaContractor_L1InfoRootMap_Call) RunAndReturn(run func(*bind.CallOpts, uint32) ([32]byte, error)) *globalExitRootBananaContractor_L1InfoRootMap_Call { +func (_c *GlobalExitRootBananaContractor_L1InfoRootMap_Call) RunAndReturn(run func(*bind.CallOpts, uint32) ([32]byte, error)) *GlobalExitRootBananaContractor_L1InfoRootMap_Call { _c.Call.Return(run) return _c } // String provides a mock function with given fields: -func (_m *globalExitRootBananaContractor) String() string { +func (_m *GlobalExitRootBananaContractor) String() string { ret := _m.Called() if len(ret) == 0 { @@ -97,40 +97,40 @@ func (_m *globalExitRootBananaContractor) String() string { return r0 } -// globalExitRootBananaContractor_String_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'String' -type globalExitRootBananaContractor_String_Call struct { +// GlobalExitRootBananaContractor_String_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'String' +type GlobalExitRootBananaContractor_String_Call struct { *mock.Call } // String is a helper method to define mock.On call -func (_e *globalExitRootBananaContractor_Expecter) String() *globalExitRootBananaContractor_String_Call { - return &globalExitRootBananaContractor_String_Call{Call: _e.mock.On("String")} +func (_e *GlobalExitRootBananaContractor_Expecter) String() *GlobalExitRootBananaContractor_String_Call { + return &GlobalExitRootBananaContractor_String_Call{Call: _e.mock.On("String")} } -func (_c *globalExitRootBananaContractor_String_Call) Run(run func()) *globalExitRootBananaContractor_String_Call { +func (_c *GlobalExitRootBananaContractor_String_Call) Run(run func()) *GlobalExitRootBananaContractor_String_Call { _c.Call.Run(func(args mock.Arguments) { run() }) return _c } -func (_c *globalExitRootBananaContractor_String_Call) Return(_a0 string) *globalExitRootBananaContractor_String_Call { +func (_c *GlobalExitRootBananaContractor_String_Call) Return(_a0 string) *GlobalExitRootBananaContractor_String_Call { _c.Call.Return(_a0) return _c } -func (_c *globalExitRootBananaContractor_String_Call) RunAndReturn(run func() string) *globalExitRootBananaContractor_String_Call { +func (_c *GlobalExitRootBananaContractor_String_Call) RunAndReturn(run func() string) *GlobalExitRootBananaContractor_String_Call { _c.Call.Return(run) return _c } -// newGlobalExitRootBananaContractor creates a new instance of globalExitRootBananaContractor. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// NewGlobalExitRootBananaContractor creates a new instance of GlobalExitRootBananaContractor. 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 newGlobalExitRootBananaContractor(t interface { +func NewGlobalExitRootBananaContractor(t interface { mock.TestingT Cleanup(func()) -}) *globalExitRootBananaContractor { - mock := &globalExitRootBananaContractor{} +}) *GlobalExitRootBananaContractor { + mock := &GlobalExitRootBananaContractor{} mock.Mock.Test(t) t.Cleanup(func() { mock.AssertExpectations(t) }) diff --git a/sequencesender/txbuilder/mocks_txbuilder/global_exit_root_banana_zkevm_contractor.go b/sequencesender/txbuilder/mocks_txbuilder/global_exit_root_banana_zkevm_contractor.go index 0f979cb4..f7aed125 100644 --- a/sequencesender/txbuilder/mocks_txbuilder/global_exit_root_banana_zkevm_contractor.go +++ b/sequencesender/txbuilder/mocks_txbuilder/global_exit_root_banana_zkevm_contractor.go @@ -7,21 +7,21 @@ import ( mock "github.com/stretchr/testify/mock" ) -// globalExitRootBananaZKEVMContractor is an autogenerated mock type for the globalExitRootBananaZKEVMContractor type -type globalExitRootBananaZKEVMContractor struct { +// GlobalExitRootBananaZKEVMContractor is an autogenerated mock type for the globalExitRootBananaZKEVMContractor type +type GlobalExitRootBananaZKEVMContractor struct { mock.Mock } -type globalExitRootBananaZKEVMContractor_Expecter struct { +type GlobalExitRootBananaZKEVMContractor_Expecter struct { mock *mock.Mock } -func (_m *globalExitRootBananaZKEVMContractor) EXPECT() *globalExitRootBananaZKEVMContractor_Expecter { - return &globalExitRootBananaZKEVMContractor_Expecter{mock: &_m.Mock} +func (_m *GlobalExitRootBananaZKEVMContractor) EXPECT() *GlobalExitRootBananaZKEVMContractor_Expecter { + return &GlobalExitRootBananaZKEVMContractor_Expecter{mock: &_m.Mock} } // L1InfoRootMap provides a mock function with given fields: opts, index -func (_m *globalExitRootBananaZKEVMContractor) L1InfoRootMap(opts *bind.CallOpts, index uint32) ([32]byte, error) { +func (_m *GlobalExitRootBananaZKEVMContractor) L1InfoRootMap(opts *bind.CallOpts, index uint32) ([32]byte, error) { ret := _m.Called(opts, index) if len(ret) == 0 { @@ -50,37 +50,37 @@ func (_m *globalExitRootBananaZKEVMContractor) L1InfoRootMap(opts *bind.CallOpts return r0, r1 } -// globalExitRootBananaZKEVMContractor_L1InfoRootMap_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'L1InfoRootMap' -type globalExitRootBananaZKEVMContractor_L1InfoRootMap_Call struct { +// GlobalExitRootBananaZKEVMContractor_L1InfoRootMap_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'L1InfoRootMap' +type GlobalExitRootBananaZKEVMContractor_L1InfoRootMap_Call struct { *mock.Call } // L1InfoRootMap is a helper method to define mock.On call // - opts *bind.CallOpts // - index uint32 -func (_e *globalExitRootBananaZKEVMContractor_Expecter) L1InfoRootMap(opts interface{}, index interface{}) *globalExitRootBananaZKEVMContractor_L1InfoRootMap_Call { - return &globalExitRootBananaZKEVMContractor_L1InfoRootMap_Call{Call: _e.mock.On("L1InfoRootMap", opts, index)} +func (_e *GlobalExitRootBananaZKEVMContractor_Expecter) L1InfoRootMap(opts interface{}, index interface{}) *GlobalExitRootBananaZKEVMContractor_L1InfoRootMap_Call { + return &GlobalExitRootBananaZKEVMContractor_L1InfoRootMap_Call{Call: _e.mock.On("L1InfoRootMap", opts, index)} } -func (_c *globalExitRootBananaZKEVMContractor_L1InfoRootMap_Call) Run(run func(opts *bind.CallOpts, index uint32)) *globalExitRootBananaZKEVMContractor_L1InfoRootMap_Call { +func (_c *GlobalExitRootBananaZKEVMContractor_L1InfoRootMap_Call) Run(run func(opts *bind.CallOpts, index uint32)) *GlobalExitRootBananaZKEVMContractor_L1InfoRootMap_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(*bind.CallOpts), args[1].(uint32)) }) return _c } -func (_c *globalExitRootBananaZKEVMContractor_L1InfoRootMap_Call) Return(_a0 [32]byte, _a1 error) *globalExitRootBananaZKEVMContractor_L1InfoRootMap_Call { +func (_c *GlobalExitRootBananaZKEVMContractor_L1InfoRootMap_Call) Return(_a0 [32]byte, _a1 error) *GlobalExitRootBananaZKEVMContractor_L1InfoRootMap_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *globalExitRootBananaZKEVMContractor_L1InfoRootMap_Call) RunAndReturn(run func(*bind.CallOpts, uint32) ([32]byte, error)) *globalExitRootBananaZKEVMContractor_L1InfoRootMap_Call { +func (_c *GlobalExitRootBananaZKEVMContractor_L1InfoRootMap_Call) RunAndReturn(run func(*bind.CallOpts, uint32) ([32]byte, error)) *GlobalExitRootBananaZKEVMContractor_L1InfoRootMap_Call { _c.Call.Return(run) return _c } // String provides a mock function with given fields: -func (_m *globalExitRootBananaZKEVMContractor) String() string { +func (_m *GlobalExitRootBananaZKEVMContractor) String() string { ret := _m.Called() if len(ret) == 0 { @@ -97,40 +97,40 @@ func (_m *globalExitRootBananaZKEVMContractor) String() string { return r0 } -// globalExitRootBananaZKEVMContractor_String_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'String' -type globalExitRootBananaZKEVMContractor_String_Call struct { +// GlobalExitRootBananaZKEVMContractor_String_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'String' +type GlobalExitRootBananaZKEVMContractor_String_Call struct { *mock.Call } // String is a helper method to define mock.On call -func (_e *globalExitRootBananaZKEVMContractor_Expecter) String() *globalExitRootBananaZKEVMContractor_String_Call { - return &globalExitRootBananaZKEVMContractor_String_Call{Call: _e.mock.On("String")} +func (_e *GlobalExitRootBananaZKEVMContractor_Expecter) String() *GlobalExitRootBananaZKEVMContractor_String_Call { + return &GlobalExitRootBananaZKEVMContractor_String_Call{Call: _e.mock.On("String")} } -func (_c *globalExitRootBananaZKEVMContractor_String_Call) Run(run func()) *globalExitRootBananaZKEVMContractor_String_Call { +func (_c *GlobalExitRootBananaZKEVMContractor_String_Call) Run(run func()) *GlobalExitRootBananaZKEVMContractor_String_Call { _c.Call.Run(func(args mock.Arguments) { run() }) return _c } -func (_c *globalExitRootBananaZKEVMContractor_String_Call) Return(_a0 string) *globalExitRootBananaZKEVMContractor_String_Call { +func (_c *GlobalExitRootBananaZKEVMContractor_String_Call) Return(_a0 string) *GlobalExitRootBananaZKEVMContractor_String_Call { _c.Call.Return(_a0) return _c } -func (_c *globalExitRootBananaZKEVMContractor_String_Call) RunAndReturn(run func() string) *globalExitRootBananaZKEVMContractor_String_Call { +func (_c *GlobalExitRootBananaZKEVMContractor_String_Call) RunAndReturn(run func() string) *GlobalExitRootBananaZKEVMContractor_String_Call { _c.Call.Return(run) return _c } -// newGlobalExitRootBananaZKEVMContractor creates a new instance of globalExitRootBananaZKEVMContractor. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// NewGlobalExitRootBananaZKEVMContractor creates a new instance of GlobalExitRootBananaZKEVMContractor. 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 newGlobalExitRootBananaZKEVMContractor(t interface { +func NewGlobalExitRootBananaZKEVMContractor(t interface { mock.TestingT Cleanup(func()) -}) *globalExitRootBananaZKEVMContractor { - mock := &globalExitRootBananaZKEVMContractor{} +}) *GlobalExitRootBananaZKEVMContractor { + mock := &GlobalExitRootBananaZKEVMContractor{} mock.Mock.Test(t) t.Cleanup(func() { mock.AssertExpectations(t) }) diff --git a/sequencesender/txbuilder/mocks_txbuilder/rollup_banana_base_contractor.go b/sequencesender/txbuilder/mocks_txbuilder/rollup_banana_base_contractor.go index 85e82206..acd82a4e 100644 --- a/sequencesender/txbuilder/mocks_txbuilder/rollup_banana_base_contractor.go +++ b/sequencesender/txbuilder/mocks_txbuilder/rollup_banana_base_contractor.go @@ -7,21 +7,21 @@ import ( mock "github.com/stretchr/testify/mock" ) -// rollupBananaBaseContractor is an autogenerated mock type for the rollupBananaBaseContractor type -type rollupBananaBaseContractor struct { +// RollupBananaBaseContractor is an autogenerated mock type for the rollupBananaBaseContractor type +type RollupBananaBaseContractor struct { mock.Mock } -type rollupBananaBaseContractor_Expecter struct { +type RollupBananaBaseContractor_Expecter struct { mock *mock.Mock } -func (_m *rollupBananaBaseContractor) EXPECT() *rollupBananaBaseContractor_Expecter { - return &rollupBananaBaseContractor_Expecter{mock: &_m.Mock} +func (_m *RollupBananaBaseContractor) EXPECT() *RollupBananaBaseContractor_Expecter { + return &RollupBananaBaseContractor_Expecter{mock: &_m.Mock} } // LastAccInputHash provides a mock function with given fields: opts -func (_m *rollupBananaBaseContractor) LastAccInputHash(opts *bind.CallOpts) ([32]byte, error) { +func (_m *RollupBananaBaseContractor) LastAccInputHash(opts *bind.CallOpts) ([32]byte, error) { ret := _m.Called(opts) if len(ret) == 0 { @@ -50,41 +50,41 @@ func (_m *rollupBananaBaseContractor) LastAccInputHash(opts *bind.CallOpts) ([32 return r0, r1 } -// rollupBananaBaseContractor_LastAccInputHash_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LastAccInputHash' -type rollupBananaBaseContractor_LastAccInputHash_Call struct { +// RollupBananaBaseContractor_LastAccInputHash_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LastAccInputHash' +type RollupBananaBaseContractor_LastAccInputHash_Call struct { *mock.Call } // LastAccInputHash is a helper method to define mock.On call // - opts *bind.CallOpts -func (_e *rollupBananaBaseContractor_Expecter) LastAccInputHash(opts interface{}) *rollupBananaBaseContractor_LastAccInputHash_Call { - return &rollupBananaBaseContractor_LastAccInputHash_Call{Call: _e.mock.On("LastAccInputHash", opts)} +func (_e *RollupBananaBaseContractor_Expecter) LastAccInputHash(opts interface{}) *RollupBananaBaseContractor_LastAccInputHash_Call { + return &RollupBananaBaseContractor_LastAccInputHash_Call{Call: _e.mock.On("LastAccInputHash", opts)} } -func (_c *rollupBananaBaseContractor_LastAccInputHash_Call) Run(run func(opts *bind.CallOpts)) *rollupBananaBaseContractor_LastAccInputHash_Call { +func (_c *RollupBananaBaseContractor_LastAccInputHash_Call) Run(run func(opts *bind.CallOpts)) *RollupBananaBaseContractor_LastAccInputHash_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(*bind.CallOpts)) }) return _c } -func (_c *rollupBananaBaseContractor_LastAccInputHash_Call) Return(_a0 [32]byte, _a1 error) *rollupBananaBaseContractor_LastAccInputHash_Call { +func (_c *RollupBananaBaseContractor_LastAccInputHash_Call) Return(_a0 [32]byte, _a1 error) *RollupBananaBaseContractor_LastAccInputHash_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *rollupBananaBaseContractor_LastAccInputHash_Call) RunAndReturn(run func(*bind.CallOpts) ([32]byte, error)) *rollupBananaBaseContractor_LastAccInputHash_Call { +func (_c *RollupBananaBaseContractor_LastAccInputHash_Call) RunAndReturn(run func(*bind.CallOpts) ([32]byte, error)) *RollupBananaBaseContractor_LastAccInputHash_Call { _c.Call.Return(run) return _c } -// newRollupBananaBaseContractor creates a new instance of rollupBananaBaseContractor. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// NewRollupBananaBaseContractor creates a new instance of RollupBananaBaseContractor. 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 newRollupBananaBaseContractor(t interface { +func NewRollupBananaBaseContractor(t interface { mock.TestingT Cleanup(func()) -}) *rollupBananaBaseContractor { - mock := &rollupBananaBaseContractor{} +}) *RollupBananaBaseContractor { + mock := &RollupBananaBaseContractor{} mock.Mock.Test(t) t.Cleanup(func() { mock.AssertExpectations(t) }) diff --git a/sequencesender/txbuilder/mocks_txbuilder/rollup_banana_validium_contractor.go b/sequencesender/txbuilder/mocks_txbuilder/rollup_banana_validium_contractor.go index 430a45b8..a59b88dd 100644 --- a/sequencesender/txbuilder/mocks_txbuilder/rollup_banana_validium_contractor.go +++ b/sequencesender/txbuilder/mocks_txbuilder/rollup_banana_validium_contractor.go @@ -13,21 +13,21 @@ import ( types "github.com/ethereum/go-ethereum/core/types" ) -// rollupBananaValidiumContractor is an autogenerated mock type for the rollupBananaValidiumContractor type -type rollupBananaValidiumContractor struct { +// RollupBananaValidiumContractor is an autogenerated mock type for the rollupBananaValidiumContractor type +type RollupBananaValidiumContractor struct { mock.Mock } -type rollupBananaValidiumContractor_Expecter struct { +type RollupBananaValidiumContractor_Expecter struct { mock *mock.Mock } -func (_m *rollupBananaValidiumContractor) EXPECT() *rollupBananaValidiumContractor_Expecter { - return &rollupBananaValidiumContractor_Expecter{mock: &_m.Mock} +func (_m *RollupBananaValidiumContractor) EXPECT() *RollupBananaValidiumContractor_Expecter { + return &RollupBananaValidiumContractor_Expecter{mock: &_m.Mock} } // LastAccInputHash provides a mock function with given fields: opts -func (_m *rollupBananaValidiumContractor) LastAccInputHash(opts *bind.CallOpts) ([32]byte, error) { +func (_m *RollupBananaValidiumContractor) LastAccInputHash(opts *bind.CallOpts) ([32]byte, error) { ret := _m.Called(opts) if len(ret) == 0 { @@ -56,36 +56,36 @@ func (_m *rollupBananaValidiumContractor) LastAccInputHash(opts *bind.CallOpts) return r0, r1 } -// rollupBananaValidiumContractor_LastAccInputHash_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LastAccInputHash' -type rollupBananaValidiumContractor_LastAccInputHash_Call struct { +// RollupBananaValidiumContractor_LastAccInputHash_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LastAccInputHash' +type RollupBananaValidiumContractor_LastAccInputHash_Call struct { *mock.Call } // LastAccInputHash is a helper method to define mock.On call // - opts *bind.CallOpts -func (_e *rollupBananaValidiumContractor_Expecter) LastAccInputHash(opts interface{}) *rollupBananaValidiumContractor_LastAccInputHash_Call { - return &rollupBananaValidiumContractor_LastAccInputHash_Call{Call: _e.mock.On("LastAccInputHash", opts)} +func (_e *RollupBananaValidiumContractor_Expecter) LastAccInputHash(opts interface{}) *RollupBananaValidiumContractor_LastAccInputHash_Call { + return &RollupBananaValidiumContractor_LastAccInputHash_Call{Call: _e.mock.On("LastAccInputHash", opts)} } -func (_c *rollupBananaValidiumContractor_LastAccInputHash_Call) Run(run func(opts *bind.CallOpts)) *rollupBananaValidiumContractor_LastAccInputHash_Call { +func (_c *RollupBananaValidiumContractor_LastAccInputHash_Call) Run(run func(opts *bind.CallOpts)) *RollupBananaValidiumContractor_LastAccInputHash_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(*bind.CallOpts)) }) return _c } -func (_c *rollupBananaValidiumContractor_LastAccInputHash_Call) Return(_a0 [32]byte, _a1 error) *rollupBananaValidiumContractor_LastAccInputHash_Call { +func (_c *RollupBananaValidiumContractor_LastAccInputHash_Call) Return(_a0 [32]byte, _a1 error) *RollupBananaValidiumContractor_LastAccInputHash_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *rollupBananaValidiumContractor_LastAccInputHash_Call) RunAndReturn(run func(*bind.CallOpts) ([32]byte, error)) *rollupBananaValidiumContractor_LastAccInputHash_Call { +func (_c *RollupBananaValidiumContractor_LastAccInputHash_Call) RunAndReturn(run func(*bind.CallOpts) ([32]byte, error)) *RollupBananaValidiumContractor_LastAccInputHash_Call { _c.Call.Return(run) return _c } // SequenceBatchesValidium provides a mock function with given fields: opts, batches, indexL1InfoRoot, maxSequenceTimestamp, expectedFinalAccInputHash, l2Coinbase, dataAvailabilityMessage -func (_m *rollupBananaValidiumContractor) SequenceBatchesValidium(opts *bind.TransactOpts, batches []polygonvalidiumetrog.PolygonValidiumEtrogValidiumBatchData, indexL1InfoRoot uint32, maxSequenceTimestamp uint64, expectedFinalAccInputHash [32]byte, l2Coinbase common.Address, dataAvailabilityMessage []byte) (*types.Transaction, error) { +func (_m *RollupBananaValidiumContractor) SequenceBatchesValidium(opts *bind.TransactOpts, batches []polygonvalidiumetrog.PolygonValidiumEtrogValidiumBatchData, indexL1InfoRoot uint32, maxSequenceTimestamp uint64, expectedFinalAccInputHash [32]byte, l2Coinbase common.Address, dataAvailabilityMessage []byte) (*types.Transaction, error) { ret := _m.Called(opts, batches, indexL1InfoRoot, maxSequenceTimestamp, expectedFinalAccInputHash, l2Coinbase, dataAvailabilityMessage) if len(ret) == 0 { @@ -114,8 +114,8 @@ func (_m *rollupBananaValidiumContractor) SequenceBatchesValidium(opts *bind.Tra return r0, r1 } -// rollupBananaValidiumContractor_SequenceBatchesValidium_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SequenceBatchesValidium' -type rollupBananaValidiumContractor_SequenceBatchesValidium_Call struct { +// RollupBananaValidiumContractor_SequenceBatchesValidium_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SequenceBatchesValidium' +type RollupBananaValidiumContractor_SequenceBatchesValidium_Call struct { *mock.Call } @@ -127,34 +127,34 @@ type rollupBananaValidiumContractor_SequenceBatchesValidium_Call struct { // - expectedFinalAccInputHash [32]byte // - l2Coinbase common.Address // - dataAvailabilityMessage []byte -func (_e *rollupBananaValidiumContractor_Expecter) SequenceBatchesValidium(opts interface{}, batches interface{}, indexL1InfoRoot interface{}, maxSequenceTimestamp interface{}, expectedFinalAccInputHash interface{}, l2Coinbase interface{}, dataAvailabilityMessage interface{}) *rollupBananaValidiumContractor_SequenceBatchesValidium_Call { - return &rollupBananaValidiumContractor_SequenceBatchesValidium_Call{Call: _e.mock.On("SequenceBatchesValidium", opts, batches, indexL1InfoRoot, maxSequenceTimestamp, expectedFinalAccInputHash, l2Coinbase, dataAvailabilityMessage)} +func (_e *RollupBananaValidiumContractor_Expecter) SequenceBatchesValidium(opts interface{}, batches interface{}, indexL1InfoRoot interface{}, maxSequenceTimestamp interface{}, expectedFinalAccInputHash interface{}, l2Coinbase interface{}, dataAvailabilityMessage interface{}) *RollupBananaValidiumContractor_SequenceBatchesValidium_Call { + return &RollupBananaValidiumContractor_SequenceBatchesValidium_Call{Call: _e.mock.On("SequenceBatchesValidium", opts, batches, indexL1InfoRoot, maxSequenceTimestamp, expectedFinalAccInputHash, l2Coinbase, dataAvailabilityMessage)} } -func (_c *rollupBananaValidiumContractor_SequenceBatchesValidium_Call) Run(run func(opts *bind.TransactOpts, batches []polygonvalidiumetrog.PolygonValidiumEtrogValidiumBatchData, indexL1InfoRoot uint32, maxSequenceTimestamp uint64, expectedFinalAccInputHash [32]byte, l2Coinbase common.Address, dataAvailabilityMessage []byte)) *rollupBananaValidiumContractor_SequenceBatchesValidium_Call { +func (_c *RollupBananaValidiumContractor_SequenceBatchesValidium_Call) Run(run func(opts *bind.TransactOpts, batches []polygonvalidiumetrog.PolygonValidiumEtrogValidiumBatchData, indexL1InfoRoot uint32, maxSequenceTimestamp uint64, expectedFinalAccInputHash [32]byte, l2Coinbase common.Address, dataAvailabilityMessage []byte)) *RollupBananaValidiumContractor_SequenceBatchesValidium_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(*bind.TransactOpts), args[1].([]polygonvalidiumetrog.PolygonValidiumEtrogValidiumBatchData), args[2].(uint32), args[3].(uint64), args[4].([32]byte), args[5].(common.Address), args[6].([]byte)) }) return _c } -func (_c *rollupBananaValidiumContractor_SequenceBatchesValidium_Call) Return(_a0 *types.Transaction, _a1 error) *rollupBananaValidiumContractor_SequenceBatchesValidium_Call { +func (_c *RollupBananaValidiumContractor_SequenceBatchesValidium_Call) Return(_a0 *types.Transaction, _a1 error) *RollupBananaValidiumContractor_SequenceBatchesValidium_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *rollupBananaValidiumContractor_SequenceBatchesValidium_Call) RunAndReturn(run func(*bind.TransactOpts, []polygonvalidiumetrog.PolygonValidiumEtrogValidiumBatchData, uint32, uint64, [32]byte, common.Address, []byte) (*types.Transaction, error)) *rollupBananaValidiumContractor_SequenceBatchesValidium_Call { +func (_c *RollupBananaValidiumContractor_SequenceBatchesValidium_Call) RunAndReturn(run func(*bind.TransactOpts, []polygonvalidiumetrog.PolygonValidiumEtrogValidiumBatchData, uint32, uint64, [32]byte, common.Address, []byte) (*types.Transaction, error)) *RollupBananaValidiumContractor_SequenceBatchesValidium_Call { _c.Call.Return(run) return _c } -// newRollupBananaValidiumContractor creates a new instance of rollupBananaValidiumContractor. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// NewRollupBananaValidiumContractor creates a new instance of RollupBananaValidiumContractor. 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 newRollupBananaValidiumContractor(t interface { +func NewRollupBananaValidiumContractor(t interface { mock.TestingT Cleanup(func()) -}) *rollupBananaValidiumContractor { - mock := &rollupBananaValidiumContractor{} +}) *RollupBananaValidiumContractor { + mock := &RollupBananaValidiumContractor{} mock.Mock.Test(t) t.Cleanup(func() { mock.AssertExpectations(t) }) diff --git a/sequencesender/txbuilder/mocks_txbuilder/rollup_banana_zkevm_contractor.go b/sequencesender/txbuilder/mocks_txbuilder/rollup_banana_zkevm_contractor.go index 4576a0de..e29e3252 100644 --- a/sequencesender/txbuilder/mocks_txbuilder/rollup_banana_zkevm_contractor.go +++ b/sequencesender/txbuilder/mocks_txbuilder/rollup_banana_zkevm_contractor.go @@ -13,21 +13,21 @@ import ( types "github.com/ethereum/go-ethereum/core/types" ) -// rollupBananaZKEVMContractor is an autogenerated mock type for the rollupBananaZKEVMContractor type -type rollupBananaZKEVMContractor struct { +// RollupBananaZKEVMContractor is an autogenerated mock type for the rollupBananaZKEVMContractor type +type RollupBananaZKEVMContractor struct { mock.Mock } -type rollupBananaZKEVMContractor_Expecter struct { +type RollupBananaZKEVMContractor_Expecter struct { mock *mock.Mock } -func (_m *rollupBananaZKEVMContractor) EXPECT() *rollupBananaZKEVMContractor_Expecter { - return &rollupBananaZKEVMContractor_Expecter{mock: &_m.Mock} +func (_m *RollupBananaZKEVMContractor) EXPECT() *RollupBananaZKEVMContractor_Expecter { + return &RollupBananaZKEVMContractor_Expecter{mock: &_m.Mock} } // LastAccInputHash provides a mock function with given fields: opts -func (_m *rollupBananaZKEVMContractor) LastAccInputHash(opts *bind.CallOpts) ([32]byte, error) { +func (_m *RollupBananaZKEVMContractor) LastAccInputHash(opts *bind.CallOpts) ([32]byte, error) { ret := _m.Called(opts) if len(ret) == 0 { @@ -56,36 +56,36 @@ func (_m *rollupBananaZKEVMContractor) LastAccInputHash(opts *bind.CallOpts) ([3 return r0, r1 } -// rollupBananaZKEVMContractor_LastAccInputHash_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LastAccInputHash' -type rollupBananaZKEVMContractor_LastAccInputHash_Call struct { +// RollupBananaZKEVMContractor_LastAccInputHash_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LastAccInputHash' +type RollupBananaZKEVMContractor_LastAccInputHash_Call struct { *mock.Call } // LastAccInputHash is a helper method to define mock.On call // - opts *bind.CallOpts -func (_e *rollupBananaZKEVMContractor_Expecter) LastAccInputHash(opts interface{}) *rollupBananaZKEVMContractor_LastAccInputHash_Call { - return &rollupBananaZKEVMContractor_LastAccInputHash_Call{Call: _e.mock.On("LastAccInputHash", opts)} +func (_e *RollupBananaZKEVMContractor_Expecter) LastAccInputHash(opts interface{}) *RollupBananaZKEVMContractor_LastAccInputHash_Call { + return &RollupBananaZKEVMContractor_LastAccInputHash_Call{Call: _e.mock.On("LastAccInputHash", opts)} } -func (_c *rollupBananaZKEVMContractor_LastAccInputHash_Call) Run(run func(opts *bind.CallOpts)) *rollupBananaZKEVMContractor_LastAccInputHash_Call { +func (_c *RollupBananaZKEVMContractor_LastAccInputHash_Call) Run(run func(opts *bind.CallOpts)) *RollupBananaZKEVMContractor_LastAccInputHash_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(*bind.CallOpts)) }) return _c } -func (_c *rollupBananaZKEVMContractor_LastAccInputHash_Call) Return(_a0 [32]byte, _a1 error) *rollupBananaZKEVMContractor_LastAccInputHash_Call { +func (_c *RollupBananaZKEVMContractor_LastAccInputHash_Call) Return(_a0 [32]byte, _a1 error) *RollupBananaZKEVMContractor_LastAccInputHash_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *rollupBananaZKEVMContractor_LastAccInputHash_Call) RunAndReturn(run func(*bind.CallOpts) ([32]byte, error)) *rollupBananaZKEVMContractor_LastAccInputHash_Call { +func (_c *RollupBananaZKEVMContractor_LastAccInputHash_Call) RunAndReturn(run func(*bind.CallOpts) ([32]byte, error)) *RollupBananaZKEVMContractor_LastAccInputHash_Call { _c.Call.Return(run) return _c } // SequenceBatches provides a mock function with given fields: opts, batches, indexL1InfoRoot, maxSequenceTimestamp, expectedFinalAccInputHash, l2Coinbase -func (_m *rollupBananaZKEVMContractor) SequenceBatches(opts *bind.TransactOpts, batches []polygonvalidiumetrog.PolygonRollupBaseEtrogBatchData, indexL1InfoRoot uint32, maxSequenceTimestamp uint64, expectedFinalAccInputHash [32]byte, l2Coinbase common.Address) (*types.Transaction, error) { +func (_m *RollupBananaZKEVMContractor) SequenceBatches(opts *bind.TransactOpts, batches []polygonvalidiumetrog.PolygonRollupBaseEtrogBatchData, indexL1InfoRoot uint32, maxSequenceTimestamp uint64, expectedFinalAccInputHash [32]byte, l2Coinbase common.Address) (*types.Transaction, error) { ret := _m.Called(opts, batches, indexL1InfoRoot, maxSequenceTimestamp, expectedFinalAccInputHash, l2Coinbase) if len(ret) == 0 { @@ -114,8 +114,8 @@ func (_m *rollupBananaZKEVMContractor) SequenceBatches(opts *bind.TransactOpts, return r0, r1 } -// rollupBananaZKEVMContractor_SequenceBatches_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SequenceBatches' -type rollupBananaZKEVMContractor_SequenceBatches_Call struct { +// RollupBananaZKEVMContractor_SequenceBatches_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SequenceBatches' +type RollupBananaZKEVMContractor_SequenceBatches_Call struct { *mock.Call } @@ -126,34 +126,34 @@ type rollupBananaZKEVMContractor_SequenceBatches_Call struct { // - maxSequenceTimestamp uint64 // - expectedFinalAccInputHash [32]byte // - l2Coinbase common.Address -func (_e *rollupBananaZKEVMContractor_Expecter) SequenceBatches(opts interface{}, batches interface{}, indexL1InfoRoot interface{}, maxSequenceTimestamp interface{}, expectedFinalAccInputHash interface{}, l2Coinbase interface{}) *rollupBananaZKEVMContractor_SequenceBatches_Call { - return &rollupBananaZKEVMContractor_SequenceBatches_Call{Call: _e.mock.On("SequenceBatches", opts, batches, indexL1InfoRoot, maxSequenceTimestamp, expectedFinalAccInputHash, l2Coinbase)} +func (_e *RollupBananaZKEVMContractor_Expecter) SequenceBatches(opts interface{}, batches interface{}, indexL1InfoRoot interface{}, maxSequenceTimestamp interface{}, expectedFinalAccInputHash interface{}, l2Coinbase interface{}) *RollupBananaZKEVMContractor_SequenceBatches_Call { + return &RollupBananaZKEVMContractor_SequenceBatches_Call{Call: _e.mock.On("SequenceBatches", opts, batches, indexL1InfoRoot, maxSequenceTimestamp, expectedFinalAccInputHash, l2Coinbase)} } -func (_c *rollupBananaZKEVMContractor_SequenceBatches_Call) Run(run func(opts *bind.TransactOpts, batches []polygonvalidiumetrog.PolygonRollupBaseEtrogBatchData, indexL1InfoRoot uint32, maxSequenceTimestamp uint64, expectedFinalAccInputHash [32]byte, l2Coinbase common.Address)) *rollupBananaZKEVMContractor_SequenceBatches_Call { +func (_c *RollupBananaZKEVMContractor_SequenceBatches_Call) Run(run func(opts *bind.TransactOpts, batches []polygonvalidiumetrog.PolygonRollupBaseEtrogBatchData, indexL1InfoRoot uint32, maxSequenceTimestamp uint64, expectedFinalAccInputHash [32]byte, l2Coinbase common.Address)) *RollupBananaZKEVMContractor_SequenceBatches_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(*bind.TransactOpts), args[1].([]polygonvalidiumetrog.PolygonRollupBaseEtrogBatchData), args[2].(uint32), args[3].(uint64), args[4].([32]byte), args[5].(common.Address)) }) return _c } -func (_c *rollupBananaZKEVMContractor_SequenceBatches_Call) Return(_a0 *types.Transaction, _a1 error) *rollupBananaZKEVMContractor_SequenceBatches_Call { +func (_c *RollupBananaZKEVMContractor_SequenceBatches_Call) Return(_a0 *types.Transaction, _a1 error) *RollupBananaZKEVMContractor_SequenceBatches_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *rollupBananaZKEVMContractor_SequenceBatches_Call) RunAndReturn(run func(*bind.TransactOpts, []polygonvalidiumetrog.PolygonRollupBaseEtrogBatchData, uint32, uint64, [32]byte, common.Address) (*types.Transaction, error)) *rollupBananaZKEVMContractor_SequenceBatches_Call { +func (_c *RollupBananaZKEVMContractor_SequenceBatches_Call) RunAndReturn(run func(*bind.TransactOpts, []polygonvalidiumetrog.PolygonRollupBaseEtrogBatchData, uint32, uint64, [32]byte, common.Address) (*types.Transaction, error)) *RollupBananaZKEVMContractor_SequenceBatches_Call { _c.Call.Return(run) return _c } -// newRollupBananaZKEVMContractor creates a new instance of rollupBananaZKEVMContractor. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// NewRollupBananaZKEVMContractor creates a new instance of RollupBananaZKEVMContractor. 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 newRollupBananaZKEVMContractor(t interface { +func NewRollupBananaZKEVMContractor(t interface { mock.TestingT Cleanup(func()) -}) *rollupBananaZKEVMContractor { - mock := &rollupBananaZKEVMContractor{} +}) *RollupBananaZKEVMContractor { + mock := &RollupBananaZKEVMContractor{} mock.Mock.Test(t) t.Cleanup(func() { mock.AssertExpectations(t) }) diff --git a/sequencesender/txbuilder/mocks_txbuilder/rollup_elderberry_validium_contractor.go b/sequencesender/txbuilder/mocks_txbuilder/rollup_elderberry_validium_contractor.go index 8560234f..0d94c081 100644 --- a/sequencesender/txbuilder/mocks_txbuilder/rollup_elderberry_validium_contractor.go +++ b/sequencesender/txbuilder/mocks_txbuilder/rollup_elderberry_validium_contractor.go @@ -13,21 +13,21 @@ import ( types "github.com/ethereum/go-ethereum/core/types" ) -// rollupElderberryValidiumContractor is an autogenerated mock type for the rollupElderberryValidiumContractor type -type rollupElderberryValidiumContractor struct { +// RollupElderberryValidiumContractor is an autogenerated mock type for the rollupElderberryValidiumContractor type +type RollupElderberryValidiumContractor struct { mock.Mock } -type rollupElderberryValidiumContractor_Expecter struct { +type RollupElderberryValidiumContractor_Expecter struct { mock *mock.Mock } -func (_m *rollupElderberryValidiumContractor) EXPECT() *rollupElderberryValidiumContractor_Expecter { - return &rollupElderberryValidiumContractor_Expecter{mock: &_m.Mock} +func (_m *RollupElderberryValidiumContractor) EXPECT() *RollupElderberryValidiumContractor_Expecter { + return &RollupElderberryValidiumContractor_Expecter{mock: &_m.Mock} } // SequenceBatchesValidium provides a mock function with given fields: opts, batches, maxSequenceTimestamp, initSequencedBatch, l2Coinbase, dataAvailabilityMessage -func (_m *rollupElderberryValidiumContractor) SequenceBatchesValidium(opts *bind.TransactOpts, batches []polygonvalidiumetrog.PolygonValidiumEtrogValidiumBatchData, maxSequenceTimestamp uint64, initSequencedBatch uint64, l2Coinbase common.Address, dataAvailabilityMessage []byte) (*types.Transaction, error) { +func (_m *RollupElderberryValidiumContractor) SequenceBatchesValidium(opts *bind.TransactOpts, batches []polygonvalidiumetrog.PolygonValidiumEtrogValidiumBatchData, maxSequenceTimestamp uint64, initSequencedBatch uint64, l2Coinbase common.Address, dataAvailabilityMessage []byte) (*types.Transaction, error) { ret := _m.Called(opts, batches, maxSequenceTimestamp, initSequencedBatch, l2Coinbase, dataAvailabilityMessage) if len(ret) == 0 { @@ -56,8 +56,8 @@ func (_m *rollupElderberryValidiumContractor) SequenceBatchesValidium(opts *bind return r0, r1 } -// rollupElderberryValidiumContractor_SequenceBatchesValidium_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SequenceBatchesValidium' -type rollupElderberryValidiumContractor_SequenceBatchesValidium_Call struct { +// RollupElderberryValidiumContractor_SequenceBatchesValidium_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SequenceBatchesValidium' +type RollupElderberryValidiumContractor_SequenceBatchesValidium_Call struct { *mock.Call } @@ -68,34 +68,34 @@ type rollupElderberryValidiumContractor_SequenceBatchesValidium_Call struct { // - initSequencedBatch uint64 // - l2Coinbase common.Address // - dataAvailabilityMessage []byte -func (_e *rollupElderberryValidiumContractor_Expecter) SequenceBatchesValidium(opts interface{}, batches interface{}, maxSequenceTimestamp interface{}, initSequencedBatch interface{}, l2Coinbase interface{}, dataAvailabilityMessage interface{}) *rollupElderberryValidiumContractor_SequenceBatchesValidium_Call { - return &rollupElderberryValidiumContractor_SequenceBatchesValidium_Call{Call: _e.mock.On("SequenceBatchesValidium", opts, batches, maxSequenceTimestamp, initSequencedBatch, l2Coinbase, dataAvailabilityMessage)} +func (_e *RollupElderberryValidiumContractor_Expecter) SequenceBatchesValidium(opts interface{}, batches interface{}, maxSequenceTimestamp interface{}, initSequencedBatch interface{}, l2Coinbase interface{}, dataAvailabilityMessage interface{}) *RollupElderberryValidiumContractor_SequenceBatchesValidium_Call { + return &RollupElderberryValidiumContractor_SequenceBatchesValidium_Call{Call: _e.mock.On("SequenceBatchesValidium", opts, batches, maxSequenceTimestamp, initSequencedBatch, l2Coinbase, dataAvailabilityMessage)} } -func (_c *rollupElderberryValidiumContractor_SequenceBatchesValidium_Call) Run(run func(opts *bind.TransactOpts, batches []polygonvalidiumetrog.PolygonValidiumEtrogValidiumBatchData, maxSequenceTimestamp uint64, initSequencedBatch uint64, l2Coinbase common.Address, dataAvailabilityMessage []byte)) *rollupElderberryValidiumContractor_SequenceBatchesValidium_Call { +func (_c *RollupElderberryValidiumContractor_SequenceBatchesValidium_Call) Run(run func(opts *bind.TransactOpts, batches []polygonvalidiumetrog.PolygonValidiumEtrogValidiumBatchData, maxSequenceTimestamp uint64, initSequencedBatch uint64, l2Coinbase common.Address, dataAvailabilityMessage []byte)) *RollupElderberryValidiumContractor_SequenceBatchesValidium_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(*bind.TransactOpts), args[1].([]polygonvalidiumetrog.PolygonValidiumEtrogValidiumBatchData), args[2].(uint64), args[3].(uint64), args[4].(common.Address), args[5].([]byte)) }) return _c } -func (_c *rollupElderberryValidiumContractor_SequenceBatchesValidium_Call) Return(_a0 *types.Transaction, _a1 error) *rollupElderberryValidiumContractor_SequenceBatchesValidium_Call { +func (_c *RollupElderberryValidiumContractor_SequenceBatchesValidium_Call) Return(_a0 *types.Transaction, _a1 error) *RollupElderberryValidiumContractor_SequenceBatchesValidium_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *rollupElderberryValidiumContractor_SequenceBatchesValidium_Call) RunAndReturn(run func(*bind.TransactOpts, []polygonvalidiumetrog.PolygonValidiumEtrogValidiumBatchData, uint64, uint64, common.Address, []byte) (*types.Transaction, error)) *rollupElderberryValidiumContractor_SequenceBatchesValidium_Call { +func (_c *RollupElderberryValidiumContractor_SequenceBatchesValidium_Call) RunAndReturn(run func(*bind.TransactOpts, []polygonvalidiumetrog.PolygonValidiumEtrogValidiumBatchData, uint64, uint64, common.Address, []byte) (*types.Transaction, error)) *RollupElderberryValidiumContractor_SequenceBatchesValidium_Call { _c.Call.Return(run) return _c } -// newRollupElderberryValidiumContractor creates a new instance of rollupElderberryValidiumContractor. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// NewRollupElderberryValidiumContractor creates a new instance of RollupElderberryValidiumContractor. 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 newRollupElderberryValidiumContractor(t interface { +func NewRollupElderberryValidiumContractor(t interface { mock.TestingT Cleanup(func()) -}) *rollupElderberryValidiumContractor { - mock := &rollupElderberryValidiumContractor{} +}) *RollupElderberryValidiumContractor { + mock := &RollupElderberryValidiumContractor{} mock.Mock.Test(t) t.Cleanup(func() { mock.AssertExpectations(t) }) diff --git a/sequencesender/txbuilder/mocks_txbuilder/rollup_elderberry_zkevm_contractor.go b/sequencesender/txbuilder/mocks_txbuilder/rollup_elderberry_zkevm_contractor.go index aa662419..1ed208ab 100644 --- a/sequencesender/txbuilder/mocks_txbuilder/rollup_elderberry_zkevm_contractor.go +++ b/sequencesender/txbuilder/mocks_txbuilder/rollup_elderberry_zkevm_contractor.go @@ -13,21 +13,21 @@ import ( types "github.com/ethereum/go-ethereum/core/types" ) -// rollupElderberryZKEVMContractor is an autogenerated mock type for the rollupElderberryZKEVMContractor type -type rollupElderberryZKEVMContractor struct { +// RollupElderberryZKEVMContractor is an autogenerated mock type for the rollupElderberryZKEVMContractor type +type RollupElderberryZKEVMContractor struct { mock.Mock } -type rollupElderberryZKEVMContractor_Expecter struct { +type RollupElderberryZKEVMContractor_Expecter struct { mock *mock.Mock } -func (_m *rollupElderberryZKEVMContractor) EXPECT() *rollupElderberryZKEVMContractor_Expecter { - return &rollupElderberryZKEVMContractor_Expecter{mock: &_m.Mock} +func (_m *RollupElderberryZKEVMContractor) EXPECT() *RollupElderberryZKEVMContractor_Expecter { + return &RollupElderberryZKEVMContractor_Expecter{mock: &_m.Mock} } // SequenceBatches provides a mock function with given fields: opts, batches, maxSequenceTimestamp, initSequencedBatch, l2Coinbase -func (_m *rollupElderberryZKEVMContractor) SequenceBatches(opts *bind.TransactOpts, batches []polygonvalidiumetrog.PolygonRollupBaseEtrogBatchData, maxSequenceTimestamp uint64, initSequencedBatch uint64, l2Coinbase common.Address) (*types.Transaction, error) { +func (_m *RollupElderberryZKEVMContractor) SequenceBatches(opts *bind.TransactOpts, batches []polygonvalidiumetrog.PolygonRollupBaseEtrogBatchData, maxSequenceTimestamp uint64, initSequencedBatch uint64, l2Coinbase common.Address) (*types.Transaction, error) { ret := _m.Called(opts, batches, maxSequenceTimestamp, initSequencedBatch, l2Coinbase) if len(ret) == 0 { @@ -56,8 +56,8 @@ func (_m *rollupElderberryZKEVMContractor) SequenceBatches(opts *bind.TransactOp return r0, r1 } -// rollupElderberryZKEVMContractor_SequenceBatches_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SequenceBatches' -type rollupElderberryZKEVMContractor_SequenceBatches_Call struct { +// RollupElderberryZKEVMContractor_SequenceBatches_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SequenceBatches' +type RollupElderberryZKEVMContractor_SequenceBatches_Call struct { *mock.Call } @@ -67,34 +67,34 @@ type rollupElderberryZKEVMContractor_SequenceBatches_Call struct { // - maxSequenceTimestamp uint64 // - initSequencedBatch uint64 // - l2Coinbase common.Address -func (_e *rollupElderberryZKEVMContractor_Expecter) SequenceBatches(opts interface{}, batches interface{}, maxSequenceTimestamp interface{}, initSequencedBatch interface{}, l2Coinbase interface{}) *rollupElderberryZKEVMContractor_SequenceBatches_Call { - return &rollupElderberryZKEVMContractor_SequenceBatches_Call{Call: _e.mock.On("SequenceBatches", opts, batches, maxSequenceTimestamp, initSequencedBatch, l2Coinbase)} +func (_e *RollupElderberryZKEVMContractor_Expecter) SequenceBatches(opts interface{}, batches interface{}, maxSequenceTimestamp interface{}, initSequencedBatch interface{}, l2Coinbase interface{}) *RollupElderberryZKEVMContractor_SequenceBatches_Call { + return &RollupElderberryZKEVMContractor_SequenceBatches_Call{Call: _e.mock.On("SequenceBatches", opts, batches, maxSequenceTimestamp, initSequencedBatch, l2Coinbase)} } -func (_c *rollupElderberryZKEVMContractor_SequenceBatches_Call) Run(run func(opts *bind.TransactOpts, batches []polygonvalidiumetrog.PolygonRollupBaseEtrogBatchData, maxSequenceTimestamp uint64, initSequencedBatch uint64, l2Coinbase common.Address)) *rollupElderberryZKEVMContractor_SequenceBatches_Call { +func (_c *RollupElderberryZKEVMContractor_SequenceBatches_Call) Run(run func(opts *bind.TransactOpts, batches []polygonvalidiumetrog.PolygonRollupBaseEtrogBatchData, maxSequenceTimestamp uint64, initSequencedBatch uint64, l2Coinbase common.Address)) *RollupElderberryZKEVMContractor_SequenceBatches_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(*bind.TransactOpts), args[1].([]polygonvalidiumetrog.PolygonRollupBaseEtrogBatchData), args[2].(uint64), args[3].(uint64), args[4].(common.Address)) }) return _c } -func (_c *rollupElderberryZKEVMContractor_SequenceBatches_Call) Return(_a0 *types.Transaction, _a1 error) *rollupElderberryZKEVMContractor_SequenceBatches_Call { +func (_c *RollupElderberryZKEVMContractor_SequenceBatches_Call) Return(_a0 *types.Transaction, _a1 error) *RollupElderberryZKEVMContractor_SequenceBatches_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *rollupElderberryZKEVMContractor_SequenceBatches_Call) RunAndReturn(run func(*bind.TransactOpts, []polygonvalidiumetrog.PolygonRollupBaseEtrogBatchData, uint64, uint64, common.Address) (*types.Transaction, error)) *rollupElderberryZKEVMContractor_SequenceBatches_Call { +func (_c *RollupElderberryZKEVMContractor_SequenceBatches_Call) RunAndReturn(run func(*bind.TransactOpts, []polygonvalidiumetrog.PolygonRollupBaseEtrogBatchData, uint64, uint64, common.Address) (*types.Transaction, error)) *RollupElderberryZKEVMContractor_SequenceBatches_Call { _c.Call.Return(run) return _c } -// newRollupElderberryZKEVMContractor creates a new instance of rollupElderberryZKEVMContractor. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// NewRollupElderberryZKEVMContractor creates a new instance of RollupElderberryZKEVMContractor. 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 newRollupElderberryZKEVMContractor(t interface { +func NewRollupElderberryZKEVMContractor(t interface { mock.TestingT Cleanup(func()) -}) *rollupElderberryZKEVMContractor { - mock := &rollupElderberryZKEVMContractor{} +}) *RollupElderberryZKEVMContractor { + mock := &RollupElderberryZKEVMContractor{} mock.Mock.Test(t) t.Cleanup(func() { mock.AssertExpectations(t) }) diff --git a/test/Makefile b/test/Makefile index 7a53df8c..b80de04e 100644 --- a/test/Makefile +++ b/test/Makefile @@ -13,7 +13,7 @@ generate-mocks-localbridgesync: ## Generates mocks for localbridgesync, using mo generate-mocks-reorgdetector: ## Generates mocks for reorgdetector, using mockery tool export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/mockery --name=EthClient --dir=../reorgdetector --output=../reorgdetector --outpkg=reorgdetector --inpackage --structname=EthClientMock --filename=mock_eth_client.go -COMMON_MOCKERY_PARAMS=--disable-version-string --with-expecter +COMMON_MOCKERY_PARAMS=--disable-version-string --with-expecter --exported .PHONY: generate-mocks-sequencesender generate-mocks-sequencesender: ## Generates mocks for sequencesender, using mockery tool rm -Rf ../sequencesender/txbuilder/mocks_txbuilder From 98ab7b7327cf7cb0cf2c0e84193f37d607d9d277 Mon Sep 17 00:00:00 2001 From: joanestebanr <129153821+joanestebanr@users.noreply.github.com> Date: Wed, 31 Jul 2024 09:26:06 +0200 Subject: [PATCH 05/10] add more test --- sequencesender/txbuilder/banana_base.go | 88 +++++++++---------- sequencesender/txbuilder/banana_base_test.go | 86 ++++++++++++++++++ sequencesender/txbuilder/banana_validium.go | 7 ++ sequencesender/txbuilder/banana_zkevm.go | 7 ++ sequencesender/txbuilder/banana_zkevm_test.go | 50 +++++++++++ .../txbuilder/elderberry_validium.go | 7 ++ .../txbuilder/elderberry_validium_test.go | 7 ++ sequencesender/txbuilder/elderberry_zkevm.go | 4 +- .../txbuilder/elderberry_zkevm_test.go | 12 +-- sequencesender/txbuilder/interface.go | 2 + sequencesender/txbuilder/interface_test.go | 44 ++++++++++ .../txbuilder/mocks_txbuilder/tx_builder.go | 50 +++++++++++ .../txbuilder/zkevm_cond_max_size.go | 7 +- .../txbuilder/zkevm_cond_max_size_test.go | 2 +- 14 files changed, 315 insertions(+), 58 deletions(-) create mode 100644 sequencesender/txbuilder/banana_base_test.go create mode 100644 sequencesender/txbuilder/banana_zkevm_test.go create mode 100644 sequencesender/txbuilder/interface_test.go diff --git a/sequencesender/txbuilder/banana_base.go b/sequencesender/txbuilder/banana_base.go index 071444c1..2def531d 100644 --- a/sequencesender/txbuilder/banana_base.go +++ b/sequencesender/txbuilder/banana_base.go @@ -38,50 +38,6 @@ func NewTxBuilderBananaBase(rollupContract rollupBananaBaseContractor, } -func convertToSequenceBanana(sequences seqsendertypes.Sequence) (etherman.SequenceBanana, error) { - seqEth, ok := sequences.(*BananaSequence) - if !ok { - log.Error("sequences is not a BananaSequence") - return etherman.SequenceBanana{}, fmt.Errorf("sequences is not a BananaSequence") - } - seqEth.SequenceBanana.Batches = make([]etherman.Batch, len(sequences.Batches())) - for _, batch := range sequences.Batches() { - ethBatch, err := convertToEthermanBatch(batch) - if err != nil { - return etherman.SequenceBanana{}, err - } - seqEth.SequenceBanana.Batches = append(seqEth.SequenceBanana.Batches, ethBatch) - } - return seqEth.SequenceBanana, nil -} - -func convertToEthermanBatch(batch seqsendertypes.Batch) (etherman.Batch, error) { - return etherman.Batch{ - L2Data: batch.L2Data(), - LastCoinbase: batch.LastCoinbase(), - ForcedGlobalExitRoot: batch.ForcedGlobalExitRoot(), - ForcedBlockHashL1: batch.ForcedBlockHashL1(), - ForcedBatchTimestamp: batch.ForcedBatchTimestamp(), - BatchNumber: batch.BatchNumber(), - L1InfoTreeIndex: batch.L1InfoTreeIndex(), - LastL2BLockTimestamp: batch.LastL2BLockTimestamp(), - GlobalExitRoot: batch.GlobalExitRoot(), - }, nil -} - -func convertToEthermanBatches(batch []seqsendertypes.Batch) ([]etherman.Batch, error) { - result := make([]etherman.Batch, len(batch)) - for i, b := range batch { - var err error - result[i], err = convertToEthermanBatch(b) - if err != nil { - return nil, err - } - } - - return result, nil -} - func (t *TxBuilderBananaBase) NewBatchFromL2Block(l2Block *datastream.L2Block) seqsendertypes.Batch { batch := ðerman.Batch{ LastL2BLockTimestamp: l2Block.Timestamp, @@ -153,3 +109,47 @@ func (t *TxBuilderBananaBase) getL1InfoRoot(indexL1InfoRoot uint32) (common.Hash return lastL1InfoTreeRoot, err } + +func convertToSequenceBanana(sequences seqsendertypes.Sequence) (etherman.SequenceBanana, error) { + seqEth, ok := sequences.(*BananaSequence) + if !ok { + log.Error("sequences is not a BananaSequence") + return etherman.SequenceBanana{}, fmt.Errorf("sequences is not a BananaSequence") + } + seqEth.SequenceBanana.Batches = make([]etherman.Batch, len(sequences.Batches())) + for _, batch := range sequences.Batches() { + ethBatch, err := convertToEthermanBatch(batch) + if err != nil { + return etherman.SequenceBanana{}, err + } + seqEth.SequenceBanana.Batches = append(seqEth.SequenceBanana.Batches, ethBatch) + } + return seqEth.SequenceBanana, nil +} + +func convertToEthermanBatch(batch seqsendertypes.Batch) (etherman.Batch, error) { + return etherman.Batch{ + L2Data: batch.L2Data(), + LastCoinbase: batch.LastCoinbase(), + ForcedGlobalExitRoot: batch.ForcedGlobalExitRoot(), + ForcedBlockHashL1: batch.ForcedBlockHashL1(), + ForcedBatchTimestamp: batch.ForcedBatchTimestamp(), + BatchNumber: batch.BatchNumber(), + L1InfoTreeIndex: batch.L1InfoTreeIndex(), + LastL2BLockTimestamp: batch.LastL2BLockTimestamp(), + GlobalExitRoot: batch.GlobalExitRoot(), + }, nil +} + +func convertToEthermanBatches(batch []seqsendertypes.Batch) ([]etherman.Batch, error) { + result := make([]etherman.Batch, len(batch)) + for i, b := range batch { + var err error + result[i], err = convertToEthermanBatch(b) + if err != nil { + return nil, err + } + } + + return result, nil +} diff --git a/sequencesender/txbuilder/banana_base_test.go b/sequencesender/txbuilder/banana_base_test.go new file mode 100644 index 00000000..a2f54566 --- /dev/null +++ b/sequencesender/txbuilder/banana_base_test.go @@ -0,0 +1,86 @@ +package txbuilder_test + +import ( + "testing" + + "github.com/0xPolygon/cdk/sequencesender/seqsendertypes" + "github.com/0xPolygon/cdk/sequencesender/txbuilder" + "github.com/0xPolygon/cdk/sequencesender/txbuilder/mocks_txbuilder" + "github.com/0xPolygon/cdk/state/datastream" + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" +) + +func TestBananaBaseNewSequenceEmpty(t *testing.T) { + testData := newBananaBaseTestData(t) + lastAcc := common.HexToHash("0x8aca9664752dbae36135fd0956c956fc4a370feeac67485b49bcd4b99608ae41") + testData.rollupContract.EXPECT().LastAccInputHash(mock.Anything).Return(lastAcc, nil) + seq, err := testData.sut.NewSequence(nil, common.Address{}) + require.NotNil(t, seq) + require.NoError(t, err) + // TODO check values + //require.Equal(t, lastAcc, seq.LastAccInputHash()) +} + +func TestBananaBaseNewBatchFromL2Block(t *testing.T) { + testData := newBananaBaseTestData(t) + l2Block := &datastream.L2Block{ + Timestamp: 1, + BatchNumber: 2, + L1InfotreeIndex: 3, + Coinbase: []byte{1, 2, 3}, + GlobalExitRoot: []byte{4, 5, 6}, + } + batch := testData.sut.NewBatchFromL2Block(l2Block) + require.NotNil(t, batch) + require.Equal(t, l2Block.Timestamp, batch.LastL2BLockTimestamp()) + require.Equal(t, l2Block.BatchNumber, batch.BatchNumber()) + require.Equal(t, l2Block.L1InfotreeIndex, batch.L1InfoTreeIndex()) + require.Equal(t, common.BytesToAddress(l2Block.Coinbase), batch.LastCoinbase()) + require.Equal(t, common.BytesToHash(l2Block.GlobalExitRoot), batch.GlobalExitRoot()) +} + +func TestBananaBaseNewSequenceBatch(t *testing.T) { + testData := newBananaBaseTestData(t) + l2Block := &datastream.L2Block{ + Timestamp: 1, + BatchNumber: 2, + L1InfotreeIndex: 3, + Coinbase: []byte{1, 2, 3}, + GlobalExitRoot: []byte{4, 5, 6}, + } + batch := testData.sut.NewBatchFromL2Block(l2Block) + batches := []seqsendertypes.Batch{batch} + lastAcc := common.HexToHash("0x8aca9664752dbae36135fd0956c956fc4a370feeac67485b49bcd4b99608ae41") + testData.rollupContract.EXPECT().LastAccInputHash(mock.Anything).Return(lastAcc, nil) + l1infoRoot := common.HexToHash("0x66ca9664752dbae36135fd0956c956fc4a370feeac67485b49bcd4b99608ae41") + testData.getContract.EXPECT().L1InfoRootMap(mock.Anything, uint32(3)).Return(l1infoRoot, nil) + + seq, err := testData.sut.NewSequence(batches, common.Address{}) + require.NotNil(t, seq) + require.NoError(t, err) + // TODO: check that the seq have the right values +} + +type testDataBananaBase struct { + rollupContract *mocks_txbuilder.RollupBananaBaseContractor + getContract *mocks_txbuilder.GlobalExitRootBananaContractor + opts bind.TransactOpts + sut *txbuilder.TxBuilderBananaBase +} + +func newBananaBaseTestData(t *testing.T) *testDataBananaBase { + zkevmContractMock := mocks_txbuilder.NewRollupBananaBaseContractor(t) + gerContractMock := mocks_txbuilder.NewGlobalExitRootBananaContractor(t) + opts := bind.TransactOpts{} + sut := txbuilder.NewTxBuilderBananaBase(zkevmContractMock, gerContractMock, opts) + require.NotNil(t, sut) + return &testDataBananaBase{ + rollupContract: zkevmContractMock, + getContract: gerContractMock, + opts: opts, + sut: sut, + } +} diff --git a/sequencesender/txbuilder/banana_validium.go b/sequencesender/txbuilder/banana_validium.go index 2cc553ad..c4b5fbc0 100644 --- a/sequencesender/txbuilder/banana_validium.go +++ b/sequencesender/txbuilder/banana_validium.go @@ -44,6 +44,13 @@ func (t *TxBuilderBananaValidium) NewSequenceIfWorthToSend(ctx context.Context, return t.condNewSeq.NewSequenceIfWorthToSend(ctx, t, sequenceBatches, l2Coinbase) } +// SetCondNewSeq allow to override the default conditional for new sequence +func (t *TxBuilderBananaValidium) SetCondNewSeq(cond CondNewSequence) CondNewSequence { + previous := t.condNewSeq + t.condNewSeq = cond + return previous +} + func (t *TxBuilderBananaValidium) BuildSequenceBatchesTx(ctx context.Context, sequences seqsendertypes.Sequence) (*ethtypes.Transaction, error) { // TODO: param sender // Post sequences to DA backend diff --git a/sequencesender/txbuilder/banana_zkevm.go b/sequencesender/txbuilder/banana_zkevm.go index 5bbcbf73..0fa9ddd9 100644 --- a/sequencesender/txbuilder/banana_zkevm.go +++ b/sequencesender/txbuilder/banana_zkevm.go @@ -41,6 +41,13 @@ func (t *TxBuilderBananaZKEVM) NewSequenceIfWorthToSend(ctx context.Context, seq return t.condNewSeq.NewSequenceIfWorthToSend(ctx, t, sequenceBatches, l2Coinbase) } +// SetCondNewSeq allow to override the default conditional for new sequence +func (t *TxBuilderBananaZKEVM) SetCondNewSeq(cond CondNewSequence) CondNewSequence { + previous := t.condNewSeq + t.condNewSeq = cond + return previous +} + func (t *TxBuilderBananaZKEVM) BuildSequenceBatchesTx(ctx context.Context, sequences seqsendertypes.Sequence) (*ethtypes.Transaction, error) { var err error ethseq, err := convertToSequenceBanana(sequences) diff --git a/sequencesender/txbuilder/banana_zkevm_test.go b/sequencesender/txbuilder/banana_zkevm_test.go new file mode 100644 index 00000000..18c48d7f --- /dev/null +++ b/sequencesender/txbuilder/banana_zkevm_test.go @@ -0,0 +1,50 @@ +package txbuilder_test + +import ( + "strings" + "testing" + + "github.com/0xPolygon/cdk/sequencesender/txbuilder" + "github.com/0xPolygon/cdk/sequencesender/txbuilder/mocks_txbuilder" + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/stretchr/testify/require" +) + +func TestBananaZkevmName(t *testing.T) { + testData := newBananaZKEVMTestData(t, txbuilder.MaxTxSizeForL1Disabled) + require.True(t, strings.Contains(testData.sut.String(), "Banana")) + require.True(t, strings.Contains(testData.sut.String(), "ZKEVM")) +} + +func TestBananaZkevmNewSequenceIfWorthToSend(t *testing.T) { + testData := newBananaZKEVMTestData(t, txbuilder.MaxTxSizeForL1Disabled) + + testSequenceIfWorthToSendNoNewSeq(t, testData.sut) + testSequenceIfWorthToSendErr(t, testData.sut) + testSetCondNewSeq(t, testData.sut) +} + +type testDataBananaZKEVM struct { + rollupContract *mocks_txbuilder.RollupBananaZKEVMContractor + getContract *mocks_txbuilder.GlobalExitRootBananaContractor + cond *mocks_txbuilder.CondNewSequence + opts bind.TransactOpts + sut *txbuilder.TxBuilderBananaZKEVM +} + +func newBananaZKEVMTestData(t *testing.T, maxTxSizeForL1 uint64) *testDataBananaZKEVM { + zkevmContractMock := mocks_txbuilder.NewRollupBananaZKEVMContractor(t) + gerContractMock := mocks_txbuilder.NewGlobalExitRootBananaContractor(t) + condMock := mocks_txbuilder.NewCondNewSequence(t) + opts := bind.TransactOpts{} + sut := txbuilder.NewTxBuilderBananaZKEVM(zkevmContractMock, gerContractMock, opts, maxTxSizeForL1) + require.NotNil(t, sut) + sut.SetCondNewSeq(condMock) + return &testDataBananaZKEVM{ + rollupContract: zkevmContractMock, + getContract: gerContractMock, + cond: condMock, + opts: opts, + sut: sut, + } +} diff --git a/sequencesender/txbuilder/elderberry_validium.go b/sequencesender/txbuilder/elderberry_validium.go index ec5c8dbc..56bad4f7 100644 --- a/sequencesender/txbuilder/elderberry_validium.go +++ b/sequencesender/txbuilder/elderberry_validium.go @@ -44,6 +44,13 @@ func (t *TxBuilderElderberryValidium) NewSequenceIfWorthToSend(ctx context.Conte return t.condNewSeq.NewSequenceIfWorthToSend(ctx, t, sequenceBatches, l2Coinbase) } +// SetCondNewSeq allow to override the default conditional for new sequence +func (t *TxBuilderElderberryValidium) SetCondNewSeq(cond CondNewSequence) CondNewSequence { + previous := t.condNewSeq + t.condNewSeq = cond + return previous +} + func (t *TxBuilderElderberryValidium) BuildSequenceBatchesTx(ctx context.Context, sequences seqsendertypes.Sequence) (*ethtypes.Transaction, error) { if sequences == nil || sequences.Len() == 0 { return nil, fmt.Errorf("can't sequence an empty sequence") diff --git a/sequencesender/txbuilder/elderberry_validium_test.go b/sequencesender/txbuilder/elderberry_validium_test.go index 2d57d0e7..1964867c 100644 --- a/sequencesender/txbuilder/elderberry_validium_test.go +++ b/sequencesender/txbuilder/elderberry_validium_test.go @@ -85,6 +85,13 @@ func TestElderberryValidiumBuildSequenceBatchesTxSequenceDAOk(t *testing.T) { require.NotNil(t, tx) } +func TestElderberryValidiumNewSequenceIfWorthToSend(t *testing.T) { + testData := newElderberryValidiumSUT(t) + testSequenceIfWorthToSendNoNewSeq(t, testData.sut) + testSequenceIfWorthToSendErr(t, testData.sut) + testSetCondNewSeq(t, testData.sut) +} + type testDataElderberryValidium struct { mockDA *mocks_da.SequenceSenderElderberry sut *txbuilder.TxBuilderElderberryValidium diff --git a/sequencesender/txbuilder/elderberry_zkevm.go b/sequencesender/txbuilder/elderberry_zkevm.go index baf3d5ae..83e70971 100644 --- a/sequencesender/txbuilder/elderberry_zkevm.go +++ b/sequencesender/txbuilder/elderberry_zkevm.go @@ -38,8 +38,10 @@ func (t *TxBuilderElderberryZKEVM) NewSequenceIfWorthToSend(ctx context.Context, } // SetCondNewSeq allow to override the default conditional for new sequence -func (t *TxBuilderElderberryZKEVM) SetCondNewSeq(cond CondNewSequence) { +func (t *TxBuilderElderberryZKEVM) SetCondNewSeq(cond CondNewSequence) CondNewSequence { + previous := t.condNewSeq t.condNewSeq = cond + return previous } func (t *TxBuilderElderberryZKEVM) BuildSequenceBatchesTx(ctx context.Context, sequences seqsendertypes.Sequence) (*ethtypes.Transaction, error) { diff --git a/sequencesender/txbuilder/elderberry_zkevm_test.go b/sequencesender/txbuilder/elderberry_zkevm_test.go index 67f9bda4..9ed29823 100644 --- a/sequencesender/txbuilder/elderberry_zkevm_test.go +++ b/sequencesender/txbuilder/elderberry_zkevm_test.go @@ -10,12 +10,10 @@ import ( "github.com/0xPolygon/cdk/etherman/contracts" "github.com/0xPolygon/cdk/sequencesender/seqsendertypes" "github.com/0xPolygon/cdk/sequencesender/txbuilder" - "github.com/0xPolygon/cdk/sequencesender/txbuilder/mocks_txbuilder" "github.com/0xPolygon/cdk/state/datastream" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" - "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -94,13 +92,9 @@ func TestElderberryZkevmBuildSequenceBatchesTxSequence1BatchError(t *testing.T) func TestElderberryZkevmNewSequenceIfWorthToSend(t *testing.T) { sut := newElderberryZkevmSUT(t) - mockCond := mocks_txbuilder.NewCondNewSequence(t) - sut.SetCondNewSeq(mockCond) - // Returns that is not work to be send - mockCond.EXPECT().NewSequenceIfWorthToSend(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, nil) - seq, err := sut.NewSequenceIfWorthToSend(context.TODO(), nil, common.Address{}, 0) - require.NoError(t, err) - require.Nil(t, seq) + testSequenceIfWorthToSendNoNewSeq(t, sut) + testSequenceIfWorthToSendErr(t, sut) + testSetCondNewSeq(t, sut) } func newElderberryZkevmSUT(t *testing.T) *txbuilder.TxBuilderElderberryZKEVM { diff --git a/sequencesender/txbuilder/interface.go b/sequencesender/txbuilder/interface.go index ddcd5105..cfb7ae21 100644 --- a/sequencesender/txbuilder/interface.go +++ b/sequencesender/txbuilder/interface.go @@ -14,6 +14,8 @@ type TxBuilder interface { NewSequence(batches []seqsendertypes.Batch, coinbase common.Address) (seqsendertypes.Sequence, error) NewSequenceIfWorthToSend(ctx context.Context, sequenceBatches []seqsendertypes.Batch, l2Coinbase common.Address, batchNumber uint64) (seqsendertypes.Sequence, error) NewBatchFromL2Block(l2Block *datastream.L2Block) seqsendertypes.Batch + //SetCondNewSeq Allows to override the condition to send a new sequence, returns previous one + SetCondNewSeq(cond CondNewSequence) CondNewSequence String() string } diff --git a/sequencesender/txbuilder/interface_test.go b/sequencesender/txbuilder/interface_test.go new file mode 100644 index 00000000..7a27e2f1 --- /dev/null +++ b/sequencesender/txbuilder/interface_test.go @@ -0,0 +1,44 @@ +package txbuilder_test + +import ( + "context" + "fmt" + "testing" + + "github.com/0xPolygon/cdk/sequencesender/txbuilder" + "github.com/0xPolygon/cdk/sequencesender/txbuilder/mocks_txbuilder" + "github.com/ethereum/go-ethereum/common" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" +) + +/* +This test ara auxiliars function based on the common behaviour of the interfaces +*/ + +func testSequenceIfWorthToSendNoNewSeq(t *testing.T, sut txbuilder.TxBuilder) { + cond := mocks_txbuilder.NewCondNewSequence(t) + sut.SetCondNewSeq(cond) + cond.EXPECT().NewSequenceIfWorthToSend(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, nil).Once() + seq, err := sut.NewSequenceIfWorthToSend(context.TODO(), nil, common.Address{}, 0) + require.NoError(t, err) + require.Nil(t, seq) +} + +func testSequenceIfWorthToSendErr(t *testing.T, sut txbuilder.TxBuilder) { + cond := mocks_txbuilder.NewCondNewSequence(t) + sut.SetCondNewSeq(cond) + returnErr := fmt.Errorf("test-error") + cond.EXPECT().NewSequenceIfWorthToSend(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, returnErr).Once() + seq, err := sut.NewSequenceIfWorthToSend(context.TODO(), nil, common.Address{}, 0) + require.ErrorIs(t, returnErr, err) + require.Nil(t, seq) +} + +func testSetCondNewSeq(t *testing.T, sut txbuilder.TxBuilder) { + cond := mocks_txbuilder.NewCondNewSequence(t) + previous := sut.SetCondNewSeq(cond) + cond2 := mocks_txbuilder.NewCondNewSequence(t) + previous = sut.SetCondNewSeq(cond2) + require.Equal(t, cond, previous) +} diff --git a/sequencesender/txbuilder/mocks_txbuilder/tx_builder.go b/sequencesender/txbuilder/mocks_txbuilder/tx_builder.go index 4b713efa..14f0539b 100644 --- a/sequencesender/txbuilder/mocks_txbuilder/tx_builder.go +++ b/sequencesender/txbuilder/mocks_txbuilder/tx_builder.go @@ -13,6 +13,8 @@ import ( seqsendertypes "github.com/0xPolygon/cdk/sequencesender/seqsendertypes" + txbuilder "github.com/0xPolygon/cdk/sequencesender/txbuilder" + types "github.com/ethereum/go-ethereum/core/types" ) @@ -256,6 +258,54 @@ func (_c *TxBuilder_NewSequenceIfWorthToSend_Call) RunAndReturn(run func(context return _c } +// SetCondNewSeq provides a mock function with given fields: cond +func (_m *TxBuilder) SetCondNewSeq(cond txbuilder.CondNewSequence) txbuilder.CondNewSequence { + ret := _m.Called(cond) + + if len(ret) == 0 { + panic("no return value specified for SetCondNewSeq") + } + + var r0 txbuilder.CondNewSequence + if rf, ok := ret.Get(0).(func(txbuilder.CondNewSequence) txbuilder.CondNewSequence); ok { + r0 = rf(cond) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(txbuilder.CondNewSequence) + } + } + + return r0 +} + +// TxBuilder_SetCondNewSeq_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetCondNewSeq' +type TxBuilder_SetCondNewSeq_Call struct { + *mock.Call +} + +// SetCondNewSeq is a helper method to define mock.On call +// - cond txbuilder.CondNewSequence +func (_e *TxBuilder_Expecter) SetCondNewSeq(cond interface{}) *TxBuilder_SetCondNewSeq_Call { + return &TxBuilder_SetCondNewSeq_Call{Call: _e.mock.On("SetCondNewSeq", cond)} +} + +func (_c *TxBuilder_SetCondNewSeq_Call) Run(run func(cond txbuilder.CondNewSequence)) *TxBuilder_SetCondNewSeq_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(txbuilder.CondNewSequence)) + }) + return _c +} + +func (_c *TxBuilder_SetCondNewSeq_Call) Return(_a0 txbuilder.CondNewSequence) *TxBuilder_SetCondNewSeq_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *TxBuilder_SetCondNewSeq_Call) RunAndReturn(run func(txbuilder.CondNewSequence) txbuilder.CondNewSequence) *TxBuilder_SetCondNewSeq_Call { + _c.Call.Return(run) + return _c +} + // String provides a mock function with given fields: func (_m *TxBuilder) String() string { ret := _m.Called() diff --git a/sequencesender/txbuilder/zkevm_cond_max_size.go b/sequencesender/txbuilder/zkevm_cond_max_size.go index 805014fe..98267e17 100644 --- a/sequencesender/txbuilder/zkevm_cond_max_size.go +++ b/sequencesender/txbuilder/zkevm_cond_max_size.go @@ -13,7 +13,8 @@ import ( var ( // ErrOversizedData when transaction input data is greater than a limit (DOS protection) - ErrOversizedData = errors.New("oversized data") + ErrOversizedData = errors.New("oversized data") + MaxTxSizeForL1Disabled = uint64(0) ) type ConditionalNewSequenceMaxSize struct { @@ -27,8 +28,8 @@ func NewConditionalNewSequenceMaxSize(maxTxSizeForL1 uint64) *ConditionalNewSequ } func (c *ConditionalNewSequenceMaxSize) NewSequenceIfWorthToSend(ctx context.Context, txBuilder TxBuilder, sequenceBatches []seqsendertypes.Batch, l2Coinbase common.Address) (seqsendertypes.Sequence, error) { - if c.maxTxSizeForL1 == 0 { - log.Debug("maxTxSizeForL1 is 0, so is disabled") + if c.maxTxSizeForL1 == MaxTxSizeForL1Disabled { + log.Debugf("maxTxSizeForL1 is %d, so is disabled", MaxTxSizeForL1Disabled) return nil, nil } sequence, err := txBuilder.NewSequence(sequenceBatches, l2Coinbase) diff --git a/sequencesender/txbuilder/zkevm_cond_max_size_test.go b/sequencesender/txbuilder/zkevm_cond_max_size_test.go index a65cdc44..32e49eed 100644 --- a/sequencesender/txbuilder/zkevm_cond_max_size_test.go +++ b/sequencesender/txbuilder/zkevm_cond_max_size_test.go @@ -16,7 +16,7 @@ import ( func TestConditionalMaxSizeDisabled(t *testing.T) { mockTxBuilder := mocks_txbuilder.NewTxBuilder(t) - sut := txbuilder.NewConditionalNewSequenceMaxSize(0) + sut := txbuilder.NewConditionalNewSequenceMaxSize(txbuilder.MaxTxSizeForL1Disabled) tx, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, nil, common.Address{}) require.NoError(t, err) From aff6261acf97d2523bd40d4fbbd65b8558467dd8 Mon Sep 17 00:00:00 2001 From: joanestebanr <129153821+joanestebanr@users.noreply.github.com> Date: Wed, 31 Jul 2024 13:30:35 +0200 Subject: [PATCH 06/10] add test for banana reaching coverage: 81.8% of statements of txbuilder --- Makefile | 2 +- dataavailability/interfaces.go | 12 +- .../mocks_da/sequence_sender_banana.go | 97 ++++++++++++++++ sequencesender/txbuilder/banana_validium.go | 13 ++- .../txbuilder/banana_validium_test.go | 107 ++++++++++++++++++ sequencesender/txbuilder/banana_zkevm_test.go | 55 +++++++++ .../txbuilder/elderberry_validium.go | 4 +- .../txbuilder/validium_cond_num_batches.go | 6 +- 8 files changed, 284 insertions(+), 12 deletions(-) create mode 100644 dataavailability/mocks_da/sequence_sender_banana.go create mode 100644 sequencesender/txbuilder/banana_validium_test.go diff --git a/Makefile b/Makefile index 90da419b..bf497dc9 100644 --- a/Makefile +++ b/Makefile @@ -86,7 +86,7 @@ test: .PHONY: test-seq_sender test-seq_sender: - trap '$(STOP)' EXIT; MallocNanoZone=0 go test -count=1 -short -race -p 1 -covermode=atomic -coverprofile=../coverage.out -coverpkg ./sequencesender/... -timeout 200s ./sequencesender/... + trap '$(STOP)' EXIT; MallocNanoZone=0 go test -count=1 -short -race -p 1 -covermode=atomic -coverprofile=../coverage.out -timeout 200s ./sequencesender/... .PHONY: install-linter diff --git a/dataavailability/interfaces.go b/dataavailability/interfaces.go index 8292fd71..2254d55a 100644 --- a/dataavailability/interfaces.go +++ b/dataavailability/interfaces.go @@ -17,18 +17,20 @@ type DABackender interface { // SequenceSender is used to send provided sequence of batches type SequenceSender interface { + SequenceSenderElderberry + SequenceSenderBanana +} + +type SequenceSenderElderberry interface { // PostSequence sends the sequence data to the data availability backend, and returns the dataAvailabilityMessage // as expected by the contract - PostSequence(ctx context.Context, sequence etherman.SequenceBanana) ([]byte, error) - // PostSequenceElderberry sends the sequence data to the data availability backend, and returns the dataAvailabilityMessage - // as expected by the contract PostSequenceElderberry(ctx context.Context, batchesData [][]byte) ([]byte, error) } -type SequenceSenderElderberry interface { +type SequenceSenderBanana interface { // PostSequence sends the sequence data to the data availability backend, and returns the dataAvailabilityMessage // as expected by the contract - PostSequenceElderberry(ctx context.Context, batchesData [][]byte) ([]byte, error) + PostSequence(ctx context.Context, sequence etherman.SequenceBanana) ([]byte, error) } // SequenceRetriever is used to retrieve batch data diff --git a/dataavailability/mocks_da/sequence_sender_banana.go b/dataavailability/mocks_da/sequence_sender_banana.go new file mode 100644 index 00000000..956490d9 --- /dev/null +++ b/dataavailability/mocks_da/sequence_sender_banana.go @@ -0,0 +1,97 @@ +// Code generated by mockery. DO NOT EDIT. + +package mocks_da + +import ( + context "context" + + etherman "github.com/0xPolygon/cdk/etherman" + + mock "github.com/stretchr/testify/mock" +) + +// SequenceSenderBanana is an autogenerated mock type for the SequenceSenderBanana type +type SequenceSenderBanana struct { + mock.Mock +} + +type SequenceSenderBanana_Expecter struct { + mock *mock.Mock +} + +func (_m *SequenceSenderBanana) EXPECT() *SequenceSenderBanana_Expecter { + return &SequenceSenderBanana_Expecter{mock: &_m.Mock} +} + +// PostSequence provides a mock function with given fields: ctx, sequence +func (_m *SequenceSenderBanana) PostSequence(ctx context.Context, sequence etherman.SequenceBanana) ([]byte, error) { + ret := _m.Called(ctx, sequence) + + if len(ret) == 0 { + panic("no return value specified for PostSequence") + } + + var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, etherman.SequenceBanana) ([]byte, error)); ok { + return rf(ctx, sequence) + } + if rf, ok := ret.Get(0).(func(context.Context, etherman.SequenceBanana) []byte); ok { + r0 = rf(ctx, sequence) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, etherman.SequenceBanana) error); ok { + r1 = rf(ctx, sequence) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// SequenceSenderBanana_PostSequence_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PostSequence' +type SequenceSenderBanana_PostSequence_Call struct { + *mock.Call +} + +// PostSequence is a helper method to define mock.On call +// - ctx context.Context +// - sequence etherman.SequenceBanana +func (_e *SequenceSenderBanana_Expecter) PostSequence(ctx interface{}, sequence interface{}) *SequenceSenderBanana_PostSequence_Call { + return &SequenceSenderBanana_PostSequence_Call{Call: _e.mock.On("PostSequence", ctx, sequence)} +} + +func (_c *SequenceSenderBanana_PostSequence_Call) Run(run func(ctx context.Context, sequence etherman.SequenceBanana)) *SequenceSenderBanana_PostSequence_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(etherman.SequenceBanana)) + }) + return _c +} + +func (_c *SequenceSenderBanana_PostSequence_Call) Return(_a0 []byte, _a1 error) *SequenceSenderBanana_PostSequence_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *SequenceSenderBanana_PostSequence_Call) RunAndReturn(run func(context.Context, etherman.SequenceBanana) ([]byte, error)) *SequenceSenderBanana_PostSequence_Call { + _c.Call.Return(run) + return _c +} + +// NewSequenceSenderBanana creates a new instance of SequenceSenderBanana. 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 NewSequenceSenderBanana(t interface { + mock.TestingT + Cleanup(func()) +}) *SequenceSenderBanana { + mock := &SequenceSenderBanana{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/sequencesender/txbuilder/banana_validium.go b/sequencesender/txbuilder/banana_validium.go index c4b5fbc0..10eb731e 100644 --- a/sequencesender/txbuilder/banana_validium.go +++ b/sequencesender/txbuilder/banana_validium.go @@ -2,12 +2,12 @@ package txbuilder import ( "context" + "fmt" "math/big" "github.com/0xPolygon/cdk-contracts-tooling/contracts/banana/polygonvalidiumetrog" "github.com/0xPolygon/cdk/dataavailability" "github.com/0xPolygon/cdk/etherman" - "github.com/0xPolygon/cdk/etherman/contracts" "github.com/0xPolygon/cdk/log" "github.com/0xPolygon/cdk/sequencesender/seqsendertypes" "github.com/ethereum/go-ethereum/accounts/abi/bind" @@ -19,7 +19,7 @@ import ( type TxBuilderBananaValidium struct { TxBuilderBananaBase - da dataavailability.SequenceSender + da dataavailability.SequenceSenderBanana condNewSeq CondNewSequence rollupContract rollupBananaValidiumContractor } @@ -30,8 +30,8 @@ type rollupBananaValidiumContractor interface { } func NewTxBuilderBananaValidium(rollupContract rollupBananaValidiumContractor, - gerContract contracts.GlobalExitRootBananaType, - da dataavailability.SequenceSender, opts bind.TransactOpts, maxBatchesForL1 uint64) *TxBuilderBananaValidium { + gerContract globalExitRootBananaContractor, + da dataavailability.SequenceSenderBanana, opts bind.TransactOpts, maxBatchesForL1 uint64) *TxBuilderBananaValidium { return &TxBuilderBananaValidium{ TxBuilderBananaBase: *NewTxBuilderBananaBase(rollupContract, gerContract, opts), da: da, @@ -67,6 +67,11 @@ func (t *TxBuilderBananaValidium) BuildSequenceBatchesTx(ctx context.Context, se log.Error("error posting sequences to the data availability protocol: ", err) return nil, err } + if dataAvailabilityMessage == nil { + err := fmt.Errorf("data availability message is nil") + log.Error("error posting sequences to the data availability protocol: ", err.Error()) + return nil, err + } // Build sequence data tx, err := t.internalBuildSequenceBatchesTx(ethseq, dataAvailabilityMessage) diff --git a/sequencesender/txbuilder/banana_validium_test.go b/sequencesender/txbuilder/banana_validium_test.go new file mode 100644 index 00000000..737425d7 --- /dev/null +++ b/sequencesender/txbuilder/banana_validium_test.go @@ -0,0 +1,107 @@ +package txbuilder_test + +import ( + "context" + "fmt" + "strings" + "testing" + + "github.com/0xPolygon/cdk/dataavailability/mocks_da" + "github.com/0xPolygon/cdk/sequencesender/seqsendertypes" + "github.com/0xPolygon/cdk/sequencesender/txbuilder" + "github.com/0xPolygon/cdk/sequencesender/txbuilder/mocks_txbuilder" + "github.com/0xPolygon/cdk/state/datastream" + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + ethtypes "github.com/ethereum/go-ethereum/core/types" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" +) + +func TestBananaValidiumName(t *testing.T) { + testData := newBananaValidiumTestData(t, txbuilder.MaxBatchesForL1Disabled) + require.NotNil(t, testData.sut) + require.True(t, strings.Contains(testData.sut.String(), "Banana")) + require.True(t, strings.Contains(testData.sut.String(), "Validium")) +} + +func TestBananaValidiumBuildSequenceBatchesTxSequenceErrorsFromDA(t *testing.T) { + testData := newBananaValidiumTestData(t, txbuilder.MaxBatchesForL1Disabled) + seq, err := newSequenceBananaValidiumForTest(testData) + require.NoError(t, err) + ctx := context.TODO() + testData.da.EXPECT().PostSequence(ctx, mock.Anything).Return(nil, nil).Once() + + _, err = testData.sut.BuildSequenceBatchesTx(ctx, seq) + require.Error(t, err, "data availability message is nil") + + testData.da.EXPECT().PostSequence(ctx, mock.Anything).Return(nil, fmt.Errorf("test error")) + _, err = testData.sut.BuildSequenceBatchesTx(ctx, seq) + require.Error(t, err, "error posting sequences to the data availability protocol: test error") + +} + +func TestBananaValidiumBuildSequenceBatchesTxSequenceDAOk(t *testing.T) { + testData := newBananaValidiumTestData(t, txbuilder.MaxBatchesForL1Disabled) + seq, err := newSequenceBananaValidiumForTest(testData) + require.NoError(t, err) + ctx := context.TODO() + daMessage := []byte{1} + testData.da.EXPECT().PostSequence(ctx, mock.Anything).Return(daMessage, nil) + inner := ðtypes.LegacyTx{} + seqBatchesTx := ethtypes.NewTx(inner) + testData.rollupContract.EXPECT().SequenceBatchesValidium(mock.MatchedBy(func(opts *bind.TransactOpts) bool { + return opts.NoSend == true + }), mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, daMessage).Return(seqBatchesTx, nil).Once() + tx, err := testData.sut.BuildSequenceBatchesTx(ctx, seq) + require.NoError(t, err) + require.Equal(t, seqBatchesTx, tx) +} + +type testDataBananaValidium struct { + rollupContract *mocks_txbuilder.RollupBananaValidiumContractor + getContract *mocks_txbuilder.GlobalExitRootBananaContractor + cond *mocks_txbuilder.CondNewSequence + da *mocks_da.SequenceSenderBanana + opts bind.TransactOpts + sut *txbuilder.TxBuilderBananaValidium +} + +func newBananaValidiumTestData(t *testing.T, maxBatchesForL1 uint64) *testDataBananaValidium { + zkevmContractMock := mocks_txbuilder.NewRollupBananaValidiumContractor(t) + gerContractMock := mocks_txbuilder.NewGlobalExitRootBananaContractor(t) + condMock := mocks_txbuilder.NewCondNewSequence(t) + daMock := mocks_da.NewSequenceSenderBanana(t) + + opts := bind.TransactOpts{} + sut := txbuilder.NewTxBuilderBananaValidium(zkevmContractMock, gerContractMock, daMock, opts, maxBatchesForL1) + require.NotNil(t, sut) + sut.SetCondNewSeq(condMock) + return &testDataBananaValidium{ + rollupContract: zkevmContractMock, + getContract: gerContractMock, + cond: condMock, + da: daMock, + opts: opts, + sut: sut, + } +} + +func newSequenceBananaValidiumForTest(testData *testDataBananaValidium) (seqsendertypes.Sequence, error) { + l2Block := &datastream.L2Block{ + Timestamp: 1, + BatchNumber: 1, + L1InfotreeIndex: 3, + Coinbase: []byte{1, 2, 3}, + GlobalExitRoot: []byte{4, 5, 6}, + } + batch := testData.sut.NewBatchFromL2Block(l2Block) + batches := []seqsendertypes.Batch{ + batch, + } + lastAcc := common.HexToHash("0x8aca9664752dbae36135fd0956c956fc4a370feeac67485b49bcd4b99608ae41") + testData.rollupContract.EXPECT().LastAccInputHash(mock.Anything).Return(lastAcc, nil).Once() + l1infoRoot := common.HexToHash("0x66ca9664752dbae36135fd0956c956fc4a370feeac67485b49bcd4b99608ae41") + testData.getContract.EXPECT().L1InfoRootMap(mock.Anything, uint32(3)).Return(l1infoRoot, nil).Once() + return testData.sut.NewSequence(batches, common.Address{}) +} diff --git a/sequencesender/txbuilder/banana_zkevm_test.go b/sequencesender/txbuilder/banana_zkevm_test.go index 18c48d7f..8653c504 100644 --- a/sequencesender/txbuilder/banana_zkevm_test.go +++ b/sequencesender/txbuilder/banana_zkevm_test.go @@ -1,12 +1,19 @@ package txbuilder_test import ( + "context" + "fmt" "strings" "testing" + "github.com/0xPolygon/cdk/sequencesender/seqsendertypes" "github.com/0xPolygon/cdk/sequencesender/txbuilder" "github.com/0xPolygon/cdk/sequencesender/txbuilder/mocks_txbuilder" + "github.com/0xPolygon/cdk/state/datastream" "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + ethtypes "github.com/ethereum/go-ethereum/core/types" + "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -24,6 +31,35 @@ func TestBananaZkevmNewSequenceIfWorthToSend(t *testing.T) { testSetCondNewSeq(t, testData.sut) } +func TestBananaZkevmBuildSequenceBatchesTxOk(t *testing.T) { + testData := newBananaZKEVMTestData(t, txbuilder.MaxTxSizeForL1Disabled) + seq, err := newSequenceBananaZKEVMForTest(testData) + require.NoError(t, err) + + inner := ðtypes.LegacyTx{} + tx := ethtypes.NewTx(inner) + + // It check that SequenceBatches is not going to be send + testData.rollupContract.EXPECT().SequenceBatches(mock.MatchedBy(func(opts *bind.TransactOpts) bool { + return opts.NoSend == true + }), mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(tx, nil).Once() + returnTx, err := testData.sut.BuildSequenceBatchesTx(context.TODO(), seq) + require.NoError(t, err) + require.Equal(t, tx, returnTx) +} + +func TestBananaZkevmBuildSequenceBatchesTxErr(t *testing.T) { + testData := newBananaZKEVMTestData(t, txbuilder.MaxTxSizeForL1Disabled) + seq, err := newSequenceBananaZKEVMForTest(testData) + require.NoError(t, err) + + err = fmt.Errorf("test-error") + testData.rollupContract.EXPECT().SequenceBatches(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, err).Once() + returnedTx, returnedErr := testData.sut.BuildSequenceBatchesTx(context.TODO(), seq) + require.ErrorContains(t, returnedErr, err.Error()) + require.Nil(t, returnedTx) +} + type testDataBananaZKEVM struct { rollupContract *mocks_txbuilder.RollupBananaZKEVMContractor getContract *mocks_txbuilder.GlobalExitRootBananaContractor @@ -48,3 +84,22 @@ func newBananaZKEVMTestData(t *testing.T, maxTxSizeForL1 uint64) *testDataBanana sut: sut, } } + +func newSequenceBananaZKEVMForTest(testData *testDataBananaZKEVM) (seqsendertypes.Sequence, error) { + l2Block := &datastream.L2Block{ + Timestamp: 1, + BatchNumber: 1, + L1InfotreeIndex: 3, + Coinbase: []byte{1, 2, 3}, + GlobalExitRoot: []byte{4, 5, 6}, + } + batch := testData.sut.NewBatchFromL2Block(l2Block) + batches := []seqsendertypes.Batch{ + batch, + } + lastAcc := common.HexToHash("0x8aca9664752dbae36135fd0956c956fc4a370feeac67485b49bcd4b99608ae41") + testData.rollupContract.EXPECT().LastAccInputHash(mock.Anything).Return(lastAcc, nil).Once() + l1infoRoot := common.HexToHash("0x66ca9664752dbae36135fd0956c956fc4a370feeac67485b49bcd4b99608ae41") + testData.getContract.EXPECT().L1InfoRootMap(mock.Anything, uint32(3)).Return(l1infoRoot, nil).Once() + return testData.sut.NewSequence(batches, common.Address{}) +} diff --git a/sequencesender/txbuilder/elderberry_validium.go b/sequencesender/txbuilder/elderberry_validium.go index 56bad4f7..638ba3b1 100644 --- a/sequencesender/txbuilder/elderberry_validium.go +++ b/sequencesender/txbuilder/elderberry_validium.go @@ -62,7 +62,9 @@ func (t *TxBuilderElderberryValidium) BuildSequenceBatchesTx(ctx context.Context return nil, err } if dataAvailabilityMessage == nil { - return nil, fmt.Errorf("data availability message is nil") + err := fmt.Errorf("data availability message is nil") + log.Error("error posting sequences to the data availability protocol: ", err.Error()) + return nil, err } newopts := t.opts newopts.NoSend = true diff --git a/sequencesender/txbuilder/validium_cond_num_batches.go b/sequencesender/txbuilder/validium_cond_num_batches.go index 1b85582b..df77486e 100644 --- a/sequencesender/txbuilder/validium_cond_num_batches.go +++ b/sequencesender/txbuilder/validium_cond_num_batches.go @@ -8,6 +8,10 @@ import ( "github.com/ethereum/go-ethereum/common" ) +var ( + MaxBatchesForL1Disabled = uint64(0) +) + type ConditionalNewSequenceNumBatches struct { maxBatchesForL1 uint64 // cfg.MaxBatchesForL1 } @@ -19,7 +23,7 @@ func NewConditionalNewSequenceNumBatches(maxBatchesForL1 uint64) *ConditionalNew } func (c *ConditionalNewSequenceNumBatches) NewSequenceIfWorthToSend(ctx context.Context, txBuilder TxBuilder, sequenceBatches []seqsendertypes.Batch, l2Coinbase common.Address) (seqsendertypes.Sequence, error) { - if c.maxBatchesForL1 > 0 && len(sequenceBatches) >= int(c.maxBatchesForL1) { + if c.maxBatchesForL1 != MaxBatchesForL1Disabled && len(sequenceBatches) >= int(c.maxBatchesForL1) { log.Infof( "[SeqSender] sequence should be sent to L1, because MaxBatchesForL1 (%d) has been reached", c.maxBatchesForL1, From 72d43be315142367ace50eb7e222dcaeca9d8807 Mon Sep 17 00:00:00 2001 From: joanestebanr <129153821+joanestebanr@users.noreply.github.com> Date: Thu, 1 Aug 2024 10:06:41 +0200 Subject: [PATCH 07/10] renamed dataavailability PostSequence to PostSequenceBanana as PR comments suggest --- dataavailability/dataavailability.go | 4 ++-- .../datacommittee/datacommittee.go | 2 +- dataavailability/interfaces.go | 2 +- dataavailability/mocks_da/da_backender.go | 22 +++++++++---------- dataavailability/mocks_da/data_manager.go | 22 +++++++++---------- dataavailability/mocks_da/sequence_sender.go | 22 +++++++++---------- .../mocks_da/sequence_sender_banana.go | 22 +++++++++---------- sequencesender/txbuilder/banana_validium.go | 2 +- .../txbuilder/banana_validium_test.go | 6 ++--- 9 files changed, 52 insertions(+), 52 deletions(-) diff --git a/dataavailability/dataavailability.go b/dataavailability/dataavailability.go index 284f0b64..2e8ec124 100644 --- a/dataavailability/dataavailability.go +++ b/dataavailability/dataavailability.go @@ -20,8 +20,8 @@ func New(backend DABackender) (*DataAvailability, error) { return da, da.backend.Init() } -func (d *DataAvailability) PostSequence(ctx context.Context, sequenceBanana etherman.SequenceBanana) ([]byte, error) { - return d.backend.PostSequence(ctx, sequenceBanana) +func (d *DataAvailability) PostSequenceBanana(ctx context.Context, sequenceBanana etherman.SequenceBanana) ([]byte, error) { + return d.backend.PostSequenceBanana(ctx, sequenceBanana) } func (d *DataAvailability) PostSequenceElderberry(ctx context.Context, batchesData [][]byte) ([]byte, error) { diff --git a/dataavailability/datacommittee/datacommittee.go b/dataavailability/datacommittee/datacommittee.go index 54b3882f..67c7884a 100644 --- a/dataavailability/datacommittee/datacommittee.go +++ b/dataavailability/datacommittee/datacommittee.go @@ -191,7 +191,7 @@ func (d *Backend) PostSequenceElderberry(ctx context.Context, batchesData [][]by return collectSignatures(committee, ch, cancelSignatureCollection) } -func (d *Backend) PostSequence(ctx context.Context, sequence etherman.SequenceBanana) ([]byte, error) { +func (d *Backend) PostSequenceBanana(ctx context.Context, sequence etherman.SequenceBanana) ([]byte, error) { // Get current committee committee, err := d.getCurrentDataCommittee() if err != nil { diff --git a/dataavailability/interfaces.go b/dataavailability/interfaces.go index 2254d55a..b3630871 100644 --- a/dataavailability/interfaces.go +++ b/dataavailability/interfaces.go @@ -30,7 +30,7 @@ type SequenceSenderElderberry interface { type SequenceSenderBanana interface { // PostSequence sends the sequence data to the data availability backend, and returns the dataAvailabilityMessage // as expected by the contract - PostSequence(ctx context.Context, sequence etherman.SequenceBanana) ([]byte, error) + PostSequenceBanana(ctx context.Context, sequence etherman.SequenceBanana) ([]byte, error) } // SequenceRetriever is used to retrieve batch data diff --git a/dataavailability/mocks_da/da_backender.go b/dataavailability/mocks_da/da_backender.go index 398356e5..773e447c 100644 --- a/dataavailability/mocks_da/da_backender.go +++ b/dataavailability/mocks_da/da_backender.go @@ -130,12 +130,12 @@ func (_c *DABackender_Init_Call) RunAndReturn(run func() error) *DABackender_Ini return _c } -// PostSequence provides a mock function with given fields: ctx, sequence -func (_m *DABackender) PostSequence(ctx context.Context, sequence etherman.SequenceBanana) ([]byte, error) { +// PostSequenceBanana provides a mock function with given fields: ctx, sequence +func (_m *DABackender) PostSequenceBanana(ctx context.Context, sequence etherman.SequenceBanana) ([]byte, error) { ret := _m.Called(ctx, sequence) if len(ret) == 0 { - panic("no return value specified for PostSequence") + panic("no return value specified for PostSequenceBanana") } var r0 []byte @@ -160,31 +160,31 @@ func (_m *DABackender) PostSequence(ctx context.Context, sequence etherman.Seque return r0, r1 } -// DABackender_PostSequence_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PostSequence' -type DABackender_PostSequence_Call struct { +// DABackender_PostSequenceBanana_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PostSequenceBanana' +type DABackender_PostSequenceBanana_Call struct { *mock.Call } -// PostSequence is a helper method to define mock.On call +// PostSequenceBanana is a helper method to define mock.On call // - ctx context.Context // - sequence etherman.SequenceBanana -func (_e *DABackender_Expecter) PostSequence(ctx interface{}, sequence interface{}) *DABackender_PostSequence_Call { - return &DABackender_PostSequence_Call{Call: _e.mock.On("PostSequence", ctx, sequence)} +func (_e *DABackender_Expecter) PostSequenceBanana(ctx interface{}, sequence interface{}) *DABackender_PostSequenceBanana_Call { + return &DABackender_PostSequenceBanana_Call{Call: _e.mock.On("PostSequenceBanana", ctx, sequence)} } -func (_c *DABackender_PostSequence_Call) Run(run func(ctx context.Context, sequence etherman.SequenceBanana)) *DABackender_PostSequence_Call { +func (_c *DABackender_PostSequenceBanana_Call) Run(run func(ctx context.Context, sequence etherman.SequenceBanana)) *DABackender_PostSequenceBanana_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(context.Context), args[1].(etherman.SequenceBanana)) }) return _c } -func (_c *DABackender_PostSequence_Call) Return(_a0 []byte, _a1 error) *DABackender_PostSequence_Call { +func (_c *DABackender_PostSequenceBanana_Call) Return(_a0 []byte, _a1 error) *DABackender_PostSequenceBanana_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *DABackender_PostSequence_Call) RunAndReturn(run func(context.Context, etherman.SequenceBanana) ([]byte, error)) *DABackender_PostSequence_Call { +func (_c *DABackender_PostSequenceBanana_Call) RunAndReturn(run func(context.Context, etherman.SequenceBanana) ([]byte, error)) *DABackender_PostSequenceBanana_Call { _c.Call.Return(run) return _c } diff --git a/dataavailability/mocks_da/data_manager.go b/dataavailability/mocks_da/data_manager.go index 4b4e300f..34345d71 100644 --- a/dataavailability/mocks_da/data_manager.go +++ b/dataavailability/mocks_da/data_manager.go @@ -85,12 +85,12 @@ func (_c *DataManager_GetBatchL2Data_Call) RunAndReturn(run func([]uint64, []com return _c } -// PostSequence provides a mock function with given fields: ctx, sequence -func (_m *DataManager) PostSequence(ctx context.Context, sequence etherman.SequenceBanana) ([]byte, error) { +// PostSequenceBanana provides a mock function with given fields: ctx, sequence +func (_m *DataManager) PostSequenceBanana(ctx context.Context, sequence etherman.SequenceBanana) ([]byte, error) { ret := _m.Called(ctx, sequence) if len(ret) == 0 { - panic("no return value specified for PostSequence") + panic("no return value specified for PostSequenceBanana") } var r0 []byte @@ -115,31 +115,31 @@ func (_m *DataManager) PostSequence(ctx context.Context, sequence etherman.Seque return r0, r1 } -// DataManager_PostSequence_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PostSequence' -type DataManager_PostSequence_Call struct { +// DataManager_PostSequenceBanana_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PostSequenceBanana' +type DataManager_PostSequenceBanana_Call struct { *mock.Call } -// PostSequence is a helper method to define mock.On call +// PostSequenceBanana is a helper method to define mock.On call // - ctx context.Context // - sequence etherman.SequenceBanana -func (_e *DataManager_Expecter) PostSequence(ctx interface{}, sequence interface{}) *DataManager_PostSequence_Call { - return &DataManager_PostSequence_Call{Call: _e.mock.On("PostSequence", ctx, sequence)} +func (_e *DataManager_Expecter) PostSequenceBanana(ctx interface{}, sequence interface{}) *DataManager_PostSequenceBanana_Call { + return &DataManager_PostSequenceBanana_Call{Call: _e.mock.On("PostSequenceBanana", ctx, sequence)} } -func (_c *DataManager_PostSequence_Call) Run(run func(ctx context.Context, sequence etherman.SequenceBanana)) *DataManager_PostSequence_Call { +func (_c *DataManager_PostSequenceBanana_Call) Run(run func(ctx context.Context, sequence etherman.SequenceBanana)) *DataManager_PostSequenceBanana_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(context.Context), args[1].(etherman.SequenceBanana)) }) return _c } -func (_c *DataManager_PostSequence_Call) Return(_a0 []byte, _a1 error) *DataManager_PostSequence_Call { +func (_c *DataManager_PostSequenceBanana_Call) Return(_a0 []byte, _a1 error) *DataManager_PostSequenceBanana_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *DataManager_PostSequence_Call) RunAndReturn(run func(context.Context, etherman.SequenceBanana) ([]byte, error)) *DataManager_PostSequence_Call { +func (_c *DataManager_PostSequenceBanana_Call) RunAndReturn(run func(context.Context, etherman.SequenceBanana) ([]byte, error)) *DataManager_PostSequenceBanana_Call { _c.Call.Return(run) return _c } diff --git a/dataavailability/mocks_da/sequence_sender.go b/dataavailability/mocks_da/sequence_sender.go index fc05dbfe..f1e44741 100644 --- a/dataavailability/mocks_da/sequence_sender.go +++ b/dataavailability/mocks_da/sequence_sender.go @@ -23,12 +23,12 @@ func (_m *SequenceSender) EXPECT() *SequenceSender_Expecter { return &SequenceSender_Expecter{mock: &_m.Mock} } -// PostSequence provides a mock function with given fields: ctx, sequence -func (_m *SequenceSender) PostSequence(ctx context.Context, sequence etherman.SequenceBanana) ([]byte, error) { +// PostSequenceBanana provides a mock function with given fields: ctx, sequence +func (_m *SequenceSender) PostSequenceBanana(ctx context.Context, sequence etherman.SequenceBanana) ([]byte, error) { ret := _m.Called(ctx, sequence) if len(ret) == 0 { - panic("no return value specified for PostSequence") + panic("no return value specified for PostSequenceBanana") } var r0 []byte @@ -53,31 +53,31 @@ func (_m *SequenceSender) PostSequence(ctx context.Context, sequence etherman.Se return r0, r1 } -// SequenceSender_PostSequence_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PostSequence' -type SequenceSender_PostSequence_Call struct { +// SequenceSender_PostSequenceBanana_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PostSequenceBanana' +type SequenceSender_PostSequenceBanana_Call struct { *mock.Call } -// PostSequence is a helper method to define mock.On call +// PostSequenceBanana is a helper method to define mock.On call // - ctx context.Context // - sequence etherman.SequenceBanana -func (_e *SequenceSender_Expecter) PostSequence(ctx interface{}, sequence interface{}) *SequenceSender_PostSequence_Call { - return &SequenceSender_PostSequence_Call{Call: _e.mock.On("PostSequence", ctx, sequence)} +func (_e *SequenceSender_Expecter) PostSequenceBanana(ctx interface{}, sequence interface{}) *SequenceSender_PostSequenceBanana_Call { + return &SequenceSender_PostSequenceBanana_Call{Call: _e.mock.On("PostSequenceBanana", ctx, sequence)} } -func (_c *SequenceSender_PostSequence_Call) Run(run func(ctx context.Context, sequence etherman.SequenceBanana)) *SequenceSender_PostSequence_Call { +func (_c *SequenceSender_PostSequenceBanana_Call) Run(run func(ctx context.Context, sequence etherman.SequenceBanana)) *SequenceSender_PostSequenceBanana_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(context.Context), args[1].(etherman.SequenceBanana)) }) return _c } -func (_c *SequenceSender_PostSequence_Call) Return(_a0 []byte, _a1 error) *SequenceSender_PostSequence_Call { +func (_c *SequenceSender_PostSequenceBanana_Call) Return(_a0 []byte, _a1 error) *SequenceSender_PostSequenceBanana_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *SequenceSender_PostSequence_Call) RunAndReturn(run func(context.Context, etherman.SequenceBanana) ([]byte, error)) *SequenceSender_PostSequence_Call { +func (_c *SequenceSender_PostSequenceBanana_Call) RunAndReturn(run func(context.Context, etherman.SequenceBanana) ([]byte, error)) *SequenceSender_PostSequenceBanana_Call { _c.Call.Return(run) return _c } diff --git a/dataavailability/mocks_da/sequence_sender_banana.go b/dataavailability/mocks_da/sequence_sender_banana.go index 956490d9..aca7b1a3 100644 --- a/dataavailability/mocks_da/sequence_sender_banana.go +++ b/dataavailability/mocks_da/sequence_sender_banana.go @@ -23,12 +23,12 @@ func (_m *SequenceSenderBanana) EXPECT() *SequenceSenderBanana_Expecter { return &SequenceSenderBanana_Expecter{mock: &_m.Mock} } -// PostSequence provides a mock function with given fields: ctx, sequence -func (_m *SequenceSenderBanana) PostSequence(ctx context.Context, sequence etherman.SequenceBanana) ([]byte, error) { +// PostSequenceBanana provides a mock function with given fields: ctx, sequence +func (_m *SequenceSenderBanana) PostSequenceBanana(ctx context.Context, sequence etherman.SequenceBanana) ([]byte, error) { ret := _m.Called(ctx, sequence) if len(ret) == 0 { - panic("no return value specified for PostSequence") + panic("no return value specified for PostSequenceBanana") } var r0 []byte @@ -53,31 +53,31 @@ func (_m *SequenceSenderBanana) PostSequence(ctx context.Context, sequence ether return r0, r1 } -// SequenceSenderBanana_PostSequence_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PostSequence' -type SequenceSenderBanana_PostSequence_Call struct { +// SequenceSenderBanana_PostSequenceBanana_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PostSequenceBanana' +type SequenceSenderBanana_PostSequenceBanana_Call struct { *mock.Call } -// PostSequence is a helper method to define mock.On call +// PostSequenceBanana is a helper method to define mock.On call // - ctx context.Context // - sequence etherman.SequenceBanana -func (_e *SequenceSenderBanana_Expecter) PostSequence(ctx interface{}, sequence interface{}) *SequenceSenderBanana_PostSequence_Call { - return &SequenceSenderBanana_PostSequence_Call{Call: _e.mock.On("PostSequence", ctx, sequence)} +func (_e *SequenceSenderBanana_Expecter) PostSequenceBanana(ctx interface{}, sequence interface{}) *SequenceSenderBanana_PostSequenceBanana_Call { + return &SequenceSenderBanana_PostSequenceBanana_Call{Call: _e.mock.On("PostSequenceBanana", ctx, sequence)} } -func (_c *SequenceSenderBanana_PostSequence_Call) Run(run func(ctx context.Context, sequence etherman.SequenceBanana)) *SequenceSenderBanana_PostSequence_Call { +func (_c *SequenceSenderBanana_PostSequenceBanana_Call) Run(run func(ctx context.Context, sequence etherman.SequenceBanana)) *SequenceSenderBanana_PostSequenceBanana_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(context.Context), args[1].(etherman.SequenceBanana)) }) return _c } -func (_c *SequenceSenderBanana_PostSequence_Call) Return(_a0 []byte, _a1 error) *SequenceSenderBanana_PostSequence_Call { +func (_c *SequenceSenderBanana_PostSequenceBanana_Call) Return(_a0 []byte, _a1 error) *SequenceSenderBanana_PostSequenceBanana_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *SequenceSenderBanana_PostSequence_Call) RunAndReturn(run func(context.Context, etherman.SequenceBanana) ([]byte, error)) *SequenceSenderBanana_PostSequence_Call { +func (_c *SequenceSenderBanana_PostSequenceBanana_Call) RunAndReturn(run func(context.Context, etherman.SequenceBanana) ([]byte, error)) *SequenceSenderBanana_PostSequenceBanana_Call { _c.Call.Return(run) return _c } diff --git a/sequencesender/txbuilder/banana_validium.go b/sequencesender/txbuilder/banana_validium.go index 10eb731e..4693c6cd 100644 --- a/sequencesender/txbuilder/banana_validium.go +++ b/sequencesender/txbuilder/banana_validium.go @@ -62,7 +62,7 @@ func (t *TxBuilderBananaValidium) BuildSequenceBatchesTx(ctx context.Context, se return nil, err } - dataAvailabilityMessage, err = t.da.PostSequence(ctx, ethseq) + dataAvailabilityMessage, err = t.da.PostSequenceBanana(ctx, ethseq) if err != nil { log.Error("error posting sequences to the data availability protocol: ", err) return nil, err diff --git a/sequencesender/txbuilder/banana_validium_test.go b/sequencesender/txbuilder/banana_validium_test.go index 737425d7..5c6f0d50 100644 --- a/sequencesender/txbuilder/banana_validium_test.go +++ b/sequencesender/txbuilder/banana_validium_test.go @@ -30,12 +30,12 @@ func TestBananaValidiumBuildSequenceBatchesTxSequenceErrorsFromDA(t *testing.T) seq, err := newSequenceBananaValidiumForTest(testData) require.NoError(t, err) ctx := context.TODO() - testData.da.EXPECT().PostSequence(ctx, mock.Anything).Return(nil, nil).Once() + testData.da.EXPECT().PostSequenceBanana(ctx, mock.Anything).Return(nil, nil).Once() _, err = testData.sut.BuildSequenceBatchesTx(ctx, seq) require.Error(t, err, "data availability message is nil") - testData.da.EXPECT().PostSequence(ctx, mock.Anything).Return(nil, fmt.Errorf("test error")) + testData.da.EXPECT().PostSequenceBanana(ctx, mock.Anything).Return(nil, fmt.Errorf("test error")) _, err = testData.sut.BuildSequenceBatchesTx(ctx, seq) require.Error(t, err, "error posting sequences to the data availability protocol: test error") @@ -47,7 +47,7 @@ func TestBananaValidiumBuildSequenceBatchesTxSequenceDAOk(t *testing.T) { require.NoError(t, err) ctx := context.TODO() daMessage := []byte{1} - testData.da.EXPECT().PostSequence(ctx, mock.Anything).Return(daMessage, nil) + testData.da.EXPECT().PostSequenceBanana(ctx, mock.Anything).Return(daMessage, nil) inner := ðtypes.LegacyTx{} seqBatchesTx := ethtypes.NewTx(inner) testData.rollupContract.EXPECT().SequenceBatchesValidium(mock.MatchedBy(func(opts *bind.TransactOpts) bool { From 35bda859ca8e60997fc991f29b9aaaad0a0e88fb Mon Sep 17 00:00:00 2001 From: joanestebanr <129153821+joanestebanr@users.noreply.github.com> Date: Thu, 1 Aug 2024 12:35:24 +0200 Subject: [PATCH 08/10] apply PR comments --- sequencesender/txbuilder/banana_base.go | 10 +++++----- sequencesender/txbuilder/interface.go | 4 ++++ sequencesender/txbuilder/validium_cond_num_batches.go | 4 +--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/sequencesender/txbuilder/banana_base.go b/sequencesender/txbuilder/banana_base.go index 2def531d..93536c6a 100644 --- a/sequencesender/txbuilder/banana_base.go +++ b/sequencesender/txbuilder/banana_base.go @@ -50,7 +50,7 @@ func (t *TxBuilderBananaBase) NewBatchFromL2Block(l2Block *datastream.L2Block) s } func (t *TxBuilderBananaBase) NewSequence(batches []seqsendertypes.Batch, coinbase common.Address) (seqsendertypes.Sequence, error) { - ethBatches, err := convertToEthermanBatches(batches) + ethBatches, err := toEthermanBatches(batches) if err != nil { return nil, err } @@ -118,7 +118,7 @@ func convertToSequenceBanana(sequences seqsendertypes.Sequence) (etherman.Sequen } seqEth.SequenceBanana.Batches = make([]etherman.Batch, len(sequences.Batches())) for _, batch := range sequences.Batches() { - ethBatch, err := convertToEthermanBatch(batch) + ethBatch, err := toEthermanBatch(batch) if err != nil { return etherman.SequenceBanana{}, err } @@ -127,7 +127,7 @@ func convertToSequenceBanana(sequences seqsendertypes.Sequence) (etherman.Sequen return seqEth.SequenceBanana, nil } -func convertToEthermanBatch(batch seqsendertypes.Batch) (etherman.Batch, error) { +func toEthermanBatch(batch seqsendertypes.Batch) (etherman.Batch, error) { return etherman.Batch{ L2Data: batch.L2Data(), LastCoinbase: batch.LastCoinbase(), @@ -141,11 +141,11 @@ func convertToEthermanBatch(batch seqsendertypes.Batch) (etherman.Batch, error) }, nil } -func convertToEthermanBatches(batch []seqsendertypes.Batch) ([]etherman.Batch, error) { +func toEthermanBatches(batch []seqsendertypes.Batch) ([]etherman.Batch, error) { result := make([]etherman.Batch, len(batch)) for i, b := range batch { var err error - result[i], err = convertToEthermanBatch(b) + result[i], err = toEthermanBatch(b) if err != nil { return nil, err } diff --git a/sequencesender/txbuilder/interface.go b/sequencesender/txbuilder/interface.go index cfb7ae21..7bfa51be 100644 --- a/sequencesender/txbuilder/interface.go +++ b/sequencesender/txbuilder/interface.go @@ -10,9 +10,13 @@ import ( ) type TxBuilder interface { + // BuildSequenceBatchesTx Builds a sequence of batches transaction BuildSequenceBatchesTx(ctx context.Context, sequences seqsendertypes.Sequence) (*ethtypes.Transaction, error) + // NewSequence Creates a new sequence NewSequence(batches []seqsendertypes.Batch, coinbase common.Address) (seqsendertypes.Sequence, error) + // NewSequenceIfWorthToSend Creates a new sequence if it is worth sending NewSequenceIfWorthToSend(ctx context.Context, sequenceBatches []seqsendertypes.Batch, l2Coinbase common.Address, batchNumber uint64) (seqsendertypes.Sequence, error) + // NewBatchFromL2Block Creates a new batch from the L2 block from a datastream NewBatchFromL2Block(l2Block *datastream.L2Block) seqsendertypes.Batch //SetCondNewSeq Allows to override the condition to send a new sequence, returns previous one SetCondNewSeq(cond CondNewSequence) CondNewSequence diff --git a/sequencesender/txbuilder/validium_cond_num_batches.go b/sequencesender/txbuilder/validium_cond_num_batches.go index df77486e..fd1ad22a 100644 --- a/sequencesender/txbuilder/validium_cond_num_batches.go +++ b/sequencesender/txbuilder/validium_cond_num_batches.go @@ -8,9 +8,7 @@ import ( "github.com/ethereum/go-ethereum/common" ) -var ( - MaxBatchesForL1Disabled = uint64(0) -) +var MaxBatchesForL1Disabled = uint64(0) type ConditionalNewSequenceNumBatches struct { maxBatchesForL1 uint64 // cfg.MaxBatchesForL1 From 961d6b4fc4dc9c0ea99b4a15caf301dbaa4b592a Mon Sep 17 00:00:00 2001 From: joanestebanr <129153821+joanestebanr@users.noreply.github.com> Date: Thu, 1 Aug 2024 15:12:30 +0200 Subject: [PATCH 09/10] fix mock generation --- aggoracle/mock_ethtxmanager_test.go | 27 +- l1infotreesync/mock_reorgdetector_test.go | 19 +- localbridgesync/mock_l2_test.go | 555 ++++++++++++++++++++++ reorgdetector/mock_eth_client.go | 19 +- sync/mock_downloader_test.go | 27 +- sync/mock_processor_test.go | 6 +- test/Makefile | 5 +- 7 files changed, 627 insertions(+), 31 deletions(-) create mode 100644 localbridgesync/mock_l2_test.go diff --git a/aggoracle/mock_ethtxmanager_test.go b/aggoracle/mock_ethtxmanager_test.go index 37bcbeda..0deb775d 100644 --- a/aggoracle/mock_ethtxmanager_test.go +++ b/aggoracle/mock_ethtxmanager_test.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.22.1. DO NOT EDIT. +// Code generated by mockery v2.39.0. DO NOT EDIT. package aggoracle @@ -25,6 +25,10 @@ type EthTxManagerMock struct { func (_m *EthTxManagerMock) Add(ctx context.Context, to *common.Address, forcedNonce *uint64, value *big.Int, data []byte, gasOffset uint64, sidecar *types.BlobTxSidecar) (common.Hash, error) { ret := _m.Called(ctx, to, forcedNonce, value, data, gasOffset, sidecar) + if len(ret) == 0 { + panic("no return value specified for Add") + } + var r0 common.Hash var r1 error if rf, ok := ret.Get(0).(func(context.Context, *common.Address, *uint64, *big.Int, []byte, uint64, *types.BlobTxSidecar) (common.Hash, error)); ok { @@ -51,6 +55,10 @@ func (_m *EthTxManagerMock) Add(ctx context.Context, to *common.Address, forcedN func (_m *EthTxManagerMock) Remove(ctx context.Context, id common.Hash) error { ret := _m.Called(ctx, id) + if len(ret) == 0 { + panic("no return value specified for Remove") + } + var r0 error if rf, ok := ret.Get(0).(func(context.Context, common.Hash) error); ok { r0 = rf(ctx, id) @@ -65,6 +73,10 @@ func (_m *EthTxManagerMock) Remove(ctx context.Context, id common.Hash) error { func (_m *EthTxManagerMock) Result(ctx context.Context, id common.Hash) (ethtxmanager.MonitoredTxResult, error) { ret := _m.Called(ctx, id) + 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, common.Hash) (ethtxmanager.MonitoredTxResult, error)); ok { @@ -89,6 +101,10 @@ func (_m *EthTxManagerMock) Result(ctx context.Context, id common.Hash) (ethtxma func (_m *EthTxManagerMock) ResultsByStatus(ctx context.Context, statuses []ethtxmanager.MonitoredTxStatus) ([]ethtxmanager.MonitoredTxResult, error) { ret := _m.Called(ctx, statuses) + 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, []ethtxmanager.MonitoredTxStatus) ([]ethtxmanager.MonitoredTxResult, error)); ok { @@ -111,13 +127,12 @@ func (_m *EthTxManagerMock) ResultsByStatus(ctx context.Context, statuses []etht return r0, r1 } -type mockConstructorTestingTNewEthTxManagerMock interface { +// 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 NewEthTxManagerMock(t interface { mock.TestingT Cleanup(func()) -} - -// 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. -func NewEthTxManagerMock(t mockConstructorTestingTNewEthTxManagerMock) *EthTxManagerMock { +}) *EthTxManagerMock { mock := &EthTxManagerMock{} mock.Mock.Test(t) diff --git a/l1infotreesync/mock_reorgdetector_test.go b/l1infotreesync/mock_reorgdetector_test.go index 22d174d4..18ac7bc8 100644 --- a/l1infotreesync/mock_reorgdetector_test.go +++ b/l1infotreesync/mock_reorgdetector_test.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.22.1. DO NOT EDIT. +// Code generated by mockery v2.39.0. DO NOT EDIT. package l1infotreesync @@ -21,6 +21,10 @@ type ReorgDetectorMock struct { func (_m *ReorgDetectorMock) AddBlockToTrack(ctx context.Context, id string, blockNum uint64, blockHash common.Hash) error { ret := _m.Called(ctx, id, blockNum, blockHash) + if len(ret) == 0 { + panic("no return value specified for AddBlockToTrack") + } + var r0 error if rf, ok := ret.Get(0).(func(context.Context, string, uint64, common.Hash) error); ok { r0 = rf(ctx, id, blockNum, blockHash) @@ -35,6 +39,10 @@ func (_m *ReorgDetectorMock) AddBlockToTrack(ctx context.Context, id string, blo func (_m *ReorgDetectorMock) Subscribe(id string) (*reorgdetector.Subscription, error) { ret := _m.Called(id) + if len(ret) == 0 { + panic("no return value specified for Subscribe") + } + var r0 *reorgdetector.Subscription var r1 error if rf, ok := ret.Get(0).(func(string) (*reorgdetector.Subscription, error)); ok { @@ -57,13 +65,12 @@ func (_m *ReorgDetectorMock) Subscribe(id string) (*reorgdetector.Subscription, return r0, r1 } -type mockConstructorTestingTNewReorgDetectorMock interface { +// NewReorgDetectorMock creates a new instance of ReorgDetectorMock. 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 NewReorgDetectorMock(t interface { mock.TestingT Cleanup(func()) -} - -// NewReorgDetectorMock creates a new instance of ReorgDetectorMock. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewReorgDetectorMock(t mockConstructorTestingTNewReorgDetectorMock) *ReorgDetectorMock { +}) *ReorgDetectorMock { mock := &ReorgDetectorMock{} mock.Mock.Test(t) diff --git a/localbridgesync/mock_l2_test.go b/localbridgesync/mock_l2_test.go new file mode 100644 index 00000000..22432fd1 --- /dev/null +++ b/localbridgesync/mock_l2_test.go @@ -0,0 +1,555 @@ +// Code generated by mockery v2.39.0. DO NOT EDIT. + +package localbridgesync + +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" +) + +// L2Mock is an autogenerated mock type for the EthClienter type +type L2Mock struct { + mock.Mock +} + +// BlockByHash provides a mock function with given fields: ctx, hash +func (_m *L2Mock) 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 *L2Mock) 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 +} + +// BlockNumber provides a mock function with given fields: ctx +func (_m *L2Mock) BlockNumber(ctx context.Context) (uint64, error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for BlockNumber") + } + + var r0 uint64 + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) (uint64, error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) uint64); ok { + r0 = rf(ctx) + } else { + r0 = ret.Get(0).(uint64) + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// CallContract provides a mock function with given fields: ctx, call, blockNumber +func (_m *L2Mock) 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, contract, blockNumber +func (_m *L2Mock) CodeAt(ctx context.Context, contract common.Address, blockNumber *big.Int) ([]byte, error) { + ret := _m.Called(ctx, contract, 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, contract, blockNumber) + } + if rf, ok := ret.Get(0).(func(context.Context, common.Address, *big.Int) []byte); ok { + r0 = rf(ctx, contract, 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, contract, blockNumber) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// EstimateGas provides a mock function with given fields: ctx, call +func (_m *L2Mock) 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 *L2Mock) 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 *L2Mock) 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 *L2Mock) 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 +} + +// PendingCodeAt provides a mock function with given fields: ctx, account +func (_m *L2Mock) 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 *L2Mock) 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 *L2Mock) 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 +} + +// SubscribeFilterLogs provides a mock function with given fields: ctx, q, ch +func (_m *L2Mock) 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 *L2Mock) 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 *L2Mock) 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 *L2Mock) 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 +} + +// TransactionCount provides a mock function with given fields: ctx, blockHash +func (_m *L2Mock) 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 *L2Mock) 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 +} + +// NewL2Mock creates a new instance of L2Mock. 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 NewL2Mock(t interface { + mock.TestingT + Cleanup(func()) +}) *L2Mock { + mock := &L2Mock{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/reorgdetector/mock_eth_client.go b/reorgdetector/mock_eth_client.go index 85376cc4..e0eef607 100644 --- a/reorgdetector/mock_eth_client.go +++ b/reorgdetector/mock_eth_client.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.22.1. DO NOT EDIT. +// Code generated by mockery v2.39.0. DO NOT EDIT. package reorgdetector @@ -20,6 +20,10 @@ type EthClientMock struct { func (_m *EthClientMock) BlockNumber(ctx context.Context) (uint64, error) { ret := _m.Called(ctx) + if len(ret) == 0 { + panic("no return value specified for BlockNumber") + } + var r0 uint64 var r1 error if rf, ok := ret.Get(0).(func(context.Context) (uint64, error)); ok { @@ -44,6 +48,10 @@ func (_m *EthClientMock) BlockNumber(ctx context.Context) (uint64, error) { func (_m *EthClientMock) 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 { @@ -66,13 +74,12 @@ func (_m *EthClientMock) HeaderByNumber(ctx context.Context, number *big.Int) (* return r0, r1 } -type mockConstructorTestingTNewEthClientMock interface { +// NewEthClientMock creates a new instance of EthClientMock. 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 NewEthClientMock(t interface { mock.TestingT Cleanup(func()) -} - -// NewEthClientMock creates a new instance of EthClientMock. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewEthClientMock(t mockConstructorTestingTNewEthClientMock) *EthClientMock { +}) *EthClientMock { mock := &EthClientMock{} mock.Mock.Test(t) diff --git a/sync/mock_downloader_test.go b/sync/mock_downloader_test.go index 738fc873..2e953672 100644 --- a/sync/mock_downloader_test.go +++ b/sync/mock_downloader_test.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.22.1. DO NOT EDIT. +// Code generated by mockery v2.39.0. DO NOT EDIT. package sync @@ -23,6 +23,10 @@ func (_m *EVMDownloaderMock) download(ctx context.Context, fromBlock uint64, dow func (_m *EVMDownloaderMock) getBlockHeader(ctx context.Context, blockNum uint64) EVMBlockHeader { ret := _m.Called(ctx, blockNum) + if len(ret) == 0 { + panic("no return value specified for getBlockHeader") + } + var r0 EVMBlockHeader if rf, ok := ret.Get(0).(func(context.Context, uint64) EVMBlockHeader); ok { r0 = rf(ctx, blockNum) @@ -37,6 +41,10 @@ func (_m *EVMDownloaderMock) getBlockHeader(ctx context.Context, blockNum uint64 func (_m *EVMDownloaderMock) getEventsByBlockRange(ctx context.Context, fromBlock uint64, toBlock uint64) []EVMBlock { ret := _m.Called(ctx, fromBlock, toBlock) + if len(ret) == 0 { + panic("no return value specified for getEventsByBlockRange") + } + var r0 []EVMBlock if rf, ok := ret.Get(0).(func(context.Context, uint64, uint64) []EVMBlock); ok { r0 = rf(ctx, fromBlock, toBlock) @@ -53,6 +61,10 @@ func (_m *EVMDownloaderMock) getEventsByBlockRange(ctx context.Context, fromBloc func (_m *EVMDownloaderMock) getLogs(ctx context.Context, fromBlock uint64, toBlock uint64) []types.Log { ret := _m.Called(ctx, fromBlock, toBlock) + if len(ret) == 0 { + panic("no return value specified for getLogs") + } + var r0 []types.Log if rf, ok := ret.Get(0).(func(context.Context, uint64, uint64) []types.Log); ok { r0 = rf(ctx, fromBlock, toBlock) @@ -69,6 +81,10 @@ func (_m *EVMDownloaderMock) getLogs(ctx context.Context, fromBlock uint64, toBl func (_m *EVMDownloaderMock) waitForNewBlocks(ctx context.Context, lastBlockSeen uint64) uint64 { ret := _m.Called(ctx, lastBlockSeen) + if len(ret) == 0 { + panic("no return value specified for waitForNewBlocks") + } + var r0 uint64 if rf, ok := ret.Get(0).(func(context.Context, uint64) uint64); ok { r0 = rf(ctx, lastBlockSeen) @@ -79,13 +95,12 @@ func (_m *EVMDownloaderMock) waitForNewBlocks(ctx context.Context, lastBlockSeen return r0 } -type mockConstructorTestingTNewEVMDownloaderMock interface { +// NewEVMDownloaderMock creates a new instance of EVMDownloaderMock. 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 NewEVMDownloaderMock(t interface { mock.TestingT Cleanup(func()) -} - -// NewEVMDownloaderMock creates a new instance of EVMDownloaderMock. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func NewEVMDownloaderMock(t mockConstructorTestingTNewEVMDownloaderMock) *EVMDownloaderMock { +}) *EVMDownloaderMock { mock := &EVMDownloaderMock{} mock.Mock.Test(t) diff --git a/sync/mock_processor_test.go b/sync/mock_processor_test.go index ed550d1c..acf57388 100644 --- a/sync/mock_processor_test.go +++ b/sync/mock_processor_test.go @@ -18,7 +18,7 @@ func (_m *ProcessorMock) GetLastProcessedBlock(ctx context.Context) (uint64, err ret := _m.Called(ctx) if len(ret) == 0 { - panic("no return value specified for getLastProcessedBlock") + panic("no return value specified for GetLastProcessedBlock") } var r0 uint64 @@ -46,7 +46,7 @@ func (_m *ProcessorMock) ProcessBlock(block Block) error { ret := _m.Called(block) if len(ret) == 0 { - panic("no return value specified for reorg") + panic("no return value specified for ProcessBlock") } var r0 error @@ -64,7 +64,7 @@ func (_m *ProcessorMock) Reorg(firstReorgedBlock uint64) error { ret := _m.Called(firstReorgedBlock) if len(ret) == 0 { - panic("no return value specified for storeBridgeEvents") + panic("no return value specified for Reorg") } var r0 error diff --git a/test/Makefile b/test/Makefile index 36521083..07f7aaaa 100644 --- a/test/Makefile +++ b/test/Makefile @@ -5,10 +5,7 @@ generate-mocks: generate-mocks-localbridgesync generate-mocks-reorgdetector gene .PHONY: generate-mocks-localbridgesync generate-mocks-localbridgesync: ## Generates mocks for localbridgesync, using mockery tool export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/mockery --name=EthClienter --dir=../localbridgesync --output=../localbridgesync --outpkg=localbridgesync --inpackage --structname=L2Mock --filename=mock_l2_test.go - export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/mockery --name=downloaderFull --dir=../localbridgesync --output=../localbridgesync --outpkg=localbridgesync --inpackage --structname=DownloaderMock --filename=mock_downloader_test.go - export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/mockery --name=processorInterface --dir=../localbridgesync --output=../localbridgesync --outpkg=localbridgesync --inpackage --structname=ProcessorMock --filename=mock_processor_test.go - export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/mockery --name=ReorgDetector --dir=../localbridgesync --output=../localbridgesync --outpkg=localbridgesync --inpackage --structname=ReorgDetectorMock --filename=mock_reorgdetector_test.go - + .PHONY: generate-mocks-reorgdetector generate-mocks-reorgdetector: ## Generates mocks for reorgdetector, using mockery tool export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/mockery --name=EthClient --dir=../reorgdetector --output=../reorgdetector --outpkg=reorgdetector --inpackage --structname=EthClientMock --filename=mock_eth_client.go From 0d2ae94c15d81ae43fd4eda323514e05d2ec2398 Mon Sep 17 00:00:00 2001 From: joanestebanr <129153821+joanestebanr@users.noreply.github.com> Date: Thu, 1 Aug 2024 15:40:53 +0200 Subject: [PATCH 10/10] reduce to 1 verified batches --- test/run-e2e-seq_sender.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/run-e2e-seq_sender.sh b/test/run-e2e-seq_sender.sh index 8fe81590..95101ed3 100755 --- a/test/run-e2e-seq_sender.sh +++ b/test/run-e2e-seq_sender.sh @@ -31,4 +31,4 @@ kurtosis clean --all kurtosis run --enclave cdk-v1 --args-file $DEST_KURTOSIS_PARAMS_YML --image-download always $KURTOSIS_FOLDER #[ $? -ne 0 ] && echo "Error running kurtosis" && exit 1 echo "Waiting 10 minutes to get some verified batch...." -$KURTOSIS_FOLDER/.github/actions/monitor-cdk-verified-batches/batch_verification_monitor.sh 1 600 \ No newline at end of file +$KURTOSIS_FOLDER/.github/actions/monitor-cdk-verified-batches/batch_verification_monitor.sh 0 600 \ No newline at end of file