Skip to content

Commit

Permalink
BE-658 | Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
deividaspetraitis committed Dec 13, 2024
1 parent e287459 commit 3d44d53
Show file tree
Hide file tree
Showing 35 changed files with 253 additions and 2,067 deletions.
10 changes: 5 additions & 5 deletions domain/candidate_routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ func TestCandidateRouteSearchOptions_ShouldSkipPool(t *testing.T) {
)

var (
defaultNonOrderBookPool = sqsdomain.PoolWrapper{
defaultNonOrderBookPool = ingesttypes.PoolWrapper{
ChainModel: &mocks.ChainPoolMock{
ID: defaultPoolID,
},
}

// instruments the given pool with orderbook data, returning new copy.
withOrderBookPool = func(pool sqsdomain.PoolWrapper) sqsdomain.PoolWrapper {
pool.SQSModel = sqsdomain.SQSPool{
withOrderBookPool = func(pool ingesttypes.PoolWrapper) ingesttypes.PoolWrapper {
pool.SQSModel = ingesttypes.SQSPool{
CosmWasmPoolModel: &cosmwasmpool.CosmWasmPoolModel{
ContractInfo: cosmwasmpool.ContractInfo{
Contract: cosmwasmpool.ORDERBOOK_CONTRACT_NAME,
Expand All @@ -48,7 +48,7 @@ func TestCandidateRouteSearchOptions_ShouldSkipPool(t *testing.T) {
}

// instruments the given pool with a new id returning new copy
withPoolID = func(pool sqsdomain.PoolWrapper, newPoolID uint64) sqsdomain.PoolWrapper {
withPoolID = func(pool ingesttypes.PoolWrapper, newPoolID uint64) ingesttypes.PoolWrapper {
pool.ChainModel = &mocks.ChainPoolMock{
ID: newPoolID,
}
Expand All @@ -63,7 +63,7 @@ func TestCandidateRouteSearchOptions_ShouldSkipPool(t *testing.T) {

poolIDsToFilter map[uint64]struct{}

poolToTest sqsdomain.PoolWrapper
poolToTest ingesttypes.PoolWrapper

expectedShouldSkip bool
}{
Expand Down
4 changes: 2 additions & 2 deletions domain/mocks/candidate_route_finder_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import (
)

type CandidateRouteFinderMock struct {
Routes sqsdomain.CandidateRoutes
Routes ingesttypes.CandidateRoutes
Error error
}

var _ domain.CandidateRouteSearcher = CandidateRouteFinderMock{}

// FindCandidateRoutes implements domain.CandidateRouteSearcher.
func (c CandidateRouteFinderMock) FindCandidateRoutes(tokenIn types.Coin, tokenOutDenom string, options domain.CandidateRouteSearchOptions) (sqsdomain.CandidateRoutes, error) {
func (c CandidateRouteFinderMock) FindCandidateRoutes(tokenIn types.Coin, tokenOutDenom string, options domain.CandidateRouteSearchOptions) (ingesttypes.CandidateRoutes, error) {
return c.Routes, c.Error
}
4 changes: 2 additions & 2 deletions domain/mocks/orderbook_usecase_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ var _ mvc.OrderBookUsecase = &OrderbookUsecaseMock{}

// OrderbookUsecaseMock is a mock implementation of the RouterUsecase interface
type OrderbookUsecaseMock struct {
ProcessPoolFunc func(ctx context.Context, pool sqsdomain.PoolI) error
ProcessPoolFunc func(ctx context.Context, pool ingesttypes.PoolI) error
GetAllTicksFunc func(poolID uint64) (map[int64]orderbookdomain.OrderbookTick, bool)
GetActiveOrdersFunc func(ctx context.Context, address string) ([]orderbookdomain.LimitOrder, bool, error)
GetActiveOrdersStreamFunc func(ctx context.Context, address string) <-chan orderbookdomain.OrderbookResult
CreateFormattedLimitOrderFunc func(orderbook domain.CanonicalOrderBooksResult, order orderbookdomain.Order) (orderbookdomain.LimitOrder, error)
GetClaimableOrdersForOrderbookFunc func(ctx context.Context, fillThreshold osmomath.Dec, orderbook domain.CanonicalOrderBooksResult) ([]orderbookdomain.ClaimableOrderbook, error)
}

func (m *OrderbookUsecaseMock) ProcessPool(ctx context.Context, pool sqsdomain.PoolI) error {
func (m *OrderbookUsecaseMock) ProcessPool(ctx context.Context, pool ingesttypes.PoolI) error {
if m.ProcessPoolFunc != nil {
return m.ProcessPoolFunc(ctx, pool)
}
Expand Down
8 changes: 4 additions & 4 deletions domain/mocks/pool_handler_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (
)

type PoolHandlerMock struct {
Pools []sqsdomain.PoolI
Pools []ingesttypes.PoolI
ForceGetPoolsError error
ForceStorePoolsError error
}

var _ mvc.PoolHandler = &PoolHandlerMock{}

// GetPools implements mvc.PoolHandler.
func (p *PoolHandlerMock) GetPools(opts ...domain.PoolsOption) ([]sqsdomain.PoolI, uint64, error) {
func (p *PoolHandlerMock) GetPools(opts ...domain.PoolsOption) ([]ingesttypes.PoolI, uint64, error) {
if p.ForceGetPoolsError != nil {
return nil, 0, p.ForceGetPoolsError
}
Expand All @@ -27,7 +27,7 @@ func (p *PoolHandlerMock) GetPools(opts ...domain.PoolsOption) ([]sqsdomain.Pool
opt(&options)
}

result := make([]sqsdomain.PoolI, 0)
result := make([]ingesttypes.PoolI, 0)
if f := options.Filter; f != nil && len(f.PoolId) > 0 {
for _, id := range f.PoolId {
for _, pool := range p.Pools {
Expand All @@ -50,7 +50,7 @@ func (p *PoolHandlerMock) GetPools(opts ...domain.PoolsOption) ([]sqsdomain.Pool
}

// StorePools implements mvc.PoolHandler.
func (p *PoolHandlerMock) StorePools(pools []sqsdomain.PoolI) error {
func (p *PoolHandlerMock) StorePools(pools []ingesttypes.PoolI) error {
if p.ForceStorePoolsError != nil {
return p.ForceStorePoolsError
}
Expand Down
44 changes: 22 additions & 22 deletions domain/mocks/pool_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type MockRoutablePool struct {
CalculateTokenOutByTokenInFunc func(ctx context.Context, tokenIn sdk.Coin) (sdk.Coin, error)

ChainPoolModel poolmanagertypes.PoolI
TickModel *sqsdomain.TickModel
TickModel *ingesttypes.TickModel
CosmWasmPoolModel *cosmwasmpool.CosmWasmPoolModel
ID uint64
Balances sdk.Coins
Expand All @@ -42,22 +42,22 @@ type MockRoutablePool struct {
PoolLiquidityCapError string
}

// GetAPRData implements sqsdomain.PoolI.
// GetAPRData implements ingesttypes.PoolI.
func (mp *MockRoutablePool) GetAPRData() sqspassthroughdomain.PoolAPRDataStatusWrap {
return mp.APRData
}

// GetFeesData implements sqsdomain.PoolI.
// GetFeesData implements ingesttypes.PoolI.
func (mp *MockRoutablePool) GetFeesData() sqspassthroughdomain.PoolFeesDataStatusWrap {
return mp.FeesData
}

// SetAPRData implements sqsdomain.PoolI.
// SetAPRData implements ingesttypes.PoolI.
func (mp *MockRoutablePool) SetAPRData(aprData sqspassthroughdomain.PoolAPRDataStatusWrap) {
mp.APRData = aprData
}

// SetFeesData implements sqsdomain.PoolI.
// SetFeesData implements ingesttypes.PoolI.
func (mp *MockRoutablePool) SetFeesData(feesData sqspassthroughdomain.PoolFeesDataStatusWrap) {
mp.FeesData = feesData
}
Expand Down Expand Up @@ -97,9 +97,9 @@ func (mp *MockRoutablePool) GetUnderlyingPool() poolmanagertypes.PoolI {
return mp.ChainPoolModel
}

// GetSQSPoolModel implements sqsdomain.PoolI.
func (mp *MockRoutablePool) GetSQSPoolModel() sqsdomain.SQSPool {
return sqsdomain.SQSPool{
// GetSQSPoolModel implements ingesttypes.PoolI.
func (mp *MockRoutablePool) GetSQSPoolModel() ingesttypes.SQSPool {
return ingesttypes.SQSPool{
Balances: mp.Balances,
PoolLiquidityCap: mp.PoolLiquidityCap,
SpreadFactor: mp.SpreadFactor,
Expand Down Expand Up @@ -138,17 +138,17 @@ func (*MockRoutablePool) String() string {
}

// GetTickModel implements domain.RoutablePool.
func (mp *MockRoutablePool) GetTickModel() (*sqsdomain.TickModel, error) {
func (mp *MockRoutablePool) GetTickModel() (*ingesttypes.TickModel, error) {
return mp.TickModel, nil
}

// SetTickModel implements sqsdomain.PoolI.
func (mp *MockRoutablePool) SetTickModel(tickModel *sqsdomain.TickModel) error {
// SetTickModel implements ingesttypes.PoolI.
func (mp *MockRoutablePool) SetTickModel(tickModel *ingesttypes.TickModel) error {
mp.TickModel = tickModel
return nil
}

// Validate implements sqsdomain.PoolI.
// Validate implements ingesttypes.PoolI.
func (*MockRoutablePool) Validate(minUOSMOTVL math.Int) error {
// Note: always valid for tests.
return nil
Expand All @@ -174,7 +174,7 @@ func (mp *MockRoutablePool) ChargeTakerFeeExactIn(tokenIn sdk.Coin) (tokenInAfte
return tokenIn.Sub(sdk.NewCoin(tokenIn.Denom, mp.TakerFee.Mul(tokenIn.Amount.ToLegacyDec()).TruncateInt()))
}

// GetTakerFee implements sqsdomain.PoolI.
// GetTakerFee implements ingesttypes.PoolI.
func (mp *MockRoutablePool) GetTakerFee() math.LegacyDec {
return mp.TakerFee
}
Expand All @@ -183,25 +183,25 @@ func (mp *MockRoutablePool) Incentive() api.IncentiveType {
return mp.IncentiveType
}

var _ sqsdomain.PoolI = &MockRoutablePool{}
var _ ingesttypes.PoolI = &MockRoutablePool{}
var _ domain.RoutablePool = &MockRoutablePool{}

// GetId implements sqsdomain.PoolI.
// GetId implements ingesttypes.PoolI.
func (mp *MockRoutablePool) GetId() uint64 {
return mp.ID
}

// GetPoolDenoms implements sqsdomain.PoolI.
// GetPoolDenoms implements ingesttypes.PoolI.
func (mp *MockRoutablePool) GetPoolDenoms() []string {
return mp.Denoms
}

// GetPoolLiquidityCap implements sqsdomain.PoolI.
// GetPoolLiquidityCap implements ingesttypes.PoolI.
func (mp *MockRoutablePool) GetPoolLiquidityCap() math.Int {
return mp.PoolLiquidityCap
}

// GetType implements sqsdomain.PoolI.
// GetType implements ingesttypes.PoolI.
func (mp *MockRoutablePool) GetType() poolmanagertypes.PoolType {
return mp.PoolType
}
Expand All @@ -216,22 +216,22 @@ func (mp *MockRoutablePool) GetCodeID() uint64 {
return 0
}

// GetLiquidityCap implements sqsdomain.PoolI.
// GetLiquidityCap implements ingesttypes.PoolI.
func (mp *MockRoutablePool) GetLiquidityCap() math.Int {
return mp.PoolLiquidityCap
}

// GetLiquidityCapError implements sqsdomain.PoolI.
// GetLiquidityCapError implements ingesttypes.PoolI.
func (mp *MockRoutablePool) GetLiquidityCapError() string {
return mp.PoolLiquidityCapError
}

// SetLiquidityCap implements sqsdomain.PoolI.
// SetLiquidityCap implements ingesttypes.PoolI.
func (mp *MockRoutablePool) SetLiquidityCap(liquidityCap math.Int) {
mp.PoolLiquidityCap = liquidityCap
}

// SetLiquidityCapError implements sqsdomain.PoolI.
// SetLiquidityCapError implements ingesttypes.PoolI.
func (mp *MockRoutablePool) SetLiquidityCapError(liquidityCapError string) {
mp.PoolLiquidityCapError = liquidityCapError
}
Expand Down
30 changes: 15 additions & 15 deletions domain/mocks/pools_usecase_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ import (
var _ mvc.PoolsUsecase = &PoolsUsecaseMock{}

type PoolsUsecaseMock struct {
GetAllPoolsFunc func() ([]sqsdomain.PoolI, error)
GetPoolsFunc func(opts ...domain.PoolsOption) ([]sqsdomain.PoolI, uint64, error)
StorePoolsFunc func(pools []sqsdomain.PoolI) error
GetRoutesFromCandidatesFunc func(candidateRoutes sqsdomain.CandidateRoutes, tokenInDenom, tokenOutDenom string) ([]route.RouteImpl, error)
GetTickModelMapFunc func(poolIDs []uint64) (map[uint64]*sqsdomain.TickModel, error)
GetPoolFunc func(poolID uint64) (sqsdomain.PoolI, error)
GetAllPoolsFunc func() ([]ingesttypes.PoolI, error)
GetPoolsFunc func(opts ...domain.PoolsOption) ([]ingesttypes.PoolI, uint64, error)
StorePoolsFunc func(pools []ingesttypes.PoolI) error
GetRoutesFromCandidatesFunc func(candidateRoutes ingesttypes.CandidateRoutes, tokenInDenom, tokenOutDenom string) ([]route.RouteImpl, error)
GetTickModelMapFunc func(poolIDs []uint64) (map[uint64]*ingesttypes.TickModel, error)
GetPoolFunc func(poolID uint64) (ingesttypes.PoolI, error)
GetPoolSpotPriceFunc func(ctx context.Context, poolID uint64, takerFee osmomath.Dec, quoteAsset, baseAsset string) (osmomath.BigDec, error)
GetCosmWasmPoolConfigFunc func() domain.CosmWasmPoolRouterConfig
CalcExitCFMMPoolFunc func(poolID uint64, exitingShares osmomath.Int) (sdk.Coins, error)
GetAllCanonicalOrderbookPoolIDsFunc func() ([]domain.CanonicalOrderBooksResult, error)

Pools []sqsdomain.PoolI
TickModelMap map[uint64]*sqsdomain.TickModel
Pools []ingesttypes.PoolI
TickModelMap map[uint64]*ingesttypes.TickModel
}

// IsCanonicalOrderbookPool implements mvc.PoolsUsecase.
Expand Down Expand Up @@ -59,7 +59,7 @@ func (pm *PoolsUsecaseMock) GetCanonicalOrderbookPool(baseDenom string, quoteDen
}

// StorePools implements mvc.PoolsUsecase.
func (pm *PoolsUsecaseMock) StorePools(pools []sqsdomain.PoolI) error {
func (pm *PoolsUsecaseMock) StorePools(pools []ingesttypes.PoolI) error {
if pm.StorePoolsFunc != nil {
return pm.StorePoolsFunc(pools)
}
Expand All @@ -79,7 +79,7 @@ func (pm *PoolsUsecaseMock) GetCosmWasmPoolConfig() domain.CosmWasmPoolRouterCon
}

// GetPools implements mvc.PoolsUsecase.
func (pm *PoolsUsecaseMock) GetPools(opts ...domain.PoolsOption) ([]sqsdomain.PoolI, uint64, error) {
func (pm *PoolsUsecaseMock) GetPools(opts ...domain.PoolsOption) ([]ingesttypes.PoolI, uint64, error) {
if pm.GetPoolsFunc != nil {
return pm.GetPoolsFunc(opts...)
}
Expand All @@ -89,7 +89,7 @@ func (pm *PoolsUsecaseMock) GetPools(opts ...domain.PoolsOption) ([]sqsdomain.Po
// GetRoutesFromCandidates implements mvc.PoolsUsecase.
// Note that taker fee are ignored and not set
// Note that tick models are not set
func (pm *PoolsUsecaseMock) GetRoutesFromCandidates(candidateRoutes sqsdomain.CandidateRoutes, tokenInDenom string, tokenOutDenom string) ([]route.RouteImpl, error) {
func (pm *PoolsUsecaseMock) GetRoutesFromCandidates(candidateRoutes ingesttypes.CandidateRoutes, tokenInDenom string, tokenOutDenom string) ([]route.RouteImpl, error) {
if pm.GetRoutesFromCandidatesFunc != nil {
return pm.GetRoutesFromCandidatesFunc(candidateRoutes, tokenInDenom, tokenOutDenom)
}
Expand All @@ -99,7 +99,7 @@ func (pm *PoolsUsecaseMock) GetRoutesFromCandidates(candidateRoutes sqsdomain.Ca
routablePools := make([]domain.RoutablePool, 0, len(candidateRoute.Pools))
for _, candidatePool := range candidateRoute.Pools {
// Get the pool data for routing
var foundPool sqsdomain.PoolI
var foundPool ingesttypes.PoolI
for _, pool := range pm.Pools {
if pool.GetId() == candidatePool.ID {
foundPool = pool
Expand Down Expand Up @@ -129,23 +129,23 @@ func (pm *PoolsUsecaseMock) GetRoutesFromCandidates(candidateRoutes sqsdomain.Ca
}

// GetAllPools implements domain.PoolsUsecase.
func (pm *PoolsUsecaseMock) GetAllPools() ([]sqsdomain.PoolI, error) {
func (pm *PoolsUsecaseMock) GetAllPools() ([]ingesttypes.PoolI, error) {
if pm.GetAllPoolsFunc != nil {
return pm.GetAllPoolsFunc()
}
return pm.Pools, nil
}

// GetTickModelMap implements mvc.PoolsUsecase.
func (pm *PoolsUsecaseMock) GetTickModelMap(poolIDs []uint64) (map[uint64]*sqsdomain.TickModel, error) {
func (pm *PoolsUsecaseMock) GetTickModelMap(poolIDs []uint64) (map[uint64]*ingesttypes.TickModel, error) {
if pm.GetTickModelMapFunc != nil {
return pm.GetTickModelMapFunc(poolIDs)
}
return pm.TickModelMap, nil
}

// GetPool implements mvc.PoolsUsecase.
func (pm *PoolsUsecaseMock) GetPool(poolID uint64) (sqsdomain.PoolI, error) {
func (pm *PoolsUsecaseMock) GetPool(poolID uint64) (ingesttypes.PoolI, error) {
if pm.GetPoolFunc != nil {
return pm.GetPoolFunc(poolID)
}
Expand Down
Loading

0 comments on commit 3d44d53

Please sign in to comment.