-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: IRO claimed amount accounting (#1620)
- Loading branch information
Showing
2 changed files
with
93 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"time" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
appparams "github.com/dymensionxyz/dymension/v3/app/params" | ||
"github.com/dymensionxyz/dymension/v3/testutil/sample" | ||
keeper "github.com/dymensionxyz/dymension/v3/x/iro/keeper" | ||
"github.com/dymensionxyz/dymension/v3/x/iro/types" | ||
) | ||
|
||
func (s *KeeperTestSuite) TestInvariantAccounting() { | ||
rollappId := s.CreateDefaultRollapp() | ||
k := s.App.IROKeeper | ||
curve := types.DefaultBondingCurve() | ||
incentives := types.DefaultIncentivePlanParams() | ||
|
||
startTime := time.Now() | ||
endTime := startTime.Add(time.Hour) | ||
amt := sdk.NewInt(1_000_000).MulRaw(1e18) | ||
rollappDenom := "test_rollapp_denom" | ||
|
||
// Create a plan | ||
rollapp := s.App.RollappKeeper.MustGetRollapp(s.Ctx, rollappId) | ||
planId, err := k.CreatePlan(s.Ctx, amt, startTime, endTime, rollapp, curve, incentives) | ||
s.Require().NoError(err) | ||
plan := k.MustGetPlan(s.Ctx, planId) | ||
planDenom := plan.TotalAllocation.Denom | ||
|
||
// Buy some tokens to create a non-zero sold amount | ||
s.Ctx = s.Ctx.WithBlockTime(startTime.Add(time.Minute)) | ||
soldAmt := sdk.NewInt(1_000).MulRaw(1e18) | ||
buyer := sample.Acc() | ||
s.BuySomeTokens(planId, buyer, soldAmt) | ||
|
||
// Check invariant before settlement - should pass | ||
inv := keeper.InvariantAccounting(*k) | ||
err = inv(s.Ctx) | ||
s.Require().NoError(err) | ||
|
||
// Fund module with RA tokens and settle the plan | ||
s.FundModuleAcc(types.ModuleName, sdk.NewCoins(sdk.NewCoin(rollappDenom, amt))) | ||
err = k.Settle(s.Ctx, rollappId, rollappDenom) | ||
s.Require().NoError(err) | ||
|
||
// Check invariant after settlement but before claims - should pass | ||
err = inv(s.Ctx) | ||
s.Require().NoError(err) | ||
|
||
// Claim some tokens | ||
err = k.Claim(s.Ctx, planId, buyer) | ||
s.Require().NoError(err) | ||
|
||
// Check invariant after claims - should pass | ||
err = inv(s.Ctx) | ||
s.Require().NoError(err) | ||
|
||
// Artificially break invariant by minting IRO tokens to module | ||
err = s.App.BankKeeper.MintCoins(s.Ctx, types.ModuleName, sdk.NewCoins(sdk.NewCoin(planDenom, sdk.NewInt(1)))) | ||
s.Require().NoError(err) | ||
|
||
// Check invariant - should be broken due to IRO tokens in module after settlement | ||
err = inv(s.Ctx) | ||
s.Require().Error(err) | ||
|
||
// Clean up minted tokens | ||
err = s.App.BankKeeper.BurnCoins(s.Ctx, types.ModuleName, sdk.NewCoins(sdk.NewCoin(planDenom, sdk.NewInt(1)))) | ||
s.Require().NoError(err) | ||
|
||
// Artificially break invariant by sending DYM to plan address | ||
dymAmt := sdk.NewInt(100).MulRaw(1e18) | ||
s.FundAcc(plan.GetAddress(), sdk.NewCoins(sdk.NewCoin(appparams.BaseDenom, dymAmt))) | ||
|
||
// Check invariant - should be broken due to DYM tokens in plan after settlement | ||
err = inv(s.Ctx) | ||
s.Require().Error(err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters