From c78d5366f9a0a0c02c0587a8efd273463cd1c039 Mon Sep 17 00:00:00 2001 From: AnkushinDaniil Date: Wed, 1 Jan 2025 17:42:06 +0900 Subject: [PATCH] Remove interfaces --- l1/eth_subscriber.go | 15 ++------ l1/eth_subscriber_test.go | 37 -------------------- mocks/mock_getter.go | 56 ------------------------------ mocks/mock_watcher.go | 73 --------------------------------------- 4 files changed, 2 insertions(+), 179 deletions(-) delete mode 100644 l1/eth_subscriber_test.go delete mode 100644 mocks/mock_getter.go delete mode 100644 mocks/mock_watcher.go diff --git a/l1/eth_subscriber.go b/l1/eth_subscriber.go index 9d60d6fa3c..f60c9f5ecd 100644 --- a/l1/eth_subscriber.go +++ b/l1/eth_subscriber.go @@ -17,24 +17,13 @@ import ( "github.com/ethereum/go-ethereum/rpc" ) -//go:generate mockgen -destination=../mocks/mock_getter.go -package=mocks github.com/NethermindEth/juno/l1 IPAddressGetter -type IPAddressGetter interface { - GetIPAddresses(*bind.CallOpts) ([]string, error) -} - -//go:generate mockgen -destination=../mocks/mock_watcher.go -package=mocks github.com/NethermindEth/juno/l1 IPWatcher -type IPWatcher interface { - WatchIPAdded(*bind.WatchOpts, chan<- *contract.IPAddressRegistryIPAdded) (event.Subscription, error) - WatchIPRemoved(*bind.WatchOpts, chan<- *contract.IPAddressRegistryIPRemoved) (event.Subscription, error) -} - type EthSubscriber struct { ethClient *ethclient.Client client *rpc.Client filterer *contract.StarknetFilterer listener EventListener - ipAddressRegistry IPAddressGetter - ipAddressRegistryFilterer IPWatcher + ipAddressRegistry *contract.IPAddressRegistry + ipAddressRegistryFilterer *contract.IPAddressRegistryFilterer } var _ Subscriber = (*EthSubscriber)(nil) diff --git a/l1/eth_subscriber_test.go b/l1/eth_subscriber_test.go deleted file mode 100644 index 54f184c8f2..0000000000 --- a/l1/eth_subscriber_test.go +++ /dev/null @@ -1,37 +0,0 @@ -package l1 - -import ( - "context" - "testing" - - "github.com/NethermindEth/juno/mocks" - "github.com/ethereum/go-ethereum/common" - "github.com/stretchr/testify/require" - "go.uber.org/mock/gomock" -) - -func TestIPAddressRegistry(t *testing.T) { - t.Parallel() - - ctrl := gomock.NewController(t) - defer ctrl.Finish() - - mockIPAddressGetter := mocks.NewMockIPAddressGetter(ctrl) - mockIPAddressGetter.EXPECT().GetIPAddresses(gomock.Any()).Return([]string{}, nil).Times(1) - - mockIPWatcher := mocks.NewMockIPWatcher(ctrl) - mockIPWatcher.EXPECT().WatchIPAdded(gomock.Any(), gomock.Any()).Return(nil, nil).Times(1) - mockIPWatcher.EXPECT().WatchIPRemoved(gomock.Any(), gomock.Any()).Return(nil, nil).Times(1) - - subscriber := &EthSubscriber{ - ipAddressRegistry: mockIPAddressGetter, - ipAddressRegistryFilterer: mockIPWatcher, - } - - _, err := subscriber.GetIPAddresses(context.Background(), common.Address{}) - require.NoError(t, err) - _, err = subscriber.WatchIPAdded(context.Background(), nil) - require.NoError(t, err) - _, err = subscriber.WatchIPRemoved(context.Background(), nil) - require.NoError(t, err) -} diff --git a/mocks/mock_getter.go b/mocks/mock_getter.go deleted file mode 100644 index cb37c8d9aa..0000000000 --- a/mocks/mock_getter.go +++ /dev/null @@ -1,56 +0,0 @@ -// Code generated by MockGen. DO NOT EDIT. -// Source: github.com/NethermindEth/juno/l1 (interfaces: IPAddressGetter) -// -// Generated by this command: -// -// mockgen -destination=../mocks/mock_getter.go -package=mocks github.com/NethermindEth/juno/l1 IPAddressGetter -// - -// Package mocks is a generated GoMock package. -package mocks - -import ( - reflect "reflect" - - bind "github.com/ethereum/go-ethereum/accounts/abi/bind" - gomock "go.uber.org/mock/gomock" -) - -// MockIPAddressGetter is a mock of IPAddressGetter interface. -type MockIPAddressGetter struct { - ctrl *gomock.Controller - recorder *MockIPAddressGetterMockRecorder - isgomock struct{} -} - -// MockIPAddressGetterMockRecorder is the mock recorder for MockIPAddressGetter. -type MockIPAddressGetterMockRecorder struct { - mock *MockIPAddressGetter -} - -// NewMockIPAddressGetter creates a new mock instance. -func NewMockIPAddressGetter(ctrl *gomock.Controller) *MockIPAddressGetter { - mock := &MockIPAddressGetter{ctrl: ctrl} - mock.recorder = &MockIPAddressGetterMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockIPAddressGetter) EXPECT() *MockIPAddressGetterMockRecorder { - return m.recorder -} - -// GetIPAddresses mocks base method. -func (m *MockIPAddressGetter) GetIPAddresses(arg0 *bind.CallOpts) ([]string, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetIPAddresses", arg0) - ret0, _ := ret[0].([]string) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetIPAddresses indicates an expected call of GetIPAddresses. -func (mr *MockIPAddressGetterMockRecorder) GetIPAddresses(arg0 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetIPAddresses", reflect.TypeOf((*MockIPAddressGetter)(nil).GetIPAddresses), arg0) -} diff --git a/mocks/mock_watcher.go b/mocks/mock_watcher.go deleted file mode 100644 index 46f3fd19b0..0000000000 --- a/mocks/mock_watcher.go +++ /dev/null @@ -1,73 +0,0 @@ -// Code generated by MockGen. DO NOT EDIT. -// Source: github.com/NethermindEth/juno/l1 (interfaces: IPWatcher) -// -// Generated by this command: -// -// mockgen -destination=../mocks/mock_watcher.go -package=mocks github.com/NethermindEth/juno/l1 IPWatcher -// - -// Package mocks is a generated GoMock package. -package mocks - -import ( - reflect "reflect" - - contract "github.com/NethermindEth/juno/l1/contract" - bind "github.com/ethereum/go-ethereum/accounts/abi/bind" - event "github.com/ethereum/go-ethereum/event" - gomock "go.uber.org/mock/gomock" -) - -// MockIPWatcher is a mock of IPWatcher interface. -type MockIPWatcher struct { - ctrl *gomock.Controller - recorder *MockIPWatcherMockRecorder - isgomock struct{} -} - -// MockIPWatcherMockRecorder is the mock recorder for MockIPWatcher. -type MockIPWatcherMockRecorder struct { - mock *MockIPWatcher -} - -// NewMockIPWatcher creates a new mock instance. -func NewMockIPWatcher(ctrl *gomock.Controller) *MockIPWatcher { - mock := &MockIPWatcher{ctrl: ctrl} - mock.recorder = &MockIPWatcherMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockIPWatcher) EXPECT() *MockIPWatcherMockRecorder { - return m.recorder -} - -// WatchIPAdded mocks base method. -func (m *MockIPWatcher) WatchIPAdded(arg0 *bind.WatchOpts, arg1 chan<- *contract.IPAddressRegistryIPAdded) (event.Subscription, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "WatchIPAdded", arg0, arg1) - ret0, _ := ret[0].(event.Subscription) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// WatchIPAdded indicates an expected call of WatchIPAdded. -func (mr *MockIPWatcherMockRecorder) WatchIPAdded(arg0, arg1 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WatchIPAdded", reflect.TypeOf((*MockIPWatcher)(nil).WatchIPAdded), arg0, arg1) -} - -// WatchIPRemoved mocks base method. -func (m *MockIPWatcher) WatchIPRemoved(arg0 *bind.WatchOpts, arg1 chan<- *contract.IPAddressRegistryIPRemoved) (event.Subscription, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "WatchIPRemoved", arg0, arg1) - ret0, _ := ret[0].(event.Subscription) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// WatchIPRemoved indicates an expected call of WatchIPRemoved. -func (mr *MockIPWatcherMockRecorder) WatchIPRemoved(arg0, arg1 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WatchIPRemoved", reflect.TypeOf((*MockIPWatcher)(nil).WatchIPRemoved), arg0, arg1) -}