chore: use sdkmath in misc packages (#14606)

Co-authored-by: atheeshp <59333759+atheeshp@users.noreply.github.com>
Co-authored-by: Marko <marbar3778@yahoo.com>
This commit is contained in:
Aleksandr Bezobchuk
2023-01-16 12:48:32 +00:00
committed by GitHub
co-authored by atheeshp Marko
parent ae1c29b8f8
commit f2b6013cee
12 changed files with 67 additions and 64 deletions
+12 -13
View File
@@ -15,19 +15,16 @@ import (
"testing"
"time"
"cosmossdk.io/depinject"
sdkmath "cosmossdk.io/math"
dbm "github.com/cosmos/cosmos-db"
"github.com/spf13/cobra"
tmlog "github.com/tendermint/tendermint/libs/log"
tmrand "github.com/tendermint/tendermint/libs/rand"
"github.com/tendermint/tendermint/node"
tmclient "github.com/tendermint/tendermint/rpc/client"
"google.golang.org/grpc"
"cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/testutil/configurator"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
tmlog "github.com/tendermint/tendermint/libs/log"
"cosmossdk.io/depinject"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/tx"
@@ -43,6 +40,8 @@ import (
servertypes "github.com/cosmos/cosmos-sdk/server/types"
pruningtypes "github.com/cosmos/cosmos-sdk/store/pruning/types"
"github.com/cosmos/cosmos-sdk/testutil"
"github.com/cosmos/cosmos-sdk/testutil/configurator"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
_ "github.com/cosmos/cosmos-sdk/x/auth" // import auth as a blank
@@ -90,9 +89,9 @@ type Config struct {
Mnemonics []string // custom user-provided validator operator mnemonics
BondDenom string // the staking bond denomination
MinGasPrices string // the minimum gas prices each validator will accept
AccountTokens math.Int // the amount of unique validator tokens (e.g. 1000node0)
StakingTokens math.Int // the amount of tokens each validator has available to stake
BondedTokens math.Int // the amount of tokens each validator stakes
AccountTokens sdkmath.Int // the amount of unique validator tokens (e.g. 1000node0)
StakingTokens sdkmath.Int // the amount of tokens each validator has available to stake
BondedTokens sdkmath.Int // the amount of tokens each validator stakes
PruningStrategy string // the pruning strategy each validator will have
EnableTMLogging bool // enable Tendermint logging to STDOUT
CleanupDir bool // remove base temporary directory during cleanup
@@ -481,7 +480,7 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {
genBalances = append(genBalances, banktypes.Balance{Address: addr.String(), Coins: balances.Sort()})
genAccounts = append(genAccounts, authtypes.NewBaseAccount(addr, nil, 0, 0))
commission, err := sdk.NewDecFromStr("0.5")
commission, err := sdkmath.LegacyNewDecFromStr("0.5")
if err != nil {
return nil, err
}
@@ -491,8 +490,8 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {
valPubKeys[i],
sdk.NewCoin(cfg.BondDenom, cfg.BondedTokens),
stakingtypes.NewDescription(nodeDirName, "", "", "", ""),
stakingtypes.NewCommissionRates(commission, math.LegacyOneDec(), math.LegacyOneDec()),
math.OneInt(),
stakingtypes.NewCommissionRates(commission, sdkmath.LegacyOneDec(), sdkmath.LegacyOneDec()),
sdkmath.OneInt(),
)
if err != nil {
return nil, err
@@ -504,7 +503,7 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {
}
memo := fmt.Sprintf("%s@%s:%s", nodeIDs[i], p2pURL.Hostname(), p2pURL.Port())
fee := sdk.NewCoins(sdk.NewCoin(fmt.Sprintf("%stoken", nodeDirName), sdk.NewInt(0)))
fee := sdk.NewCoins(sdk.NewCoin(fmt.Sprintf("%stoken", nodeDirName), sdkmath.NewInt(0)))
txBuilder := cfg.TxConfig.NewTxBuilder()
err = txBuilder.SetMsgs(createValMsg)
if err != nil {
+7 -8
View File
@@ -5,6 +5,8 @@ import (
"fmt"
"time"
"cosmossdk.io/depinject"
sdkmath "cosmossdk.io/math"
dbm "github.com/cosmos/cosmos-db"
abci "github.com/tendermint/tendermint/abci/types"
tmjson "github.com/tendermint/tendermint/libs/json"
@@ -12,9 +14,6 @@ import (
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmtypes "github.com/tendermint/tendermint/types"
"cosmossdk.io/depinject"
"cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
@@ -84,7 +83,7 @@ type StartupConfig struct {
func DefaultStartUpConfig() StartupConfig {
priv := secp256k1.GenPrivKey()
ba := authtypes.NewBaseAccount(priv.PubKey().Address().Bytes(), priv.PubKey(), 0, 0)
ga := GenesisAccount{ba, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100000000000000)))}
ga := GenesisAccount{ba, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(100000000000000)))}
return StartupConfig{
ValidatorSet: CreateRandomValidatorSet,
AtGenesis: false,
@@ -216,15 +215,15 @@ func GenesisStateWithValSet(
Jailed: false,
Status: stakingtypes.Bonded,
Tokens: bondAmt,
DelegatorShares: math.LegacyOneDec(),
DelegatorShares: sdkmath.LegacyOneDec(),
Description: stakingtypes.Description{},
UnbondingHeight: int64(0),
UnbondingTime: time.Unix(0, 0).UTC(),
Commission: stakingtypes.NewCommission(math.LegacyZeroDec(), math.LegacyZeroDec(), math.LegacyZeroDec()),
MinSelfDelegation: math.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(), math.LegacyOneDec()))
delegations = append(delegations, stakingtypes.NewDelegation(genAccs[0].GetAddress(), val.Address.Bytes(), sdkmath.LegacyOneDec()))
}