Skip to content

Commit

Permalink
resolve unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
go7066 committed Jan 11, 2024
1 parent 182d8d7 commit 959eaad
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 29 deletions.
3 changes: 2 additions & 1 deletion app/ante_handler.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions cmd/teritorid/cmd/richest_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
11 changes: 7 additions & 4 deletions x/mint/keeper/abci_test.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
25 changes: 13 additions & 12 deletions x/mint/keeper/distribute.go
Original file line number Diff line number Diff line change
@@ -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"
)
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -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
}
}

Expand Down
7 changes: 5 additions & 2 deletions x/mint/keeper/distribute_test.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions x/mint/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion x/mint/keeper/params_test.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions x/mint/simulation/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)},
},
}
)
Expand Down
3 changes: 2 additions & 1 deletion x/mint/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"strings"

"cosmossdk.io/math"
yaml "gopkg.in/yaml.v2"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -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{},
})
}

Expand Down

0 comments on commit 959eaad

Please sign in to comment.