From be94a18fa6fa8f500b04de17104dc97a7ea19ad0 Mon Sep 17 00:00:00 2001 From: Mantre Date: Mon, 30 Dec 2024 16:25:52 +0800 Subject: [PATCH] chore: update client log (#218) --- .../engine/command/voucher/create_test.go | 6 +- internal/repository/mock.go | 130 +++++++-------- pkg/client/client.go | 12 +- pkg/client/client_mgr.go | 13 +- pkg/client/client_mgr_test.go | 1 + pkg/client/interface.go | 2 +- pkg/client/mock.go | 150 +++++++++--------- pkg/wallet/mock.go | 15 -- 8 files changed, 161 insertions(+), 168 deletions(-) diff --git a/internal/engine/command/voucher/create_test.go b/internal/engine/command/voucher/create_test.go index 8ba184be..ae0aa540 100644 --- a/internal/engine/command/voucher/create_test.go +++ b/internal/engine/command/voucher/create_test.go @@ -14,13 +14,13 @@ import ( "go.uber.org/mock/gomock" ) -func setup(t *testing.T) (*Voucher, repository.MockDatabase, client.MockManager, wallet.MockIWallet) { +func setup(t *testing.T) (*Voucher, repository.MockIDatabase, client.MockIManager, wallet.MockIWallet) { t.Helper() ctrl := gomock.NewController(t) - mockDB := repository.NewMockDatabase(ctrl) - mockClient := client.NewMockManager(ctrl) + mockDB := repository.NewMockIDatabase(ctrl) + mockClient := client.NewMockIManager(ctrl) mockWallet := wallet.NewMockIWallet(ctrl) mockVoucher := NewVoucher(mockDB, mockWallet, mockClient) diff --git a/internal/repository/mock.go b/internal/repository/mock.go index c41fbb89..1f6e331a 100644 --- a/internal/repository/mock.go +++ b/internal/repository/mock.go @@ -16,32 +16,32 @@ import ( gomock "go.uber.org/mock/gomock" ) -// MockDatabase is a mock of Database interface. -type MockDatabase struct { +// MockIDatabase is a mock of IDatabase interface. +type MockIDatabase struct { ctrl *gomock.Controller - recorder *MockDatabaseMockRecorder + recorder *MockIDatabaseMockRecorder isgomock struct{} } -// MockDatabaseMockRecorder is the mock recorder for MockDatabase. -type MockDatabaseMockRecorder struct { - mock *MockDatabase +// MockIDatabaseMockRecorder is the mock recorder for MockIDatabase. +type MockIDatabaseMockRecorder struct { + mock *MockIDatabase } -// NewMockDatabase creates a new mock instance. -func NewMockDatabase(ctrl *gomock.Controller) *MockDatabase { - mock := &MockDatabase{ctrl: ctrl} - mock.recorder = &MockDatabaseMockRecorder{mock} +// NewMockIDatabase creates a new mock instance. +func NewMockIDatabase(ctrl *gomock.Controller) *MockIDatabase { + mock := &MockIDatabase{ctrl: ctrl} + mock.recorder = &MockIDatabaseMockRecorder{mock} return mock } // EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockDatabase) EXPECT() *MockDatabaseMockRecorder { +func (m *MockIDatabase) EXPECT() *MockIDatabaseMockRecorder { return m.recorder } // AddFaucet mocks base method. -func (m *MockDatabase) AddFaucet(f *entity.PhoenixFaucet) error { +func (m *MockIDatabase) AddFaucet(f *entity.PhoenixFaucet) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "AddFaucet", f) ret0, _ := ret[0].(error) @@ -49,13 +49,13 @@ func (m *MockDatabase) AddFaucet(f *entity.PhoenixFaucet) error { } // AddFaucet indicates an expected call of AddFaucet. -func (mr *MockDatabaseMockRecorder) AddFaucet(f any) *gomock.Call { +func (mr *MockIDatabaseMockRecorder) AddFaucet(f any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddFaucet", reflect.TypeOf((*MockDatabase)(nil).AddFaucet), f) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddFaucet", reflect.TypeOf((*MockIDatabase)(nil).AddFaucet), f) } // AddNotification mocks base method. -func (m *MockDatabase) AddNotification(v *entity.Notification) error { +func (m *MockIDatabase) AddNotification(v *entity.Notification) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "AddNotification", v) ret0, _ := ret[0].(error) @@ -63,13 +63,13 @@ func (m *MockDatabase) AddNotification(v *entity.Notification) error { } // AddNotification indicates an expected call of AddNotification. -func (mr *MockDatabaseMockRecorder) AddNotification(v any) *gomock.Call { +func (mr *MockIDatabaseMockRecorder) AddNotification(v any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddNotification", reflect.TypeOf((*MockDatabase)(nil).AddNotification), v) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddNotification", reflect.TypeOf((*MockIDatabase)(nil).AddNotification), v) } // AddUser mocks base method. -func (m *MockDatabase) AddUser(u *entity.User) error { +func (m *MockIDatabase) AddUser(u *entity.User) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "AddUser", u) ret0, _ := ret[0].(error) @@ -77,13 +77,13 @@ func (m *MockDatabase) AddUser(u *entity.User) error { } // AddUser indicates an expected call of AddUser. -func (mr *MockDatabaseMockRecorder) AddUser(u any) *gomock.Call { +func (mr *MockIDatabaseMockRecorder) AddUser(u any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddUser", reflect.TypeOf((*MockDatabase)(nil).AddUser), u) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddUser", reflect.TypeOf((*MockIDatabase)(nil).AddUser), u) } // AddValidator mocks base method. -func (m *MockDatabase) AddValidator(arg0 *entity.Validator) error { +func (m *MockIDatabase) AddValidator(arg0 *entity.Validator) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "AddValidator", arg0) ret0, _ := ret[0].(error) @@ -91,13 +91,13 @@ func (m *MockDatabase) AddValidator(arg0 *entity.Validator) error { } // AddValidator indicates an expected call of AddValidator. -func (mr *MockDatabaseMockRecorder) AddValidator(arg0 any) *gomock.Call { +func (mr *MockIDatabaseMockRecorder) AddValidator(arg0 any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddValidator", reflect.TypeOf((*MockDatabase)(nil).AddValidator), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddValidator", reflect.TypeOf((*MockIDatabase)(nil).AddValidator), arg0) } // AddVoucher mocks base method. -func (m *MockDatabase) AddVoucher(v *entity.Voucher) error { +func (m *MockIDatabase) AddVoucher(v *entity.Voucher) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "AddVoucher", v) ret0, _ := ret[0].(error) @@ -105,13 +105,13 @@ func (m *MockDatabase) AddVoucher(v *entity.Voucher) error { } // AddVoucher indicates an expected call of AddVoucher. -func (mr *MockDatabaseMockRecorder) AddVoucher(v any) *gomock.Call { +func (mr *MockIDatabaseMockRecorder) AddVoucher(v any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddVoucher", reflect.TypeOf((*MockDatabase)(nil).AddVoucher), v) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddVoucher", reflect.TypeOf((*MockIDatabase)(nil).AddVoucher), v) } // AddZealyUser mocks base method. -func (m *MockDatabase) AddZealyUser(u *entity.ZealyUser) error { +func (m *MockIDatabase) AddZealyUser(u *entity.ZealyUser) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "AddZealyUser", u) ret0, _ := ret[0].(error) @@ -119,13 +119,13 @@ func (m *MockDatabase) AddZealyUser(u *entity.ZealyUser) error { } // AddZealyUser indicates an expected call of AddZealyUser. -func (mr *MockDatabaseMockRecorder) AddZealyUser(u any) *gomock.Call { +func (mr *MockIDatabaseMockRecorder) AddZealyUser(u any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddZealyUser", reflect.TypeOf((*MockDatabase)(nil).AddZealyUser), u) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddZealyUser", reflect.TypeOf((*MockIDatabase)(nil).AddZealyUser), u) } // CanGetFaucet mocks base method. -func (m *MockDatabase) CanGetFaucet(user *entity.User) bool { +func (m *MockIDatabase) CanGetFaucet(user *entity.User) bool { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "CanGetFaucet", user) ret0, _ := ret[0].(bool) @@ -133,13 +133,13 @@ func (m *MockDatabase) CanGetFaucet(user *entity.User) bool { } // CanGetFaucet indicates an expected call of CanGetFaucet. -func (mr *MockDatabaseMockRecorder) CanGetFaucet(user any) *gomock.Call { +func (mr *MockIDatabaseMockRecorder) CanGetFaucet(user any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CanGetFaucet", reflect.TypeOf((*MockDatabase)(nil).CanGetFaucet), user) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CanGetFaucet", reflect.TypeOf((*MockIDatabase)(nil).CanGetFaucet), user) } // ClaimVoucher mocks base method. -func (m *MockDatabase) ClaimVoucher(id uint, txHash string, claimer uint) error { +func (m *MockIDatabase) ClaimVoucher(id uint, txHash string, claimer uint) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ClaimVoucher", id, txHash, claimer) ret0, _ := ret[0].(error) @@ -147,13 +147,13 @@ func (m *MockDatabase) ClaimVoucher(id uint, txHash string, claimer uint) error } // ClaimVoucher indicates an expected call of ClaimVoucher. -func (mr *MockDatabaseMockRecorder) ClaimVoucher(id, txHash, claimer any) *gomock.Call { +func (mr *MockIDatabaseMockRecorder) ClaimVoucher(id, txHash, claimer any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ClaimVoucher", reflect.TypeOf((*MockDatabase)(nil).ClaimVoucher), id, txHash, claimer) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ClaimVoucher", reflect.TypeOf((*MockIDatabase)(nil).ClaimVoucher), id, txHash, claimer) } // GetAllZealyUser mocks base method. -func (m *MockDatabase) GetAllZealyUser() ([]*entity.ZealyUser, error) { +func (m *MockIDatabase) GetAllZealyUser() ([]*entity.ZealyUser, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetAllZealyUser") ret0, _ := ret[0].([]*entity.ZealyUser) @@ -162,13 +162,13 @@ func (m *MockDatabase) GetAllZealyUser() ([]*entity.ZealyUser, error) { } // GetAllZealyUser indicates an expected call of GetAllZealyUser. -func (mr *MockDatabaseMockRecorder) GetAllZealyUser() *gomock.Call { +func (mr *MockIDatabaseMockRecorder) GetAllZealyUser() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAllZealyUser", reflect.TypeOf((*MockDatabase)(nil).GetAllZealyUser)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAllZealyUser", reflect.TypeOf((*MockIDatabase)(nil).GetAllZealyUser)) } // GetPendingMailNotification mocks base method. -func (m *MockDatabase) GetPendingMailNotification() (*entity.Notification, error) { +func (m *MockIDatabase) GetPendingMailNotification() (*entity.Notification, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetPendingMailNotification") ret0, _ := ret[0].(*entity.Notification) @@ -177,13 +177,13 @@ func (m *MockDatabase) GetPendingMailNotification() (*entity.Notification, error } // GetPendingMailNotification indicates an expected call of GetPendingMailNotification. -func (mr *MockDatabaseMockRecorder) GetPendingMailNotification() *gomock.Call { +func (mr *MockIDatabaseMockRecorder) GetPendingMailNotification() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPendingMailNotification", reflect.TypeOf((*MockDatabase)(nil).GetPendingMailNotification)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPendingMailNotification", reflect.TypeOf((*MockIDatabase)(nil).GetPendingMailNotification)) } // GetUserByApp mocks base method. -func (m *MockDatabase) GetUserByApp(appID entity.AppID, callerID string) (*entity.User, error) { +func (m *MockIDatabase) GetUserByApp(appID entity.AppID, callerID string) (*entity.User, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetUserByApp", appID, callerID) ret0, _ := ret[0].(*entity.User) @@ -192,13 +192,13 @@ func (m *MockDatabase) GetUserByApp(appID entity.AppID, callerID string) (*entit } // GetUserByApp indicates an expected call of GetUserByApp. -func (mr *MockDatabaseMockRecorder) GetUserByApp(appID, callerID any) *gomock.Call { +func (mr *MockIDatabaseMockRecorder) GetUserByApp(appID, callerID any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetUserByApp", reflect.TypeOf((*MockDatabase)(nil).GetUserByApp), appID, callerID) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetUserByApp", reflect.TypeOf((*MockIDatabase)(nil).GetUserByApp), appID, callerID) } // GetValidator mocks base method. -func (m *MockDatabase) GetValidator(arg0 uint) (entity.Validator, error) { +func (m *MockIDatabase) GetValidator(arg0 uint) (entity.Validator, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetValidator", arg0) ret0, _ := ret[0].(entity.Validator) @@ -207,13 +207,13 @@ func (m *MockDatabase) GetValidator(arg0 uint) (entity.Validator, error) { } // GetValidator indicates an expected call of GetValidator. -func (mr *MockDatabaseMockRecorder) GetValidator(arg0 any) *gomock.Call { +func (mr *MockIDatabaseMockRecorder) GetValidator(arg0 any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetValidator", reflect.TypeOf((*MockDatabase)(nil).GetValidator), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetValidator", reflect.TypeOf((*MockIDatabase)(nil).GetValidator), arg0) } // GetVoucherByCode mocks base method. -func (m *MockDatabase) GetVoucherByCode(code string) (entity.Voucher, error) { +func (m *MockIDatabase) GetVoucherByCode(code string) (entity.Voucher, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetVoucherByCode", code) ret0, _ := ret[0].(entity.Voucher) @@ -222,13 +222,13 @@ func (m *MockDatabase) GetVoucherByCode(code string) (entity.Voucher, error) { } // GetVoucherByCode indicates an expected call of GetVoucherByCode. -func (mr *MockDatabaseMockRecorder) GetVoucherByCode(code any) *gomock.Call { +func (mr *MockIDatabaseMockRecorder) GetVoucherByCode(code any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetVoucherByCode", reflect.TypeOf((*MockDatabase)(nil).GetVoucherByCode), code) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetVoucherByCode", reflect.TypeOf((*MockIDatabase)(nil).GetVoucherByCode), code) } // GetZealyUser mocks base method. -func (m *MockDatabase) GetZealyUser(id string) (*entity.ZealyUser, error) { +func (m *MockIDatabase) GetZealyUser(id string) (*entity.ZealyUser, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetZealyUser", id) ret0, _ := ret[0].(*entity.ZealyUser) @@ -237,13 +237,13 @@ func (m *MockDatabase) GetZealyUser(id string) (*entity.ZealyUser, error) { } // GetZealyUser indicates an expected call of GetZealyUser. -func (mr *MockDatabaseMockRecorder) GetZealyUser(id any) *gomock.Call { +func (mr *MockIDatabaseMockRecorder) GetZealyUser(id any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetZealyUser", reflect.TypeOf((*MockDatabase)(nil).GetZealyUser), id) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetZealyUser", reflect.TypeOf((*MockIDatabase)(nil).GetZealyUser), id) } // HasUser mocks base method. -func (m *MockDatabase) HasUser(id string) bool { +func (m *MockIDatabase) HasUser(id string) bool { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "HasUser", id) ret0, _ := ret[0].(bool) @@ -251,13 +251,13 @@ func (m *MockDatabase) HasUser(id string) bool { } // HasUser indicates an expected call of HasUser. -func (mr *MockDatabaseMockRecorder) HasUser(id any) *gomock.Call { +func (mr *MockIDatabaseMockRecorder) HasUser(id any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HasUser", reflect.TypeOf((*MockDatabase)(nil).HasUser), id) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HasUser", reflect.TypeOf((*MockIDatabase)(nil).HasUser), id) } // ListVoucher mocks base method. -func (m *MockDatabase) ListVoucher() ([]*entity.Voucher, error) { +func (m *MockIDatabase) ListVoucher() ([]*entity.Voucher, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ListVoucher") ret0, _ := ret[0].([]*entity.Voucher) @@ -266,13 +266,13 @@ func (m *MockDatabase) ListVoucher() ([]*entity.Voucher, error) { } // ListVoucher indicates an expected call of ListVoucher. -func (mr *MockDatabaseMockRecorder) ListVoucher() *gomock.Call { +func (mr *MockIDatabaseMockRecorder) ListVoucher() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListVoucher", reflect.TypeOf((*MockDatabase)(nil).ListVoucher)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListVoucher", reflect.TypeOf((*MockIDatabase)(nil).ListVoucher)) } // UpdateNotificationStatus mocks base method. -func (m *MockDatabase) UpdateNotificationStatus(id uint, status entity.NotificationStatus) error { +func (m *MockIDatabase) UpdateNotificationStatus(id uint, status entity.NotificationStatus) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "UpdateNotificationStatus", id, status) ret0, _ := ret[0].(error) @@ -280,13 +280,13 @@ func (m *MockDatabase) UpdateNotificationStatus(id uint, status entity.Notificat } // UpdateNotificationStatus indicates an expected call of UpdateNotificationStatus. -func (mr *MockDatabaseMockRecorder) UpdateNotificationStatus(id, status any) *gomock.Call { +func (mr *MockIDatabaseMockRecorder) UpdateNotificationStatus(id, status any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateNotificationStatus", reflect.TypeOf((*MockDatabase)(nil).UpdateNotificationStatus), id, status) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateNotificationStatus", reflect.TypeOf((*MockIDatabase)(nil).UpdateNotificationStatus), id, status) } // UpdateZealyUser mocks base method. -func (m *MockDatabase) UpdateZealyUser(id, txHash string) error { +func (m *MockIDatabase) UpdateZealyUser(id, txHash string) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "UpdateZealyUser", id, txHash) ret0, _ := ret[0].(error) @@ -294,7 +294,7 @@ func (m *MockDatabase) UpdateZealyUser(id, txHash string) error { } // UpdateZealyUser indicates an expected call of UpdateZealyUser. -func (mr *MockDatabaseMockRecorder) UpdateZealyUser(id, txHash any) *gomock.Call { +func (mr *MockIDatabaseMockRecorder) UpdateZealyUser(id, txHash any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateZealyUser", reflect.TypeOf((*MockDatabase)(nil).UpdateZealyUser), id, txHash) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateZealyUser", reflect.TypeOf((*MockIDatabase)(nil).UpdateZealyUser), id, txHash) } diff --git a/pkg/client/client.go b/pkg/client/client.go index ec9eaa3a..f88df906 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -14,24 +14,30 @@ type Client struct { networkClient pactus.NetworkClient transactionClient pactus.TransactionClient conn *grpc.ClientConn + target string } -func NewClient(endpoint string) (*Client, error) { - conn, err := grpc.NewClient(endpoint, grpc.WithTransportCredentials(insecure.NewCredentials())) +func NewClient(target string) (*Client, error) { + conn, err := grpc.NewClient(target, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { return nil, err } - log.Info("establishing new connection", "addr", endpoint) + log.Info("establishing new connection", "addr", target) return &Client{ blockchainClient: pactus.NewBlockchainClient(conn), networkClient: pactus.NewNetworkClient(conn), transactionClient: pactus.NewTransactionClient(conn), conn: conn, + target: target, }, nil } +func (c *Client) Target() string { + return c.target +} + func (c *Client) GetBlockchainInfo(ctx context.Context) (*pactus.GetBlockchainInfoResponse, error) { blockchainInfo, err := c.blockchainClient.GetBlockchainInfo(ctx, &pactus.GetBlockchainInfoRequest{}) if err != nil { diff --git a/pkg/client/client_mgr.go b/pkg/client/client_mgr.go index 908cf0cd..f9f76587 100644 --- a/pkg/client/client_mgr.go +++ b/pkg/client/client_mgr.go @@ -59,29 +59,28 @@ func (cm *Manager) Stop() { func (cm *Manager) updateValMap() { freshValMap := make(map[string]*pactus.PeerInfo) - for _, c := range cm.clients { - networkInfo, err := c.GetNetworkInfo(cm.ctx) + for _, client := range cm.clients { + networkInfo, err := client.GetNetworkInfo(cm.ctx) if err != nil { - logger.Warn("cannot connect to client", "err", err) + logger.Warn("cannot connect to client", "err", err, "target", client.Target()) continue } if networkInfo == nil { - logger.Warn("network info is nil") + logger.Warn("network info is nil", "target", client.Target()) continue } if len(networkInfo.GetConnectedPeers()) == 0 { - logger.Warn("no connected peers") + logger.Warn("no connected peers", "target", client.Target()) continue } - logger.Info("connected peers = ", "count", networkInfo.ConnectedPeersCount) + logger.Info("fetching network information", "target", client.Target(), "connected", networkInfo.ConnectedPeersCount) for _, peer := range networkInfo.ConnectedPeers { - logger.Info("sync peer", "peerId", peer.PeerId) for _, addr := range peer.ConsensusAddresses { current := freshValMap[addr] if current != nil { diff --git a/pkg/client/client_mgr_test.go b/pkg/client/client_mgr_test.go index 7eb7a758..c40e61ea 100644 --- a/pkg/client/client_mgr_test.go +++ b/pkg/client/client_mgr_test.go @@ -23,6 +23,7 @@ func setup(t *testing.T) (*Manager, *MockIClient) { func TestFindPublicKey(t *testing.T) { clientMgr, mockClient := setup(t) + mockClient.EXPECT().Target().AnyTimes().Return("target") mockClient.EXPECT().GetNetworkInfo(gomock.Any()).Return( &pactus.GetNetworkInfoResponse{ ConnectedPeers: []*pactus.PeerInfo{ diff --git a/pkg/client/interface.go b/pkg/client/interface.go index 4f4fc24c..fe2a13aa 100644 --- a/pkg/client/interface.go +++ b/pkg/client/interface.go @@ -7,6 +7,7 @@ import ( ) type IClient interface { + Target() string GetBlockchainInfo(context.Context) (*pactus.GetBlockchainInfoResponse, error) GetBlockchainHeight(context.Context) (uint32, error) GetLastBlockTime(context.Context) (uint32, uint32) @@ -22,7 +23,6 @@ type IClient interface { type IManager interface { Start() Stop() - updateValMap() AddClient(c IClient) GetLocalClient() IClient GetRandomClient() IClient diff --git a/pkg/client/mock.go b/pkg/client/mock.go index d007c19f..c031bb42 100644 --- a/pkg/client/mock.go +++ b/pkg/client/mock.go @@ -190,44 +190,58 @@ func (mr *MockIClientMockRecorder) GetValidatorInfoByNumber(arg0, arg1 any) *gom return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetValidatorInfoByNumber", reflect.TypeOf((*MockIClient)(nil).GetValidatorInfoByNumber), arg0, arg1) } -// MockManager is a mock of Manager interface. -type MockManager struct { +// Target mocks base method. +func (m *MockIClient) Target() string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Target") + ret0, _ := ret[0].(string) + return ret0 +} + +// Target indicates an expected call of Target. +func (mr *MockIClientMockRecorder) Target() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Target", reflect.TypeOf((*MockIClient)(nil).Target)) +} + +// MockIManager is a mock of IManager interface. +type MockIManager struct { ctrl *gomock.Controller - recorder *MockManagerMockRecorder + recorder *MockIManagerMockRecorder isgomock struct{} } -// MockManagerMockRecorder is the mock recorder for MockManager. -type MockManagerMockRecorder struct { - mock *MockManager +// MockIManagerMockRecorder is the mock recorder for MockIManager. +type MockIManagerMockRecorder struct { + mock *MockIManager } -// NewMockManager creates a new mock instance. -func NewMockManager(ctrl *gomock.Controller) *MockManager { - mock := &MockManager{ctrl: ctrl} - mock.recorder = &MockManagerMockRecorder{mock} +// NewMockIManager creates a new mock instance. +func NewMockIManager(ctrl *gomock.Controller) *MockIManager { + mock := &MockIManager{ctrl: ctrl} + mock.recorder = &MockIManagerMockRecorder{mock} return mock } // EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockManager) EXPECT() *MockManagerMockRecorder { +func (m *MockIManager) EXPECT() *MockIManagerMockRecorder { return m.recorder } // AddClient mocks base method. -func (m *MockManager) AddClient(c IClient) { +func (m *MockIManager) AddClient(c IClient) { m.ctrl.T.Helper() m.ctrl.Call(m, "AddClient", c) } // AddClient indicates an expected call of AddClient. -func (mr *MockManagerMockRecorder) AddClient(c any) *gomock.Call { +func (mr *MockIManagerMockRecorder) AddClient(c any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddClient", reflect.TypeOf((*MockManager)(nil).AddClient), c) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddClient", reflect.TypeOf((*MockIManager)(nil).AddClient), c) } // FindPublicKey mocks base method. -func (m *MockManager) FindPublicKey(address string, firstVal bool) (string, error) { +func (m *MockIManager) FindPublicKey(address string, firstVal bool) (string, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "FindPublicKey", address, firstVal) ret0, _ := ret[0].(string) @@ -236,13 +250,13 @@ func (m *MockManager) FindPublicKey(address string, firstVal bool) (string, erro } // FindPublicKey indicates an expected call of FindPublicKey. -func (mr *MockManagerMockRecorder) FindPublicKey(address, firstVal any) *gomock.Call { +func (mr *MockIManagerMockRecorder) FindPublicKey(address, firstVal any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindPublicKey", reflect.TypeOf((*MockManager)(nil).FindPublicKey), address, firstVal) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindPublicKey", reflect.TypeOf((*MockIManager)(nil).FindPublicKey), address, firstVal) } // GetBalance mocks base method. -func (m *MockManager) GetBalance(addr string) (int64, error) { +func (m *MockIManager) GetBalance(addr string) (int64, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetBalance", addr) ret0, _ := ret[0].(int64) @@ -251,13 +265,13 @@ func (m *MockManager) GetBalance(addr string) (int64, error) { } // GetBalance indicates an expected call of GetBalance. -func (mr *MockManagerMockRecorder) GetBalance(addr any) *gomock.Call { +func (mr *MockIManagerMockRecorder) GetBalance(addr any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBalance", reflect.TypeOf((*MockManager)(nil).GetBalance), addr) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBalance", reflect.TypeOf((*MockIManager)(nil).GetBalance), addr) } // GetBlockchainHeight mocks base method. -func (m *MockManager) GetBlockchainHeight() (uint32, error) { +func (m *MockIManager) GetBlockchainHeight() (uint32, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetBlockchainHeight") ret0, _ := ret[0].(uint32) @@ -266,13 +280,13 @@ func (m *MockManager) GetBlockchainHeight() (uint32, error) { } // GetBlockchainHeight indicates an expected call of GetBlockchainHeight. -func (mr *MockManagerMockRecorder) GetBlockchainHeight() *gomock.Call { +func (mr *MockIManagerMockRecorder) GetBlockchainHeight() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBlockchainHeight", reflect.TypeOf((*MockManager)(nil).GetBlockchainHeight)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBlockchainHeight", reflect.TypeOf((*MockIManager)(nil).GetBlockchainHeight)) } // GetBlockchainInfo mocks base method. -func (m *MockManager) GetBlockchainInfo() (*pactus.GetBlockchainInfoResponse, error) { +func (m *MockIManager) GetBlockchainInfo() (*pactus.GetBlockchainInfoResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetBlockchainInfo") ret0, _ := ret[0].(*pactus.GetBlockchainInfoResponse) @@ -281,13 +295,13 @@ func (m *MockManager) GetBlockchainInfo() (*pactus.GetBlockchainInfoResponse, er } // GetBlockchainInfo indicates an expected call of GetBlockchainInfo. -func (mr *MockManagerMockRecorder) GetBlockchainInfo() *gomock.Call { +func (mr *MockIManagerMockRecorder) GetBlockchainInfo() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBlockchainInfo", reflect.TypeOf((*MockManager)(nil).GetBlockchainInfo)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBlockchainInfo", reflect.TypeOf((*MockIManager)(nil).GetBlockchainInfo)) } // GetCirculatingSupply mocks base method. -func (m *MockManager) GetCirculatingSupply() int64 { +func (m *MockIManager) GetCirculatingSupply() int64 { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetCirculatingSupply") ret0, _ := ret[0].(int64) @@ -295,13 +309,13 @@ func (m *MockManager) GetCirculatingSupply() int64 { } // GetCirculatingSupply indicates an expected call of GetCirculatingSupply. -func (mr *MockManagerMockRecorder) GetCirculatingSupply() *gomock.Call { +func (mr *MockIManagerMockRecorder) GetCirculatingSupply() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCirculatingSupply", reflect.TypeOf((*MockManager)(nil).GetCirculatingSupply)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCirculatingSupply", reflect.TypeOf((*MockIManager)(nil).GetCirculatingSupply)) } // GetFee mocks base method. -func (m *MockManager) GetFee(amt int64) (int64, error) { +func (m *MockIManager) GetFee(amt int64) (int64, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetFee", amt) ret0, _ := ret[0].(int64) @@ -310,13 +324,13 @@ func (m *MockManager) GetFee(amt int64) (int64, error) { } // GetFee indicates an expected call of GetFee. -func (mr *MockManagerMockRecorder) GetFee(amt any) *gomock.Call { +func (mr *MockIManagerMockRecorder) GetFee(amt any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetFee", reflect.TypeOf((*MockManager)(nil).GetFee), amt) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetFee", reflect.TypeOf((*MockIManager)(nil).GetFee), amt) } // GetLastBlockTime mocks base method. -func (m *MockManager) GetLastBlockTime() (uint32, uint32) { +func (m *MockIManager) GetLastBlockTime() (uint32, uint32) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetLastBlockTime") ret0, _ := ret[0].(uint32) @@ -325,13 +339,13 @@ func (m *MockManager) GetLastBlockTime() (uint32, uint32) { } // GetLastBlockTime indicates an expected call of GetLastBlockTime. -func (mr *MockManagerMockRecorder) GetLastBlockTime() *gomock.Call { +func (mr *MockIManagerMockRecorder) GetLastBlockTime() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLastBlockTime", reflect.TypeOf((*MockManager)(nil).GetLastBlockTime)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLastBlockTime", reflect.TypeOf((*MockIManager)(nil).GetLastBlockTime)) } // GetLocalClient mocks base method. -func (m *MockManager) GetLocalClient() IClient { +func (m *MockIManager) GetLocalClient() IClient { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetLocalClient") ret0, _ := ret[0].(IClient) @@ -339,13 +353,13 @@ func (m *MockManager) GetLocalClient() IClient { } // GetLocalClient indicates an expected call of GetLocalClient. -func (mr *MockManagerMockRecorder) GetLocalClient() *gomock.Call { +func (mr *MockIManagerMockRecorder) GetLocalClient() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLocalClient", reflect.TypeOf((*MockManager)(nil).GetLocalClient)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLocalClient", reflect.TypeOf((*MockIManager)(nil).GetLocalClient)) } // GetNetworkInfo mocks base method. -func (m *MockManager) GetNetworkInfo() (*pactus.GetNetworkInfoResponse, error) { +func (m *MockIManager) GetNetworkInfo() (*pactus.GetNetworkInfoResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetNetworkInfo") ret0, _ := ret[0].(*pactus.GetNetworkInfoResponse) @@ -354,13 +368,13 @@ func (m *MockManager) GetNetworkInfo() (*pactus.GetNetworkInfoResponse, error) { } // GetNetworkInfo indicates an expected call of GetNetworkInfo. -func (mr *MockManagerMockRecorder) GetNetworkInfo() *gomock.Call { +func (mr *MockIManagerMockRecorder) GetNetworkInfo() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetNetworkInfo", reflect.TypeOf((*MockManager)(nil).GetNetworkInfo)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetNetworkInfo", reflect.TypeOf((*MockIManager)(nil).GetNetworkInfo)) } // GetPeerInfo mocks base method. -func (m *MockManager) GetPeerInfo(address string) (*pactus.PeerInfo, error) { +func (m *MockIManager) GetPeerInfo(address string) (*pactus.PeerInfo, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetPeerInfo", address) ret0, _ := ret[0].(*pactus.PeerInfo) @@ -369,13 +383,13 @@ func (m *MockManager) GetPeerInfo(address string) (*pactus.PeerInfo, error) { } // GetPeerInfo indicates an expected call of GetPeerInfo. -func (mr *MockManagerMockRecorder) GetPeerInfo(address any) *gomock.Call { +func (mr *MockIManagerMockRecorder) GetPeerInfo(address any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPeerInfo", reflect.TypeOf((*MockManager)(nil).GetPeerInfo), address) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPeerInfo", reflect.TypeOf((*MockIManager)(nil).GetPeerInfo), address) } // GetRandomClient mocks base method. -func (m *MockManager) GetRandomClient() IClient { +func (m *MockIManager) GetRandomClient() IClient { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetRandomClient") ret0, _ := ret[0].(IClient) @@ -383,13 +397,13 @@ func (m *MockManager) GetRandomClient() IClient { } // GetRandomClient indicates an expected call of GetRandomClient. -func (mr *MockManagerMockRecorder) GetRandomClient() *gomock.Call { +func (mr *MockIManagerMockRecorder) GetRandomClient() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetRandomClient", reflect.TypeOf((*MockManager)(nil).GetRandomClient)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetRandomClient", reflect.TypeOf((*MockIManager)(nil).GetRandomClient)) } // GetTransactionData mocks base method. -func (m *MockManager) GetTransactionData(txID string) (*pactus.GetTransactionResponse, error) { +func (m *MockIManager) GetTransactionData(txID string) (*pactus.GetTransactionResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetTransactionData", txID) ret0, _ := ret[0].(*pactus.GetTransactionResponse) @@ -398,13 +412,13 @@ func (m *MockManager) GetTransactionData(txID string) (*pactus.GetTransactionRes } // GetTransactionData indicates an expected call of GetTransactionData. -func (mr *MockManagerMockRecorder) GetTransactionData(txID any) *gomock.Call { +func (mr *MockIManagerMockRecorder) GetTransactionData(txID any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTransactionData", reflect.TypeOf((*MockManager)(nil).GetTransactionData), txID) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTransactionData", reflect.TypeOf((*MockIManager)(nil).GetTransactionData), txID) } // GetValidatorInfo mocks base method. -func (m *MockManager) GetValidatorInfo(address string) (*pactus.GetValidatorResponse, error) { +func (m *MockIManager) GetValidatorInfo(address string) (*pactus.GetValidatorResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetValidatorInfo", address) ret0, _ := ret[0].(*pactus.GetValidatorResponse) @@ -413,13 +427,13 @@ func (m *MockManager) GetValidatorInfo(address string) (*pactus.GetValidatorResp } // GetValidatorInfo indicates an expected call of GetValidatorInfo. -func (mr *MockManagerMockRecorder) GetValidatorInfo(address any) *gomock.Call { +func (mr *MockIManagerMockRecorder) GetValidatorInfo(address any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetValidatorInfo", reflect.TypeOf((*MockManager)(nil).GetValidatorInfo), address) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetValidatorInfo", reflect.TypeOf((*MockIManager)(nil).GetValidatorInfo), address) } // GetValidatorInfoByNumber mocks base method. -func (m *MockManager) GetValidatorInfoByNumber(num int32) (*pactus.GetValidatorResponse, error) { +func (m *MockIManager) GetValidatorInfoByNumber(num int32) (*pactus.GetValidatorResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetValidatorInfoByNumber", num) ret0, _ := ret[0].(*pactus.GetValidatorResponse) @@ -428,43 +442,31 @@ func (m *MockManager) GetValidatorInfoByNumber(num int32) (*pactus.GetValidatorR } // GetValidatorInfoByNumber indicates an expected call of GetValidatorInfoByNumber. -func (mr *MockManagerMockRecorder) GetValidatorInfoByNumber(num any) *gomock.Call { +func (mr *MockIManagerMockRecorder) GetValidatorInfoByNumber(num any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetValidatorInfoByNumber", reflect.TypeOf((*MockManager)(nil).GetValidatorInfoByNumber), num) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetValidatorInfoByNumber", reflect.TypeOf((*MockIManager)(nil).GetValidatorInfoByNumber), num) } // Start mocks base method. -func (m *MockManager) Start() { +func (m *MockIManager) Start() { m.ctrl.T.Helper() m.ctrl.Call(m, "Start") } // Start indicates an expected call of Start. -func (mr *MockManagerMockRecorder) Start() *gomock.Call { +func (mr *MockIManagerMockRecorder) Start() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Start", reflect.TypeOf((*MockManager)(nil).Start)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Start", reflect.TypeOf((*MockIManager)(nil).Start)) } // Stop mocks base method. -func (m *MockManager) Stop() { +func (m *MockIManager) Stop() { m.ctrl.T.Helper() m.ctrl.Call(m, "Stop") } // Stop indicates an expected call of Stop. -func (mr *MockManagerMockRecorder) Stop() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Stop", reflect.TypeOf((*MockManager)(nil).Stop)) -} - -// updateValMap mocks base method. -func (m *MockManager) updateValMap() { - m.ctrl.T.Helper() - m.ctrl.Call(m, "updateValMap") -} - -// updateValMap indicates an expected call of updateValMap. -func (mr *MockManagerMockRecorder) updateValMap() *gomock.Call { +func (mr *MockIManagerMockRecorder) Stop() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "updateValMap", reflect.TypeOf((*MockManager)(nil).updateValMap)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Stop", reflect.TypeOf((*MockIManager)(nil).Stop)) } diff --git a/pkg/wallet/mock.go b/pkg/wallet/mock.go index b46155f6..558acc9d 100644 --- a/pkg/wallet/mock.go +++ b/pkg/wallet/mock.go @@ -83,21 +83,6 @@ func (mr *MockIWalletMockRecorder) BondTransaction(pubKey, toAddress, memo, amt return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BondTransaction", reflect.TypeOf((*MockIWallet)(nil).BondTransaction), pubKey, toAddress, memo, amt) } -// NewAddress mocks base method. -func (m *MockIWallet) NewAddress(lb string) (string, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "NewAddress", lb) - ret0, _ := ret[0].(string) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// NewAddress indicates an expected call of NewAddress. -func (mr *MockIWalletMockRecorder) NewAddress(lb any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewAddress", reflect.TypeOf((*MockIWallet)(nil).NewAddress), lb) -} - // TransferTransaction mocks base method. func (m *MockIWallet) TransferTransaction(toAddress, memo string, amt amount.Amount) (string, error) { m.ctrl.T.Helper()