From 959eaade433a1ee012be9d1094b8fe5fc36fb8c3 Mon Sep 17 00:00:00 2001 From: gopherjk121 Date: Thu, 11 Jan 2024 18:21:15 +0800 Subject: [PATCH] resolve unit tests --- app/ante_handler.go | 3 ++- cmd/teritorid/cmd/richest_snapshot.go | 7 ++++--- x/mint/keeper/abci_test.go | 11 +++++++---- x/mint/keeper/distribute.go | 25 +++++++++++++------------ x/mint/keeper/distribute_test.go | 7 +++++-- x/mint/keeper/keeper.go | 5 +++-- x/mint/keeper/params_test.go | 5 ++++- x/mint/simulation/genesis.go | 7 ++++--- x/mint/types/params.go | 3 ++- 9 files changed, 44 insertions(+), 29 deletions(-) diff --git a/app/ante_handler.go b/app/ante_handler.go index 682aa80..311c0ad 100644 --- a/app/ante_handler.go +++ b/app/ante_handler.go @@ -1,6 +1,7 @@ package teritori import ( + "cosmossdk.io/math" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" wasmTypes "github.com/CosmWasm/wasmd/x/wasm/types" airdropkeeper "github.com/TERITORI/teritori-chain/x/airdrop/keeper" @@ -160,7 +161,7 @@ func (min MinCommissionDecorator) getValidator(ctx sdk.Context, bech32ValAddr st return val, nil } -func (min MinCommissionDecorator) getTotalDelegatedTokens(ctx sdk.Context) sdk.Int { +func (min MinCommissionDecorator) getTotalDelegatedTokens(ctx sdk.Context) math.Int { bondDenom := min.sk.BondDenom(ctx) bondedPool := min.sk.GetBondedPool(ctx) notBondedPool := min.sk.GetNotBondedPool(ctx) diff --git a/cmd/teritorid/cmd/richest_snapshot.go b/cmd/teritorid/cmd/richest_snapshot.go index 197fa64..0b240b4 100644 --- a/cmd/teritorid/cmd/richest_snapshot.go +++ b/cmd/teritorid/cmd/richest_snapshot.go @@ -8,6 +8,7 @@ import ( "os" "sort" + "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server" @@ -45,9 +46,9 @@ type AppState struct { // SnapshotAccount provide fields of snapshot per account type SnapshotAccount struct { Address string - Balance sdk.Int - StakedBalance sdk.Int - TotalBalance sdk.Int + Balance math.Int + StakedBalance math.Int + TotalBalance math.Int } // ExportRichestSnapshotCmd generates a snapshot.csv from a provided chain genesis export. diff --git a/x/mint/keeper/abci_test.go b/x/mint/keeper/abci_test.go index 4854df9..803c89b 100644 --- a/x/mint/keeper/abci_test.go +++ b/x/mint/keeper/abci_test.go @@ -1,6 +1,7 @@ package keeper_test import ( + "cosmossdk.io/math" "github.com/TERITORI/teritori-chain/x/mint/types" "github.com/cometbft/cometbft/crypto/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" @@ -29,17 +30,19 @@ func (suite *KeeperTestSuite) TestEndBlocker() { WeightedDeveloperRewardsReceivers: []types.MonthlyVestingAddress{ { Address: dev1Addr.String(), - MonthlyAmounts: []sdk.Int{sdk.NewInt(6000), sdk.NewInt(6000), sdk.NewInt(6000)}, + MonthlyAmounts: []math.Int{sdk.NewInt(6000), sdk.NewInt(6000), sdk.NewInt(6000)}, }, { Address: dev2Addr.String(), - MonthlyAmounts: []sdk.Int{sdk.NewInt(4000), sdk.NewInt(4000), sdk.NewInt(4000)}, + MonthlyAmounts: []math.Int{sdk.NewInt(4000), sdk.NewInt(4000), sdk.NewInt(4000)}, }, }, UsageIncentiveAddress: usageIncentiveAddr.String(), GrantsProgramAddress: grantsAddr.String(), TeamReserveAddress: teamReserveAddr.String(), MintingRewardsDistributionStartBlock: 10, + BlocksPerYear: 5733818, + TotalBurntAmount: sdk.Coins{}, } suite.SetupTest() @@ -157,11 +160,11 @@ func (suite *KeeperTestSuite) TestEndBlocker90MonthsCheck() { params.WeightedDeveloperRewardsReceivers = []types.MonthlyVestingAddress{ { Address: dev1Addr.String(), - MonthlyAmounts: []sdk.Int{sdk.NewInt(6000), sdk.NewInt(6000), sdk.NewInt(6000)}, + MonthlyAmounts: []math.Int{sdk.NewInt(6000), sdk.NewInt(6000), sdk.NewInt(6000)}, }, { Address: dev2Addr.String(), - MonthlyAmounts: []sdk.Int{sdk.NewInt(4000), sdk.NewInt(4000), sdk.NewInt(4000)}, + MonthlyAmounts: []math.Int{sdk.NewInt(4000), sdk.NewInt(4000), sdk.NewInt(4000)}, }, } suite.app.MintKeeper.SetParams(suite.ctx, params) diff --git a/x/mint/keeper/distribute.go b/x/mint/keeper/distribute.go index e53ae98..1bdecd4 100644 --- a/x/mint/keeper/distribute.go +++ b/x/mint/keeper/distribute.go @@ -1,6 +1,7 @@ package keeper import ( + "cosmossdk.io/math" "github.com/TERITORI/teritori-chain/x/mint/types" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -59,41 +60,41 @@ func (k Keeper) DistributeMintedCoin(ctx sdk.Context, mintedCoin sdk.Coin) error } // distributeToModule distributes mintedCoin multiplied by proportion to the recepient account. -func (k Keeper) distributeToAddress(ctx sdk.Context, recipientAddr string, mintedCoin sdk.Coin, proportion sdk.Dec) (sdk.Int, error) { +func (k Keeper) distributeToAddress(ctx sdk.Context, recipientAddr string, mintedCoin sdk.Coin, proportion sdk.Dec) (math.Int, error) { distributionCoin, err := getProportions(mintedCoin, proportion) if err != nil { - return sdk.Int{}, err + return math.Int{}, err } recipient, err := sdk.AccAddressFromBech32(recipientAddr) if err != nil { - return sdk.Int{}, err + return math.Int{}, err } if err := k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, recipient, sdk.NewCoins(distributionCoin)); err != nil { - return sdk.Int{}, err + return math.Int{}, err } return distributionCoin.Amount, nil } // 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) { +func (k Keeper) distributeToModule(ctx sdk.Context, recipientModule string, mintedCoin sdk.Coin, proportion sdk.Dec) (math.Int, error) { distributionCoin, err := getProportions(mintedCoin, proportion) if err != nil { - return sdk.Int{}, err + return math.Int{}, err } if err := k.bankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, recipientModule, sdk.NewCoins(distributionCoin)); err != nil { - return sdk.Int{}, err + return math.Int{}, err } return distributionCoin.Amount, nil } -func (k Keeper) distributeDeveloperRewards(ctx sdk.Context, totalMintedCoin sdk.Coin, developerRewardsProportion sdk.Dec, developerRewardsReceivers []types.MonthlyVestingAddress) (sdk.Int, error) { +func (k Keeper) distributeDeveloperRewards(ctx sdk.Context, totalMintedCoin sdk.Coin, developerRewardsProportion sdk.Dec, developerRewardsReceivers []types.MonthlyVestingAddress) (math.Int, error) { params := k.GetParams(ctx) totalDevRewards, err := getProportions(totalMintedCoin, developerRewardsProportion) if err != nil { - return sdk.Int{}, err + return math.Int{}, err } vestedAmount := sdk.ZeroInt() @@ -112,11 +113,11 @@ func (k Keeper) distributeDeveloperRewards(ctx sdk.Context, totalMintedCoin sdk. if w.Address != emptyAddressReceiver { devRewardsAddr, err := sdk.AccAddressFromBech32(w.Address) if err != nil { - return sdk.Int{}, err + return math.Int{}, err } err = k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, devRewardsAddr, devRewardPortionCoins) if err != nil { - return sdk.Int{}, err + return math.Int{}, err } vestedAmount = vestedAmount.Add(devPortionAmount) @@ -134,7 +135,7 @@ func (k Keeper) distributeDeveloperRewards(ctx sdk.Context, totalMintedCoin sdk. err = k.bankKeeper.SendCoinsFromModuleToAccount( ctx, types.ModuleName, reserve, sdk.Coins{remainingCoins}) if err != nil { - return sdk.Int{}, err + return math.Int{}, err } } diff --git a/x/mint/keeper/distribute_test.go b/x/mint/keeper/distribute_test.go index 4f4235c..4d6e30b 100644 --- a/x/mint/keeper/distribute_test.go +++ b/x/mint/keeper/distribute_test.go @@ -1,6 +1,7 @@ package keeper_test import ( + "cosmossdk.io/math" "github.com/TERITORI/teritori-chain/x/mint/types" "github.com/cometbft/cometbft/crypto/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" @@ -28,17 +29,19 @@ func (suite *KeeperTestSuite) TestDistributeMintedCoin() { WeightedDeveloperRewardsReceivers: []types.MonthlyVestingAddress{ { Address: dev1Addr.String(), - MonthlyAmounts: []sdk.Int{sdk.NewInt(7000000), sdk.NewInt(7000000), sdk.NewInt(7000000)}, + MonthlyAmounts: []math.Int{sdk.NewInt(7000000), sdk.NewInt(7000000), sdk.NewInt(7000000)}, }, { Address: dev2Addr.String(), - MonthlyAmounts: []sdk.Int{sdk.NewInt(3000000), sdk.NewInt(3000000), sdk.NewInt(3000000)}, + MonthlyAmounts: []math.Int{sdk.NewInt(3000000), sdk.NewInt(3000000), sdk.NewInt(3000000)}, }, }, UsageIncentiveAddress: usageIncentiveAddr.String(), GrantsProgramAddress: grantsAddr.String(), TeamReserveAddress: teamReserveAddr.String(), MintingRewardsDistributionStartBlock: 1, + BlocksPerYear: 5733818, + TotalBurntAmount: sdk.Coins{}, } tests := []struct { diff --git a/x/mint/keeper/keeper.go b/x/mint/keeper/keeper.go index dbcd966..da4610a 100644 --- a/x/mint/keeper/keeper.go +++ b/x/mint/keeper/keeper.go @@ -3,6 +3,7 @@ package keeper import ( "fmt" + "cosmossdk.io/math" "github.com/cometbft/cometbft/libs/log" "github.com/TERITORI/teritori-chain/x/mint/types" @@ -35,8 +36,8 @@ func (e invalidRatioError) Error() string { } type insufficientDevVestingBalanceError struct { - ActualBalance sdk.Int - AttemptedDistribution sdk.Int + ActualBalance math.Int + AttemptedDistribution math.Int } func (e insufficientDevVestingBalanceError) Error() string { diff --git a/x/mint/keeper/params_test.go b/x/mint/keeper/params_test.go index 08b0a19..021d6b1 100644 --- a/x/mint/keeper/params_test.go +++ b/x/mint/keeper/params_test.go @@ -1,6 +1,7 @@ package keeper_test import ( + "cosmossdk.io/math" "github.com/TERITORI/teritori-chain/x/mint/types" "github.com/cometbft/cometbft/crypto/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" @@ -25,13 +26,15 @@ func (suite *KeeperTestSuite) TestParamsGetSet() { WeightedDeveloperRewardsReceivers: []types.MonthlyVestingAddress{ { Address: "", - MonthlyAmounts: []sdk.Int{sdk.NewInt(7000), sdk.NewInt(7000), sdk.NewInt(7000)}, + MonthlyAmounts: []math.Int{sdk.NewInt(7000), sdk.NewInt(7000), sdk.NewInt(7000)}, }, }, UsageIncentiveAddress: addr.String(), GrantsProgramAddress: addr.String(), TeamReserveAddress: addr.String(), MintingRewardsDistributionStartBlock: 1, + BlocksPerYear: 5733818, + TotalBurntAmount: sdk.Coins(nil), } suite.app.MintKeeper.SetParams(suite.ctx, params) diff --git a/x/mint/simulation/genesis.go b/x/mint/simulation/genesis.go index 2090072..16b00ce 100644 --- a/x/mint/simulation/genesis.go +++ b/x/mint/simulation/genesis.go @@ -5,6 +5,7 @@ package simulation import ( "math/rand" + "cosmossdk.io/math" "github.com/TERITORI/teritori-chain/x/mint/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -33,15 +34,15 @@ var ( weightedDevRewardReceivers = []types.MonthlyVestingAddress{ { Address: "tori1g2escsu26508tgrpv865d80d62pvmw69je2ztn", - MonthlyAmounts: []sdk.Int{sdk.NewInt(7000), sdk.NewInt(7000), sdk.NewInt(7000)}, + MonthlyAmounts: []math.Int{sdk.NewInt(7000), sdk.NewInt(7000), sdk.NewInt(7000)}, }, { Address: "tori1g2escsu26508tgrpv865d80d62pvmw69je2ztn", - MonthlyAmounts: []sdk.Int{sdk.NewInt(2000), sdk.NewInt(2000), sdk.NewInt(2000)}, + MonthlyAmounts: []math.Int{sdk.NewInt(2000), sdk.NewInt(2000), sdk.NewInt(2000)}, }, { Address: "tori1g2escsu26508tgrpv865d80d62pvmw69je2ztn", - MonthlyAmounts: []sdk.Int{sdk.NewInt(1000), sdk.NewInt(1000), sdk.NewInt(1000)}, + MonthlyAmounts: []math.Int{sdk.NewInt(1000), sdk.NewInt(1000), sdk.NewInt(1000)}, }, } ) diff --git a/x/mint/types/params.go b/x/mint/types/params.go index b483717..911289a 100644 --- a/x/mint/types/params.go +++ b/x/mint/types/params.go @@ -6,6 +6,7 @@ import ( "fmt" "strings" + "cosmossdk.io/math" yaml "gopkg.in/yaml.v2" sdk "github.com/cosmos/cosmos-sdk/types" @@ -102,7 +103,7 @@ func parseMonthlyVesting() []MonthlyVestingAddress { for _, addr := range records[0] { vAddrs = append(vAddrs, MonthlyVestingAddress{ Address: addressMap[addr], - MonthlyAmounts: []sdk.Int{}, + MonthlyAmounts: []math.Int{}, }) }