Skip to content

Commit

Permalink
refactor(app/apptesting): PrepareBalancerPool helpers (simplifying sw…
Browse files Browse the repository at this point in the history
…aprouter merge PR) (#3772)

* refactor(app/apptesting): PrepareBalancerPool helpers

* improve godoc

* merge conflict

(cherry picked from commit 6206709)

# Conflicts:
#	app/apptesting/gamm.go
  • Loading branch information
p0mvn authored and mergify[bot] committed Dec 17, 2022
1 parent bda1d93 commit 71e6479
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
36 changes: 31 additions & 5 deletions app/apptesting/gamm.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ func (s *KeeperTestHelper) PrepareBalancerPoolWithCoinsAndWeights(coins sdk.Coin
poolAssets = append(poolAssets, poolAsset)
}

return s.PrepareBalancerPoolWithPoolAsset(poolAssets)
return s.PrepareCustomBalancerPool(poolAssets, balancer.PoolParams{
SwapFee: sdk.ZeroDec(),
ExitFee: sdk.ZeroDec(),
})
}

// PrepareBalancerPool returns a Balancer pool's pool-ID with pool params set in PrepareBalancerPoolWithPoolParams.
Expand Down Expand Up @@ -128,33 +131,56 @@ func (s *KeeperTestHelper) PrepareImbalancedStableswapPool() uint64 {

// PrepareBalancerPoolWithPoolParams sets up a Balancer pool with poolParams.
func (s *KeeperTestHelper) PrepareBalancerPoolWithPoolParams(poolParams balancer.PoolParams) uint64 {
// Mint some assets to the account.
s.FundAcc(s.TestAccs[0], DefaultAcctFunds)
<<<<<<< HEAD

msg := balancer.NewMsgCreateBalancerPool(s.TestAccs[0], poolParams, DefaultPoolAssets, "")
poolId, err := s.App.GAMMKeeper.CreatePool(s.Ctx, msg)
s.NoError(err)
return poolId
=======
return s.PrepareCustomBalancerPool(DefaultPoolAssets, poolParams)
>>>>>>> 62067092 (refactor(app/apptesting): PrepareBalancerPool helpers (simplifying swaprouter merge PR) (#3772))
}

// PrepareBalancerPoolWithPoolAsset sets up a Balancer pool with an array of assets.
func (s *KeeperTestHelper) PrepareBalancerPoolWithPoolAsset(assets []balancer.PoolAsset) uint64 {
// PrepareCustomBalancerPool sets up a Balancer pool with an array of assets and given parameters
func (s *KeeperTestHelper) PrepareCustomBalancerPool(assets []balancer.PoolAsset, params balancer.PoolParams) uint64 {
// Add coins for pool creation fee + coins needed to mint balances
fundCoins := sdk.Coins{sdk.NewCoin("uosmo", sdk.NewInt(10000000000))}
fundCoins := sdk.NewCoins(sdk.NewCoin("uosmo", sdk.NewInt(10000000000)))
for _, a := range assets {
fundCoins = fundCoins.Add(a.Token)
}
s.FundAcc(s.TestAccs[0], fundCoins)

<<<<<<< HEAD
msg := balancer.NewMsgCreateBalancerPool(s.TestAccs[0], balancer.PoolParams{
SwapFee: sdk.ZeroDec(),
ExitFee: sdk.ZeroDec(),
}, assets, "")
poolId, err := s.App.GAMMKeeper.CreatePool(s.Ctx, msg)
=======
msg := balancer.NewMsgCreateBalancerPool(s.TestAccs[0], params, assets, "")
poolId, err := s.App.SwapRouterKeeper.CreatePool(s.Ctx, msg)
>>>>>>> 62067092 (refactor(app/apptesting): PrepareBalancerPool helpers (simplifying swaprouter merge PR) (#3772))
s.NoError(err)
return poolId
}

// PrepareCustomBalancerPoolFromCoins sets up a Balancer pool with an array of coins and given parameters
// The coins are converted to pool assets where each asset has a weight of 1.
func (s *KeeperTestHelper) PrepareCustomBalancerPoolFromCoins(coins sdk.Coins, params balancer.PoolParams) uint64 {
var poolAssets []balancer.PoolAsset
for _, coin := range coins {
poolAsset := balancer.PoolAsset{
Weight: sdk.NewInt(1),
Token: coin,
}
poolAssets = append(poolAssets, poolAsset)
}

return s.PrepareCustomBalancerPool(poolAssets, params)
}

// Modify spotprice of a pool to target spotprice
func (s *KeeperTestHelper) ModifySpotPrice(poolID uint64, targetSpotPrice sdk.Dec, baseDenom string) {
var quoteDenom string
Expand Down
2 changes: 1 addition & 1 deletion x/gamm/pool-models/balancer/pool_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ func (suite *KeeperTestSuite) TestBalancerSpotPriceBounds() {
}

poolAssets := []balancer.PoolAsset{defaultBaseAsset, defaultQuoteAsset}
poolId := suite.PrepareBalancerPoolWithPoolAsset(poolAssets)
poolId := suite.PrepareCustomBalancerPool(poolAssets, balancer.PoolParams{SwapFee: sdk.ZeroDec(), ExitFee: sdk.ZeroDec()})

pool, err := suite.App.GAMMKeeper.GetPoolAndPoke(suite.Ctx, poolId)
suite.Require().NoError(err, "test: %s", tc.name)
Expand Down

0 comments on commit 71e6479

Please sign in to comment.