Skip to content

Commit

Permalink
[Test] gamm: Make test case for GetPoolDenoms (#2240)
Browse files Browse the repository at this point in the history
Closes: #2200

## What is the purpose of the change
Add test for function GetPoolDenoms 

## Brief Changelog
n/a

## Testing and Verifying
added unit test 

## Documentation and Release Note

  - Does this pull request introduce a new feature or user-facing behavior changes? (no)
  - Is a relevant changelog entry added to the `Unreleased` section in `CHANGELOG.md`? (no)
  - How is the feature or change documented? (not applicable   /   specification (`x/<module>/spec/`)  /  [Osmosis docs repo](https://github.com/osmosis-labs/docs)   /   not documented)
  • Loading branch information
stackman27 authored Jul 28, 2022
1 parent 9f9736c commit cf39ea3
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
6 changes: 6 additions & 0 deletions x/gamm/keeper/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,14 @@ func (k Keeper) DeletePool(ctx sdk.Context, poolId uint64) error {
// return nil
// }

// GetPoolDenom retrieves the pool based on PoolId and
// returns the coin denoms that it holds.
func (k Keeper) GetPoolDenoms(ctx sdk.Context, poolId uint64) ([]string, error) {
pool, err := k.GetPoolAndPoke(ctx, poolId)
if err != nil {
return nil, err
}

denoms := osmoutils.CoinsDenoms(pool.GetTotalPoolLiquidity(ctx))
return denoms, err
}
Expand Down
39 changes: 39 additions & 0 deletions x/gamm/keeper/pool_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,45 @@ func (suite *KeeperTestSuite) TestJoinSwapExactAmountInConsistency() {
}
}

func (suite *KeeperTestSuite) TestGetPoolDenom() {
// setup pool with denoms
suite.FundAcc(suite.TestAccs[0], defaultAcctFunds)
poolCreateMsg := balancer.NewMsgCreateBalancerPool(suite.TestAccs[0], defaultPoolParams, defaultPoolAssets, defaultFutureGovernor)
_, err := suite.App.GAMMKeeper.CreatePool(suite.Ctx, poolCreateMsg)
suite.Require().NoError(err)

for _, tc := range []struct {
desc string
poolId uint64
expectDenoms []string
expectErr bool
}{
{
desc: "Valid PoolId",
poolId: 1,
expectDenoms: []string{"bar", "foo"},
expectErr: false,
},
{
desc: "Invalid PoolId",
poolId: 2,
expectDenoms: []string{"bar", "foo"},
expectErr: true,
},
} {
suite.Run(tc.desc, func() {
denoms, err := suite.App.GAMMKeeper.GetPoolDenoms(suite.Ctx, tc.poolId)

if tc.expectErr {
suite.Require().Error(err)
} else {
suite.Require().NoError(err)
suite.Require().Equal(denoms, tc.expectDenoms)
}
})
}
}

// func (suite *KeeperTestSuite) TestSetStableSwapScalingFactors() {
// stableSwapPoolParams := stableswap.PoolParams{
// SwapFee: defaultSwapFee,
Expand Down

0 comments on commit cf39ea3

Please sign in to comment.