Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(app/apptesting): PrepareBalancerPool helpers (simplifying swaprouter merge PR) #3772

Merged
merged 4 commits into from
Dec 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 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,40 @@ func (s *KeeperTestHelper) PrepareImbalancedStableswapPool() uint64 {

// PrepareBalancerPoolWithPoolParams sets up a Balancer pool with poolParams.
p0mvn marked this conversation as resolved.
Show resolved Hide resolved
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.SwapRouterKeeper.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.SwapRouterKeeper.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