Skip to content

Commit

Permalink
fix: replace depricated math types
Browse files Browse the repository at this point in the history
  • Loading branch information
ivivanov authored and Lockwarr committed Dec 22, 2023
1 parent a7cdef1 commit 48d38da
Show file tree
Hide file tree
Showing 22 changed files with 233 additions and 213 deletions.
10 changes: 7 additions & 3 deletions app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ import (
"path/filepath"
"testing"

simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
simcli "github.com/cosmos/cosmos-sdk/x/simulation/client/cli"
sdkmath "cosmossdk.io/math"

"github.com/stretchr/testify/require"

tmdb "github.com/cometbft/cometbft-db"
"github.com/cometbft/cometbft/libs/log"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/store"
"github.com/cosmos/cosmos-sdk/store/prefix"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/kv"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
Expand All @@ -33,8 +35,10 @@ import (
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/cosmos/cosmos-sdk/x/simulation"
simcli "github.com/cosmos/cosmos-sdk/x/simulation/client/cli"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types"
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
Expand Down Expand Up @@ -78,7 +82,7 @@ func appParamsConfigurationSim(t *testing.T, config *simtypes.Config) {
}

reflectContractPath := filepath.Join(pkg.Dir, "testdata/reflect_1_1.wasm")
minDepositBytes, err := json.Marshal(sdk.NewCoins((sdk.NewCoin("nolus", sdk.NewInt(500000)))))
minDepositBytes, err := json.Marshal(sdk.NewCoins((sdk.NewCoin("nolus", sdkmath.NewInt(500000)))))
if err != nil {
t.Fatal("Marshaling of sdk coins to be used for min deposit param in gov module failed")
}
Expand Down
5 changes: 4 additions & 1 deletion app/upgrades/v03/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import (
"github.com/Nolus-Protocol/nolus-core/app/keepers"
"github.com/Nolus-Protocol/nolus-core/app/params"

sdkmath "cosmossdk.io/math"

"github.com/cosmos/cosmos-sdk/codec"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
Expand All @@ -23,7 +26,7 @@ func CreateUpgradeHandler(
ctx.Logger().Info("Running migrations")
interchainQueriesParams := icqtypes.Params{
QuerySubmitTimeout: uint64(1036800),
QueryDeposit: sdk.NewCoins(sdk.NewCoin(params.BaseCoinUnit, sdk.NewInt(1000000))),
QueryDeposit: sdk.NewCoins(sdk.NewCoin(params.BaseCoinUnit, sdkmath.NewInt(1000000))),
TxQueryRemovalLimit: uint64(10000),
}
err := keepers.InterchainQueriesKeeper.SetParams(ctx, interchainQueriesParams)
Expand Down
35 changes: 19 additions & 16 deletions testutil/simapp/simapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,33 @@ import (
"testing"
"time"

"github.com/cometbft/cometbft/libs/json"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/testutil/mock"
"github.com/cosmos/cosmos-sdk/testutil/network"
"github.com/cosmos/cosmos-sdk/testutil/sims"
sdkmath "cosmossdk.io/math"

"github.com/stretchr/testify/require"

"github.com/Nolus-Protocol/nolus-core/app"
tmdb "github.com/cometbft/cometbft-db"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/libs/json"
"github.com/cometbft/cometbft/libs/log"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
cometbfttypes "github.com/cometbft/cometbft/types"
tmtypes "github.com/cometbft/cometbft/types"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
pruningtypes "github.com/cosmos/cosmos-sdk/store/pruning/types"
"github.com/cosmos/cosmos-sdk/testutil/mock"
"github.com/cosmos/cosmos-sdk/testutil/network"
"github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/stretchr/testify/require"

cometbfttypes "github.com/cometbft/cometbft/types"
pruningtypes "github.com/cosmos/cosmos-sdk/store/pruning/types"
"github.com/Nolus-Protocol/nolus-core/app"
)

// New creates application instance with in-memory database and disabled logging.
Expand Down Expand Up @@ -57,7 +60,7 @@ func New(t *testing.T, dir string, withDefaultGenesisState bool) *app.App {
acc := authtypes.NewBaseAccount(senderPubKey.Address().Bytes(), senderPubKey, 0, 0)
balance := banktypes.Balance{
Address: acc.GetAddress().String(),
Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100000000000000))),
Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(100000000000000))),
}

genState := NewDefaultGenesisState(encoding.Marshaler)
Expand Down Expand Up @@ -135,15 +138,15 @@ func genesisStateWithValSet(t *testing.T,
Jailed: false,
Status: stakingtypes.Bonded,
Tokens: bondAmt,
DelegatorShares: sdk.OneDec(),
DelegatorShares: sdkmath.LegacyOneDec(),
Description: stakingtypes.Description{},
UnbondingHeight: int64(0),
UnbondingTime: time.Unix(0, 0).UTC(),
Commission: stakingtypes.NewCommission(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()),
MinSelfDelegation: sdk.ZeroInt(),
Commission: stakingtypes.NewCommission(sdkmath.LegacyZeroDec(), sdkmath.LegacyZeroDec(), sdkmath.LegacyZeroDec()),
MinSelfDelegation: sdkmath.ZeroInt(),
}
validators = append(validators, validator)
delegations = append(delegations, stakingtypes.NewDelegation(genAccs[0].GetAddress(), val.Address.Bytes(), sdk.OneDec()))
delegations = append(delegations, stakingtypes.NewDelegation(genAccs[0].GetAddress(), val.Address.Bytes(), sdkmath.LegacyOneDec()))

}
// set validators and delegations
Expand Down
22 changes: 12 additions & 10 deletions wasmbinding/test/custom_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import (
"encoding/json"
"testing"

"github.com/CosmWasm/wasmd/x/wasm/keeper"
"github.com/CosmWasm/wasmvm/types"
host "github.com/cosmos/ibc-go/v7/modules/core/24-host"
ibchost "github.com/cosmos/ibc-go/v7/modules/core/exported"
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/stretchr/testify/suite"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/CosmWasm/wasmd/x/wasm/keeper"
"github.com/CosmWasm/wasmvm/types"

"github.com/Nolus-Protocol/nolus-core/wasmbinding/bindings"
host "github.com/cosmos/ibc-go/v7/modules/core/24-host"
ibchost "github.com/cosmos/ibc-go/v7/modules/core/exported"

"github.com/neutron-org/neutron/app"
"github.com/neutron-org/neutron/app/params"
Expand All @@ -24,6 +24,8 @@ import (
icqtypes "github.com/neutron-org/neutron/x/interchainqueries/types"
ictxkeeper "github.com/neutron-org/neutron/x/interchaintxs/keeper"
ictxtypes "github.com/neutron-org/neutron/x/interchaintxs/types"

"github.com/Nolus-Protocol/nolus-core/wasmbinding/bindings"
)

type CustomMessengerTestSuite struct {
Expand Down Expand Up @@ -105,7 +107,7 @@ func (suite *CustomMessengerTestSuite) TestRegisterInterchainQuery() {

// Top up contract balance
senderAddress := suite.ChainA.SenderAccounts[0].SenderAccount.GetAddress()
coinsAmnt := sdk.NewCoins(sdk.NewCoin(params.DefaultDenom, sdk.NewInt(int64(10_000_000))))
coinsAmnt := sdk.NewCoins(sdk.NewCoin(params.DefaultDenom, sdkmath.NewInt(int64(10_000_000))))
bankKeeper := suite.neutron.BankKeeper
err = bankKeeper.SendCoins(suite.ctx, senderAddress, suite.contractAddress, coinsAmnt)
suite.NoError(err)
Expand Down Expand Up @@ -229,7 +231,7 @@ func (suite *CustomMessengerTestSuite) TestSubmitTx() {
suite.Require().NotEmpty(suite.contractAddress)

senderAddress := suite.ChainA.SenderAccounts[0].SenderAccount.GetAddress()
coinsAmnt := sdk.NewCoins(sdk.NewCoin(params.DefaultDenom, sdk.NewInt(int64(10_000_000))))
coinsAmnt := sdk.NewCoins(sdk.NewCoin(params.DefaultDenom, sdkmath.NewInt(int64(10_000_000))))
bankKeeper := suite.neutron.BankKeeper
err := bankKeeper.SendCoins(suite.ctx, senderAddress, suite.contractAddress, coinsAmnt)
suite.NoError(err)
Expand Down Expand Up @@ -295,8 +297,8 @@ func (suite *CustomMessengerTestSuite) craftMarshaledMsgSubmitTxWithNumMsgs(numM
Timeout: 2000,
Fee: feetypes.Fee{
RecvFee: sdk.NewCoins(),
AckFee: sdk.NewCoins(sdk.NewCoin(params.DefaultDenom, sdk.NewInt(1000))),
TimeoutFee: sdk.NewCoins(sdk.NewCoin(params.DefaultDenom, sdk.NewInt(1000))),
AckFee: sdk.NewCoins(sdk.NewCoin(params.DefaultDenom, sdkmath.NewInt(1000))),
TimeoutFee: sdk.NewCoins(sdk.NewCoin(params.DefaultDenom, sdkmath.NewInt(1000))),
},
},
})
Expand Down
18 changes: 10 additions & 8 deletions x/mint/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ import (
"time"

sdkmath "cosmossdk.io/math"
"github.com/Nolus-Protocol/nolus-core/x/mint/keeper"
"github.com/Nolus-Protocol/nolus-core/x/mint/types"

"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/Nolus-Protocol/nolus-core/x/mint/keeper"
"github.com/Nolus-Protocol/nolus-core/x/mint/types"
)

var (
normInitialTotal = types.CalcTokensByIntegral(types.NormOffset)
nanoSecondsInMonth = sdk.NewDec(time.Hour.Nanoseconds() * 24 * 30)
nanoSecondsInMonth = sdkmath.LegacyNewDec(time.Hour.Nanoseconds() * 24 * 30)
nanoSecondsInFormula = types.MonthsInFormula.Mul(nanoSecondsInMonth)
twelveMonths = sdk.MustNewDecFromStr("12.0")
twelveMonths = sdkmath.LegacyMustNewDecFromStr("12.0")

errTimeInFutureBeforeTimePassed = errors.New("time in future can not be before passed time")
errNegativeBlockTime = errors.New("block time can not be less then zero")
Expand Down Expand Up @@ -68,7 +70,7 @@ func calcTokens(blockTime sdkmath.Uint, minter *types.Minter, maxMintableSeconds
} else {
// After reaching 96 normalized time, mint fixed amount of tokens per month until we reach the minting cap
normIncrement := calcFixedIncrement(nsecPassed)
delta := sdk.NewUint((normIncrement.Mul(types.DecFromUint(types.FixedMintedAmount))).TruncateInt().Uint64())
delta := sdkmath.NewUint((normIncrement.Mul(types.DecFromUint(types.FixedMintedAmount))).TruncateInt().Uint64())

if minter.TotalMinted.Add(delta).GT(types.MintingCap) {
// Trim off excess tokens if the cap is reached
Expand Down Expand Up @@ -124,7 +126,7 @@ func predictMintedByFixedAmount(totalMinted sdkmath.Uint, normTimePassed, timeAh
}

normFixedPeriod := normTimeInFuture.Sub(calcFunctionIncrement(sdkmath.Uint(nanoSecondsInFormula.TruncateInt())))
if normFixedPeriod.LTE(sdk.ZeroDec()) {
if normFixedPeriod.LTE(sdkmath.LegacyZeroDec()) {
return sdkmath.ZeroUint(), nil
}

Expand Down Expand Up @@ -172,14 +174,14 @@ func BeginBlocker(ctx sdk.Context, k keeper.Keeper) {
panic(errNegativeBlockTime)
}

coinAmount := calcTokens(sdk.NewUint(uint64(blockTime)), &minter, params.MaxMintableNanoseconds)
coinAmount := calcTokens(sdkmath.NewUint(uint64(blockTime)), &minter, params.MaxMintableNanoseconds)
minter.AnnualInflation = predictTotalMinted(minter.TotalMinted, minter.NormTimePassed, twelveMonths)
ctx.Logger().Debug(fmt.Sprintf("miner: %v total, %v norm time, %v minted", minter.TotalMinted.String(), minter.NormTimePassed.String(), coinAmount.String()))
k.SetMinter(ctx, minter)

if coinAmount.GT(sdkmath.ZeroUint()) {
// mint coins, update supply
mintedCoins := sdk.NewCoins(sdk.NewCoin(params.MintDenom, sdk.NewIntFromBigInt(coinAmount.BigInt())))
mintedCoins := sdk.NewCoins(sdk.NewCoin(params.MintDenom, sdkmath.NewIntFromBigInt(coinAmount.BigInt())))

err := k.MintCoins(ctx, mintedCoins)
if err != nil {
Expand Down
Loading

0 comments on commit 48d38da

Please sign in to comment.