diff --git a/Makefile b/Makefile index e081dcb7..9b0d5b74 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 -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/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/cmd/run.go b/cmd/run.go index f7d36b74..7f9ed6ed 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -181,15 +181,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/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 8292fd71..b3630871 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) + PostSequenceBanana(ctx context.Context, sequence etherman.SequenceBanana) ([]byte, error) } // SequenceRetriever is used to retrieve batch data 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..773e447c --- /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 +} + +// 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 PostSequenceBanana") + } + + 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_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 +} + +// PostSequenceBanana is a helper method to define mock.On call +// - ctx context.Context +// - sequence etherman.SequenceBanana +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_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_PostSequenceBanana_Call) Return(_a0 []byte, _a1 error) *DABackender_PostSequenceBanana_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *DABackender_PostSequenceBanana_Call) RunAndReturn(run func(context.Context, etherman.SequenceBanana) ([]byte, error)) *DABackender_PostSequenceBanana_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..34345d71 --- /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 +} + +// 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 PostSequenceBanana") + } + + 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_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 +} + +// PostSequenceBanana is a helper method to define mock.On call +// - ctx context.Context +// - sequence etherman.SequenceBanana +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_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_PostSequenceBanana_Call) Return(_a0 []byte, _a1 error) *DataManager_PostSequenceBanana_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *DataManager_PostSequenceBanana_Call) RunAndReturn(run func(context.Context, etherman.SequenceBanana) ([]byte, error)) *DataManager_PostSequenceBanana_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..6a343269 --- /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..f1e44741 --- /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} +} + +// 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 PostSequenceBanana") + } + + 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_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 +} + +// PostSequenceBanana is a helper method to define mock.On call +// - ctx context.Context +// - sequence etherman.SequenceBanana +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_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_PostSequenceBanana_Call) Return(_a0 []byte, _a1 error) *SequenceSender_PostSequenceBanana_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *SequenceSender_PostSequenceBanana_Call) RunAndReturn(run func(context.Context, etherman.SequenceBanana) ([]byte, error)) *SequenceSender_PostSequenceBanana_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_banana.go b/dataavailability/mocks_da/sequence_sender_banana.go new file mode 100644 index 00000000..aca7b1a3 --- /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} +} + +// 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 PostSequenceBanana") + } + + 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_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 +} + +// PostSequenceBanana is a helper method to define mock.On call +// - ctx context.Context +// - sequence etherman.SequenceBanana +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_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_PostSequenceBanana_Call) Return(_a0 []byte, _a1 error) *SequenceSenderBanana_PostSequenceBanana_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *SequenceSenderBanana_PostSequenceBanana_Call) RunAndReturn(run func(context.Context, etherman.SequenceBanana) ([]byte, error)) *SequenceSenderBanana_PostSequenceBanana_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/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/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/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/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..93536c6a 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,71 +12,32 @@ 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) +} + +type globalExitRootBananaContractor interface { + L1InfoRootMap(opts *bind.CallOpts, index uint32) ([32]byte, error) + String() string +} - opts bind.TransactOpts - SenderAddress common.Address +type TxBuilderBananaBase struct { + rollupContract rollupBananaBaseContractor + globalExitRootContract globalExitRootBananaContractor + opts bind.TransactOpts } -func NewTxBuilderBananaBase(rollupContract contracts.RollupBananaType, - gerContract contracts.GlobalExitRootBananaType, - opts bind.TransactOpts, - sender common.Address) *TxBuilderBananaBase { +func NewTxBuilderBananaBase(rollupContract rollupBananaBaseContractor, + gerContract globalExitRootBananaContractor, + opts bind.TransactOpts) *TxBuilderBananaBase { return &TxBuilderBananaBase{ rollupContract: rollupContract, globalExitRootContract: gerContract, opts: opts, - SenderAddress: sender, } } -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, @@ -90,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 } @@ -103,7 +63,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 } @@ -141,11 +101,55 @@ 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) } } 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 := toEthermanBatch(batch) + if err != nil { + return etherman.SequenceBanana{}, err + } + seqEth.SequenceBanana.Batches = append(seqEth.SequenceBanana.Batches, ethBatch) + } + return seqEth.SequenceBanana, nil +} + +func toEthermanBatch(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 toEthermanBatches(batch []seqsendertypes.Batch) ([]etherman.Batch, error) { + result := make([]etherman.Batch, len(batch)) + for i, b := range batch { + var err error + result[i], err = toEthermanBatch(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 d926143a..4693c6cd 100644 --- a/sequencesender/txbuilder/banana_validium.go +++ b/sequencesender/txbuilder/banana_validium.go @@ -2,43 +2,56 @@ 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" "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.SequenceSenderBanana + condNewSeq CondNewSequence + rollupContract rollupBananaValidiumContractor } -func NewTxBuilderBananaValidium(rollupContract contracts.RollupBananaType, - gerContract contracts.GlobalExitRootBananaType, - da dataavailability.SequenceSender, opts bind.TransactOpts, sender common.Address, maxBatchesForL1 uint64) *TxBuilderBananaValidium { +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 globalExitRootBananaContractor, + da dataavailability.SequenceSenderBanana, opts bind.TransactOpts, maxBatchesForL1 uint64) *TxBuilderBananaValidium { return &TxBuilderBananaValidium{ - TxBuilderBananaBase: *NewTxBuilderBananaBase(rollupContract, gerContract, opts, sender), + TxBuilderBananaBase: *NewTxBuilderBananaBase(rollupContract, gerContract, opts), da: da, - condNewSeq: &NewSequenceConditionalNumBatches{ - maxBatchesForL1: maxBatchesForL1, - }, + condNewSeq: NewConditionalNewSequenceNumBatches(maxBatchesForL1), + rollupContract: rollupContract, } } 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, 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, 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 @@ -49,14 +62,19 @@ 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 } + 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(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 +83,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 @@ -94,7 +112,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_validium_test.go b/sequencesender/txbuilder/banana_validium_test.go new file mode 100644 index 00000000..5c6f0d50 --- /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().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().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") + +} + +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().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 { + 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.go b/sequencesender/txbuilder/banana_zkevm.go index dbb679fb..0fa9ddd9 100644 --- a/sequencesender/txbuilder/banana_zkevm.go +++ b/sequencesender/txbuilder/banana_zkevm.go @@ -6,33 +6,49 @@ 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, sender common.Address, 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, sender), - condNewSeq: &NewSequenceConditionalMaxSize{ - maxTxSizeForL1: maxTxSizeForL1, - }, + TxBuilderBananaBase: *NewTxBuilderBananaBase(rollupContract, gerContract, opts), + condNewSeq: NewConditionalNewSequenceMaxSize(maxTxSizeForL1), + rollupContract: rollupContract, } } 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, 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, 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 { @@ -71,7 +87,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/banana_zkevm_test.go b/sequencesender/txbuilder/banana_zkevm_test.go new file mode 100644 index 00000000..8653c504 --- /dev/null +++ b/sequencesender/txbuilder/banana_zkevm_test.go @@ -0,0 +1,105 @@ +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" +) + +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) +} + +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 + 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, + } +} + +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_base.go b/sequencesender/txbuilder/elderberry_base.go index f643a96c..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,17 +9,20 @@ 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, } } +// 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 +46,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..43141f22 --- /dev/null +++ b/sequencesender/txbuilder/elderberry_base_test.go @@ -0,0 +1,98 @@ +package txbuilder + +import ( + "testing" + + "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) { + opts := bind.TransactOpts{} + sut := NewTxBuilderElderberryBase(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 { + opts := bind.TransactOpts{} + sut := NewTxBuilderElderberryBase(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..638ba3b1 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" @@ -20,35 +21,51 @@ 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, sender common.Address, maxBatchesForL1 uint64) *TxBuilderElderberryValidium { + opts bind.TransactOpts, maxBatchesForL1 uint64) *TxBuilderElderberryValidium { return &TxBuilderElderberryValidium{ - da: da, - TxBuilderElderberryBase: *NewTxBuilderElderberryBase( - zkevm, opts, - ), - condNewSeq: &NewSequenceConditionalNumBatches{ - maxBatchesForL1: 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) { - return t.condNewSeq.NewSequenceIfWorthToSend(ctx, t, sequenceBatches, t.opts.From, l2Coinbase, batchNumber) + return t.condNewSeq.NewSequenceIfWorthToSend(ctx, t, sequenceBatches, l2Coinbase) } -func (t *TxBuilderElderberryValidium) 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 *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") + } 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 { + 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 @@ -76,10 +93,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 new file mode 100644 index 00000000..1964867c --- /dev/null +++ b/sequencesender/txbuilder/elderberry_validium_test.go @@ -0,0 +1,116 @@ +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, nil) + require.Error(t, err) + + seq, err := testData.sut.NewSequence(nil, common.Address{}) + require.NoError(t, err) + _, err = testData.sut.BuildSequenceBatchesTx(ctx, 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, 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, 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, seq) + require.NoError(t, err) + 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 +} + +func newElderberryValidiumSUT(t *testing.T) *testDataElderberryValidium { + 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) + opts, err := bind.NewKeyedTransactorWithChainID(privateKey, big.NewInt(1)) + require.NoError(t, err) + + da := mocks_da.NewSequenceSenderElderberry(t) + + sut := txbuilder.NewTxBuilderElderberryValidium(*zkevmContract, da, *opts, 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..83e70971 100644 --- a/sequencesender/txbuilder/elderberry_zkevm.go +++ b/sequencesender/txbuilder/elderberry_zkevm.go @@ -2,11 +2,11 @@ package txbuilder import ( "context" + "fmt" "math/big" "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" @@ -17,26 +17,34 @@ import ( type TxBuilderElderberryZKEVM struct { TxBuilderElderberryBase - condNewSeq CondNewSequence + condNewSeq CondNewSequence + rollupContract rollupElderberryZKEVMContractor } -func NewTxBuilderElderberryZKEVM(zkevm contracts.RollupElderberryType, opts bind.TransactOpts, sender common.Address, 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: &NewSequenceConditionalMaxSize{ - maxTxSizeForL1: maxTxSizeForL1, - }, + TxBuilderElderberryBase: *NewTxBuilderElderberryBase(opts), + condNewSeq: NewConditionalNewSequenceMaxSize(maxTxSizeForL1), + rollupContract: zkevm, } } 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, 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) CondNewSequence { + previous := t.condNewSeq + t.condNewSeq = cond + return previous +} +func (t *TxBuilderElderberryZKEVM) BuildSequenceBatchesTx(ctx context.Context, sequences seqsendertypes.Sequence) (*ethtypes.Transaction, error) { newopts := t.opts newopts.NoSend = true @@ -49,6 +57,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 @@ -65,8 +76,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 new file mode 100644 index 00000000..9ed29823 --- /dev/null +++ b/sequencesender/txbuilder/elderberry_zkevm_test.go @@ -0,0 +1,110 @@ +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/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/require" +) + +func TestElderberryZkevmName(t *testing.T) { + zkevmContract := contracts.RollupElderberryType{} + opts := bind.TransactOpts{} + 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")) +} + +func TestElderberryZkevmNewSequence(t *testing.T) { + zkevmContract := contracts.RollupElderberryType{} + opts := bind.TransactOpts{} + sut := txbuilder.NewTxBuilderElderberryZKEVM(zkevmContract, opts, 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, nil) + require.Error(t, err) + + seq, err := sut.NewSequence(nil, common.Address{}) + require.NoError(t, err) + _, err = sut.BuildSequenceBatchesTx(ctx, 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, 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, seq) + require.Error(t, err) +} + +func TestElderberryZkevmNewSequenceIfWorthToSend(t *testing.T) { + sut := newElderberryZkevmSUT(t) + testSequenceIfWorthToSendNoNewSeq(t, sut) + testSequenceIfWorthToSendErr(t, sut) + testSetCondNewSeq(t, sut) +} + +func newElderberryZkevmSUT(t *testing.T) *txbuilder.TxBuilderElderberryZKEVM { + 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) + opts, err := bind.NewKeyedTransactorWithChainID(privateKey, big.NewInt(1)) + require.NoError(t, err) + 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 8f3b4661..7bfa51be 100644 --- a/sequencesender/txbuilder/interface.go +++ b/sequencesender/txbuilder/interface.go @@ -10,13 +10,20 @@ import ( ) type TxBuilder interface { - BuildSequenceBatchesTx(ctx context.Context, sender common.Address, sequences seqsendertypes.Sequence) (*ethtypes.Transaction, error) + // 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 String() string } 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, l2Coinbase common.Address) (seqsendertypes.Sequence, error) } 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/cond_new_sequence.go b/sequencesender/txbuilder/mocks_txbuilder/cond_new_sequence.go new file mode 100644 index 00000000..ae818ce9 --- /dev/null +++ b/sequencesender/txbuilder/mocks_txbuilder/cond_new_sequence.go @@ -0,0 +1,103 @@ +// 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, 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") + } + + var r0 seqsendertypes.Sequence + var r1 error + 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) 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) error); ok { + r1 = rf(ctx, txBuilder, sequenceBatches, 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 +// - l2Coinbase common.Address +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, 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)) + }) + 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) (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/global_exit_root_banana_contractor.go b/sequencesender/txbuilder/mocks_txbuilder/global_exit_root_banana_contractor.go new file mode 100644 index 00000000..93dadeef --- /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..f7aed125 --- /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..acd82a4e --- /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..a59b88dd --- /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..e29e3252 --- /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..0d94c081 --- /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..1ed208ab --- /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 +} diff --git a/sequencesender/txbuilder/mocks_txbuilder/tx_builder.go b/sequencesender/txbuilder/mocks_txbuilder/tx_builder.go new file mode 100644 index 00000000..14f0539b --- /dev/null +++ b/sequencesender/txbuilder/mocks_txbuilder/tx_builder.go @@ -0,0 +1,366 @@ +// 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" + + txbuilder "github.com/0xPolygon/cdk/sequencesender/txbuilder" + + 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, 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") + } + + var r0 *types.Transaction + var r1 error + 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, 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, seqsendertypes.Sequence) error); ok { + r1 = rf(ctx, 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 +// - sequences seqsendertypes.Sequence +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, sequences seqsendertypes.Sequence)) *TxBuilder_BuildSequenceBatchesTx_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(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, 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 +} + +// 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() + + 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..fd1ad22a 100644 --- a/sequencesender/txbuilder/validium_cond_num_batches.go +++ b/sequencesender/txbuilder/validium_cond_num_batches.go @@ -8,12 +8,20 @@ import ( "github.com/ethereum/go-ethereum/common" ) -type NewSequenceConditionalNumBatches struct { +var MaxBatchesForL1Disabled = uint64(0) + +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) { - if c.maxBatchesForL1 > 0 && len(sequenceBatches) >= int(c.maxBatchesForL1) { +func NewConditionalNewSequenceNumBatches(maxBatchesForL1 uint64) *ConditionalNewSequenceNumBatches { + return &ConditionalNewSequenceNumBatches{ + maxBatchesForL1: maxBatchesForL1, + } +} + +func (c *ConditionalNewSequenceNumBatches) NewSequenceIfWorthToSend(ctx context.Context, txBuilder TxBuilder, sequenceBatches []seqsendertypes.Batch, l2Coinbase common.Address) (seqsendertypes.Sequence, error) { + 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, 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..c449f161 --- /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{}) + 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{}) + 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{}) + 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..98267e17 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" @@ -12,29 +13,50 @@ 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 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, l2Coinbase common.Address) (seqsendertypes.Sequence, error) { + if c.maxTxSizeForL1 == MaxTxSizeForL1Disabled { + log.Debugf("maxTxSizeForL1 is %d, so is disabled", MaxTxSizeForL1Disabled) + 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) + 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()) + 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 +65,42 @@ func (c *NewSequenceConditionalMaxSize) NewSequenceIfWorthToSend(ctx context.Con return nil, err } - _, 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) + } 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..32e49eed --- /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(txbuilder.MaxTxSizeForL1Disabled) + + tx, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, nil, 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{}) + 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).Return(nil, nil) + _, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, sequenceBatches, 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).Return(tx, nil) + + res, err := sut.NewSequenceIfWorthToSend(nil, mockTxBuilder, sequenceBatches, 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, 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, newSeqReduced).Return(tx, nil) + + res, err := sut.NewSequenceIfWorthToSend(ctx, mockTxBuilder, newSeq.Batches(), 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/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_l2_test.go b/sync/mock_l2_test.go index 0d1e03da..7a4bae36 100644 --- a/sync/mock_l2_test.go +++ b/sync/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 sync @@ -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/sync/mock_processor_test.go b/sync/mock_processor_test.go index d2c3e299..acf57388 100644 --- a/sync/mock_processor_test.go +++ b/sync/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 sync @@ -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) ProcessBlock(block Block) error { ret := _m.Called(block) + if len(ret) == 0 { + panic("no return value specified for ProcessBlock") + } + var r0 error if rf, ok := ret.Get(0).(func(Block) error); ok { r0 = rf(block) @@ -55,6 +63,10 @@ func (_m *ProcessorMock) ProcessBlock(block Block) error { 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) @@ -65,13 +77,12 @@ func (_m *ProcessorMock) Reorg(firstReorgedBlock uint64) error { 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/sync/mock_reorgdetector_test.go b/sync/mock_reorgdetector_test.go index 056da2a1..9689f7e7 100644 --- a/sync/mock_reorgdetector_test.go +++ b/sync/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 sync @@ -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/test/Makefile b/test/Makefile index 0e671023..07f7aaaa 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,14 +1,27 @@ .PHONY: generate-mocks -generate-mocks: - $(MAKE) generate-mocks-reorgdetector - $(MAKE) generate-mocks-l1infotreesync - $(MAKE) generate-mocks-aggoracle - $(MAKE) generate-mocks-sync +generate-mocks: generate-mocks-localbridgesync generate-mocks-reorgdetector generate-mocks-sequencesender generate-mocks-da generate-mocks-l1infotreesync generate-mocks-aggoracle generate-mocks-sync + +.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 + .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 +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 + 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 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