From e3a7c589b446e871646acf263480ca615a9e16b4 Mon Sep 17 00:00:00 2001 From: wjrjerome Date: Tue, 15 Oct 2024 00:28:51 +1100 Subject: [PATCH] add mocks --- Makefile | 3 +- config/config-docker.yml | 2 + config/config-local.yml | 2 +- tests/mocks/mock_bbn_client.go | 161 +++++++++++++++++++++++++++++++++ tests/mocks/mock_btc_client.go | 52 +++++++++++ tests/mocks/mock_db_client.go | 30 +++++- 6 files changed, 243 insertions(+), 7 deletions(-) create mode 100644 tests/mocks/mock_bbn_client.go create mode 100644 tests/mocks/mock_btc_client.go diff --git a/Makefile b/Makefile index 9170445..34854ac 100644 --- a/Makefile +++ b/Makefile @@ -44,7 +44,8 @@ run-local: generate-mock-interface: cd internal/db && mockery --name=DbInterface --output=../../tests/mocks --outpkg=mocks --filename=mock_db_client.go - cd internal/btcclient && mockery --name=BtcInterface --output=../../tests/mocks --outpkg=mocks --filename=mock_btc_client.go + cd internal/clients/btcclient && mockery --name=BtcInterface --output=../../../tests/mocks --outpkg=mocks --filename=mock_btc_client.go + cd internal/clients/bbnclient && mockery --name=BbnInterface --output=../../../tests/mocks --outpkg=mocks --filename=mock_bbn_client.go test: ./bin/local-startup.sh; diff --git a/config/config-docker.yml b/config/config-docker.yml index a35860b..834f7b9 100644 --- a/config/config-docker.yml +++ b/config/config-docker.yml @@ -15,6 +15,8 @@ btc: bbn: rpc-addr: https://rpc.devnet.babylonchain.io:443 timeout: 30s +poller: + param-polling-interval: 60s queue: queue_user: user # can be replaced by values in .env file queue_password: password diff --git a/config/config-local.yml b/config/config-local.yml index aa1647a..c3e4843 100644 --- a/config/config-local.yml +++ b/config/config-local.yml @@ -13,7 +13,7 @@ bbn: rpc-addr: https://rpc.devnet.babylonchain.io:443 timeout: 30s poller: - param-polling-interval: 10s + param-polling-interval: 30s queue: queue_user: user # can be replaced by values in .env file queue_password: password diff --git a/tests/mocks/mock_bbn_client.go b/tests/mocks/mock_bbn_client.go new file mode 100644 index 0000000..5bc0b55 --- /dev/null +++ b/tests/mocks/mock_bbn_client.go @@ -0,0 +1,161 @@ +// Code generated by mockery v2.41.0. DO NOT EDIT. + +package mocks + +import ( + bbnclient "github.com/babylonlabs-io/babylon-staking-indexer/internal/clients/bbnclient" + btccheckpointtypes "github.com/babylonlabs-io/babylon/x/btccheckpoint/types" + + context "context" + + coretypes "github.com/cometbft/cometbft/rpc/core/types" + + mock "github.com/stretchr/testify/mock" + + types "github.com/babylonlabs-io/babylon-staking-indexer/internal/types" +) + +// BbnInterface is an autogenerated mock type for the BbnInterface type +type BbnInterface struct { + mock.Mock +} + +// GetAllStakingParams provides a mock function with given fields: ctx +func (_m *BbnInterface) GetAllStakingParams(ctx context.Context) (map[uint32]bbnclient.StakingParams, *types.Error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for GetAllStakingParams") + } + + var r0 map[uint32]bbnclient.StakingParams + var r1 *types.Error + if rf, ok := ret.Get(0).(func(context.Context) (map[uint32]bbnclient.StakingParams, *types.Error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) map[uint32]bbnclient.StakingParams); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(map[uint32]bbnclient.StakingParams) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) *types.Error); ok { + r1 = rf(ctx) + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).(*types.Error) + } + } + + return r0, r1 +} + +// GetBlockResults provides a mock function with given fields: ctx, blockHeight +func (_m *BbnInterface) GetBlockResults(ctx context.Context, blockHeight int64) (*coretypes.ResultBlockResults, *types.Error) { + ret := _m.Called(ctx, blockHeight) + + if len(ret) == 0 { + panic("no return value specified for GetBlockResults") + } + + var r0 *coretypes.ResultBlockResults + var r1 *types.Error + if rf, ok := ret.Get(0).(func(context.Context, int64) (*coretypes.ResultBlockResults, *types.Error)); ok { + return rf(ctx, blockHeight) + } + if rf, ok := ret.Get(0).(func(context.Context, int64) *coretypes.ResultBlockResults); ok { + r0 = rf(ctx, blockHeight) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*coretypes.ResultBlockResults) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, int64) *types.Error); ok { + r1 = rf(ctx, blockHeight) + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).(*types.Error) + } + } + + return r0, r1 +} + +// GetCheckpointParams provides a mock function with given fields: ctx +func (_m *BbnInterface) GetCheckpointParams(ctx context.Context) (*btccheckpointtypes.Params, *types.Error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for GetCheckpointParams") + } + + var r0 *btccheckpointtypes.Params + var r1 *types.Error + if rf, ok := ret.Get(0).(func(context.Context) (*btccheckpointtypes.Params, *types.Error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) *btccheckpointtypes.Params); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*btccheckpointtypes.Params) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) *types.Error); ok { + r1 = rf(ctx) + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).(*types.Error) + } + } + + return r0, r1 +} + +// GetLatestBlockNumber provides a mock function with given fields: ctx +func (_m *BbnInterface) GetLatestBlockNumber(ctx context.Context) (int64, *types.Error) { + ret := _m.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for GetLatestBlockNumber") + } + + var r0 int64 + var r1 *types.Error + if rf, ok := ret.Get(0).(func(context.Context) (int64, *types.Error)); ok { + return rf(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) int64); ok { + r0 = rf(ctx) + } else { + r0 = ret.Get(0).(int64) + } + + if rf, ok := ret.Get(1).(func(context.Context) *types.Error); ok { + r1 = rf(ctx) + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).(*types.Error) + } + } + + return r0, r1 +} + +// NewBbnInterface creates a new instance of BbnInterface. 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 NewBbnInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *BbnInterface { + mock := &BbnInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/tests/mocks/mock_btc_client.go b/tests/mocks/mock_btc_client.go new file mode 100644 index 0000000..21a8239 --- /dev/null +++ b/tests/mocks/mock_btc_client.go @@ -0,0 +1,52 @@ +// Code generated by mockery v2.41.0. DO NOT EDIT. + +package mocks + +import mock "github.com/stretchr/testify/mock" + +// BtcInterface is an autogenerated mock type for the BtcInterface type +type BtcInterface struct { + mock.Mock +} + +// GetBlockCount provides a mock function with given fields: +func (_m *BtcInterface) GetBlockCount() (int64, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetBlockCount") + } + + var r0 int64 + var r1 error + if rf, ok := ret.Get(0).(func() (int64, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() int64); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(int64) + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// NewBtcInterface creates a new instance of BtcInterface. 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 NewBtcInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *BtcInterface { + mock := &BtcInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/tests/mocks/mock_db_client.go b/tests/mocks/mock_db_client.go index 31c89ff..2f88c4e 100644 --- a/tests/mocks/mock_db_client.go +++ b/tests/mocks/mock_db_client.go @@ -16,22 +16,24 @@ type DbInterface struct { } // GetFinalityProviderByBtcPk provides a mock function with given fields: ctx, btcPk -func (_m *DbInterface) GetFinalityProviderByBtcPk(ctx context.Context, btcPk string) (model.FinalityProviderDetails, error) { +func (_m *DbInterface) GetFinalityProviderByBtcPk(ctx context.Context, btcPk string) (*model.FinalityProviderDetails, error) { ret := _m.Called(ctx, btcPk) if len(ret) == 0 { panic("no return value specified for GetFinalityProviderByBtcPk") } - var r0 model.FinalityProviderDetails + var r0 *model.FinalityProviderDetails var r1 error - if rf, ok := ret.Get(0).(func(context.Context, string) (model.FinalityProviderDetails, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, string) (*model.FinalityProviderDetails, error)); ok { return rf(ctx, btcPk) } - if rf, ok := ret.Get(0).(func(context.Context, string) model.FinalityProviderDetails); ok { + if rf, ok := ret.Get(0).(func(context.Context, string) *model.FinalityProviderDetails); ok { r0 = rf(ctx, btcPk) } else { - r0 = ret.Get(0).(model.FinalityProviderDetails) + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.FinalityProviderDetails) + } } if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { @@ -61,6 +63,24 @@ func (_m *DbInterface) Ping(ctx context.Context) error { return r0 } +// SaveGlobalParams provides a mock function with given fields: ctx, param +func (_m *DbInterface) SaveGlobalParams(ctx context.Context, param *model.GolablParamDocument) error { + ret := _m.Called(ctx, param) + + if len(ret) == 0 { + panic("no return value specified for SaveGlobalParams") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *model.GolablParamDocument) error); ok { + r0 = rf(ctx, param) + } else { + r0 = ret.Error(0) + } + + return r0 +} + // SaveNewFinalityProvider provides a mock function with given fields: ctx, fpDoc func (_m *DbInterface) SaveNewFinalityProvider(ctx context.Context, fpDoc *model.FinalityProviderDetails) error { ret := _m.Called(ctx, fpDoc)