Skip to content

Commit

Permalink
resolve unit test on amm and leveragelp
Browse files Browse the repository at this point in the history
  • Loading branch information
jelysn committed Nov 22, 2023
1 parent 72c574f commit aeae137
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions x/amm/keeper/apply_exit_pool_state_change_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package keeper_test

import (
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
simapp "github.com/elys-network/elys/app"
"github.com/elys-network/elys/x/amm/types"
Expand Down Expand Up @@ -73,6 +75,7 @@ func (suite *KeeperTestSuite) TestApplyExitPoolStateChange_WithdrawFromCommitmen
lpTokenBalance := bk.GetBalance(ctx, addrs[0], lpTokenDenom)
suite.Require().True(lpTokenBalance.Amount.Equal(sdk.ZeroInt()))

ctx = ctx.WithBlockTime(ctx.BlockTime().Add(time.Hour))
err = app.AmmKeeper.ApplyExitPoolStateChange(ctx, pool, addrs[0], pool.TotalShares.Amount, coins)
suite.Require().NoError(err)
}
3 changes: 3 additions & 0 deletions x/amm/keeper/msg_server_exit_pool_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package keeper_test

import (
"time"

"github.com/cometbft/cometbft/crypto/ed25519"
sdk "github.com/cosmos/cosmos-sdk/types"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
Expand Down Expand Up @@ -142,6 +144,7 @@ func (suite *KeeperTestSuite) TestMsgServerExitPool() {
})
suite.Require().NoError(err)
pool := suite.app.AmmKeeper.GetAllPool(suite.ctx)[0]
suite.ctx = suite.ctx.WithBlockTime(suite.ctx.BlockTime().Add(time.Hour))
resp, err := msgServer.ExitPool(
sdk.WrapSDKContext(suite.ctx),
&types.MsgExitPool{
Expand Down
2 changes: 1 addition & 1 deletion x/commitment/keeper/msg_server_commit_liquid_tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (k msgServer) CommitLiquidTokens(goCtx context.Context, msg *types.MsgCommi
commitments := k.GetCommitments(ctx, msg.Creator)

// Update the commitments
commitments.AddCommittedTokens(msg.Denom, msg.Amount, uint64(ctx.BlockTime().Unix())+msg.MinLock)
commitments.AddCommittedTokens(msg.Denom, msg.Amount, msg.MinLock)
k.SetCommitments(ctx, commitments)

// Emit Hook commitment changed
Expand Down
2 changes: 2 additions & 0 deletions x/leveragelp/keeper/position.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
"fmt"
"math"
"time"

"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -208,6 +209,7 @@ func (k Keeper) GetPositionHealth(ctx sdk.Context, position types.Position, ammP
params := k.stableKeeper.GetParams(ctx)
for _, commitment := range commitments.CommittedTokens {
cacheCtx, _ := ctx.CacheContext()
cacheCtx = cacheCtx.WithBlockTime(cacheCtx.BlockTime().Add(time.Hour))
exitCoins, err := k.amm.ExitPool(cacheCtx, position.GetPositionAddress(), ammPool.PoolId, commitment.Amount, sdk.Coins{}, params.DepositDenom)
if err != nil {
return sdk.ZeroDec(), err
Expand Down
1 change: 1 addition & 0 deletions x/leveragelp/keeper/position_close_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func (suite KeeperTestSuite) TestForceCloseLong() {
position, pool := suite.OpenPosition(addr)
repayAmount := math.NewInt(4000)

suite.ctx = suite.ctx.WithBlockTime(suite.ctx.BlockTime().Add(time.Hour))
repayAmountOut, err := k.ForceCloseLong(suite.ctx, *position, pool)
suite.Require().NoError(err)
suite.Require().Equal(repayAmount.String(), repayAmountOut.String())
Expand Down

0 comments on commit aeae137

Please sign in to comment.