Repository: osmosis-labs/osmosis
Pull request #5253 (2023-05-22 02:01:40)

chore(deps): bump github.com/stretchr/testify from 1.8.2 to 1.8.3
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.8.2 to 1.8.3.
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/stretchr/testify/commit/4c93d8f201cb46ed50de949ee65804f944b570f8"><code>4c93d8f</code></a> EqualExportedValues: Handle nested pointer, slice and map fields (<a href="https://redirect.github.com/stretchr/testify/issues/1379">#1379</a>)</li>
<li><a href="https://github.com/stretchr/testify/commit/4b2f4d2bcff3848b6a4e63d462da6ce3c21e9c78"><code>4b2f4d2</code></a> add EventuallyWithT assertion (<a href="https://redirect.github.com/stretchr/testify/issues/1264">#1264</a>)</li>
<li><a href="https://github.com/stretchr/testify/commit/b3106d772c7aa439743e1a3f4de81149e323cf70"><code>b3106d7</code></a> allow testing for functional options (<a href="https://redirect.github.com/stretchr/testify/issues/1023">#1023</a>)</li>
<li><a href="https://github.com/stretchr/testify/commit/437071b948cd89bdbaaf43a41f19fbe1a0945f6f"><code>437071b</code></a> assert: fix error message formatting for NotContains (<a href="https://redirect.github.com/stretchr/testify/issues/1362">#1362</a>)</li>
<li><a href="https://github.com/stretchr/testify/commit/c5fc9d6b6b21ea89be8480c0dc35e2977ab988f6"><code>c5fc9d6</code></a> Compare public elements of struct (<a href="https://redirect.github.com/stretchr/testify/issues/1309">#1309</a>)</li>
<li>See full diff in <a href="https://github.com/stretchr/testify/compare/v1.8.2...v1.8.3">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=github.com/stretchr/testify&package-manager=go_modules&previous-version=1.8.2&new-version=1.8.3)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>


Patch:
diff --git a/go.mod b/go.mod
index a7c88a282..1df8f7cf5 100644
--- a/go.mod
+++ b/go.mod
@@ -31,7 +31,7 @@ require (
 	github.com/spf13/viper v1.15.0
 	github.com/strangelove-ventures/async-icq/v4 v4.0.0-rc0
 	github.com/strangelove-ventures/packet-forward-middleware/v4 v4.0.5
-	github.com/stretchr/testify v1.8.2
+	github.com/stretchr/testify v1.8.3
 	github.com/tendermint/tendermint v0.34.26
 	github.com/tendermint/tm-db v0.6.8-0.20220506192307-f628bb5dc95b
 	github.com/tidwall/btree v1.6.0
diff --git a/go.sum b/go.sum
index 85fb44ff8..afb38ce74 100644
--- a/go.sum
+++ b/go.sum
@@ -1158,8 +1158,9 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
 github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
 github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
-github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
 github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
+github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
+github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
 github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8=
 github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0=
 github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=


Test patch:
diff --git a/x/gamm/keeper/export_test.go b/x/gamm/keeper/export_test.go
index 2a15cdbaa..ff9e5bd1a 100644
--- a/x/gamm/keeper/export_test.go
+++ b/x/gamm/keeper/export_test.go
@@ -29,3 +29,7 @@ func (k Keeper) UnmarshalPoolLegacy(bz []byte) (poolmanagertypes.PoolI, error) {
 	var acc poolmanagertypes.PoolI
 	return acc, k.cdc.UnmarshalInterface(bz, &acc)
 }
+
+func GetMaximalNoSwapLPAmount(ctx sdk.Context, pool types.CFMMPoolI, shareOutAmount sdk.Int) (neededLpLiquidity sdk.Coins, err error) {
+	return getMaximalNoSwapLPAmount(ctx, pool, shareOutAmount)
+}
diff --git a/x/gamm/keeper/pool_test.go b/x/gamm/keeper/pool_test.go
index 37de1be79..e4eec2b7d 100644
--- a/x/gamm/keeper/pool_test.go
+++ b/x/gamm/keeper/pool_test.go
@@ -518,6 +518,227 @@ func (s *KeeperTestSuite) TestSetStableSwapScalingFactors() {
 	}
 }
 
+func (suite *KeeperTestSuite) TestGetMaximalNoSwapLPAmount() {
+	tests := map[string]struct {
+		poolId              uint64
+		shareOutAmount      sdk.Int
+		expectedLpLiquidity sdk.Coins
+		err				error
+	}{
+		"Balancer pool: Share ratio is zero": {
+			poolId: suite.prepareCustomBalancerPool(defaultAcctFunds, defaultPoolAssets, balancer.PoolParams{
+				SwapFee: defaultSpreadFactor,
+				ExitFee: defaultZeroExitFee,
+			}),
+			shareOutAmount: sdk.ZeroInt(),
+			err: types.ErrInvalidMathApprox,
+		},
+
+		"Balancer pool: Share ratio is negative": {
+			poolId: suite.prepareCustomBalancerPool(defaultAcctFunds, defaultPoolAssets, balancer.PoolParams{
+				SwapFee: defaultSpreadFactor,
+				ExitFee: defaultZeroExitFee,
+			}),
+			shareOutAmount: sdk.NewInt(-1),
+			err: types.ErrInvalidMathApprox,
+		},
+
+		"Balancer pool: Pass": {
+			poolId: suite.prepareCustomBalancerPool(defaultAcctFunds, defaultPoolAssets, balancer.PoolParams{
+				SwapFee: defaultSpreadFactor,
+				ExitFee: defaultZeroExitFee,
+			}),
+
+			// totalShare:   100_000_000_000_000_000_000
+			// shareOutAmount: 8_000_000_000_000_000_000
+			// shareRatio = shareOutAmount/totalShare = 0.08
+			// Amount of tokens in poolAssets:
+			// 		- defaultPoolAssets[1].Token.Amount: 10000
+			//  	- defaultPoolAssets[0].Token.Amount: 10000
+			shareOutAmount: sdk.NewInt(8_000_000_000_000_000_000),
+			expectedLpLiquidity: sdk.Coins{
+				sdk.NewInt64Coin(defaultPoolAssets[1].Token.Denom, 800),
+				sdk.NewInt64Coin(defaultPoolAssets[0].Token.Denom, 800),
+			},
+		},
+
+		"Balancer pool: Pass with ceiling result": {
+			poolId: suite.prepareCustomBalancerPool(defaultAcctFunds, defaultPoolAssets, balancer.PoolParams{
+				SwapFee: defaultSpreadFactor,
+				ExitFee: defaultZeroExitFee,
+			}),
+
+			// totalShare:   100_000_000_000_000_000_000
+			// shareOutAmount: 8_888_000_000_000_000_000
+			// shareRatio = shareOutAmount/totalShare = 0.08888
+			// Amount of tokens in poolAssets:
+			// 		- defaultPoolAssets[1].Token.Amount: 10000
+			//  	- defaultPoolAssets[0].Token.Amount: 10000
+			shareOutAmount: sdk.NewInt(8_888_000_000_000_000_000),
+			expectedLpLiquidity: sdk.Coins{
+				sdk.NewInt64Coin(defaultPoolAssets[1].Token.Denom, 889),
+				sdk.NewInt64Coin(defaultPoolAssets[0].Token.Denom, 889),
+			},
+		},
+
+		"Stableswap pool: Share ratio is zero with even two-asset": {
+			poolId: suite.prepareCustomStableswapPool(
+				defaultAcctFunds, 
+				stableswap.PoolParams{
+					SwapFee: defaultSpreadFactor,
+					ExitFee: defaultZeroExitFee,
+				}, 
+				sdk.NewCoins(sdk.NewCoin(defaultAcctFunds[1].Denom, defaultAcctFunds[1].Amount), sdk.NewCoin(defaultAcctFunds[2].Denom, defaultAcctFunds[2].Amount)),
+				[]uint64{1, 1},
+			),
+			shareOutAmount: sdk.ZeroInt(),
+			err: types.ErrInvalidMathApprox,
+		},
+
+		"Stableswap pool: Share ratio is zero with uneven two-asset": {
+			poolId: suite.prepareCustomStableswapPool(
+				defaultAcctFunds, 
+				stableswap.PoolParams{
+					SwapFee: defaultSpreadFactor,
+					ExitFee: defaultZeroExitFee,
+				}, 
+				sdk.NewCoins(sdk.NewCoin(defaultAcctFunds[1].Denom, defaultAcctFunds[1].Amount.QuoRaw(2)), sdk.NewCoin(defaultAcctFunds[2].Denom, defaultAcctFunds[2].Amount)),
+				[]uint64{1, 1},
+			),
+			shareOutAmount: sdk.ZeroInt(),
+			err: types.ErrInvalidMathApprox,
+		},
+
+		"Stableswap pool: Share ratio is negative with even two-asset": {
+			poolId: suite.prepareCustomStableswapPool(
+				defaultAcctFunds, 
+				stableswap.PoolParams{
+					SwapFee: defaultSpreadFactor,
+					ExitFee: defaultZeroExitFee,
+				}, 
+				sdk.NewCoins(sdk.NewCoin(defaultAcctFunds[1].Denom, defaultAcctFunds[1].Amount), sdk.NewCoin(defaultAcctFunds[2].Denom, defaultAcctFunds[2].Amount)),
+				[]uint64{1, 1},
+			),
+			shareOutAmount: sdk.NewInt(-1),
+			err: types.ErrInvalidMathApprox,
+		},
+
+		"Stableswap pool: Share ratio is negative with uneven two-asset": {
+			poolId: suite.prepareCustomStableswapPool(
+				defaultAcctFunds, 
+				stableswap.PoolParams{
+					SwapFee: defaultSpreadFactor,
+					ExitFee: defaultZeroExitFee,
+				}, 
+				sdk.NewCoins(sdk.NewCoin(defaultAcctFunds[1].Denom, defaultAcctFunds[1].Amount.QuoRaw(2)), sdk.NewCoin(defaultAcctFunds[2].Denom, defaultAcctFunds[2].Amount)),
+				[]uint64{1, 1},
+			),
+			shareOutAmount: sdk.NewInt(-1),
+			err: types.ErrInvalidMathApprox,
+		},
+
+		"Stableswap pool: Pass with even two-asset": {
+			poolId: suite.prepareCustomStableswapPool(
+				defaultAcctFunds, 
+				stableswap.PoolParams{
+					SwapFee: defaultSpreadFactor,
+					ExitFee: defaultZeroExitFee,
+				}, 
+				sdk.NewCoins(sdk.NewCoin(defaultAcctFunds[1].Denom, defaultAcctFunds[1].Amount), sdk.NewCoin(defaultAcctFunds[2].Denom, defaultAcctFunds[2].Amount)),
+				[]uint64{1, 1},
+			),
+			shareOutAmount: sdk.NewInt(8_000_000_000_000_000_000),
+			expectedLpLiquidity: sdk.Coins{
+				sdk.NewInt64Coin(defaultAcctFunds[1].Denom, 800000),
+				sdk.NewInt64Coin(defaultAcctFunds[2].Denom, 800000),
+			},
+		},
+
+		"Stableswap pool: Pass with even two-asset, ceiling result": {
+			poolId: suite.prepareCustomStableswapPool(
+				defaultAcctFunds, 
+				stableswap.PoolParams{
+					SwapFee: defaultSpreadFactor,
+					ExitFee: defaultZeroExitFee,
+				}, 
+				sdk.NewCoins(sdk.NewCoin(defaultAcctFunds[1].Denom, defaultAcctFunds[1].Amount), sdk.NewCoin(defaultAcctFunds[2].Denom, defaultAcctFunds[2].Amount)),
+				[]uint64{1, 1},
+			),
+			// totalShare:   100_000_000_000_000_000_000
+			// shareOutAmount: 8_888_888_000_000_000_000
+			// shareRatio = shareOutAmount/totalShare = 0.08888888
+			// Amount of tokens in liquidity:
+			// 		- defaultAcctFunds[1].Amount: 10000000
+			//  	- defaultAcctFunds[2].Amount: 10000000
+			shareOutAmount: sdk.NewInt(8_888_888_000_000_000_000),
+			expectedLpLiquidity: sdk.Coins{
+				sdk.NewInt64Coin(defaultAcctFunds[1].Denom, 888889),
+				sdk.NewInt64Coin(defaultAcctFunds[2].Denom, 888889),
+			},
+		},
+
+		"Stableswap pool: Pass with uneven two-asset": {
+			poolId: suite.prepareCustomStableswapPool(
+				defaultAcctFunds, 
+				stableswap.PoolParams{
+					SwapFee: defaultSpreadFactor,
+					ExitFee: defaultZeroExitFee,
+				}, 
+				sdk.NewCoins(sdk.NewCoin(defaultAcctFunds[1].Denom, defaultAcctFunds[1].Amount.QuoRaw(2)), sdk.NewCoin(defaultAcctFunds[2].Denom, defaultAcctFunds[2].Amount)),
+				[]uint64{1, 1},
+			),
+			shareOutAmount: sdk.NewInt(8_000_000_000_000_000_000),
+			expectedLpLiquidity: sdk.Coins{
+				sdk.NewInt64Coin(defaultAcctFunds[1].Denom, 400000),
+				sdk.NewInt64Coin(defaultAcctFunds[2].Denom, 800000),
+			},
+		},
+
+		"Stableswap pool: Pass with uneven two-asset, ceiling result": {
+			poolId: suite.prepareCustomStableswapPool(
+				defaultAcctFunds, 
+				stableswap.PoolParams{
+					SwapFee: defaultSpreadFactor,
+					ExitFee: defaultZeroExitFee,
+				}, 
+				sdk.NewCoins(sdk.NewCoin(defaultAcctFunds[1].Denom, defaultAcctFunds[1].Amount.QuoRaw(2)), sdk.NewCoin(defaultAcctFunds[2].Denom, defaultAcctFunds[2].Amount)),
+				[]uint64{1, 1},
+			),
+			// totalShare:   100_000_000_000_000_000_000
+			// shareOutAmount: 8_888_888_000_000_000_000
+			// shareRatio = shareOutAmount/totalShare = 0.08888888
+			// Amount of tokens in liquidity:
+			// 		- defaultAcctFunds[1].Amount: 10000000
+			//  	- defaultAcctFunds[2].Amount: 5000000
+			shareOutAmount: sdk.NewInt(8_888_888_000_000_000_000),
+			expectedLpLiquidity: sdk.Coins{
+				sdk.NewInt64Coin(defaultAcctFunds[1].Denom, 444445),
+				sdk.NewInt64Coin(defaultAcctFunds[2].Denom, 888889),
+			},
+		},
+	}
+	for name, tc := range tests {
+		suite.Run(name, func() {
+			k := suite.App.GAMMKeeper
+
+			pool, err := k.GetPoolAndPoke(suite.Ctx, tc.poolId)
+			suite.Require().NoError(err)
+			suite.Require().Equal(tc.poolId, pool.GetId())
+
+			neededLpLiquidity, err := keeper.GetMaximalNoSwapLPAmount(suite.Ctx, pool, tc.shareOutAmount)
+			if tc.err != nil {
+				suite.Require().Error(err)
+				msgError := fmt.Sprintf("Too few shares out wanted. (debug: getMaximalNoSwapLPAmount share ratio is zero or negative): %s", tc.err)
+				suite.Require().EqualError(err, msgError)
+			} else {
+				suite.Require().NoError(err)
+				suite.Require().Equal(neededLpLiquidity, tc.expectedLpLiquidity)
+			}
+
+		})
+	}
+}
+
 func (suite *KeeperTestSuite) TestGetTotalPoolShares() {
 	tests := map[string]struct {
 		sharesJoined   sdk.Int