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) (backport #3772) (#3781)

Co-authored-by: Roman <[email protected]>
  • Loading branch information
mergify[bot] and p0mvn authored Dec 19, 2022
1 parent 564598c commit 7dd1747
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
37 changes: 24 additions & 13 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,41 @@ 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)

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)
}

// 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)

msg := balancer.NewMsgCreateBalancerPool(s.TestAccs[0], balancer.PoolParams{
SwapFee: sdk.ZeroDec(),
ExitFee: sdk.ZeroDec(),
}, assets, "")
msg := balancer.NewMsgCreateBalancerPool(s.TestAccs[0], params, assets, "")
poolId, err := s.App.GAMMKeeper.CreatePool(s.Ctx, msg)
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 7dd1747

Please sign in to comment.