Skip to content

Commit

Permalink
BE-654 | Fix Go tests
Browse files Browse the repository at this point in the history
  • Loading branch information
deividaspetraitis committed Nov 21, 2024
1 parent 72c7298 commit 9f5d0cb
Show file tree
Hide file tree
Showing 14 changed files with 272 additions and 221 deletions.
2 changes: 2 additions & 0 deletions domain/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ var (
DefaultCoin0 = routertesting.DefaultCoin0
DefaultCoin1 = routertesting.DefaultCoin1

DefaultLiquidityCap = routertesting.DefaultLiquidityCap
DefaultLiquidityAmt = routertesting.DefaultLiquidityAmt

// router specific variables
Expand Down Expand Up @@ -117,6 +118,7 @@ func (s *RouterTestSuite) TestPrepareResultPools() {
DefaultSpreadFactor,
DenomOne,
DefaultTakerFee,
DefaultLiquidityCap,
notCosmWasmPoolCodeID,
),
},
Expand Down
2 changes: 1 addition & 1 deletion pools/usecase/pools_usecase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ func (s *PoolsUsecaseTestSuite) TestCalcExitCFMMPool_HappyPath() {
s.Require().NoError(err)

// Create sqs pool
sqsPool := sqsdomain.NewPool(cfmmPool, cfmmPool.GetSpreadFactor(s.Ctx), poolBalances)
sqsPool := sqsdomain.NewPool(cfmmPool, cfmmPool.GetSpreadFactor(s.Ctx), poolBalances, s.PoolOneLiquidityCap())

// Create default use case
poolsUseCase := s.newDefaultPoolsUseCase()
Expand Down
3 changes: 2 additions & 1 deletion router/usecase/pools/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ func NewRoutableCosmWasmPoolWithCustomModel(
cosmWasmPoolsParams cosmwasmdomain.CosmWasmPoolsParams,
tokenOutDenom string,
takerFee osmomath.Dec,
liquidityCap osmomath.Int,
) (domain.RoutablePool, error) {
return newRoutableCosmWasmPoolWithCustomModel(pool, cosmwasmPool, cosmWasmPoolsParams, tokenOutDenom, takerFee)
return newRoutableCosmWasmPoolWithCustomModel(pool, cosmwasmPool, cosmWasmPoolsParams, tokenOutDenom, takerFee, liquidityCap)
}

func (r *routableAlloyTransmuterPoolImpl) CheckStaticRateLimiter(tokenInCoin sdk.Coin) error {
Expand Down
5 changes: 4 additions & 1 deletion router/usecase/pools/pool_factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func TestNewRoutableCosmWasmPoolWithCustomModel(t *testing.T) {
cosmWasmConfig domain.CosmWasmPoolRouterConfig
tokenOutDenom string
takerFee osmomath.Dec
liquidityCap osmomath.Int
expectedRoutablePool domain.RoutablePool
expectedError error
}{
Expand Down Expand Up @@ -137,13 +138,15 @@ func TestNewRoutableCosmWasmPoolWithCustomModel(t *testing.T) {
},
tokenOutDenom: "quote",
takerFee: orderbookTakerFee,
liquidityCap: osmomath.NewInt(851594865),
expectedRoutablePool: &pools.RoutableOrderbookPoolImpl{
ChainPool: &orderbookCosmWasmPool,
OrderbookData: orderbookModel.Data.Orderbook,
Balances: orderbookBalances,
TokenOutDenom: "quote",
TakerFee: orderbookTakerFee,
SpreadFactor: orderbookSpreadFactor,
LiquidityCap: osmomath.NewInt(851594865),
},
},
{
Expand Down Expand Up @@ -194,7 +197,7 @@ func TestNewRoutableCosmWasmPoolWithCustomModel(t *testing.T) {
cosmWasmPoolsParams := cosmwasmdomain.CosmWasmPoolsParams{
Config: tt.cosmWasmConfig,
}
routablePool, err := pools.NewRoutableCosmWasmPoolWithCustomModel(tt.pool, tt.cosmwasmPool, cosmWasmPoolsParams, tt.tokenOutDenom, tt.takerFee)
routablePool, err := pools.NewRoutableCosmWasmPoolWithCustomModel(tt.pool, tt.cosmwasmPool, cosmWasmPoolsParams, tt.tokenOutDenom, tt.takerFee, tt.liquidityCap)

if tt.expectedError != nil {
require.Equal(t, tt.expectedError, err)
Expand Down
4 changes: 3 additions & 1 deletion router/usecase/quote_out_given_in.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ func (q *quoteExactAmountIn) PrepareResult(ctx context.Context, scalingFactor os

// Calculate total liquidity cap for the route
for _, pool := range newPools {
totalLiquidityCap = totalLiquidityCap.Add(pool.GetLiquidityCap())
if cap := pool.GetLiquidityCap(); !cap.IsNil() {
totalLiquidityCap = totalLiquidityCap.Add(pool.GetLiquidityCap())
}
}

resultRoutes = append(resultRoutes, &RouteWithOutAmount{
Expand Down
6 changes: 6 additions & 0 deletions router/usecase/quote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func (s *RouterTestSuite) TestPrepareResult() {
poolOne.GetSpreadFactor(sdk.Context{}),
USDT,
takerFeeOne,
s.PoolOneLiquidityCap(),
notCosmWasmPoolCodeID,
),
pools.NewRoutableResultPool(
Expand All @@ -95,6 +96,7 @@ func (s *RouterTestSuite) TestPrepareResult() {
poolTwo.GetSpreadFactor(sdk.Context{}),
USDC,
takerFeeTwo,
s.PoolTwoLiquidityCap(),
notCosmWasmPoolCodeID,
),
},
Expand All @@ -114,6 +116,7 @@ func (s *RouterTestSuite) TestPrepareResult() {
poolThree.GetSpreadFactor(sdk.Context{}),
USDC,
takerFeeThree,
s.PoolThreeLiquidityCap(),
notCosmWasmPoolCodeID,
),
},
Expand All @@ -140,6 +143,7 @@ func (s *RouterTestSuite) TestPrepareResult() {
poolOne.GetSpreadFactor(sdk.Context{}),
USDT,
takerFeeOne,
s.PoolOneLiquidityCap(),
notCosmWasmPoolCodeID,
),
pools.NewExactAmountOutRoutableResultPool(
Expand All @@ -148,6 +152,7 @@ func (s *RouterTestSuite) TestPrepareResult() {
poolTwo.GetSpreadFactor(sdk.Context{}),
USDC,
takerFeeTwo,
s.PoolTwoLiquidityCap(),
notCosmWasmPoolCodeID,
),
},
Expand All @@ -165,6 +170,7 @@ func (s *RouterTestSuite) TestPrepareResult() {
poolThree.GetSpreadFactor(sdk.Context{}),
USDC,
takerFeeThree,
s.PoolThreeLiquidityCap(),
notCosmWasmPoolCodeID,
),
},
Expand Down
3 changes: 3 additions & 0 deletions router/usecase/route/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ func (s *RouterTestSuite) TestPrepareResultPools() {
DefaultSpreadFactor,
DenomOne,
DefaultTakerFee,
osmomath.NewInt(3195955),
notCosmWasmPoolCodeID,
),
},
Expand All @@ -183,6 +184,7 @@ func (s *RouterTestSuite) TestPrepareResultPools() {
DefaultSpreadFactor,
DenomOne,
DefaultTakerFee,
osmomath.NewInt(515881661),
notCosmWasmPoolCodeID,
),
pools.NewRoutableResultPool(
Expand All @@ -191,6 +193,7 @@ func (s *RouterTestSuite) TestPrepareResultPools() {
DefaultSpreadFactor,
DenomThree,
DefaultTakerFee,
osmomath.NewInt(71519599),
transmuter.GetCodeId(),
),
},
Expand Down
100 changes: 52 additions & 48 deletions router/usecase/routertesting/parsing/quote_amount_in_response.json
Original file line number Diff line number Diff line change
@@ -1,50 +1,54 @@
{
"amount_in": {
"denom": "ibc/EA1D43981D5C9A1C4AAEA9C23BB1D4FA126BA9BC7020A25E0AE4AA841EA25DC5",
"amount": "10000000"
},
"amount_out": "40000000",
"route": [
{
"pools": [
{
"id": 1,
"type": 0,
"balances": [],
"spread_factor": "0.010000000000000000",
"token_out_denom": "ibc/4ABBEF4C8926DDDB320AE5188CFD63267ABBCEFC0583E4AE05D6E5AA2401DDAB",
"taker_fee": "0.020000000000000000"
},
{
"id": 2,
"type": 0,
"balances": [],
"spread_factor": "0.030000000000000000",
"token_out_denom": "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4",
"taker_fee": "0.000400000000000000"
}
],
"has-cw-pool": false,
"out_amount": "20000000",
"in_amount": "5000000"
},
{
"pools": [
{
"id": 3,
"type": 0,
"balances": [],
"spread_factor": "0.005000000000000000",
"token_out_denom": "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4",
"taker_fee": "0.003000000000000000"
}
],
"has-cw-pool": false,
"out_amount": "20000000",
"in_amount": "5000000"
}
],
"effective_fee": "0.011696000000000000",
"price_impact": "-0.565353638051463862",
"in_base_out_quote_spot_price": "4.500000000000000000"
"amount_in": {
"denom": "ibc/EA1D43981D5C9A1C4AAEA9C23BB1D4FA126BA9BC7020A25E0AE4AA841EA25DC5",
"amount": "10000000"
},
"amount_out": "40000000",
"route": [
{
"pools": [
{
"id": 1,
"type": 0,
"balances": [],
"spread_factor": "0.010000000000000000",
"token_out_denom": "ibc/4ABBEF4C8926DDDB320AE5188CFD63267ABBCEFC0583E4AE05D6E5AA2401DDAB",
"taker_fee": "0.020000000000000000",
"liquidity_cap": "1519153195"
},
{
"id": 2,
"type": 0,
"balances": [],
"spread_factor": "0.030000000000000000",
"token_out_denom": "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4",
"taker_fee": "0.000400000000000000",
"liquidity_cap": "85196078"
}
],
"has-cw-pool": false,
"out_amount": "20000000",
"in_amount": "5000000"
},
{
"pools": [
{
"id": 3,
"type": 0,
"balances": [],
"spread_factor": "0.005000000000000000",
"token_out_denom": "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4",
"taker_fee": "0.003000000000000000",
"liquidity_cap": "719951"
}
],
"has-cw-pool": false,
"out_amount": "20000000",
"in_amount": "5000000"
}
],
"liquidity_cap": "1605069224",
"effective_fee": "0.011696000000000000",
"price_impact": "-0.565353638051463862",
"in_base_out_quote_spot_price": "4.500000000000000000"
}
Original file line number Diff line number Diff line change
@@ -1,57 +1,60 @@
{
"amount_in": {
"denom": "ibc/EA1D43981D5C9A1C4AAEA9C23BB1D4FA126BA9BC7020A25E0AE4AA841EA25DC5",
"amount": "10000000"
},
"amount_out": "40000000",
"route": [
{
"pools": [
{
"id": 1,
"type": 0,
"balances": [],
"spread_factor": "0.010000000000000000",
"token_out_denom": "ibc/4ABBEF4C8926DDDB320AE5188CFD63267ABBCEFC0583E4AE05D6E5AA2401DDAB",
"taker_fee": "0.020000000000000000"
},
{
"id": 2,
"type": 0,
"balances": [],
"spread_factor": "0.030000000000000000",
"token_out_denom": "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4",
"taker_fee": "0.000400000000000000"
}
],
"has-cw-pool": false,
"out_amount": "20000000",
"in_amount": "5000000"
},
{
"pools": [
{
"id": 3,
"type": 0,
"balances": [],
"spread_factor": "0.005000000000000000",
"token_out_denom": "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4",
"taker_fee": "0.003000000000000000"
}
],
"has-cw-pool": false,
"out_amount": "20000000",
"in_amount": "5000000"
}
],
"effective_fee": "0.011696000000000000",
"price_impact": "-0.565353638051463862",
"in_base_out_quote_spot_price": "4.500000000000000000",
"price_info": {
"fee_coin": {
"amount": "0"
},
"base_fee": "0.500000000000000000"
}
}

"amount_in": {
"denom": "ibc/EA1D43981D5C9A1C4AAEA9C23BB1D4FA126BA9BC7020A25E0AE4AA841EA25DC5",
"amount": "10000000"
},
"amount_out": "40000000",
"route": [
{
"pools": [
{
"id": 1,
"type": 0,
"balances": [],
"spread_factor": "0.010000000000000000",
"token_out_denom": "ibc/4ABBEF4C8926DDDB320AE5188CFD63267ABBCEFC0583E4AE05D6E5AA2401DDAB",
"taker_fee": "0.020000000000000000",
"liquidity_cap": "1519153195"
},
{
"id": 2,
"type": 0,
"balances": [],
"spread_factor": "0.030000000000000000",
"token_out_denom": "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4",
"taker_fee": "0.000400000000000000",
"liquidity_cap": "85196078"
}
],
"has-cw-pool": false,
"out_amount": "20000000",
"in_amount": "5000000"
},
{
"pools": [
{
"id": 3,
"type": 0,
"balances": [],
"spread_factor": "0.005000000000000000",
"token_out_denom": "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4",
"taker_fee": "0.003000000000000000",
"liquidity_cap": "719951"
}
],
"has-cw-pool": false,
"out_amount": "20000000",
"in_amount": "5000000"
}
],
"liquidity_cap": "1605069224",
"effective_fee": "0.011696000000000000",
"price_impact": "-0.565353638051463862",
"in_base_out_quote_spot_price": "4.500000000000000000",
"price_info": {
"fee_coin": {
"amount": "0"
},
"base_fee": "0.500000000000000000"
}
}
Loading

0 comments on commit 9f5d0cb

Please sign in to comment.