Skip to content

Commit

Permalink
Tests: Edge case tests for CalcJoinPoolShares (#1776)
Browse files Browse the repository at this point in the history
* edge case tests for CalcJoinPoolShares

* add test comments

* move tests to increase coverage and add further comments

* remove expectLiq from new tests

* fix conflicts

Co-authored-by: Roman <[email protected]>
  • Loading branch information
AlpinYukseloglu and p0mvn authored Jun 15, 2022
1 parent b6c7ccb commit d0239e9
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions x/gamm/pool-models/balancer/amm_joinpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,46 @@ var calcSingleAssetJoinTestCases = []calcJoinSharesTestCase{
expectShares: sdk.ZeroInt(),
expErr: sdkerrors.Wrapf(types.ErrDenomNotFoundInPool, fmt.Sprintf(balancer.ErrMsgFormatNoPoolAssetFound, doesNotExistDenom)),
},
{
// Pool liquidity is changed by 1e-12 / 2
// P_issued = 1e20 * 1e-12 / 2 = 1e8 / 2 = 50_000_000
name: "minimum input single asset equal liquidity",
swapFee: sdk.MustNewDecFromStr("0"),
poolAssets: []balancer.PoolAsset{
{
Token: sdk.NewInt64Coin("uosmo", 1_000_000_000_000),
Weight: sdk.NewInt(100),
},
{
Token: sdk.NewInt64Coin("uatom", 1_000_000_000_000),
Weight: sdk.NewInt(100),
},
},
tokensIn: sdk.NewCoins(
sdk.NewInt64Coin("uosmo", 1),
),
expectShares: sdk.NewInt(50_000_000),
},
{
// P_issued should be 1/10th that of the previous test
// p_issued = 50_000_000 / 10 = 5_000_000
name: "minimum input single asset imbalanced liquidity",
swapFee: sdk.MustNewDecFromStr("0"),
poolAssets: []balancer.PoolAsset{
{
Token: sdk.NewInt64Coin("uosmo", 10_000_000_000_000),
Weight: sdk.NewInt(100),
},
{
Token: sdk.NewInt64Coin("uatom", 1_000_000_000_000),
Weight: sdk.NewInt(100),
},
},
tokensIn: sdk.NewCoins(
sdk.NewInt64Coin("uosmo", 1),
),
expectShares: sdk.NewInt(5_000_000),
},
}

func (suite *KeeperTestSuite) TestCalcJoinPoolShares() {
Expand Down Expand Up @@ -501,6 +541,49 @@ func (suite *KeeperTestSuite) TestCalcJoinPoolShares() {
),
expectShares: sdk.NewInt(1250000000000 + 609374990000),
},
{
// This test doubles the liquidity in a fresh pool, so it should generate the base number of LP shares for pool creation as new shares
// This is set to 1e20 (or 100 * 10^18) for Osmosis, so we should expect:
// P_issued = 1e20
name: "minimum input with two assets and minimum liquidity",
swapFee: sdk.MustNewDecFromStr("0"),
poolAssets: []balancer.PoolAsset{
{
Token: sdk.NewInt64Coin("uosmo", 1),
Weight: sdk.NewInt(100),
},
{
Token: sdk.NewInt64Coin("uatom", 1),
Weight: sdk.NewInt(100),
},
},
tokensIn: sdk.NewCoins(
sdk.NewInt64Coin("uosmo", 1),
sdk.NewInt64Coin("uatom", 1),
),
expectShares: sdk.NewInt(1e18).Mul(sdk.NewInt(100)),
},
{
// Pool liquidity is changed by 1e-12
// P_issued = 1e20 * 1e-12 = 1e8
name: "minimum input two assets equal liquidity",
swapFee: sdk.MustNewDecFromStr("0"),
poolAssets: []balancer.PoolAsset{
{
Token: sdk.NewInt64Coin("uosmo", 1_000_000_000_000),
Weight: sdk.NewInt(100),
},
{
Token: sdk.NewInt64Coin("uatom", 1_000_000_000_000),
Weight: sdk.NewInt(100),
},
},
tokensIn: sdk.NewCoins(
sdk.NewInt64Coin("uosmo", 1),
sdk.NewInt64Coin("uatom", 1),
),
expectShares: sdk.NewInt(100_000_000),
},
}
testCases = append(testCases, calcSingleAssetJoinTestCases...)

Expand Down

0 comments on commit d0239e9

Please sign in to comment.