From dda9222b85a9de8906861f132e9931a307e25abc Mon Sep 17 00:00:00 2001 From: Sishir Giri Date: Mon, 18 Jul 2022 15:45:43 -0700 Subject: [PATCH] refactor(x/mint, x/gamm errors): move errors in mint and gamm keeper to errors.go (#2067) * moved mint errors * errors formatted * rom and bez feedback * rebased * addressed all comments (cherry picked from commit e5ffb813c624772051b636f3634aac6dabb2a409) --- x/gamm/pool-models/balancer/amm.go | 4 +-- x/gamm/pool-models/balancer/export_test.go | 6 ++--- x/gamm/pool-models/balancer/pool.go | 29 +++++++++++----------- x/gamm/types/errors.go | 1 + x/mint/keeper/export_test.go | 4 --- x/mint/keeper/hooks_test.go | 16 ++++++------ x/mint/keeper/keeper.go | 22 ++++++---------- x/mint/keeper/keeper_test.go | 22 ++++++++-------- x/mint/types/errors.go | 11 ++++++++ 9 files changed, 60 insertions(+), 55 deletions(-) create mode 100644 x/mint/types/errors.go diff --git a/x/gamm/pool-models/balancer/amm.go b/x/gamm/pool-models/balancer/amm.go index eaa7c69d19d..baab46209eb 100644 --- a/x/gamm/pool-models/balancer/amm.go +++ b/x/gamm/pool-models/balancer/amm.go @@ -151,7 +151,7 @@ func getPoolAssetsByDenom(poolAssets []PoolAsset) (map[string]PoolAsset, error) for _, poolAsset := range poolAssets { _, ok := poolAssetsByDenom[poolAsset.Token.Denom] if ok { - return nil, fmt.Errorf(errMsgFormatRepeatingPoolAssetsNotAllowed, poolAsset.Token.Denom) + return nil, fmt.Errorf(formatRepeatingPoolAssetsNotAllowedErrFormat, poolAsset.Token.Denom) } poolAssetsByDenom[poolAsset.Token.Denom] = poolAsset @@ -174,7 +174,7 @@ func updateIntermediaryPoolAssetsLiquidity(liquidity sdk.Coins, poolAssetsByDeno for _, coin := range liquidity { poolAsset, ok := poolAssetsByDenom[coin.Denom] if !ok { - return fmt.Errorf(errMsgFormatFailedInterimLiquidityUpdate, coin.Denom) + return fmt.Errorf(failedInterimLiquidityUpdateErrFormat, coin.Denom) } poolAsset.Token.Amount = poolAssetsByDenom[coin.Denom].Token.Amount.Add(coin.Amount) diff --git a/x/gamm/pool-models/balancer/export_test.go b/x/gamm/pool-models/balancer/export_test.go index 75677b7e559..5f65f9c2c0e 100644 --- a/x/gamm/pool-models/balancer/export_test.go +++ b/x/gamm/pool-models/balancer/export_test.go @@ -3,12 +3,12 @@ package balancer import sdk "github.com/cosmos/cosmos-sdk/types" const ( - ErrMsgFormatRepeatingPoolAssetsNotAllowed = errMsgFormatRepeatingPoolAssetsNotAllowed - ErrMsgFormatNoPoolAssetFound = errMsgFormatNoPoolAssetFound + ErrMsgFormatRepeatingPoolAssetsNotAllowed = formatRepeatingPoolAssetsNotAllowedErrFormat + ErrMsgFormatNoPoolAssetFound = formatNoPoolAssetFoundErrFormat ) var ( - ErrMsgFormatFailedInterimLiquidityUpdate = errMsgFormatFailedInterimLiquidityUpdate + ErrMsgFormatFailedInterimLiquidityUpdate = failedInterimLiquidityUpdateErrFormat CalcPoolSharesOutGivenSingleAssetIn = calcPoolSharesOutGivenSingleAssetIn CalcSingleAssetInGivenPoolSharesOut = calcSingleAssetInGivenPoolSharesOut diff --git a/x/gamm/pool-models/balancer/pool.go b/x/gamm/pool-models/balancer/pool.go index 18b248ce23c..c399bb78077 100644 --- a/x/gamm/pool-models/balancer/pool.go +++ b/x/gamm/pool-models/balancer/pool.go @@ -16,13 +16,14 @@ import ( ) const ( - errMsgFormatSharesAmountNotPositive = "shares amount must be positive, was %d" - errMsgFormatTokenAmountNotPositive = "token amount must be positive, was %d" - errMsgFormatTokensLargerThanMax = "%d resulted tokens is larger than the max amount of %d" - errMsgFormatSharesLargerThanMax = "%d resulted shares is larger than the max amount of %d" - errMsgFormatFailedInterimLiquidityUpdate = "failed to update interim liquidity - pool asset %s does not exist" - errMsgFormatRepeatingPoolAssetsNotAllowed = "repeating pool assets not allowed, found %s" - errMsgFormatNoPoolAssetFound = "can't find the PoolAsset (%s)" + nonPostiveSharesAmountErrFormat = "shares amount must be positive, was %d" + nonPostiveTokenAmountErrFormat = "token amount must be positive, was %d" + sharesLargerThanMaxErrFormat = "%d resulted shares is larger than the max amount of %d" + invalidInputDenomsErrFormat = "input denoms must already exist in the pool (%s)" + + failedInterimLiquidityUpdateErrFormat = "failed to update interim liquidity - pool asset %s does not exist" + formatRepeatingPoolAssetsNotAllowedErrFormat = "repeating pool assets not allowed, found %s" + formatNoPoolAssetFoundErrFormat = "can't find the PoolAsset (%s)" v10Fork = 4713065 ) @@ -223,7 +224,7 @@ func (pa Pool) getPoolAssetAndIndex(denom string) (int, PoolAsset, error) { } if len(pa.PoolAssets) == 0 { - return -1, PoolAsset{}, sdkerrors.Wrapf(types.ErrDenomNotFoundInPool, fmt.Sprintf(errMsgFormatNoPoolAssetFound, denom)) + return -1, PoolAsset{}, sdkerrors.Wrapf(types.ErrDenomNotFoundInPool, fmt.Sprintf(formatNoPoolAssetFoundErrFormat, denom)) } i := sort.Search(len(pa.PoolAssets), func(i int) bool { @@ -234,11 +235,11 @@ func (pa Pool) getPoolAssetAndIndex(denom string) (int, PoolAsset, error) { }) if i < 0 || i >= len(pa.PoolAssets) { - return -1, PoolAsset{}, sdkerrors.Wrapf(types.ErrDenomNotFoundInPool, fmt.Sprintf(errMsgFormatNoPoolAssetFound, denom)) + return -1, PoolAsset{}, sdkerrors.Wrapf(types.ErrDenomNotFoundInPool, fmt.Sprintf(formatNoPoolAssetFoundErrFormat, denom)) } if pa.PoolAssets[i].Token.Denom != denom { - return -1, PoolAsset{}, sdkerrors.Wrapf(types.ErrDenomNotFoundInPool, fmt.Sprintf(errMsgFormatNoPoolAssetFound, denom)) + return -1, PoolAsset{}, sdkerrors.Wrapf(types.ErrDenomNotFoundInPool, fmt.Sprintf(formatNoPoolAssetFoundErrFormat, denom)) } return i, pa.PoolAssets[i], nil @@ -875,7 +876,7 @@ func (p *Pool) CalcTokenInShareAmountOut( ).Ceil().TruncateInt() if !tokenInAmount.IsPositive() { - return sdk.Int{}, sdkerrors.Wrapf(types.ErrInvalidMathApprox, errMsgFormatTokenAmountNotPositive, tokenInAmount.Int64()) + return sdk.Int{}, sdkerrors.Wrapf(types.ErrNotPositiveRequireAmount, nonPostiveTokenAmountErrFormat, tokenInAmount.Int64()) } return tokenInAmount, nil @@ -902,7 +903,7 @@ func (p *Pool) JoinPoolTokenInMaxShareAmountOut( ).TruncateInt() if !tokenInAmount.IsPositive() { - return sdk.Int{}, sdkerrors.Wrapf(types.ErrInvalidMathApprox, errMsgFormatTokenAmountNotPositive, tokenInAmount.Int64()) + return sdk.Int{}, sdkerrors.Wrapf(types.ErrNotPositiveRequireAmount, nonPostiveTokenAmountErrFormat, tokenInAmount.Int64()) } poolAssetIn.Token.Amount = poolAssetIn.Token.Amount.Add(tokenInAmount) @@ -934,11 +935,11 @@ func (p *Pool) ExitSwapExactAmountOut( ).TruncateInt() if !sharesIn.IsPositive() { - return sdk.Int{}, sdkerrors.Wrapf(types.ErrInvalidMathApprox, errMsgFormatSharesAmountNotPositive, sharesIn.Int64()) + return sdk.Int{}, sdkerrors.Wrapf(types.ErrNotPositiveRequireAmount, nonPostiveSharesAmountErrFormat, sharesIn.Int64()) } if sharesIn.GT(shareInMaxAmount) { - return sdk.Int{}, sdkerrors.Wrapf(types.ErrLimitMaxAmount, errMsgFormatSharesLargerThanMax, sharesIn.Int64(), shareInMaxAmount.Uint64()) + return sdk.Int{}, sdkerrors.Wrapf(types.ErrLimitMaxAmount, sharesLargerThanMaxErrFormat, sharesIn.Int64(), shareInMaxAmount.Uint64()) } if err := p.exitPool(ctx, sdk.NewCoins(tokenOut), sharesIn); err != nil { diff --git a/x/gamm/types/errors.go b/x/gamm/types/errors.go index faa26df35dc..dcf6dc70cdf 100644 --- a/x/gamm/types/errors.go +++ b/x/gamm/types/errors.go @@ -15,6 +15,7 @@ var ( ErrAlreadyInvalidPool = sdkerrors.Register(ModuleName, 9, "destruction on already invalid pool") ErrInvalidPool = sdkerrors.Register(ModuleName, 10, "attempting to create an invalid pool") ErrDenomNotFoundInPool = sdkerrors.Register(ModuleName, 11, "denom does not exist in pool") + ErrDenomAlreadyInPool = sdkerrors.Register(ModuleName, 12, "denom already exists in the pool") ErrEmptyRoutes = sdkerrors.Register(ModuleName, 21, "routes not defined") ErrEmptyPoolAssets = sdkerrors.Register(ModuleName, 22, "PoolAssets not defined") diff --git a/x/mint/keeper/export_test.go b/x/mint/keeper/export_test.go index 888411f125f..6c27f1aebbb 100644 --- a/x/mint/keeper/export_test.go +++ b/x/mint/keeper/export_test.go @@ -15,10 +15,6 @@ const ( ) var ( - ErrAmountCannotBeNilOrZero = errAmountCannotBeNilOrZero - ErrDevVestingModuleAccountAlreadyCreated = errDevVestingModuleAccountAlreadyCreated - ErrDevVestingModuleAccountNotCreated = errDevVestingModuleAccountNotCreated - GetProportions = getProportions ) diff --git a/x/mint/keeper/hooks_test.go b/x/mint/keeper/hooks_test.go index 011a612df95..7c27af73d03 100644 --- a/x/mint/keeper/hooks_test.go +++ b/x/mint/keeper/hooks_test.go @@ -54,7 +54,7 @@ func (suite *KeeperTestSuite) TestEndOfEpochMintedCoinDistribution() { mintParams = app.MintKeeper.GetParams(ctx) mintedCoin := app.MintKeeper.GetMinter(ctx).EpochProvision(mintParams) - expectedRewardsCoin, err := keeper.GetProportions(mintedCoin, mintParams.DistributionProportions.Staking) + expectedRewardsCoin, err := keeper.GetProportions(ctx, mintedCoin, mintParams.DistributionProportions.Staking) suite.NoError(err) expectedRewards := sdk.NewDecCoin("stake", expectedRewardsCoin.Amount) @@ -71,7 +71,7 @@ func (suite *KeeperTestSuite) TestEndOfEpochMintedCoinDistribution() { // test that the dev rewards module account balance decreased by the correct amount devRewardsModuleAfter := app.BankKeeper.GetAllBalances(ctx, devRewardsModuleAcc.GetAddress()) - expectedDevRewards, err := keeper.GetProportions(mintedCoin, mintParams.DistributionProportions.DeveloperRewards) + expectedDevRewards, err := keeper.GetProportions(ctx, mintedCoin, mintParams.DistributionProportions.DeveloperRewards) suite.NoError(err) suite.Equal(devRewardsModuleAfter.Add(expectedDevRewards), devRewardsModuleOrigin, expectedRewards.String()) } @@ -92,7 +92,7 @@ func (suite *KeeperTestSuite) TestEndOfEpochMintedCoinDistribution() { mintParams = app.MintKeeper.GetParams(ctx) mintedCoin := app.MintKeeper.GetMinter(ctx).EpochProvision(mintParams) - expectedRewardsCoin, err := keeper.GetProportions(mintedCoin, mintParams.DistributionProportions.Staking) + expectedRewardsCoin, err := keeper.GetProportions(ctx, mintedCoin, mintParams.DistributionProportions.Staking) suite.NoError(err) expectedRewards := sdk.NewDecCoin("stake", expectedRewardsCoin.Amount) @@ -102,7 +102,7 @@ func (suite *KeeperTestSuite) TestEndOfEpochMintedCoinDistribution() { // test that the balance decreased by the correct amount devRewardsModuleAfter := app.BankKeeper.GetAllBalances(ctx, devRewardsModuleAcc.GetAddress()) - expectedDevRewardsCoin, err := keeper.GetProportions(mintedCoin, mintParams.DistributionProportions.DeveloperRewards) + expectedDevRewardsCoin, err := keeper.GetProportions(ctx, mintedCoin, mintParams.DistributionProportions.DeveloperRewards) suite.NoError(err) suite.Equal(devRewardsModuleAfter.Add(expectedDevRewardsCoin), devRewardsModuleOrigin, expectedRewards.String()) } @@ -132,7 +132,7 @@ func (suite *KeeperTestSuite) TestMintedCoinDistributionWhenDevRewardsAddressEmp mintParams := app.MintKeeper.GetParams(ctx) mintedCoin := app.MintKeeper.GetMinter(ctx).EpochProvision(mintParams) - expectedRewardsCoin, err := keeper.GetProportions(mintedCoin, mintParams.DistributionProportions.Staking.Add(mintParams.DistributionProportions.DeveloperRewards)) + expectedRewardsCoin, err := keeper.GetProportions(ctx, mintedCoin, mintParams.DistributionProportions.Staking.Add(mintParams.DistributionProportions.DeveloperRewards)) suite.NoError(err) expectedRewards := sdk.NewDecCoin("stake", expectedRewardsCoin.Amount) @@ -142,7 +142,7 @@ func (suite *KeeperTestSuite) TestMintedCoinDistributionWhenDevRewardsAddressEmp // test that the dev rewards module account balance decreased by the correct amount devRewardsModuleAfter := app.BankKeeper.GetAllBalances(ctx, devRewardsModuleAcc.GetAddress()) - expectedDevRewardsCoin, err := keeper.GetProportions(mintedCoin, mintParams.DistributionProportions.DeveloperRewards) + expectedDevRewardsCoin, err := keeper.GetProportions(ctx, mintedCoin, mintParams.DistributionProportions.DeveloperRewards) suite.NoError(err) suite.Equal(devRewardsModuleAfter.Add(expectedDevRewardsCoin), devRewardsModuleOrigin, expectedRewards.String()) } @@ -163,7 +163,7 @@ func (suite *KeeperTestSuite) TestMintedCoinDistributionWhenDevRewardsAddressEmp mintParams := app.MintKeeper.GetParams(ctx) mintedCoin := app.MintKeeper.GetMinter(ctx).EpochProvision(mintParams) - expectedRewardsCoin, err := keeper.GetProportions(mintedCoin, mintParams.DistributionProportions.Staking.Add(mintParams.DistributionProportions.DeveloperRewards)) + expectedRewardsCoin, err := keeper.GetProportions(ctx, mintedCoin, mintParams.DistributionProportions.Staking.Add(mintParams.DistributionProportions.DeveloperRewards)) suite.NoError(err) expectedRewards := sdk.NewDecCoin("stake", expectedRewardsCoin.Amount) @@ -173,7 +173,7 @@ func (suite *KeeperTestSuite) TestMintedCoinDistributionWhenDevRewardsAddressEmp // test that the dev rewards module account balance decreased by the correct amount devRewardsModuleAfter := app.BankKeeper.GetAllBalances(ctx, devRewardsModuleAcc.GetAddress()) - expectedDevRewardsCoin, err := keeper.GetProportions(mintedCoin, mintParams.DistributionProportions.DeveloperRewards) + expectedDevRewardsCoin, err := keeper.GetProportions(ctx, mintedCoin, mintParams.DistributionProportions.DeveloperRewards) suite.NoError(err) suite.Equal(devRewardsModuleAfter.Add(expectedDevRewardsCoin), devRewardsModuleOrigin, expectedRewards.String()) } diff --git a/x/mint/keeper/keeper.go b/x/mint/keeper/keeper.go index e348f7d4a27..2694b2953eb 100644 --- a/x/mint/keeper/keeper.go +++ b/x/mint/keeper/keeper.go @@ -1,7 +1,6 @@ package keeper import ( - "errors" "fmt" "github.com/tendermint/tendermint/libs/log" @@ -11,6 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" ) @@ -36,12 +36,6 @@ func (e invalidRatioError) Error() string { return fmt.Sprintf("mint allocation ratio (%s) is greater than 1", e.ActualRatio) } -var ( - errAmountCannotBeNilOrZero = errors.New("amount cannot be nil or zero") - errDevVestingModuleAccountAlreadyCreated = fmt.Errorf("%s module account already exists", types.DeveloperVestingModuleAcctName) - errDevVestingModuleAccountNotCreated = fmt.Errorf("%s module account does not exist", types.DeveloperVestingModuleAcctName) -) - // NewKeeper creates a new mint Keeper instance. func NewKeeper( cdc codec.BinaryCodec, key sdk.StoreKey, paramSpace paramtypes.Subspace, @@ -79,7 +73,7 @@ func NewKeeper( // queries. The method returns an error if current height in ctx is greater than the v7 upgrade height. func (k Keeper) SetInitialSupplyOffsetDuringMigration(ctx sdk.Context) error { if !k.accountKeeper.HasAccount(ctx, k.accountKeeper.GetModuleAddress(types.DeveloperVestingModuleAcctName)) { - return errDevVestingModuleAccountNotCreated + return sdkerrors.Wrapf(types.ErrModuleDoesnotExist, "%s vesting module account doesnot exist", types.DeveloperVestingModuleAcctName) } moduleAccBalance := k.bankKeeper.GetBalance(ctx, k.accountKeeper.GetModuleAddress(types.DeveloperVestingModuleAcctName), k.GetParams(ctx).MintDenom) @@ -96,10 +90,10 @@ func (k Keeper) SetInitialSupplyOffsetDuringMigration(ctx sdk.Context) error { // - developer vesting module account is already created prior to calling this method. func (k Keeper) CreateDeveloperVestingModuleAccount(ctx sdk.Context, amount sdk.Coin) error { if amount.IsNil() || amount.Amount.IsZero() { - return errAmountCannotBeNilOrZero + return sdkerrors.Wrap(types.ErrAmountNilOrZero, "amount cannot be nil or zero") } if k.accountKeeper.HasAccount(ctx, k.accountKeeper.GetModuleAddress(types.DeveloperVestingModuleAcctName)) { - return errDevVestingModuleAccountAlreadyCreated + return sdkerrors.Wrapf(types.ErrModuleAccountAlreadyExist, "%s vesting module account already exist", types.DeveloperVestingModuleAcctName) } moduleAcc := authtypes.NewEmptyModuleAccount( @@ -231,7 +225,7 @@ func (k Keeper) DistributeMintedCoin(ctx sdk.Context, mintedCoin sdk.Coin) error // distributeToModule distributes mintedCoin multiplied by proportion to the recepientModule account. func (k Keeper) distributeToModule(ctx sdk.Context, recipientModule string, mintedCoin sdk.Coin, proportion sdk.Dec) (sdk.Int, error) { - distributionCoin, err := getProportions(mintedCoin, proportion) + distributionCoin, err := getProportions(ctx, mintedCoin, proportion) if err != nil { return sdk.Int{}, err } @@ -257,7 +251,7 @@ func (k Keeper) distributeToModule(ctx sdk.Context, recipientModule string, mint // - weights in developerRewardsReceivers add up to 1. // - addresses in developerRewardsReceivers are valid. func (k Keeper) distributeDeveloperRewards(ctx sdk.Context, totalMintedCoin sdk.Coin, developerRewardsProportion sdk.Dec, developerRewardsReceivers []types.WeightedAddress) (sdk.Int, error) { - devRewardCoin, err := getProportions(totalMintedCoin, developerRewardsProportion) + devRewardCoin, err := getProportions(ctx, totalMintedCoin, developerRewardsProportion) if err != nil { return sdk.Int{}, err } @@ -281,7 +275,7 @@ func (k Keeper) distributeDeveloperRewards(ctx sdk.Context, totalMintedCoin sdk. } else { // allocate developer rewards to addresses by weight for _, w := range developerRewardsReceivers { - devPortionCoin, err := getProportions(devRewardCoin, w.Weight) + devPortionCoin, err := getProportions(ctx, devRewardCoin, w.Weight) if err != nil { return sdk.Int{}, err } @@ -318,7 +312,7 @@ func (k Keeper) distributeDeveloperRewards(ctx sdk.Context, totalMintedCoin sdk. // allocation ratio. Returns error if ratio is greater than 1. // TODO: this currently rounds down and is the cause of rounding discrepancies. // To be fixed in: https://github.com/osmosis-labs/osmosis/issues/1917 -func getProportions(mintedCoin sdk.Coin, ratio sdk.Dec) (sdk.Coin, error) { +func getProportions(ctx sdk.Context, mintedCoin sdk.Coin, ratio sdk.Dec) (sdk.Coin, error) { if ratio.GT(sdk.OneDec()) { return sdk.Coin{}, invalidRatioError{ratio} } diff --git a/x/mint/keeper/keeper_test.go b/x/mint/keeper/keeper_test.go index f68e2d41893..ecde05b23c7 100644 --- a/x/mint/keeper/keeper_test.go +++ b/x/mint/keeper/keeper_test.go @@ -130,7 +130,7 @@ func (suite *KeeperTestSuite) TestGetProportions() { for _, tc := range tests { suite.Run(tc.name, func() { - coin, err := keeper.GetProportions(tc.mintedCoin, tc.ratio) + coin, err := keeper.GetProportions(suite.Ctx, tc.mintedCoin, tc.ratio) if tc.expectedError != nil { suite.Require().Equal(tc.expectedError, err) @@ -168,7 +168,8 @@ func (suite *KeeperTestSuite) TestDistributeMintedCoin_ToDeveloperRewardsAddr() { Address: testAddressOne.String(), Weight: sdk.NewDec(1), - }}, + }, + }, mintCoin: sdk.NewCoin("stake", sdk.NewInt(10000)), }, { @@ -181,7 +182,8 @@ func (suite *KeeperTestSuite) TestDistributeMintedCoin_ToDeveloperRewardsAddr() { Address: testAddressFour.String(), Weight: sdk.NewDecWithPrec(4, 1), - }}, + }, + }, mintCoin: sdk.NewCoin("stake", sdk.NewInt(100000)), }, { @@ -236,7 +238,7 @@ func (suite *KeeperTestSuite) TestDistributeMintedCoin_ToDeveloperRewardsAddr() feePool.CommunityPool.AmountOf("stake")) } else { suite.Equal( - //distribution go to community pool because nil dev reward addresses. + // distribution go to community pool because nil dev reward addresses. tc.mintCoin.Amount.ToDec().Mul((params.DistributionProportions.DeveloperRewards).Add(params.DistributionProportions.CommunityPool)), feePool.CommunityPool.AmountOf("stake")) } @@ -313,18 +315,18 @@ func (suite *KeeperTestSuite) TestCreateDeveloperVestingModuleAccount() { }, "nil amount": { blockHeight: 0, - expectedError: keeper.ErrAmountCannotBeNilOrZero, + expectedError: sdkerrors.Wrap(types.ErrAmountNilOrZero, "amount cannot be nil or zero"), }, "zero amount": { blockHeight: 0, amount: sdk.NewCoin("stake", sdk.NewInt(0)), - expectedError: keeper.ErrAmountCannotBeNilOrZero, + expectedError: sdkerrors.Wrap(types.ErrAmountNilOrZero, "amount cannot be nil or zero"), }, "module account is already created": { blockHeight: 0, amount: sdk.NewCoin("stake", sdk.NewInt(keeper.DeveloperVestingAmount)), isDeveloperModuleAccountCreated: true, - expectedError: keeper.ErrDevVestingModuleAccountAlreadyCreated, + expectedError: sdkerrors.Wrapf(types.ErrModuleAccountAlreadyExist, "%s vesting module account already exist", types.DeveloperVestingModuleAcctName), }, } @@ -338,7 +340,7 @@ func (suite *KeeperTestSuite) TestCreateDeveloperVestingModuleAccount() { if tc.expectedError != nil { suite.Error(actualError) - suite.Equal(actualError, tc.expectedError) + suite.ErrorIs(actualError, tc.expectedError) return } suite.NoError(actualError) @@ -359,7 +361,7 @@ func (suite *KeeperTestSuite) TestSetInitialSupplyOffsetDuringMigration() { }, "dev vesting module account does not exist": { blockHeight: 1, - expectedError: keeper.ErrDevVestingModuleAccountNotCreated, + expectedError: sdkerrors.Wrapf(types.ErrModuleDoesnotExist, "%s vesting module account doesnot exist", types.DeveloperVestingModuleAcctName), }, } @@ -378,7 +380,7 @@ func (suite *KeeperTestSuite) TestSetInitialSupplyOffsetDuringMigration() { if tc.expectedError != nil { suite.Error(actualError) - suite.Equal(actualError, tc.expectedError) + suite.ErrorIs(actualError, tc.expectedError) suite.Equal(supplyWithOffsetBefore.Amount, bankKeeper.GetSupplyWithOffset(ctx, sdk.DefaultBondDenom).Amount) suite.Equal(supplyOffsetBefore, bankKeeper.GetSupplyOffset(ctx, sdk.DefaultBondDenom)) diff --git a/x/mint/types/errors.go b/x/mint/types/errors.go new file mode 100644 index 00000000000..6f721cb74a7 --- /dev/null +++ b/x/mint/types/errors.go @@ -0,0 +1,11 @@ +package types + +import ( + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +var ( + ErrAmountNilOrZero = sdkerrors.Register(ModuleName, 2, "amount cannot be nil or zero") + ErrModuleAccountAlreadyExist = sdkerrors.Register(ModuleName, 3, "module account already exists") + ErrModuleDoesnotExist = sdkerrors.Register(ModuleName, 4, "module account does not exist") +)