chore: use math.Int instead of math.Int and apply linting (#12702)
* linting round * fix changelog * revert docs changes * Update CHANGELOG.md * revert an accidental change to security.md * Update simapp/integration/client/grpc/tmservice/service_test.go Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
parent
e7bd66841d
commit
5decd22cd3
@ -6,7 +6,6 @@ run:
|
||||
linters:
|
||||
disable-all: true
|
||||
enable:
|
||||
- bodyclose
|
||||
- deadcode
|
||||
- depguard
|
||||
- dogsled
|
||||
@ -23,11 +22,9 @@ linters:
|
||||
- nakedret
|
||||
- nolintlint
|
||||
- staticcheck
|
||||
- structcheck
|
||||
- stylecheck
|
||||
- typecheck
|
||||
- unconvert
|
||||
- unparam
|
||||
- unused
|
||||
|
||||
issues:
|
||||
|
||||
@ -47,6 +47,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
|
||||
### Improvements
|
||||
|
||||
* [#12702](https://github.com/cosmos/cosmos-sdk/pull/12702) Linting and tidiness, fixed two minor security warnings.
|
||||
* [#12668](https://github.com/cosmos/cosmos-sdk/pull/12668) Add `authz_msg_index` event attribute to message events emitted when executing via `MsgExec` through `x/authz`.
|
||||
* [#12634](https://github.com/cosmos/cosmos-sdk/pull/12634) Move `sdk.Dec` to math package.
|
||||
* [#12596](https://github.com/cosmos/cosmos-sdk/pull/12596) Remove all imports of the non-existent gogo/protobuf v1.3.3 to ease downstream use and go workspaces.
|
||||
|
||||
@ -25,8 +25,9 @@ func StartGRPCWeb(grpcSrv *grpc.Server, config config.Config) (*http.Server, err
|
||||
|
||||
wrappedServer := grpcweb.WrapServer(grpcSrv, options...)
|
||||
grpcWebSrv := &http.Server{
|
||||
Addr: config.GRPCWeb.Address,
|
||||
Handler: wrappedServer,
|
||||
Addr: config.GRPCWeb.Address,
|
||||
Handler: wrappedServer,
|
||||
ReadHeaderTimeout: 500000000, // added because G112: Potential Slowloris Attack because ReadHeaderTimeout is not configured in the http.Server
|
||||
}
|
||||
|
||||
errCh := make(chan error)
|
||||
|
||||
@ -27,7 +27,6 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
pruningtypes "github.com/cosmos/cosmos-sdk/pruning/types"
|
||||
"github.com/cosmos/cosmos-sdk/server/api"
|
||||
"github.com/cosmos/cosmos-sdk/server/config"
|
||||
serverconfig "github.com/cosmos/cosmos-sdk/server/config"
|
||||
servergrpc "github.com/cosmos/cosmos-sdk/server/grpc"
|
||||
"github.com/cosmos/cosmos-sdk/server/rosetta"
|
||||
@ -502,7 +501,7 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App
|
||||
return WaitForQuitSignals()
|
||||
}
|
||||
|
||||
func startTelemetry(cfg config.Config) (*telemetry.Metrics, error) {
|
||||
func startTelemetry(cfg serverconfig.Config) (*telemetry.Metrics, error) {
|
||||
if !cfg.Telemetry.Enabled {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@ -31,7 +31,6 @@ type IntegrationTestSuite struct {
|
||||
}
|
||||
|
||||
func TestIntegrationTestSuite(t *testing.T) {
|
||||
//t.Skip() // to be re-enabled in https://github.com/cosmos/cosmos-sdk/pull/12482/
|
||||
|
||||
suite.Run(t, new(IntegrationTestSuite))
|
||||
}
|
||||
|
||||
@ -11,6 +11,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
"github.com/spf13/cobra"
|
||||
tmconfig "github.com/tendermint/tendermint/config"
|
||||
tmos "github.com/tendermint/tendermint/libs/os"
|
||||
@ -297,7 +298,7 @@ func initTestnetFiles(
|
||||
sdk.NewCoin(sdk.DefaultBondDenom, valTokens),
|
||||
stakingtypes.NewDescription(nodeDirName, "", "", "", ""),
|
||||
stakingtypes.NewCommissionRates(sdk.OneDec(), sdk.OneDec(), sdk.OneDec()),
|
||||
sdk.OneInt(),
|
||||
math.OneInt(),
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@ -11,7 +11,7 @@ import (
|
||||
tmjson "github.com/tendermint/tendermint/libs/json"
|
||||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
"cosmossdk.io/math"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||
simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
|
||||
@ -88,7 +88,7 @@ func AppStateFn(cdc codec.JSONCodec, simManager *module.SimulationManager) simty
|
||||
panic(err)
|
||||
}
|
||||
// compute not bonded balance
|
||||
notBondedTokens := sdk.ZeroInt()
|
||||
notBondedTokens := math.ZeroInt()
|
||||
for _, val := range stakingState.Validators {
|
||||
if val.Status != stakingtypes.Unbonded {
|
||||
continue
|
||||
@ -149,11 +149,11 @@ func AppStateRandomizedFn(
|
||||
// number of bonded accounts
|
||||
var (
|
||||
numInitiallyBonded int64
|
||||
initialStake sdkmath.Int
|
||||
initialStake math.Int
|
||||
)
|
||||
appParams.GetOrGenerate(
|
||||
cdc, simappparams.StakePerAccount, &initialStake, r,
|
||||
func(r *rand.Rand) { initialStake = sdkmath.NewInt(r.Int63n(1e12)) },
|
||||
func(r *rand.Rand) { initialStake = math.NewInt(r.Int63n(1e12)) },
|
||||
)
|
||||
appParams.GetOrGenerate(
|
||||
cdc, simappparams.InitiallyBondedValidators, &numInitiallyBonded, r,
|
||||
|
||||
@ -25,7 +25,6 @@ import (
|
||||
pruningtypes "github.com/cosmos/cosmos-sdk/pruning/types"
|
||||
"github.com/cosmos/cosmos-sdk/server"
|
||||
"github.com/cosmos/cosmos-sdk/server/types"
|
||||
servertypes "github.com/cosmos/cosmos-sdk/server/types"
|
||||
simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/mock"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/network"
|
||||
@ -366,7 +365,7 @@ func NewTestNetworkFixture() network.TestFixture {
|
||||
Amino: encodingCfg.Amino,
|
||||
InterfaceRegistry: encodingCfg.InterfaceRegistry,
|
||||
}
|
||||
appCtr := func(val testutil.Validator) servertypes.Application {
|
||||
appCtr := func(val testutil.Validator) types.Application {
|
||||
return NewSimApp(
|
||||
val.GetCtx().Logger, dbm.NewMemDB(), nil, true,
|
||||
encodingCfg,
|
||||
|
||||
@ -417,6 +417,7 @@ var _ types.Iterator = (*iavlIterator)(nil)
|
||||
// newIAVLIterator will create a new iavlIterator.
|
||||
// CONTRACT: Caller must release the iavlIterator, as each one creates a new
|
||||
// goroutine.
|
||||
//nolint:deadcode,unused
|
||||
func newIAVLIterator(tree *iavl.ImmutableTree, start, end []byte, ascending bool) *iavlIterator {
|
||||
iterator, err := tree.Iterator(start, end, ascending)
|
||||
if err != nil {
|
||||
|
||||
@ -484,7 +484,7 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {
|
||||
sdk.NewCoin(cfg.BondDenom, cfg.BondedTokens),
|
||||
stakingtypes.NewDescription(nodeDirName, "", "", "", ""),
|
||||
stakingtypes.NewCommissionRates(commission, sdk.OneDec(), sdk.OneDec()),
|
||||
sdk.OneInt(),
|
||||
math.OneInt(),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@ -14,6 +14,7 @@ import (
|
||||
dbm "github.com/tendermint/tm-db"
|
||||
|
||||
"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"
|
||||
@ -199,7 +200,7 @@ func GenesisStateWithValSet(codec codec.Codec, genesisState map[string]json.RawM
|
||||
UnbondingHeight: int64(0),
|
||||
UnbondingTime: time.Unix(0, 0).UTC(),
|
||||
Commission: stakingtypes.NewCommission(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()),
|
||||
MinSelfDelegation: sdk.ZeroInt(),
|
||||
MinSelfDelegation: math.ZeroInt(),
|
||||
}
|
||||
validators = append(validators, validator)
|
||||
delegations = append(delegations, stakingtypes.NewDelegation(genAccs[0].GetAddress(), val.Address.Bytes(), sdk.OneDec()))
|
||||
|
||||
@ -5,6 +5,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
@ -27,7 +28,7 @@ func TestCoinTestSuite(t *testing.T) {
|
||||
|
||||
func (s *coinTestSuite) SetupSuite() {
|
||||
zero := sdk.NewInt(0)
|
||||
one := sdk.OneInt()
|
||||
one := math.OneInt()
|
||||
two := sdk.NewInt(2)
|
||||
four := sdk.NewInt(4)
|
||||
|
||||
@ -90,15 +91,15 @@ func (s *coinTestSuite) TestCoinIsValid() {
|
||||
}{
|
||||
{sdk.Coin{testDenom1, sdk.NewInt(-1)}, false},
|
||||
{sdk.Coin{testDenom1, sdk.NewInt(0)}, true},
|
||||
{sdk.Coin{testDenom1, sdk.OneInt()}, true},
|
||||
{sdk.Coin{"Atom", sdk.OneInt()}, true},
|
||||
{sdk.Coin{"ATOM", sdk.OneInt()}, true},
|
||||
{sdk.Coin{"a", sdk.OneInt()}, false},
|
||||
{sdk.Coin{loremIpsum, sdk.OneInt()}, false},
|
||||
{sdk.Coin{"ibc/7F1D3FCF4AE79E1554D670D1AD949A9BA4E4A3C76C63093E17E446A46061A7A2", sdk.OneInt()}, true},
|
||||
{sdk.Coin{"atOm", sdk.OneInt()}, true},
|
||||
{sdk.Coin{"x:y-z.1_2", sdk.OneInt()}, true},
|
||||
{sdk.Coin{" ", sdk.OneInt()}, false},
|
||||
{sdk.Coin{testDenom1, math.OneInt()}, true},
|
||||
{sdk.Coin{"Atom", math.OneInt()}, true},
|
||||
{sdk.Coin{"ATOM", math.OneInt()}, true},
|
||||
{sdk.Coin{"a", math.OneInt()}, false},
|
||||
{sdk.Coin{loremIpsum, math.OneInt()}, false},
|
||||
{sdk.Coin{"ibc/7F1D3FCF4AE79E1554D670D1AD949A9BA4E4A3C76C63093E17E446A46061A7A2", math.OneInt()}, true},
|
||||
{sdk.Coin{"atOm", math.OneInt()}, true},
|
||||
{sdk.Coin{"x:y-z.1_2", math.OneInt()}, true},
|
||||
{sdk.Coin{" ", math.OneInt()}, false},
|
||||
}
|
||||
|
||||
for i, tc := range cases {
|
||||
@ -130,7 +131,6 @@ func (s *coinTestSuite) TestCustomValidation() {
|
||||
}
|
||||
|
||||
func (s *coinTestSuite) TestCoinsDenoms() {
|
||||
|
||||
cases := []struct {
|
||||
coins sdk.Coins
|
||||
testOutput []string
|
||||
@ -155,7 +155,6 @@ func (s *coinTestSuite) TestCoinsDenoms() {
|
||||
}
|
||||
s.Require().Equal(count == 0, tc.expectPass, "unexpected result for coins.Denoms, tc #%d", i)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *coinTestSuite) TestAddCoin() {
|
||||
@ -184,7 +183,7 @@ func (s *coinTestSuite) TestAddCoin() {
|
||||
func (s *coinTestSuite) TestAddCoinAmount() {
|
||||
cases := []struct {
|
||||
coin sdk.Coin
|
||||
amount sdk.Int
|
||||
amount math.Int
|
||||
expected sdk.Coin
|
||||
}{
|
||||
{sdk.NewInt64Coin(testDenom1, 1), sdk.NewInt(1), sdk.NewInt64Coin(testDenom1, 2)},
|
||||
@ -232,7 +231,7 @@ func (s *coinTestSuite) TestSubCoin() {
|
||||
func (s *coinTestSuite) TestSubCoinAmount() {
|
||||
cases := []struct {
|
||||
coin sdk.Coin
|
||||
amount sdk.Int
|
||||
amount math.Int
|
||||
expected sdk.Coin
|
||||
shouldPanic bool
|
||||
}{
|
||||
@ -256,7 +255,7 @@ func (s *coinTestSuite) TestSubCoinAmount() {
|
||||
func (s *coinTestSuite) TestMulIntCoins() {
|
||||
testCases := []struct {
|
||||
input sdk.Coins
|
||||
multiplier sdk.Int
|
||||
multiplier math.Int
|
||||
expected sdk.Coins
|
||||
shouldPanic bool
|
||||
}{
|
||||
@ -281,7 +280,7 @@ func (s *coinTestSuite) TestMulIntCoins() {
|
||||
func (s *coinTestSuite) TestQuoIntCoins() {
|
||||
testCases := []struct {
|
||||
input sdk.Coins
|
||||
divisor sdk.Int
|
||||
divisor math.Int
|
||||
expected sdk.Coins
|
||||
isValid bool
|
||||
shouldPanic bool
|
||||
@ -413,7 +412,7 @@ func (s *coinTestSuite) TestFilteredZeroCoins() {
|
||||
{
|
||||
name: "all greater than zero",
|
||||
input: sdk.Coins{
|
||||
{"testa", sdk.OneInt()},
|
||||
{"testa", math.OneInt()},
|
||||
{"testb", sdk.NewInt(2)},
|
||||
{"testc", sdk.NewInt(3)},
|
||||
{"testd", sdk.NewInt(4)},
|
||||
@ -425,7 +424,7 @@ func (s *coinTestSuite) TestFilteredZeroCoins() {
|
||||
{
|
||||
name: "zero coin in middle",
|
||||
input: sdk.Coins{
|
||||
{"testa", sdk.OneInt()},
|
||||
{"testa", math.OneInt()},
|
||||
{"testb", sdk.NewInt(2)},
|
||||
{"testc", sdk.NewInt(0)},
|
||||
{"testd", sdk.NewInt(4)},
|
||||
@ -439,7 +438,7 @@ func (s *coinTestSuite) TestFilteredZeroCoins() {
|
||||
input: sdk.Coins{
|
||||
{"teste", sdk.NewInt(5)},
|
||||
{"testc", sdk.NewInt(3)},
|
||||
{"testa", sdk.OneInt()},
|
||||
{"testa", math.OneInt()},
|
||||
{"testd", sdk.NewInt(4)},
|
||||
{"testb", sdk.NewInt(0)},
|
||||
},
|
||||
@ -471,15 +470,15 @@ func (s *coinTestSuite) TestCoins_String() {
|
||||
},
|
||||
{
|
||||
"single coin",
|
||||
sdk.Coins{{"tree", sdk.OneInt()}},
|
||||
sdk.Coins{{"tree", math.OneInt()}},
|
||||
"1tree",
|
||||
},
|
||||
{
|
||||
"multiple coins",
|
||||
sdk.Coins{
|
||||
{"tree", sdk.OneInt()},
|
||||
{"gas", sdk.OneInt()},
|
||||
{"mineral", sdk.OneInt()},
|
||||
{"tree", math.OneInt()},
|
||||
{"gas", math.OneInt()},
|
||||
{"mineral", math.OneInt()},
|
||||
},
|
||||
"1tree,1gas,1mineral",
|
||||
},
|
||||
@ -619,87 +618,87 @@ func (s *coinTestSuite) TestCoins_Validate() {
|
||||
{
|
||||
"valid lowercase coins",
|
||||
sdk.Coins{
|
||||
{"gas", sdk.OneInt()},
|
||||
{"mineral", sdk.OneInt()},
|
||||
{"tree", sdk.OneInt()},
|
||||
{"gas", math.OneInt()},
|
||||
{"mineral", math.OneInt()},
|
||||
{"tree", math.OneInt()},
|
||||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"valid uppercase coins",
|
||||
sdk.Coins{
|
||||
{"GAS", sdk.OneInt()},
|
||||
{"MINERAL", sdk.OneInt()},
|
||||
{"TREE", sdk.OneInt()},
|
||||
{"GAS", math.OneInt()},
|
||||
{"MINERAL", math.OneInt()},
|
||||
{"TREE", math.OneInt()},
|
||||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"valid uppercase coin",
|
||||
sdk.Coins{
|
||||
{"ATOM", sdk.OneInt()},
|
||||
{"ATOM", math.OneInt()},
|
||||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"valid lower and uppercase coins (1)",
|
||||
sdk.Coins{
|
||||
{"GAS", sdk.OneInt()},
|
||||
{"gAs", sdk.OneInt()},
|
||||
{"GAS", math.OneInt()},
|
||||
{"gAs", math.OneInt()},
|
||||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"valid lower and uppercase coins (2)",
|
||||
sdk.Coins{
|
||||
{"ATOM", sdk.OneInt()},
|
||||
{"Atom", sdk.OneInt()},
|
||||
{"atom", sdk.OneInt()},
|
||||
{"ATOM", math.OneInt()},
|
||||
{"Atom", math.OneInt()},
|
||||
{"atom", math.OneInt()},
|
||||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"mixed case (1)",
|
||||
sdk.Coins{
|
||||
{"MineraL", sdk.OneInt()},
|
||||
{"TREE", sdk.OneInt()},
|
||||
{"gAs", sdk.OneInt()},
|
||||
{"MineraL", math.OneInt()},
|
||||
{"TREE", math.OneInt()},
|
||||
{"gAs", math.OneInt()},
|
||||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"mixed case (2)",
|
||||
sdk.Coins{
|
||||
{"gAs", sdk.OneInt()},
|
||||
{"mineral", sdk.OneInt()},
|
||||
{"gAs", math.OneInt()},
|
||||
{"mineral", math.OneInt()},
|
||||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"mixed case (3)",
|
||||
sdk.Coins{
|
||||
{"gAs", sdk.OneInt()},
|
||||
{"gAs", math.OneInt()},
|
||||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"unicode letters and numbers",
|
||||
sdk.Coins{
|
||||
{"𐀀𐀆𐀉Ⅲ", sdk.OneInt()},
|
||||
{"𐀀𐀆𐀉Ⅲ", math.OneInt()},
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"emojis",
|
||||
sdk.Coins{
|
||||
{"🤑😋🤔", sdk.OneInt()},
|
||||
{"🤑😋🤔", math.OneInt()},
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"IBC denominations (ADR 001)",
|
||||
sdk.Coins{
|
||||
{"ibc/7F1D3FCF4AE79E1554D670D1AD949A9BA4E4A3C76C63093E17E446A46061A7A2", sdk.OneInt()},
|
||||
{"ibc/7F1D3FCF4AE79E1554D670D1AD949A9BA4E4A3C76C63093E17E446A46061A7A2", math.OneInt()},
|
||||
{"ibc/876563AAAACF739EB061C67CDB5EDF2B7C9FD4AA9D876450CC21210807C2820A", sdk.NewInt(2)},
|
||||
},
|
||||
true,
|
||||
@ -717,44 +716,44 @@ func (s *coinTestSuite) TestCoins_Validate() {
|
||||
{
|
||||
"invalid denomination (1)",
|
||||
sdk.Coins{
|
||||
{"MineraL", sdk.OneInt()},
|
||||
{"0TREE", sdk.OneInt()},
|
||||
{"gAs", sdk.OneInt()},
|
||||
{"MineraL", math.OneInt()},
|
||||
{"0TREE", math.OneInt()},
|
||||
{"gAs", math.OneInt()},
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"invalid denomination (2)",
|
||||
sdk.Coins{
|
||||
{"-GAS", sdk.OneInt()},
|
||||
{"gAs", sdk.OneInt()},
|
||||
{"-GAS", math.OneInt()},
|
||||
{"gAs", math.OneInt()},
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"bad sort (1)",
|
||||
sdk.Coins{
|
||||
{"tree", sdk.OneInt()},
|
||||
{"gas", sdk.OneInt()},
|
||||
{"mineral", sdk.OneInt()},
|
||||
{"tree", math.OneInt()},
|
||||
{"gas", math.OneInt()},
|
||||
{"mineral", math.OneInt()},
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"bad sort (2)",
|
||||
sdk.Coins{
|
||||
{"gas", sdk.OneInt()},
|
||||
{"tree", sdk.OneInt()},
|
||||
{"mineral", sdk.OneInt()},
|
||||
{"gas", math.OneInt()},
|
||||
{"tree", math.OneInt()},
|
||||
{"mineral", math.OneInt()},
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"non-positive amount (1)",
|
||||
sdk.Coins{
|
||||
{"gas", sdk.OneInt()},
|
||||
{"gas", math.OneInt()},
|
||||
{"tree", sdk.NewInt(0)},
|
||||
{"mineral", sdk.OneInt()},
|
||||
{"mineral", math.OneInt()},
|
||||
},
|
||||
false,
|
||||
},
|
||||
@ -762,17 +761,17 @@ func (s *coinTestSuite) TestCoins_Validate() {
|
||||
"non-positive amount (2)",
|
||||
sdk.Coins{
|
||||
{"gas", sdk.NewInt(-1)},
|
||||
{"tree", sdk.OneInt()},
|
||||
{"mineral", sdk.OneInt()},
|
||||
{"tree", math.OneInt()},
|
||||
{"mineral", math.OneInt()},
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"duplicate denomination",
|
||||
sdk.Coins{
|
||||
{"gas", sdk.OneInt()},
|
||||
{"gas", sdk.OneInt()},
|
||||
{"mineral", sdk.OneInt()},
|
||||
{"gas", math.OneInt()},
|
||||
{"gas", math.OneInt()},
|
||||
{"mineral", math.OneInt()},
|
||||
},
|
||||
false,
|
||||
},
|
||||
@ -789,7 +788,7 @@ func (s *coinTestSuite) TestCoins_Validate() {
|
||||
}
|
||||
|
||||
func (s *coinTestSuite) TestMinMax() {
|
||||
one := sdk.OneInt()
|
||||
one := math.OneInt()
|
||||
two := sdk.NewInt(2)
|
||||
|
||||
cases := []struct {
|
||||
@ -821,7 +820,7 @@ func (s *coinTestSuite) TestMinMax() {
|
||||
}
|
||||
|
||||
func (s *coinTestSuite) TestCoinsGT() {
|
||||
one := sdk.OneInt()
|
||||
one := math.OneInt()
|
||||
two := sdk.NewInt(2)
|
||||
|
||||
s.Require().False(sdk.Coins{}.IsAllGT(sdk.Coins{}))
|
||||
@ -833,7 +832,7 @@ func (s *coinTestSuite) TestCoinsGT() {
|
||||
}
|
||||
|
||||
func (s *coinTestSuite) TestCoinsLT() {
|
||||
one := sdk.OneInt()
|
||||
one := math.OneInt()
|
||||
two := sdk.NewInt(2)
|
||||
|
||||
s.Require().False(sdk.Coins{}.IsAllLT(sdk.Coins{}))
|
||||
@ -848,7 +847,7 @@ func (s *coinTestSuite) TestCoinsLT() {
|
||||
}
|
||||
|
||||
func (s *coinTestSuite) TestCoinsLTE() {
|
||||
one := sdk.OneInt()
|
||||
one := math.OneInt()
|
||||
two := sdk.NewInt(2)
|
||||
|
||||
s.Require().True(sdk.Coins{}.IsAllLTE(sdk.Coins{}))
|
||||
@ -863,7 +862,7 @@ func (s *coinTestSuite) TestCoinsLTE() {
|
||||
}
|
||||
|
||||
func (s *coinTestSuite) TestParseCoins() {
|
||||
one := sdk.OneInt()
|
||||
one := math.OneInt()
|
||||
|
||||
cases := []struct {
|
||||
input string
|
||||
@ -1033,7 +1032,7 @@ func (s *coinTestSuite) TestSearch() {
|
||||
}
|
||||
|
||||
func (s *coinTestSuite) TestCoinsIsAnyGTE() {
|
||||
one := sdk.OneInt()
|
||||
one := math.OneInt()
|
||||
two := sdk.NewInt(2)
|
||||
|
||||
s.Require().False(sdk.Coins{}.IsAnyGTE(sdk.Coins{}))
|
||||
@ -1053,7 +1052,7 @@ func (s *coinTestSuite) TestCoinsIsAnyGTE() {
|
||||
}
|
||||
|
||||
func (s *coinTestSuite) TestCoinsIsAllGT() {
|
||||
one := sdk.OneInt()
|
||||
one := math.OneInt()
|
||||
two := sdk.NewInt(2)
|
||||
|
||||
s.Require().False(sdk.Coins{}.IsAllGT(sdk.Coins{}))
|
||||
@ -1073,7 +1072,7 @@ func (s *coinTestSuite) TestCoinsIsAllGT() {
|
||||
}
|
||||
|
||||
func (s *coinTestSuite) TestCoinsIsAllGTE() {
|
||||
one := sdk.OneInt()
|
||||
one := math.OneInt()
|
||||
two := sdk.NewInt(2)
|
||||
|
||||
s.Require().True(sdk.Coins{}.IsAllGTE(sdk.Coins{}))
|
||||
@ -1098,7 +1097,7 @@ func (s *coinTestSuite) TestNewCoins() {
|
||||
tenatom := sdk.NewInt64Coin("atom", 10)
|
||||
tenbtc := sdk.NewInt64Coin("btc", 10)
|
||||
zeroeth := sdk.NewInt64Coin("eth", 0)
|
||||
invalidCoin := sdk.Coin{"0ETH", sdk.OneInt()}
|
||||
invalidCoin := sdk.Coin{"0ETH", math.OneInt()}
|
||||
tests := []struct {
|
||||
name string
|
||||
coins sdk.Coins
|
||||
|
||||
@ -16,7 +16,6 @@ import (
|
||||
var addr1 = sdk.AccAddress([]byte("addr1"))
|
||||
|
||||
func (s *paginationTestSuite) TestFilteredPaginations() {
|
||||
|
||||
var balances sdk.Coins
|
||||
for i := 0; i < numBalances; i++ {
|
||||
denom := fmt.Sprintf("foo%ddenom", i)
|
||||
@ -248,7 +247,6 @@ func execFilterPaginate(store sdk.KVStore, pageReq *query.PageRequest, appCodec
|
||||
}
|
||||
|
||||
func (s *paginationTestSuite) TestFilteredPaginationsNextKey() {
|
||||
|
||||
var balances sdk.Coins
|
||||
|
||||
for i := 1; i <= 10; i++ {
|
||||
|
||||
@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
"github.com/stretchr/testify/suite"
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
|
||||
@ -74,8 +75,7 @@ func (s *paginationTestSuite) SetupTest() {
|
||||
|
||||
ctx := app.BaseApp.NewContext(false, tmproto.Header{Height: 1})
|
||||
|
||||
s.ctx, s.bankKeeper, s.accountKeeper, s.cdc, s.app, s.interfaceReg =
|
||||
ctx, bankKeeper, accountKeeper, cdc, app, reg
|
||||
s.ctx, s.bankKeeper, s.accountKeeper, s.cdc, s.app, s.interfaceReg = ctx, bankKeeper, accountKeeper, cdc, app, reg
|
||||
}
|
||||
|
||||
func (s *paginationTestSuite) TestParsePagination() {
|
||||
@ -352,7 +352,7 @@ func (s *paginationTestSuite) TestPaginate() {
|
||||
balancesStore := prefix.NewStore(authStore, types.BalancesPrefix)
|
||||
accountStore := prefix.NewStore(balancesStore, address.MustLengthPrefix(addr1))
|
||||
pageRes, err := query.Paginate(accountStore, request.Pagination, func(key []byte, value []byte) error {
|
||||
var amount sdk.Int
|
||||
var amount math.Int
|
||||
err := amount.Unmarshal(value)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@ -42,13 +42,13 @@ func RandStringOfLength(r *rand.Rand, n int) string {
|
||||
|
||||
// RandPositiveInt get a rand positive math.Int
|
||||
func RandPositiveInt(r *rand.Rand, max math.Int) (math.Int, error) {
|
||||
if !max.GTE(sdk.OneInt()) {
|
||||
if !max.GTE(math.OneInt()) {
|
||||
return math.Int{}, errors.New("max too small")
|
||||
}
|
||||
|
||||
max = max.Sub(sdk.OneInt())
|
||||
max = max.Sub(math.OneInt())
|
||||
|
||||
return sdk.NewIntFromBigInt(new(big.Int).Rand(r, max.BigInt())).Add(sdk.OneInt()), nil
|
||||
return sdk.NewIntFromBigInt(new(big.Int).Rand(r, max.BigInt())).Add(math.OneInt()), nil
|
||||
}
|
||||
|
||||
// RandomAmount generates a random amount
|
||||
|
||||
@ -7,6 +7,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank/testutil"
|
||||
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
|
||||
|
||||
@ -486,7 +487,7 @@ func (suite *AnteTestSuite) TestAnteHandlerFees() {
|
||||
modAcc := suite.accountKeeper.GetModuleAccount(suite.ctx, types.FeeCollectorName)
|
||||
|
||||
suite.Require().True(suite.bankKeeper.GetAllBalances(suite.ctx, modAcc.GetAddress()).Empty())
|
||||
require.True(sdk.IntEq(suite.T(), suite.bankKeeper.GetAllBalances(suite.ctx, addr0).AmountOf("atom"), sdk.NewInt(149)))
|
||||
require.True(math.IntEq(suite.T(), suite.bankKeeper.GetAllBalances(suite.ctx, addr0).AmountOf("atom"), sdk.NewInt(149)))
|
||||
|
||||
err := testutil.FundAccount(suite.bankKeeper, suite.ctx, addr0, sdk.NewCoins(sdk.NewInt64Coin("atom", 1)))
|
||||
suite.Require().NoError(err)
|
||||
@ -500,8 +501,8 @@ func (suite *AnteTestSuite) TestAnteHandlerFees() {
|
||||
func() {
|
||||
modAcc := suite.accountKeeper.GetModuleAccount(suite.ctx, types.FeeCollectorName)
|
||||
|
||||
require.True(sdk.IntEq(suite.T(), suite.bankKeeper.GetAllBalances(suite.ctx, modAcc.GetAddress()).AmountOf("atom"), sdk.NewInt(150)))
|
||||
require.True(sdk.IntEq(suite.T(), suite.bankKeeper.GetAllBalances(suite.ctx, addr0).AmountOf("atom"), sdk.NewInt(0)))
|
||||
require.True(math.IntEq(suite.T(), suite.bankKeeper.GetAllBalances(suite.ctx, modAcc.GetAddress()).AmountOf("atom"), sdk.NewInt(150)))
|
||||
require.True(math.IntEq(suite.T(), suite.bankKeeper.GetAllBalances(suite.ctx, addr0).AmountOf("atom"), sdk.NewInt(0)))
|
||||
},
|
||||
false,
|
||||
false,
|
||||
|
||||
@ -47,10 +47,10 @@ func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bo
|
||||
}
|
||||
|
||||
var (
|
||||
priority int64
|
||||
err error
|
||||
priority int64
|
||||
err error
|
||||
)
|
||||
|
||||
|
||||
fee := feeTx.GetFee()
|
||||
if !simulate {
|
||||
fee, priority, err = dfd.txFeeChecker(ctx, tx)
|
||||
|
||||
@ -22,7 +22,7 @@ var _ paramtypes.ParamSet = &Params{}
|
||||
|
||||
// ParamKeyTable for auth module
|
||||
//
|
||||
// NOTE: Deprecated.
|
||||
// Deprecated.
|
||||
func ParamKeyTable() paramtypes.KeyTable {
|
||||
return paramtypes.NewKeyTable().RegisterParamSet(&Params{})
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
"sigs.k8s.io/yaml"
|
||||
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
@ -69,7 +70,7 @@ func (bva *BaseVestingAccount) TrackDelegation(balance, vestingCoins, amount sdk
|
||||
// compute x and y per the specification, where:
|
||||
// X := min(max(V - DV, 0), D)
|
||||
// Y := D - X
|
||||
x := sdk.MinInt(sdk.MaxInt(vestingAmt.Sub(delVestingAmt), sdk.ZeroInt()), coin.Amount)
|
||||
x := sdk.MinInt(sdk.MaxInt(vestingAmt.Sub(delVestingAmt), math.ZeroInt()), coin.Amount)
|
||||
y := coin.Amount.Sub(x)
|
||||
|
||||
if !x.IsZero() {
|
||||
|
||||
@ -3,6 +3,7 @@ package testutil
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
"github.com/gogo/protobuf/proto"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
@ -82,7 +83,7 @@ func (s *IntegrationTestSuite) TestTotalSupplyGRPCHandler() {
|
||||
},
|
||||
&types.QuerySupplyOfResponse{},
|
||||
&types.QuerySupplyOfResponse{
|
||||
Amount: sdk.NewCoin("foobar", sdk.ZeroInt()),
|
||||
Amount: sdk.NewCoin("foobar", math.ZeroInt()),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@ -144,7 +144,7 @@ func (s *IntegrationTestSuite) TestGetBalancesCmd() {
|
||||
},
|
||||
false,
|
||||
&sdk.Coin{},
|
||||
NewCoin("foobar", sdk.ZeroInt()),
|
||||
NewCoin("foobar", math.ZeroInt()),
|
||||
},
|
||||
}
|
||||
|
||||
@ -214,7 +214,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryTotalSupply() {
|
||||
respType: &sdk.Coin{},
|
||||
expected: &sdk.Coin{
|
||||
Denom: "foobar",
|
||||
Amount: sdk.ZeroInt(),
|
||||
Amount: math.ZeroInt(),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@ -92,7 +92,7 @@ func (k BaseKeeper) SpendableBalances(ctx context.Context, req *types.QuerySpend
|
||||
|
||||
balances := sdk.NewCoins()
|
||||
accountStore := k.getAccountStore(sdkCtx, addr)
|
||||
zeroAmt := sdk.ZeroInt()
|
||||
zeroAmt := math.ZeroInt()
|
||||
|
||||
pageRes, err := query.Paginate(accountStore, req.Pagination, func(key, _ []byte) error {
|
||||
balances = append(balances, sdk.NewCoin(string(key), zeroAmt))
|
||||
|
||||
@ -6,6 +6,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/suite"
|
||||
@ -500,9 +501,9 @@ func (suite *IntegrationTestSuite) TestSendEnabled() {
|
||||
|
||||
suite.Require().NoError(app.BankKeeper.SetParams(ctx, params))
|
||||
|
||||
bondCoin := sdk.NewCoin(sdk.DefaultBondDenom, sdk.OneInt())
|
||||
fooCoin := sdk.NewCoin("foocoin", sdk.OneInt())
|
||||
barCoin := sdk.NewCoin("barcoin", sdk.OneInt())
|
||||
bondCoin := sdk.NewCoin(sdk.DefaultBondDenom, math.OneInt())
|
||||
fooCoin := sdk.NewCoin("foocoin", math.OneInt())
|
||||
barCoin := sdk.NewCoin("barcoin", math.OneInt())
|
||||
|
||||
// assert with default (all denom) send enabled both Bar and Bond Denom are enabled
|
||||
suite.Require().Equal(enabled, app.BankKeeper.IsSendEnabledCoin(ctx, barCoin))
|
||||
@ -614,8 +615,9 @@ func (suite *IntegrationTestSuite) TestMsgMultiSendEvents() {
|
||||
newCoins := sdk.NewCoins(sdk.NewInt64Coin(fooDenom, 50))
|
||||
newCoins2 := sdk.NewCoins(sdk.NewInt64Coin(barDenom, 100))
|
||||
input := []types.Input{
|
||||
{Address: addr.String(),
|
||||
Coins: coins,
|
||||
{
|
||||
Address: addr.String(),
|
||||
Coins: coins,
|
||||
},
|
||||
}
|
||||
outputs := []types.Output{
|
||||
|
||||
@ -8,7 +8,6 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/telemetry"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/errors"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
)
|
||||
@ -42,7 +41,7 @@ func (k msgServer) Send(goCtx context.Context, msg *types.MsgSend) (*types.MsgSe
|
||||
}
|
||||
|
||||
if k.BlockedAddr(to) {
|
||||
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive funds", msg.ToAddress)
|
||||
return nil, errors.Wrapf(errors.ErrUnauthorized, "%s is not allowed to receive funds", msg.ToAddress)
|
||||
}
|
||||
|
||||
err = k.SendCoins(ctx, from, to, msg.Amount)
|
||||
@ -86,7 +85,7 @@ func (k msgServer) MultiSend(goCtx context.Context, msg *types.MsgMultiSend) (*t
|
||||
accAddr := sdk.MustAccAddressFromBech32(out.Address)
|
||||
|
||||
if k.BlockedAddr(accAddr) {
|
||||
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive transactions", out.Address)
|
||||
return nil, errors.Wrapf(errors.ErrUnauthorized, "%s is not allowed to receive transactions", out.Address)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -99,6 +99,7 @@ func (k BaseSendKeeper) GetParams(ctx sdk.Context) (params types.Params) {
|
||||
}
|
||||
|
||||
// SetParams sets the total set of bank parameters.
|
||||
//nolint:staticcheck // params.SendEnabled is deprecated but it should be here regardless.
|
||||
func (k BaseSendKeeper) SetParams(ctx sdk.Context, params types.Params) error {
|
||||
// normally SendEnabled is deprecated but we still support it for backwards compatibility
|
||||
// using params.Validate() would fail due to the SendEnabled deprecation
|
||||
|
||||
@ -100,7 +100,7 @@ func (k BaseViewKeeper) GetAccountsBalances(ctx sdk.Context) []types.Balance {
|
||||
// by address.
|
||||
func (k BaseViewKeeper) GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin {
|
||||
accountStore := k.getAccountStore(ctx, addr)
|
||||
amount := sdk.ZeroInt()
|
||||
amount := math.ZeroInt()
|
||||
bz := accountStore.Get([]byte(denom))
|
||||
if bz == nil {
|
||||
return sdk.NewCoin(denom, amount)
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package v2
|
||||
|
||||
import (
|
||||
"cosmossdk.io/math"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/store/prefix"
|
||||
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
||||
@ -118,7 +119,7 @@ func pruneZeroSupply(store sdk.KVStore) error {
|
||||
defer iterator.Close()
|
||||
|
||||
for ; iterator.Valid(); iterator.Next() {
|
||||
var amount sdk.Int
|
||||
var amount math.Int
|
||||
if err := amount.Unmarshal(iterator.Value()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ package v2_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
@ -41,7 +42,7 @@ func TestSupplyMigration(t *testing.T) {
|
||||
// New supply is indexed by denom.
|
||||
supplyStore := prefix.NewStore(store, types.SupplyKey)
|
||||
bz := supplyStore.Get([]byte("foo"))
|
||||
var amount sdk.Int
|
||||
var amount math.Int
|
||||
err = amount.Unmarshal(bz)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@ package v3_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
@ -41,7 +42,7 @@ func TestMigrateStore(t *testing.T) {
|
||||
for _, b := range balances {
|
||||
addrPrefixStore := prefix.NewStore(store, types.CreateAccountBalancesPrefix(addr))
|
||||
bz := addrPrefixStore.Get([]byte(b.Denom))
|
||||
var expected sdk.Int
|
||||
var expected math.Int
|
||||
require.NoError(t, expected.Unmarshal(bz))
|
||||
require.Equal(t, expected, b.Amount)
|
||||
}
|
||||
@ -64,9 +65,9 @@ func TestMigrateDenomMetaData(t *testing.T) {
|
||||
Symbol: "ATOM",
|
||||
Description: "The native staking token of the Cosmos Hub.",
|
||||
DenomUnits: []*types.DenomUnit{
|
||||
{"uatom", uint32(0), []string{"microatom"}},
|
||||
{"matom", uint32(3), []string{"milliatom"}},
|
||||
{"atom", uint32(6), nil},
|
||||
{Denom: "uatom", Exponent: uint32(0), Aliases: []string{"microatom"}},
|
||||
{Denom: "matom", Exponent: uint32(3), Aliases: []string{"milliatom"}},
|
||||
{Denom: "atom", Exponent: uint32(6), Aliases: nil},
|
||||
},
|
||||
Base: "uatom",
|
||||
Display: "atom",
|
||||
@ -76,9 +77,9 @@ func TestMigrateDenomMetaData(t *testing.T) {
|
||||
Symbol: "TOKEN",
|
||||
Description: "The native staking token of the Token Hub.",
|
||||
DenomUnits: []*types.DenomUnit{
|
||||
{"1token", uint32(5), []string{"decitoken"}},
|
||||
{"2token", uint32(4), []string{"centitoken"}},
|
||||
{"3token", uint32(7), []string{"dekatoken"}},
|
||||
{Denom: "1token", Exponent: uint32(5), Aliases: []string{"decitoken"}},
|
||||
{Denom: "2token", Exponent: uint32(4), Aliases: []string{"centitoken"}},
|
||||
{Denom: "3token", Exponent: uint32(7), Aliases: []string{"dekatoken"}},
|
||||
},
|
||||
Base: "utoken",
|
||||
Display: "token",
|
||||
|
||||
@ -177,7 +177,7 @@ func SimulateMsgMultiSend(ak types.AccountKeeper, bk keeper.Keeper) simtypes.Ope
|
||||
accs []simtypes.Account, chainID string,
|
||||
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
|
||||
// random number of inputs/outputs between [1, 3]
|
||||
inputs := make([]types.Input, r.Intn(1)+1)
|
||||
inputs := make([]types.Input, r.Intn(1)+1) //nolint:staticcheck // SA4030: (*math/rand.Rand).Intn(n) generates a random value 0 <= x < n; that is, the generated values don't include n; r.Intn(1) therefore always returns 0
|
||||
outputs := make([]types.Output, r.Intn(3)+1)
|
||||
|
||||
// collect signer privKeys
|
||||
|
||||
@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
@ -49,7 +50,7 @@ func TestBalanceValidate(t *testing.T) {
|
||||
bank.Balance{
|
||||
Address: "cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t",
|
||||
Coins: sdk.Coins{
|
||||
sdk.Coin{Denom: "", Amount: sdk.OneInt()},
|
||||
sdk.Coin{Denom: "", Amount: math.OneInt()},
|
||||
},
|
||||
},
|
||||
true,
|
||||
|
||||
@ -3,6 +3,7 @@ package types
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
@ -137,7 +138,7 @@ func TestGenesisStateValidate(t *testing.T) {
|
||||
{
|
||||
"invalid supply",
|
||||
GenesisState{
|
||||
Supply: sdk.Coins{sdk.Coin{Denom: "", Amount: sdk.OneInt()}},
|
||||
Supply: sdk.Coins{sdk.Coin{Denom: "", Amount: math.OneInt()}},
|
||||
},
|
||||
true,
|
||||
},
|
||||
|
||||
@ -52,6 +52,7 @@ func (se SendEnabled) Validate() error {
|
||||
}
|
||||
|
||||
// validateSendEnabledParams is used by the x/params module to validate the params for the bank module.
|
||||
//nolint:deadcode,unused
|
||||
func validateSendEnabledParams(i interface{}) error {
|
||||
params, ok := i.([]*SendEnabled)
|
||||
if !ok {
|
||||
@ -86,6 +87,7 @@ func (se SendEnabled) String() string {
|
||||
}
|
||||
|
||||
// validateSendEnabled is used by the x/params module to validate a single SendEnabled entry.
|
||||
//nolint:unused
|
||||
func validateSendEnabled(i interface{}) error {
|
||||
param, ok := i.(SendEnabled)
|
||||
if !ok {
|
||||
|
||||
@ -4,18 +4,18 @@ import paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
|
||||
|
||||
var (
|
||||
// KeySendEnabled is store's key for SendEnabled Params
|
||||
// DEPRECATED: Use the SendEnabled functionality in the keeper.
|
||||
// Deprecated: Use the SendEnabled functionality in the keeper.
|
||||
KeySendEnabled = []byte("SendEnabled")
|
||||
// KeyDefaultSendEnabled is store's key for the DefaultSendEnabled option
|
||||
KeyDefaultSendEnabled = []byte("DefaultSendEnabled")
|
||||
)
|
||||
|
||||
// DEPRECATED: ParamKeyTable for bank module.
|
||||
// Deprecated: ParamKeyTable for bank module.
|
||||
func ParamKeyTable() paramtypes.KeyTable {
|
||||
return paramtypes.NewKeyTable().RegisterParamSet(&Params{})
|
||||
}
|
||||
|
||||
// DEPRECATED: ParamSetPairs implements params.ParamSet
|
||||
// Deprecated: ParamSetPairs implements params.ParamSet
|
||||
func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
|
||||
return paramtypes.ParamSetPairs{
|
||||
paramtypes.NewParamSetPair(KeyDefaultSendEnabled, &p.DefaultSendEnabled, validateIsBool),
|
||||
|
||||
@ -3,6 +3,7 @@ package types
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
@ -18,7 +19,7 @@ func Test_validateSendEnabledParam(t *testing.T) {
|
||||
args args
|
||||
wantErr bool
|
||||
}{
|
||||
{"invalid type", args{sdk.NewCoin(sdk.DefaultBondDenom, sdk.OneInt())}, true},
|
||||
{"invalid type", args{sdk.NewCoin(sdk.DefaultBondDenom, math.OneInt())}, true},
|
||||
|
||||
{"invalid empty denom send enabled", args{*NewSendEnabled("", true)}, true},
|
||||
{"invalid empty denom send disabled", args{*NewSendEnabled("", false)}, true},
|
||||
|
||||
@ -6,6 +6,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/stretchr/testify/suite"
|
||||
tmcli "github.com/tendermint/tendermint/libs/cli"
|
||||
@ -540,14 +541,14 @@ func (s *IntegrationTestSuite) TestNewWithdrawRewardsCmd() {
|
||||
// can't use unpackAny as response types are not registered.
|
||||
err = s.cfg.Codec.Unmarshal(msgResponse.Value, &resp)
|
||||
s.Require().NoError(err)
|
||||
s.Require().True(resp.Amount.IsAllGT(sdk.NewCoins(sdk.NewCoin("stake", sdk.OneInt()))),
|
||||
s.Require().True(resp.Amount.IsAllGT(sdk.NewCoins(sdk.NewCoin("stake", math.OneInt()))),
|
||||
fmt.Sprintf("expected a positive coin value, got %v", resp.Amount))
|
||||
case "/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommissionResponse":
|
||||
var resp distrtypes.MsgWithdrawValidatorCommissionResponse
|
||||
// can't use unpackAny as response types are not registered.
|
||||
err = s.cfg.Codec.Unmarshal(msgResponse.Value, &resp)
|
||||
s.Require().NoError(err)
|
||||
s.Require().True(resp.Amount.IsAllGT(sdk.NewCoins(sdk.NewCoin("stake", sdk.OneInt()))),
|
||||
s.Require().True(resp.Amount.IsAllGT(sdk.NewCoins(sdk.NewCoin("stake", math.OneInt()))),
|
||||
fmt.Sprintf("expected a positive coin value, got %v", resp.Amount))
|
||||
}
|
||||
}
|
||||
@ -626,14 +627,14 @@ func (s *IntegrationTestSuite) TestNewWithdrawAllRewardsCmd() {
|
||||
// can't use unpackAny as response types are not registered.
|
||||
err = s.cfg.Codec.Unmarshal(msgResponse.Value, &resp)
|
||||
s.Require().NoError(err)
|
||||
s.Require().True(resp.Amount.IsAllGT(sdk.NewCoins(sdk.NewCoin("stake", sdk.OneInt()))),
|
||||
s.Require().True(resp.Amount.IsAllGT(sdk.NewCoins(sdk.NewCoin("stake", math.OneInt()))),
|
||||
fmt.Sprintf("expected a positive coin value, got %v", resp.Amount))
|
||||
case "/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommissionResponse":
|
||||
var resp distrtypes.MsgWithdrawValidatorCommissionResponse
|
||||
// can't use unpackAny as response types are not registered.
|
||||
err = s.cfg.Codec.Unmarshal(msgResponse.Value, &resp)
|
||||
s.Require().NoError(err)
|
||||
s.Require().True(resp.Amount.IsAllGT(sdk.NewCoins(sdk.NewCoin("stake", sdk.OneInt()))),
|
||||
s.Require().True(resp.Amount.IsAllGT(sdk.NewCoins(sdk.NewCoin("stake", math.OneInt()))),
|
||||
fmt.Sprintf("expected a positive coin value, got %v", resp.Amount))
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ package keeper_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
"github.com/stretchr/testify/require"
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
|
||||
@ -807,7 +808,7 @@ func Test100PercentCommissionReward(t *testing.T) {
|
||||
zeroRewards := sdk.Coins{
|
||||
sdk.Coin{
|
||||
Denom: denom,
|
||||
Amount: sdk.ZeroInt(),
|
||||
Amount: math.ZeroInt(),
|
||||
},
|
||||
}
|
||||
require.True(t, rewards.IsEqual(zeroRewards))
|
||||
|
||||
@ -3,6 +3,7 @@ package keeper
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
@ -101,7 +102,7 @@ func (k Keeper) WithdrawDelegationRewards(ctx sdk.Context, delAddr sdk.AccAddres
|
||||
baseDenom, _ := sdk.GetBaseDenom()
|
||||
rewards = sdk.Coins{sdk.Coin{
|
||||
Denom: baseDenom,
|
||||
Amount: sdk.ZeroInt(),
|
||||
Amount: math.ZeroInt(),
|
||||
}}
|
||||
}
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@ package keeper_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
"github.com/stretchr/testify/require"
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
|
||||
@ -169,7 +170,7 @@ func TestFundCommunityPool(t *testing.T) {
|
||||
// reset fee pool
|
||||
distrKeeper.SetFeePool(ctx, types.InitialFeePool())
|
||||
|
||||
addr := simtestutil.AddTestAddrs(bankKeeper, stakingKeeper, ctx, 2, sdk.ZeroInt())
|
||||
addr := simtestutil.AddTestAddrs(bankKeeper, stakingKeeper, ctx, 2, math.ZeroInt())
|
||||
|
||||
amount := sdk.NewCoins(sdk.NewInt64Coin("stake", 100))
|
||||
require.NoError(t, banktestutil.FundAccount(bankKeeper, ctx, addr[0], amount))
|
||||
|
||||
@ -7,6 +7,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
"github.com/stretchr/testify/suite"
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
|
||||
@ -53,7 +54,7 @@ func (suite *GenTxTestSuite) SetupTest() {
|
||||
|
||||
var err error
|
||||
amount := sdk.NewInt64Coin(sdk.DefaultBondDenom, 50)
|
||||
one := sdk.OneInt()
|
||||
one := math.OneInt()
|
||||
suite.msg1, err = stakingtypes.NewMsgCreateValidator(
|
||||
sdk.ValAddress(pk1.Address()), pk1, amount, desc, comm, one)
|
||||
suite.NoError(err)
|
||||
|
||||
@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
@ -38,11 +39,11 @@ func TestValidateGenesisMultipleMessages(t *testing.T) {
|
||||
comm := stakingtypes.CommissionRates{}
|
||||
|
||||
msg1, err := stakingtypes.NewMsgCreateValidator(sdk.ValAddress(pk1.Address()), pk1,
|
||||
sdk.NewInt64Coin(sdk.DefaultBondDenom, 50), desc, comm, sdk.OneInt())
|
||||
sdk.NewInt64Coin(sdk.DefaultBondDenom, 50), desc, comm, math.OneInt())
|
||||
require.NoError(t, err)
|
||||
|
||||
msg2, err := stakingtypes.NewMsgCreateValidator(sdk.ValAddress(pk2.Address()), pk2,
|
||||
sdk.NewInt64Coin(sdk.DefaultBondDenom, 50), desc, comm, sdk.OneInt())
|
||||
sdk.NewInt64Coin(sdk.DefaultBondDenom, 50), desc, comm, math.OneInt())
|
||||
require.NoError(t, err)
|
||||
|
||||
txGen := simapp.MakeTestEncodingConfig().TxConfig
|
||||
|
||||
@ -4,6 +4,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
"github.com/stretchr/testify/require"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
@ -376,7 +377,7 @@ func createValidators(t *testing.T, stakingMsgSvr stakingtypes.MsgServer, ctx sd
|
||||
valTokens := sdk.TokensFromConsensusPower(powerAmt[i], sdk.DefaultPowerReduction)
|
||||
valCreateMsg, err := stakingtypes.NewMsgCreateValidator(
|
||||
addrs[i], pubkeys[i], sdk.NewCoin(sdk.DefaultBondDenom, valTokens),
|
||||
TestDescription, TestCommissionRates, sdk.OneInt(),
|
||||
TestDescription, TestCommissionRates, math.OneInt(),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
res, err := stakingMsgSvr.CreateValidator(sdk.WrapSDKContext(ctx), valCreateMsg)
|
||||
|
||||
@ -6,6 +6,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
@ -36,7 +37,7 @@ func TestDecodeStore(t *testing.T) {
|
||||
|
||||
proposalIDBz := make([]byte, 8)
|
||||
binary.LittleEndian.PutUint64(proposalIDBz, 1)
|
||||
deposit := v1beta1.NewDeposit(1, delAddr1, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.OneInt())))
|
||||
deposit := v1beta1.NewDeposit(1, delAddr1, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, math.OneInt())))
|
||||
vote := v1beta1.NewVote(1, delAddr1, v1beta1.NewNonSplitVoteOption(v1beta1.OptionYes))
|
||||
|
||||
proposalBzA, err := cdc.Marshal(&proposalA)
|
||||
|
||||
@ -49,7 +49,7 @@ func NewTallyResultFromMap(results map[VoteOption]sdk.Dec) TallyResult {
|
||||
|
||||
// EmptyTallyResult returns an empty TallyResult.
|
||||
func EmptyTallyResult() TallyResult {
|
||||
return NewTallyResult(sdk.ZeroInt(), sdk.ZeroInt(), sdk.ZeroInt(), sdk.ZeroInt())
|
||||
return NewTallyResult(math.ZeroInt(), math.ZeroInt(), math.ZeroInt(), math.ZeroInt())
|
||||
}
|
||||
|
||||
// Equals returns if two tally results are equal.
|
||||
|
||||
@ -51,7 +51,7 @@ func NewTallyResultFromMap(results map[VoteOption]sdk.Dec) TallyResult {
|
||||
|
||||
// EmptyTallyResult returns an empty TallyResult.
|
||||
func EmptyTallyResult() TallyResult {
|
||||
return NewTallyResult(sdk.ZeroInt(), sdk.ZeroInt(), sdk.ZeroInt(), sdk.ZeroInt())
|
||||
return NewTallyResult(math.ZeroInt(), math.ZeroInt(), math.ZeroInt(), math.ZeroInt())
|
||||
}
|
||||
|
||||
// Equals returns if two proposals are equal.
|
||||
|
||||
@ -277,6 +277,7 @@ func (k Keeper) abortProposals(ctx sdk.Context, groupPolicyAddr sdk.AccAddress)
|
||||
return err
|
||||
}
|
||||
|
||||
//nolint:gosec // "implicit memory aliasing in the for loop (because of the pointer on &proposalInfo)"
|
||||
for _, proposalInfo := range proposals {
|
||||
// Mark all proposals still in the voting phase as aborted.
|
||||
if proposalInfo.Status == group.PROPOSAL_STATUS_SUBMITTED {
|
||||
@ -321,6 +322,7 @@ func (k Keeper) pruneVotes(ctx sdk.Context, proposalID uint64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
//nolint:gosec // "implicit memory aliasing in the for loop (because of the pointer on &v)"
|
||||
for _, v := range votes {
|
||||
err = k.voteTable.Delete(ctx.KVStore(k.key), &v)
|
||||
if err != nil {
|
||||
@ -375,11 +377,13 @@ func (k Keeper) PruneProposals(ctx sdk.Context) error {
|
||||
// TallyProposalsAtVPEnd iterates over all proposals whose voting period
|
||||
// has ended, tallies their votes, prunes them, and updates the proposal's
|
||||
// `FinalTallyResult` field.
|
||||
|
||||
func (k Keeper) TallyProposalsAtVPEnd(ctx sdk.Context) error {
|
||||
proposals, err := k.proposalsByVPEnd(ctx, ctx.BlockTime())
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
//nolint:gosec // "implicit memory aliasing in the for loop (because of the pointers in the loop)"
|
||||
for _, proposal := range proposals {
|
||||
policyInfo, err := k.getGroupPolicyInfo(ctx, proposal.GroupPolicyAddress)
|
||||
if err != nil {
|
||||
|
||||
@ -7,6 +7,7 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
sdkmath "cosmossdk.io/math"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/module"
|
||||
@ -50,7 +51,7 @@ func TestRandomizedGenState(t *testing.T) {
|
||||
require.Equal(t, dec3, mintGenesis.Params.InflationMin)
|
||||
require.Equal(t, "stake", mintGenesis.Params.MintDenom)
|
||||
require.Equal(t, "0stake", mintGenesis.Minter.BlockProvision(mintGenesis.Params).String())
|
||||
require.Equal(t, "0.170000000000000000", mintGenesis.Minter.NextAnnualProvisions(mintGenesis.Params, sdk.OneInt()).String())
|
||||
require.Equal(t, "0.170000000000000000", mintGenesis.Minter.NextAnnualProvisions(mintGenesis.Params, math.OneInt()).String())
|
||||
require.Equal(t, "0.169999926644441493", mintGenesis.Minter.NextInflationRate(mintGenesis.Params, sdk.OneDec()).String())
|
||||
require.Equal(t, "0.170000000000000000", mintGenesis.Minter.Inflation.String())
|
||||
require.Equal(t, "0.000000000000000000", mintGenesis.Minter.AnnualProvisions.String())
|
||||
|
||||
@ -87,7 +87,7 @@ func TestBlockProvision(t *testing.T) {
|
||||
}
|
||||
|
||||
// Benchmarking :)
|
||||
// previously using sdk.Int operations:
|
||||
// previously using math.Int operations:
|
||||
// BenchmarkBlockProvision-4 5000000 220 ns/op
|
||||
//
|
||||
// using sdk.Dec operations: (current implementation)
|
||||
|
||||
@ -21,14 +21,14 @@ var (
|
||||
|
||||
// ParamTable for minting module.
|
||||
//
|
||||
// NOTE: Deprecated.
|
||||
// Deprecated.
|
||||
func ParamKeyTable() paramtypes.KeyTable {
|
||||
return paramtypes.NewKeyTable().RegisterParamSet(&Params{})
|
||||
}
|
||||
|
||||
// Implements params.ParamSet
|
||||
//
|
||||
// NOTE: Deprecated.
|
||||
// Deprecated.
|
||||
func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
|
||||
return paramtypes.ParamSetPairs{
|
||||
paramtypes.NewParamSetPair(KeyMintDenom, &p.MintDenom, validateMintDenom),
|
||||
|
||||
@ -4,6 +4,7 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
@ -189,7 +190,7 @@ func TestSubspace(t *testing.T) {
|
||||
{"uint16", uint16(1), uint16(0), new(uint16)},
|
||||
{"uint32", uint32(1), uint32(0), new(uint32)},
|
||||
{"uint64", uint64(1), uint64(0), new(uint64)},
|
||||
{"int", sdk.NewInt(1), *new(sdk.Int), new(sdk.Int)},
|
||||
{"int", sdk.NewInt(1), *new(math.Int), new(math.Int)},
|
||||
{"uint", sdk.NewUint(1), *new(sdk.Uint), new(sdk.Uint)},
|
||||
{"dec", sdk.NewDec(1), *new(sdk.Dec), new(sdk.Dec)},
|
||||
{"struct", s{1}, s{0}, new(s)},
|
||||
@ -204,7 +205,7 @@ func TestSubspace(t *testing.T) {
|
||||
types.NewParamSetPair([]byte("uint16"), uint16(0), validateNoOp),
|
||||
types.NewParamSetPair([]byte("uint32"), uint32(0), validateNoOp),
|
||||
types.NewParamSetPair([]byte("uint64"), uint64(0), validateNoOp),
|
||||
types.NewParamSetPair([]byte("int"), sdk.Int{}, validateNoOp),
|
||||
types.NewParamSetPair([]byte("int"), math.Int{}, validateNoOp),
|
||||
types.NewParamSetPair([]byte("uint"), sdk.Uint{}, validateNoOp),
|
||||
types.NewParamSetPair([]byte("dec"), sdk.Dec{}, validateNoOp),
|
||||
types.NewParamSetPair([]byte("struct"), s{}, validateNoOp),
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
package params_test
|
||||
|
||||
import (
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
"testing"
|
||||
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
|
||||
@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
"github.com/stretchr/testify/require"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
@ -64,7 +65,7 @@ func TestSlashingMsgs(t *testing.T) {
|
||||
commission := stakingtypes.NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec())
|
||||
|
||||
createValidatorMsg, err := stakingtypes.NewMsgCreateValidator(
|
||||
sdk.ValAddress(addr1), valKey.PubKey(), bondCoin, description, commission, sdk.OneInt(),
|
||||
sdk.ValAddress(addr1), valKey.PubKey(), bondCoin, description, commission, math.OneInt(),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -80,7 +81,7 @@ func TestSlashingMsgs(t *testing.T) {
|
||||
validator := checkValidator(t, app, addr1, true)
|
||||
require.Equal(t, sdk.ValAddress(addr1).String(), validator.OperatorAddress)
|
||||
require.Equal(t, stakingtypes.Bonded, validator.Status)
|
||||
require.True(sdk.IntEq(t, bondTokens, validator.BondedTokens()))
|
||||
require.True(math.IntEq(t, bondTokens, validator.BondedTokens()))
|
||||
unjailMsg := &types.MsgUnjail{ValidatorAddr: sdk.ValAddress(addr1).String()}
|
||||
|
||||
checkValidatorSigningInfo(t, app, sdk.ConsAddress(valAddr), true)
|
||||
|
||||
@ -25,7 +25,7 @@ The slashing module emits the following events:
|
||||
| slash | power | {validatorPower} |
|
||||
| slash | reason | {slashReason} |
|
||||
| slash | jailed [0] | {validatorConsensusAddress} |
|
||||
| slash | burned coins | {sdk.Int} |
|
||||
| slash | burned coins | {math.Int} |
|
||||
|
||||
* [0] Only included if the validator is jailed.
|
||||
|
||||
|
||||
@ -20,14 +20,14 @@ var (
|
||||
|
||||
// ParamKeyTable for slashing module
|
||||
//
|
||||
// NOTE: Deprecated.
|
||||
// Deprecated.
|
||||
func ParamKeyTable() paramtypes.KeyTable {
|
||||
return paramtypes.NewKeyTable().RegisterParamSet(&Params{})
|
||||
}
|
||||
|
||||
// ParamSetPairs - Implements params.ParamSet
|
||||
//
|
||||
// NOTE: Deprecated.
|
||||
// Deprecated.
|
||||
func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
|
||||
return paramtypes.ParamSetPairs{
|
||||
paramtypes.NewParamSetPair(KeySignedBlocksWindow, &p.SignedBlocksWindow, validateSignedBlocksWindow),
|
||||
|
||||
@ -3,6 +3,7 @@ package staking_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
"github.com/stretchr/testify/require"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
@ -65,7 +66,7 @@ func TestStakingMsgs(t *testing.T) {
|
||||
// create validator
|
||||
description := types.NewDescription("foo_moniker", "", "", "", "")
|
||||
createValidatorMsg, err := types.NewMsgCreateValidator(
|
||||
sdk.ValAddress(addr1), valKey.PubKey(), bondCoin, description, commissionRates, sdk.OneInt(),
|
||||
sdk.ValAddress(addr1), valKey.PubKey(), bondCoin, description, commissionRates, math.OneInt(),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -81,7 +82,7 @@ func TestStakingMsgs(t *testing.T) {
|
||||
validator := checkValidator(t, app, sdk.ValAddress(addr1), true)
|
||||
require.Equal(t, sdk.ValAddress(addr1).String(), validator.OperatorAddress)
|
||||
require.Equal(t, types.Bonded, validator.Status)
|
||||
require.True(sdk.IntEq(t, bondTokens, validator.BondedTokens()))
|
||||
require.True(math.IntEq(t, bondTokens, validator.BondedTokens()))
|
||||
|
||||
header = tmproto.Header{Height: app.LastBlockHeight() + 1}
|
||||
app.BeginBlock(abci.RequestBeginBlock{Header: header})
|
||||
|
||||
@ -1,11 +1,13 @@
|
||||
package staking_test
|
||||
|
||||
import (
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
@ -58,7 +60,7 @@ func getBaseSimappWithCustomKeeper(t *testing.T) (*codec.LegacyAmino, *simapp.Si
|
||||
}
|
||||
|
||||
// generateAddresses generates numAddrs of normal AccAddrs and ValAddrs
|
||||
func generateAddresses(app *simapp.SimApp, ctx sdk.Context, numAddrs int, accAmount sdk.Int) ([]sdk.AccAddress, []sdk.ValAddress) {
|
||||
func generateAddresses(app *simapp.SimApp, ctx sdk.Context, numAddrs int, accAmount math.Int) ([]sdk.AccAddress, []sdk.ValAddress) {
|
||||
addrDels := simapp.AddTestAddrsIncremental(app, ctx, numAddrs, accAmount)
|
||||
addrVals := simtestutil.ConvertAddrsToValAddrs(addrDels)
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@ package staking_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
@ -16,7 +17,7 @@ func TestValidateGenesis(t *testing.T) {
|
||||
genValidators1 := make([]types.Validator, 1, 5)
|
||||
pk := ed25519.GenPrivKey().PubKey()
|
||||
genValidators1[0] = teststaking.NewValidator(t, sdk.ValAddress(pk.Address()), pk)
|
||||
genValidators1[0].Tokens = sdk.OneInt()
|
||||
genValidators1[0].Tokens = math.OneInt()
|
||||
genValidators1[0].DelegatorShares = sdk.OneDec()
|
||||
|
||||
tests := []struct {
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
package keeper_test
|
||||
|
||||
import (
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
|
||||
@ -183,7 +183,7 @@ func (k Keeper) IterateUnbondingDelegations(ctx sdk.Context, fn func(index int64
|
||||
|
||||
// GetDelegatorUnbonding returns the total amount a delegator has unbonding.
|
||||
func (k Keeper) GetDelegatorUnbonding(ctx sdk.Context, delegator sdk.AccAddress) math.Int {
|
||||
unbonding := sdk.ZeroInt()
|
||||
unbonding := math.ZeroInt()
|
||||
k.IterateDelegatorUnbondingDelegations(ctx, delegator, func(ubd types.UnbondingDelegation) bool {
|
||||
for _, entry := range ubd.Entries {
|
||||
unbonding = unbonding.Add(entry.Balance)
|
||||
|
||||
@ -4,6 +4,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
@ -33,7 +34,7 @@ func TestDelegation(t *testing.T) {
|
||||
valAddrs := simtestutil.ConvertAddrsToValAddrs(addrDels)
|
||||
|
||||
// construct the validators
|
||||
amts := []sdk.Int{sdk.NewInt(9), sdk.NewInt(8), sdk.NewInt(7)}
|
||||
amts := []math.Int{sdk.NewInt(9), sdk.NewInt(8), sdk.NewInt(7)}
|
||||
var validators [3]types.Validator
|
||||
for i, amt := range amts {
|
||||
validators[i] = teststaking.NewValidator(t, valAddrs[i], PKs[i])
|
||||
@ -257,7 +258,7 @@ func TestUnbondingDelegationsMaxEntries(t *testing.T) {
|
||||
require.Equal(t, startTokens, issuedShares.RoundInt())
|
||||
|
||||
validator = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validator, true)
|
||||
require.True(sdk.IntEq(t, startTokens, validator.BondedTokens()))
|
||||
require.True(math.IntEq(t, startTokens, validator.BondedTokens()))
|
||||
require.True(t, validator.IsBonded())
|
||||
|
||||
delegation := types.NewDelegation(addrDels[0], addrVals[0], issuedShares)
|
||||
@ -278,8 +279,8 @@ func TestUnbondingDelegationsMaxEntries(t *testing.T) {
|
||||
|
||||
newBonded := app.BankKeeper.GetBalance(ctx, app.StakingKeeper.GetBondedPool(ctx).GetAddress(), bondDenom).Amount
|
||||
newNotBonded := app.BankKeeper.GetBalance(ctx, app.StakingKeeper.GetNotBondedPool(ctx).GetAddress(), bondDenom).Amount
|
||||
require.True(sdk.IntEq(t, newBonded, oldBonded.SubRaw(int64(maxEntries))))
|
||||
require.True(sdk.IntEq(t, newNotBonded, oldNotBonded.AddRaw(int64(maxEntries))))
|
||||
require.True(math.IntEq(t, newBonded, oldBonded.SubRaw(int64(maxEntries))))
|
||||
require.True(math.IntEq(t, newNotBonded, oldNotBonded.AddRaw(int64(maxEntries))))
|
||||
|
||||
oldBonded = app.BankKeeper.GetBalance(ctx, app.StakingKeeper.GetBondedPool(ctx).GetAddress(), bondDenom).Amount
|
||||
oldNotBonded = app.BankKeeper.GetBalance(ctx, app.StakingKeeper.GetNotBondedPool(ctx).GetAddress(), bondDenom).Amount
|
||||
@ -291,8 +292,8 @@ func TestUnbondingDelegationsMaxEntries(t *testing.T) {
|
||||
newBonded = app.BankKeeper.GetBalance(ctx, app.StakingKeeper.GetBondedPool(ctx).GetAddress(), bondDenom).Amount
|
||||
newNotBonded = app.BankKeeper.GetBalance(ctx, app.StakingKeeper.GetNotBondedPool(ctx).GetAddress(), bondDenom).Amount
|
||||
|
||||
require.True(sdk.IntEq(t, newBonded, oldBonded))
|
||||
require.True(sdk.IntEq(t, newNotBonded, oldNotBonded))
|
||||
require.True(math.IntEq(t, newBonded, oldBonded))
|
||||
require.True(math.IntEq(t, newNotBonded, oldNotBonded))
|
||||
|
||||
// mature unbonding delegations
|
||||
ctx = ctx.WithBlockTime(completionTime)
|
||||
@ -301,8 +302,8 @@ func TestUnbondingDelegationsMaxEntries(t *testing.T) {
|
||||
|
||||
newBonded = app.BankKeeper.GetBalance(ctx, app.StakingKeeper.GetBondedPool(ctx).GetAddress(), bondDenom).Amount
|
||||
newNotBonded = app.BankKeeper.GetBalance(ctx, app.StakingKeeper.GetNotBondedPool(ctx).GetAddress(), bondDenom).Amount
|
||||
require.True(sdk.IntEq(t, newBonded, oldBonded))
|
||||
require.True(sdk.IntEq(t, newNotBonded, oldNotBonded.SubRaw(int64(maxEntries))))
|
||||
require.True(math.IntEq(t, newBonded, oldBonded))
|
||||
require.True(math.IntEq(t, newNotBonded, oldNotBonded.SubRaw(int64(maxEntries))))
|
||||
|
||||
oldNotBonded = app.BankKeeper.GetBalance(ctx, app.StakingKeeper.GetNotBondedPool(ctx).GetAddress(), bondDenom).Amount
|
||||
|
||||
@ -312,8 +313,8 @@ func TestUnbondingDelegationsMaxEntries(t *testing.T) {
|
||||
|
||||
newBonded = app.BankKeeper.GetBalance(ctx, app.StakingKeeper.GetBondedPool(ctx).GetAddress(), bondDenom).Amount
|
||||
newNotBonded = app.BankKeeper.GetBalance(ctx, app.StakingKeeper.GetNotBondedPool(ctx).GetAddress(), bondDenom).Amount
|
||||
require.True(sdk.IntEq(t, newBonded, oldBonded.SubRaw(1)))
|
||||
require.True(sdk.IntEq(t, newNotBonded, oldNotBonded.AddRaw(1)))
|
||||
require.True(math.IntEq(t, newBonded, oldBonded.SubRaw(1)))
|
||||
require.True(math.IntEq(t, newNotBonded, oldNotBonded.AddRaw(1)))
|
||||
}
|
||||
|
||||
//// test undelegating self delegation from a validator pushing it below MinSelfDelegation
|
||||
|
||||
@ -3,6 +3,7 @@ package keeper
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@ -15,8 +16,8 @@ import (
|
||||
// data. Finally, it updates the bonded validators.
|
||||
// Returns final validator set after applying all declaration and delegations
|
||||
func (k Keeper) InitGenesis(ctx sdk.Context, data *types.GenesisState) (res []abci.ValidatorUpdate) {
|
||||
bondedTokens := sdk.ZeroInt()
|
||||
notBondedTokens := sdk.ZeroInt()
|
||||
bondedTokens := math.ZeroInt()
|
||||
notBondedTokens := math.ZeroInt()
|
||||
|
||||
// We need to pretend to be "n blocks before genesis", where "n" is the
|
||||
// validator update delay, so that e.g. slashing periods are correctly
|
||||
|
||||
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
"github.com/stretchr/testify/require"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
@ -171,7 +172,7 @@ func TestInitGenesisLargeValidatorSet(t *testing.T) {
|
||||
|
||||
var err error
|
||||
|
||||
bondedPoolAmt := sdk.ZeroInt()
|
||||
bondedPoolAmt := math.ZeroInt()
|
||||
for i := range validators {
|
||||
validators[i], err = types.NewValidator(
|
||||
sdk.ValAddress(addrs[i]),
|
||||
|
||||
@ -3,9 +3,10 @@ package keeper_test
|
||||
import (
|
||||
gocontext "context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@ package keeper_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
"github.com/stretchr/testify/require"
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
|
||||
@ -14,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
// IsValSetSorted reports whether valset is sorted.
|
||||
func IsValSetSorted(data []types.Validator, powerReduction sdk.Int) bool {
|
||||
func IsValSetSorted(data []types.Validator, powerReduction math.Int) bool {
|
||||
n := len(data)
|
||||
for i := n - 1; i > 0; i-- {
|
||||
if types.ValidatorsByVotingPower(data).Less(i, i-1, powerReduction) {
|
||||
|
||||
@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
@ -46,8 +47,8 @@ func AllInvariants(k *Keeper) sdk.Invariant {
|
||||
// reflects the tokens actively bonded and not bonded
|
||||
func ModuleAccountInvariants(k *Keeper) sdk.Invariant {
|
||||
return func(ctx sdk.Context) (string, bool) {
|
||||
bonded := sdk.ZeroInt()
|
||||
notBonded := sdk.ZeroInt()
|
||||
bonded := math.ZeroInt()
|
||||
notBonded := math.ZeroInt()
|
||||
bondedPool := k.GetBondedPool(ctx)
|
||||
notBondedPool := k.GetNotBondedPool(ctx)
|
||||
bondDenom := k.BondDenom(ctx)
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
"cosmossdk.io/math"
|
||||
"fmt"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
|
||||
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
|
||||
@ -47,7 +48,7 @@ func NewKeeper(
|
||||
|
||||
// ensure that authority is a valid AccAddress
|
||||
if _, err := sdk.AccAddressFromBech32(authority); err != nil {
|
||||
panic(fmt.Sprintf("authority is not a valid acc address"))
|
||||
panic(("authority is not a valid acc address"))
|
||||
}
|
||||
|
||||
return &Keeper{
|
||||
@ -80,7 +81,7 @@ func (k Keeper) GetLastTotalPower(ctx sdk.Context) math.Int {
|
||||
bz := store.Get(types.LastTotalPowerKey)
|
||||
|
||||
if bz == nil {
|
||||
return sdk.ZeroInt()
|
||||
return math.ZeroInt()
|
||||
}
|
||||
|
||||
ip := sdk.IntProto{}
|
||||
|
||||
@ -3,8 +3,8 @@ package keeper
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/exported"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/migrations/v2"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/migrations/v3"
|
||||
v2 "github.com/cosmos/cosmos-sdk/x/staking/migrations/v2"
|
||||
v3 "github.com/cosmos/cosmos-sdk/x/staking/migrations/v3"
|
||||
v4 "github.com/cosmos/cosmos-sdk/x/staking/migrations/v4"
|
||||
)
|
||||
|
||||
|
||||
@ -2,10 +2,11 @@ package keeper
|
||||
|
||||
import (
|
||||
"context"
|
||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
|
||||
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
"github.com/stretchr/testify/require"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
@ -25,7 +26,7 @@ func TestNewQuerier(t *testing.T) {
|
||||
addrVal1, _ := sdk.ValAddress(addrs[0]), sdk.ValAddress(addrs[1])
|
||||
|
||||
// Create Validators
|
||||
amts := []sdk.Int{sdk.NewInt(9), sdk.NewInt(8)}
|
||||
amts := []math.Int{sdk.NewInt(9), sdk.NewInt(8)}
|
||||
var validators [2]types.Validator
|
||||
for i, amt := range amts {
|
||||
validators[i] = teststaking.NewValidator(t, sdk.ValAddress(addrs[i]), PKs[i])
|
||||
@ -144,7 +145,7 @@ func TestQueryValidators(t *testing.T) {
|
||||
addrs := simapp.AddTestAddrs(app, ctx, 500, app.StakingKeeper.TokensFromConsensusPower(ctx, 10000))
|
||||
|
||||
// Create Validators
|
||||
amts := []sdk.Int{sdk.NewInt(8), sdk.NewInt(7)}
|
||||
amts := []math.Int{sdk.NewInt(8), sdk.NewInt(7)}
|
||||
status := []types.BondStatus{types.Unbonded, types.Unbonding}
|
||||
var validators [2]types.Validator
|
||||
for i, amt := range amts {
|
||||
|
||||
@ -106,7 +106,7 @@ func (k Keeper) Slash(ctx sdk.Context, consAddr sdk.ConsAddress, infractionHeigh
|
||||
|
||||
// cannot decrease balance below zero
|
||||
tokensToBurn := sdk.MinInt(remainingSlashAmount, validator.Tokens)
|
||||
tokensToBurn = sdk.MaxInt(tokensToBurn, sdk.ZeroInt()) // defensive.
|
||||
tokensToBurn = sdk.MaxInt(tokensToBurn, math.ZeroInt()) // defensive.
|
||||
|
||||
// we need to calculate the *effective* slash fraction for distribution
|
||||
if validator.Tokens.IsPositive() {
|
||||
@ -170,8 +170,8 @@ func (k Keeper) SlashUnbondingDelegation(ctx sdk.Context, unbondingDelegation ty
|
||||
infractionHeight int64, slashFactor sdk.Dec,
|
||||
) (totalSlashAmount math.Int) {
|
||||
now := ctx.BlockHeader().Time
|
||||
totalSlashAmount = sdk.ZeroInt()
|
||||
burnedAmount := sdk.ZeroInt()
|
||||
totalSlashAmount = math.ZeroInt()
|
||||
burnedAmount := math.ZeroInt()
|
||||
|
||||
// perform slashing on all entries within the unbonding delegation
|
||||
for i, entry := range unbondingDelegation.Entries {
|
||||
@ -224,8 +224,8 @@ func (k Keeper) SlashRedelegation(ctx sdk.Context, srcValidator types.Validator,
|
||||
infractionHeight int64, slashFactor sdk.Dec,
|
||||
) (totalSlashAmount math.Int) {
|
||||
now := ctx.BlockHeader().Time
|
||||
totalSlashAmount = sdk.ZeroInt()
|
||||
bondedBurnedAmount, notBondedBurnedAmount := sdk.ZeroInt(), sdk.ZeroInt()
|
||||
totalSlashAmount = math.ZeroInt()
|
||||
bondedBurnedAmount, notBondedBurnedAmount := math.ZeroInt(), math.ZeroInt()
|
||||
|
||||
// perform slashing on all entries within the redelegation
|
||||
for _, entry := range redelegation.Entries {
|
||||
|
||||
@ -4,6 +4,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
@ -422,10 +423,10 @@ func TestSlashWithRedelegation(t *testing.T) {
|
||||
|
||||
// burn bonded tokens from only from delegations
|
||||
bondedPoolBalance := app.BankKeeper.GetBalance(ctx, bondedPool.GetAddress(), bondDenom).Amount
|
||||
require.True(sdk.IntEq(t, oldBonded.Sub(burnAmount), bondedPoolBalance))
|
||||
require.True(math.IntEq(t, oldBonded.Sub(burnAmount), bondedPoolBalance))
|
||||
|
||||
notBondedPoolBalance := app.BankKeeper.GetBalance(ctx, notBondedPool.GetAddress(), bondDenom).Amount
|
||||
require.True(sdk.IntEq(t, oldNotBonded, notBondedPoolBalance))
|
||||
require.True(math.IntEq(t, oldNotBonded, notBondedPoolBalance))
|
||||
oldBonded = app.BankKeeper.GetBalance(ctx, bondedPool.GetAddress(), bondDenom).Amount
|
||||
|
||||
// read updating redelegation
|
||||
@ -454,14 +455,14 @@ func TestSlashWithRedelegation(t *testing.T) {
|
||||
|
||||
// seven bonded tokens burned
|
||||
bondedPoolBalance = app.BankKeeper.GetBalance(ctx, bondedPool.GetAddress(), bondDenom).Amount
|
||||
require.True(sdk.IntEq(t, oldBonded.Sub(burnAmount), bondedPoolBalance))
|
||||
require.True(sdk.IntEq(t, oldNotBonded, notBondedPoolBalance))
|
||||
require.True(math.IntEq(t, oldBonded.Sub(burnAmount), bondedPoolBalance))
|
||||
require.True(math.IntEq(t, oldNotBonded, notBondedPoolBalance))
|
||||
|
||||
bondedPoolBalance = app.BankKeeper.GetBalance(ctx, bondedPool.GetAddress(), bondDenom).Amount
|
||||
require.True(sdk.IntEq(t, oldBonded.Sub(burnAmount), bondedPoolBalance))
|
||||
require.True(math.IntEq(t, oldBonded.Sub(burnAmount), bondedPoolBalance))
|
||||
|
||||
notBondedPoolBalance = app.BankKeeper.GetBalance(ctx, notBondedPool.GetAddress(), bondDenom).Amount
|
||||
require.True(sdk.IntEq(t, oldNotBonded, notBondedPoolBalance))
|
||||
require.True(math.IntEq(t, oldNotBonded, notBondedPoolBalance))
|
||||
oldBonded = app.BankKeeper.GetBalance(ctx, bondedPool.GetAddress(), bondDenom).Amount
|
||||
|
||||
// read updating redelegation
|
||||
@ -489,9 +490,9 @@ func TestSlashWithRedelegation(t *testing.T) {
|
||||
notBondedPool = app.StakingKeeper.GetNotBondedPool(ctx)
|
||||
|
||||
bondedPoolBalance = app.BankKeeper.GetBalance(ctx, bondedPool.GetAddress(), bondDenom).Amount
|
||||
require.True(sdk.IntEq(t, oldBonded.Sub(burnAmount), bondedPoolBalance))
|
||||
require.True(math.IntEq(t, oldBonded.Sub(burnAmount), bondedPoolBalance))
|
||||
notBondedPoolBalance = app.BankKeeper.GetBalance(ctx, notBondedPool.GetAddress(), bondDenom).Amount
|
||||
require.True(sdk.IntEq(t, oldNotBonded, notBondedPoolBalance))
|
||||
require.True(math.IntEq(t, oldNotBonded, notBondedPoolBalance))
|
||||
oldBonded = app.BankKeeper.GetBalance(ctx, bondedPool.GetAddress(), bondDenom).Amount
|
||||
|
||||
// read updating redelegation
|
||||
@ -519,9 +520,9 @@ func TestSlashWithRedelegation(t *testing.T) {
|
||||
notBondedPool = app.StakingKeeper.GetNotBondedPool(ctx)
|
||||
|
||||
bondedPoolBalance = app.BankKeeper.GetBalance(ctx, bondedPool.GetAddress(), bondDenom).Amount
|
||||
require.True(sdk.IntEq(t, oldBonded, bondedPoolBalance))
|
||||
require.True(math.IntEq(t, oldBonded, bondedPoolBalance))
|
||||
notBondedPoolBalance = app.BankKeeper.GetBalance(ctx, notBondedPool.GetAddress(), bondDenom).Amount
|
||||
require.True(sdk.IntEq(t, oldNotBonded, notBondedPoolBalance))
|
||||
require.True(math.IntEq(t, oldNotBonded, notBondedPoolBalance))
|
||||
|
||||
// read updating redelegation
|
||||
rd, found = app.StakingKeeper.GetRedelegation(ctx, addrDels[0], addrVals[0], addrVals[1])
|
||||
@ -587,10 +588,10 @@ func TestSlashBoth(t *testing.T) {
|
||||
notBondedPool = app.StakingKeeper.GetNotBondedPool(ctx)
|
||||
|
||||
bondedPoolBalance := app.BankKeeper.GetBalance(ctx, bondedPool.GetAddress(), bondDenom).Amount
|
||||
require.True(sdk.IntEq(t, oldBonded.Sub(burnedBondAmount), bondedPoolBalance))
|
||||
require.True(math.IntEq(t, oldBonded.Sub(burnedBondAmount), bondedPoolBalance))
|
||||
|
||||
notBondedPoolBalance := app.BankKeeper.GetBalance(ctx, notBondedPool.GetAddress(), bondDenom).Amount
|
||||
require.True(sdk.IntEq(t, oldNotBonded.Sub(burnedNotBondedAmount), notBondedPoolBalance))
|
||||
require.True(math.IntEq(t, oldNotBonded.Sub(burnedNotBondedAmount), notBondedPoolBalance))
|
||||
|
||||
// read updating redelegation
|
||||
rdA, found = app.StakingKeeper.GetRedelegation(ctx, addrDels[0], addrVals[0], addrVals[1])
|
||||
@ -608,7 +609,7 @@ func TestSlashAmount(t *testing.T) {
|
||||
consAddr := sdk.ConsAddress(PKs[0].Address())
|
||||
fraction := sdk.NewDecWithPrec(5, 1)
|
||||
burnedCoins := app.StakingKeeper.Slash(ctx, consAddr, ctx.BlockHeight(), 10, fraction)
|
||||
require.True(t, burnedCoins.GT(sdk.ZeroInt()))
|
||||
require.True(t, burnedCoins.GT(math.ZeroInt()))
|
||||
|
||||
// test the case where the validator was not found, which should return no coins
|
||||
_, addrVals := generateAddresses(app, ctx, 100)
|
||||
|
||||
@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
gogotypes "github.com/gogo/protobuf/types"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
|
||||
@ -109,8 +110,8 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx sdk.Context) (updates []ab
|
||||
params := k.GetParams(ctx)
|
||||
maxValidators := params.MaxValidators
|
||||
powerReduction := k.PowerReduction(ctx)
|
||||
totalPower := sdk.ZeroInt()
|
||||
amtFromBondedToNotBonded, amtFromNotBondedToBonded := sdk.ZeroInt(), sdk.ZeroInt()
|
||||
totalPower := math.ZeroInt()
|
||||
amtFromBondedToNotBonded, amtFromNotBondedToBonded := math.ZeroInt(), math.ZeroInt()
|
||||
|
||||
// Retrieve the last validator set.
|
||||
// The persistent set is updated later in this function.
|
||||
|
||||
@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
@ -259,7 +260,7 @@ func TestValidatorBasics(t *testing.T) {
|
||||
for i, power := range powers {
|
||||
validators[i] = teststaking.NewValidator(t, addrVals[i], PKs[i])
|
||||
validators[i].Status = types.Unbonded
|
||||
validators[i].Tokens = sdk.ZeroInt()
|
||||
validators[i].Tokens = math.ZeroInt()
|
||||
tokens := app.StakingKeeper.TokensFromConsensusPower(ctx, power)
|
||||
|
||||
validators[i], _ = validators[i].AddTokensFromDel(tokens)
|
||||
@ -296,7 +297,7 @@ func TestValidatorBasics(t *testing.T) {
|
||||
require.Equal(t, 1, len(resVals))
|
||||
assert.True(ValEq(t, validators[0], resVals[0]))
|
||||
assert.Equal(t, types.Bonded, validators[0].Status)
|
||||
assert.True(sdk.IntEq(t, app.StakingKeeper.TokensFromConsensusPower(ctx, 9), validators[0].BondedTokens()))
|
||||
assert.True(math.IntEq(t, app.StakingKeeper.TokensFromConsensusPower(ctx, 9), validators[0].BondedTokens()))
|
||||
|
||||
// modify a records, save, and retrieve
|
||||
validators[0].Status = types.Bonded
|
||||
@ -341,7 +342,7 @@ func TestValidatorBasics(t *testing.T) {
|
||||
"attempting to remove a validator which still contains tokens",
|
||||
func() { app.StakingKeeper.RemoveValidator(ctx, validators[1].GetOperator()) })
|
||||
|
||||
validators[1].Tokens = sdk.ZeroInt() // ...remove all tokens
|
||||
validators[1].Tokens = math.ZeroInt() // ...remove all tokens
|
||||
app.StakingKeeper.SetValidator(ctx, validators[1]) // ...set the validator
|
||||
app.StakingKeeper.RemoveValidator(ctx, validators[1].GetOperator()) // Now it can be removed.
|
||||
_, found = app.StakingKeeper.GetValidator(ctx, addrVals[1])
|
||||
@ -353,7 +354,7 @@ func TestGetValidatorSortingUnmixed(t *testing.T) {
|
||||
app, ctx, addrs, _ := bootstrapValidatorTest(t, 1000, 20)
|
||||
|
||||
// initialize some validators into the state
|
||||
amts := []sdk.Int{
|
||||
amts := []math.Int{
|
||||
sdk.NewIntFromUint64(0),
|
||||
app.StakingKeeper.PowerReduction(ctx).MulRaw(100),
|
||||
app.StakingKeeper.PowerReduction(ctx),
|
||||
@ -447,7 +448,7 @@ func TestGetValidatorSortingMixed(t *testing.T) {
|
||||
app.StakingKeeper.SetParams(ctx, params)
|
||||
|
||||
// initialize some validators into the state
|
||||
amts := []sdk.Int{
|
||||
amts := []math.Int{
|
||||
sdk.NewIntFromUint64(0),
|
||||
app.StakingKeeper.PowerReduction(ctx).MulRaw(100),
|
||||
app.StakingKeeper.PowerReduction(ctx),
|
||||
|
||||
@ -7,7 +7,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/types/address"
|
||||
v042auth "github.com/cosmos/cosmos-sdk/x/auth/migrations/v042"
|
||||
v043distribution "github.com/cosmos/cosmos-sdk/x/distribution/migrations/v043"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/migrations/v1"
|
||||
v1 "github.com/cosmos/cosmos-sdk/x/staking/migrations/v1"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
|
||||
@ -4,11 +4,12 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"sort"
|
||||
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/exported"
|
||||
"math/rand"
|
||||
"sort"
|
||||
|
||||
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
"github.com/spf13/cobra"
|
||||
@ -160,11 +161,9 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
|
||||
m := keeper.NewMigrator(am.keeper, am.legacySubspace)
|
||||
if err := cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2); err != nil {
|
||||
panic(fmt.Sprintf("failed to migrate x/%s from version 1 to 2: %v", types.ModuleName, err))
|
||||
|
||||
}
|
||||
if err := cfg.RegisterMigration(types.ModuleName, 2, m.Migrate2to3); err != nil {
|
||||
panic(fmt.Sprintf("failed to migrate x/%s from version 2 to 3: %v", types.ModuleName, err))
|
||||
|
||||
}
|
||||
if err := cfg.RegisterMigration(types.ModuleName, 3, m.Migrate3to4); err != nil {
|
||||
panic(fmt.Sprintf("failed to migrate x/%s from version 3 to 4: %v", types.ModuleName, err))
|
||||
|
||||
@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
@ -39,12 +40,12 @@ func TestDecodeStore(t *testing.T) {
|
||||
val, err := types.NewValidator(valAddr1, delPk1, types.NewDescription("test", "test", "test", "test", "test"))
|
||||
require.NoError(t, err)
|
||||
del := types.NewDelegation(delAddr1, valAddr1, sdk.OneDec())
|
||||
ubd := types.NewUnbondingDelegation(delAddr1, valAddr1, 15, bondTime, sdk.OneInt())
|
||||
red := types.NewRedelegation(delAddr1, valAddr1, valAddr1, 12, bondTime, sdk.OneInt(), sdk.OneDec())
|
||||
ubd := types.NewUnbondingDelegation(delAddr1, valAddr1, 15, bondTime, math.OneInt())
|
||||
red := types.NewRedelegation(delAddr1, valAddr1, valAddr1, 12, bondTime, math.OneInt(), sdk.OneDec())
|
||||
|
||||
kvPairs := kv.Pairs{
|
||||
Pairs: []kv.Pair{
|
||||
{Key: types.LastTotalPowerKey, Value: cdc.MustMarshal(&sdk.IntProto{Int: sdk.OneInt()})},
|
||||
{Key: types.LastTotalPowerKey, Value: cdc.MustMarshal(&sdk.IntProto{Int: math.OneInt()})},
|
||||
{Key: types.GetValidatorKey(valAddr1), Value: cdc.MustMarshal(&val)},
|
||||
{Key: types.LastValidatorPowerKey, Value: valAddr1.Bytes()},
|
||||
{Key: types.GetDelegationKey(delAddr1, valAddr1), Value: cdc.MustMarshal(&del)},
|
||||
@ -58,7 +59,7 @@ func TestDecodeStore(t *testing.T) {
|
||||
name string
|
||||
expectedLog string
|
||||
}{
|
||||
{"LastTotalPower", fmt.Sprintf("%v\n%v", sdk.OneInt(), sdk.OneInt())},
|
||||
{"LastTotalPower", fmt.Sprintf("%v\n%v", math.OneInt(), math.OneInt())},
|
||||
{"Validator", fmt.Sprintf("%v\n%v", val, val)},
|
||||
{"LastValidatorPower/ValidatorsByConsAddr/ValidatorsByPowerIndex", fmt.Sprintf("%v\n%v", valAddr1, valAddr1)},
|
||||
{"Delegation", fmt.Sprintf("%v\n%v", del, del)},
|
||||
|
||||
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
|
||||
@ -159,7 +160,7 @@ func SimulateMsgCreateValidator(ak types.AccountKeeper, bk types.BankKeeper, k *
|
||||
simtypes.RandomDecAmount(r, maxCommission),
|
||||
)
|
||||
|
||||
msg, err := types.NewMsgCreateValidator(address, simAccount.ConsKey.PubKey(), selfDelegation, description, commission, sdk.OneInt())
|
||||
msg, err := types.NewMsgCreateValidator(address, simAccount.ConsKey.PubKey(), selfDelegation, description, commission, math.OneInt())
|
||||
if err != nil {
|
||||
return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to create CreateValidator message"), nil, err
|
||||
}
|
||||
|
||||
@ -13,7 +13,7 @@ Pool is used for tracking bonded and not-bonded token supply of the bond denomin
|
||||
LastTotalPower tracks the total amounts of bonded tokens recorded during the previous end block.
|
||||
Store entries prefixed with "Last" must remain unchanged until EndBlock.
|
||||
|
||||
* LastTotalPower: `0x12 -> ProtocolBuffer(sdk.Int)`
|
||||
* LastTotalPower: `0x12 -> ProtocolBuffer(math.Int)`
|
||||
|
||||
## Params
|
||||
|
||||
|
||||
@ -51,7 +51,7 @@ func (sh *Helper) CreateValidatorWithValPower(addr sdk.ValAddress, pk cryptotype
|
||||
// CreateValidatorMsg returns a message used to create validator in this service.
|
||||
func (sh *Helper) CreateValidatorMsg(addr sdk.ValAddress, pk cryptotypes.PubKey, stakeAmount math.Int) *stakingtypes.MsgCreateValidator {
|
||||
coin := sdk.NewCoin(sh.Denom, stakeAmount)
|
||||
msg, err := stakingtypes.NewMsgCreateValidator(addr, pk, coin, stakingtypes.Description{}, sh.Commission, sdk.OneInt())
|
||||
msg, err := stakingtypes.NewMsgCreateValidator(addr, pk, coin, stakingtypes.Description{}, sh.Commission, math.OneInt())
|
||||
require.NoError(sh.t, err)
|
||||
return msg
|
||||
}
|
||||
@ -62,7 +62,7 @@ func (sh *Helper) CreateValidatorWithMsg(ctx context.Context, msg *stakingtypes.
|
||||
}
|
||||
|
||||
func (sh *Helper) createValidator(addr sdk.ValAddress, pk cryptotypes.PubKey, coin sdk.Coin, ok bool) {
|
||||
msg, err := stakingtypes.NewMsgCreateValidator(addr, pk, coin, stakingtypes.Description{}, sh.Commission, sdk.OneInt())
|
||||
msg, err := stakingtypes.NewMsgCreateValidator(addr, pk, coin, stakingtypes.Description{}, sh.Commission, math.OneInt())
|
||||
require.NoError(sh.t, err)
|
||||
res, err := sh.msgSrvr.CreateValidator(sdk.WrapSDKContext(sh.Ctx), msg)
|
||||
if ok {
|
||||
|
||||
@ -7,6 +7,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
@ -26,7 +27,7 @@ var (
|
||||
func TestGetValidatorPowerRank(t *testing.T) {
|
||||
valAddr1 := sdk.ValAddress(keysAddr1)
|
||||
val1 := newValidator(t, valAddr1, keysPK1)
|
||||
val1.Tokens = sdk.ZeroInt()
|
||||
val1.Tokens = math.ZeroInt()
|
||||
val2, val3, val4 := val1, val1, val1
|
||||
val2.Tokens = sdk.TokensFromConsensusPower(1, sdk.DefaultPowerReduction)
|
||||
val3.Tokens = sdk.TokensFromConsensusPower(10, sdk.DefaultPowerReduction)
|
||||
|
||||
@ -1,11 +1,13 @@
|
||||
package types_test
|
||||
|
||||
import (
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
@ -40,7 +42,7 @@ func TestMsgDecode(t *testing.T) {
|
||||
// now let's try to serialize the whole message
|
||||
|
||||
commission1 := types.NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec())
|
||||
msg, err := types.NewMsgCreateValidator(valAddr1, pk1, coinPos, types.Description{}, commission1, sdk.OneInt())
|
||||
msg, err := types.NewMsgCreateValidator(valAddr1, pk1, coinPos, types.Description{}, commission1, math.OneInt())
|
||||
require.NoError(t, err)
|
||||
msgSerialized, err := cdc.MarshalInterface(msg)
|
||||
require.NoError(t, err)
|
||||
@ -62,22 +64,22 @@ func TestMsgCreateValidator(t *testing.T) {
|
||||
tests := []struct {
|
||||
name, moniker, identity, website, securityContact, details string
|
||||
CommissionRates types.CommissionRates
|
||||
minSelfDelegation sdk.Int
|
||||
minSelfDelegation math.Int
|
||||
validatorAddr sdk.ValAddress
|
||||
pubkey cryptotypes.PubKey
|
||||
bond sdk.Coin
|
||||
expectPass bool
|
||||
}{
|
||||
{"basic good", "a", "b", "c", "d", "e", commission1, sdk.OneInt(), valAddr1, pk1, coinPos, true},
|
||||
{"partial description", "", "", "c", "", "", commission1, sdk.OneInt(), valAddr1, pk1, coinPos, true},
|
||||
{"empty description", "", "", "", "", "", commission2, sdk.OneInt(), valAddr1, pk1, coinPos, false},
|
||||
{"empty address", "a", "b", "c", "d", "e", commission2, sdk.OneInt(), emptyAddr, pk1, coinPos, false},
|
||||
{"empty pubkey", "a", "b", "c", "d", "e", commission1, sdk.OneInt(), valAddr1, emptyPubkey, coinPos, false},
|
||||
{"empty bond", "a", "b", "c", "d", "e", commission2, sdk.OneInt(), valAddr1, pk1, coinZero, false},
|
||||
{"nil bond", "a", "b", "c", "d", "e", commission2, sdk.OneInt(), valAddr1, pk1, sdk.Coin{}, false},
|
||||
{"zero min self delegation", "a", "b", "c", "d", "e", commission1, sdk.ZeroInt(), valAddr1, pk1, coinPos, false},
|
||||
{"basic good", "a", "b", "c", "d", "e", commission1, math.OneInt(), valAddr1, pk1, coinPos, true},
|
||||
{"partial description", "", "", "c", "", "", commission1, math.OneInt(), valAddr1, pk1, coinPos, true},
|
||||
{"empty description", "", "", "", "", "", commission2, math.OneInt(), valAddr1, pk1, coinPos, false},
|
||||
{"empty address", "a", "b", "c", "d", "e", commission2, math.OneInt(), emptyAddr, pk1, coinPos, false},
|
||||
{"empty pubkey", "a", "b", "c", "d", "e", commission1, math.OneInt(), valAddr1, emptyPubkey, coinPos, false},
|
||||
{"empty bond", "a", "b", "c", "d", "e", commission2, math.OneInt(), valAddr1, pk1, coinZero, false},
|
||||
{"nil bond", "a", "b", "c", "d", "e", commission2, math.OneInt(), valAddr1, pk1, sdk.Coin{}, false},
|
||||
{"zero min self delegation", "a", "b", "c", "d", "e", commission1, math.ZeroInt(), valAddr1, pk1, coinPos, false},
|
||||
{"negative min self delegation", "a", "b", "c", "d", "e", commission1, sdk.NewInt(-1), valAddr1, pk1, coinPos, false},
|
||||
{"delegation less than min self delegation", "a", "b", "c", "d", "e", commission1, coinPos.Amount.Add(sdk.OneInt()), valAddr1, pk1, coinPos, false},
|
||||
{"delegation less than min self delegation", "a", "b", "c", "d", "e", commission1, coinPos.Amount.Add(math.OneInt()), valAddr1, pk1, coinPos, false},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
@ -98,13 +100,13 @@ func TestMsgEditValidator(t *testing.T) {
|
||||
name, moniker, identity, website, securityContact, details string
|
||||
validatorAddr sdk.ValAddress
|
||||
expectPass bool
|
||||
minSelfDelegation sdk.Int
|
||||
minSelfDelegation math.Int
|
||||
}{
|
||||
{"basic good", "a", "b", "c", "d", "e", valAddr1, true, sdk.OneInt()},
|
||||
{"partial description", "", "", "c", "", "", valAddr1, true, sdk.OneInt()},
|
||||
{"empty description", "", "", "", "", "", valAddr1, false, sdk.OneInt()},
|
||||
{"empty address", "a", "b", "c", "d", "e", emptyAddr, false, sdk.OneInt()},
|
||||
{"nil int", "a", "b", "c", "d", "e", emptyAddr, false, sdk.Int{}},
|
||||
{"basic good", "a", "b", "c", "d", "e", valAddr1, true, math.OneInt()},
|
||||
{"partial description", "", "", "c", "", "", valAddr1, true, math.OneInt()},
|
||||
{"empty description", "", "", "", "", "", valAddr1, false, math.OneInt()},
|
||||
{"empty address", "a", "b", "c", "d", "e", emptyAddr, false, math.OneInt()},
|
||||
{"nil int", "a", "b", "c", "d", "e", emptyAddr, false, math.Int{}},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
|
||||
@ -14,13 +14,13 @@ var (
|
||||
var _ paramtypes.ParamSet = (*Params)(nil)
|
||||
|
||||
// ParamTable for staking module
|
||||
// NOTE: Deprecated now params can be accesed on key `0x51` on the staking store.
|
||||
// Deprecated: now params can be accesed on key `0x51` on the staking store.
|
||||
func ParamKeyTable() paramtypes.KeyTable {
|
||||
return paramtypes.NewKeyTable().RegisterParamSet(&Params{})
|
||||
}
|
||||
|
||||
// Implements params.ParamSet
|
||||
// NOTE: Deprecated.
|
||||
// Deprecated.
|
||||
func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
|
||||
return paramtypes.ParamSetPairs{
|
||||
paramtypes.NewParamSetPair(KeyUnbondingTime, &p.UnbondingTime, validateUnbondingTime),
|
||||
|
||||
@ -51,13 +51,13 @@ func NewValidator(operator sdk.ValAddress, pubKey cryptotypes.PubKey, descriptio
|
||||
ConsensusPubkey: pkAny,
|
||||
Jailed: false,
|
||||
Status: Unbonded,
|
||||
Tokens: sdk.ZeroInt(),
|
||||
Tokens: math.ZeroInt(),
|
||||
DelegatorShares: sdk.ZeroDec(),
|
||||
Description: description,
|
||||
UnbondingHeight: int64(0),
|
||||
UnbondingTime: time.Unix(0, 0).UTC(),
|
||||
Commission: NewCommission(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()),
|
||||
MinSelfDelegation: sdk.OneInt(),
|
||||
MinSelfDelegation: math.OneInt(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@ -352,7 +352,7 @@ func (v Validator) BondedTokens() math.Int {
|
||||
return v.Tokens
|
||||
}
|
||||
|
||||
return sdk.ZeroInt()
|
||||
return math.ZeroInt()
|
||||
}
|
||||
|
||||
// ConsensusPower gets the consensus-engine power. Aa reduction of 10^6 from
|
||||
@ -424,7 +424,7 @@ func (v Validator) RemoveDelShares(delShares sdk.Dec) (Validator, math.Int) {
|
||||
if remainingShares.IsZero() {
|
||||
// last delegation share gets any trimmings
|
||||
issuedTokens = v.Tokens
|
||||
v.Tokens = sdk.ZeroInt()
|
||||
v.Tokens = math.ZeroInt()
|
||||
} else {
|
||||
// leave excess tokens in the validator
|
||||
// however fully use all the delegator shares
|
||||
|
||||
@ -5,6 +5,7 @@ import (
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
@ -105,7 +106,7 @@ func TestAddTokensValidatorBonded(t *testing.T) {
|
||||
validator, delShares := validator.AddTokensFromDel(sdk.NewInt(10))
|
||||
|
||||
assert.True(sdk.DecEq(t, sdk.NewDec(10), delShares))
|
||||
assert.True(sdk.IntEq(t, sdk.NewInt(10), validator.BondedTokens()))
|
||||
assert.True(math.IntEq(t, sdk.NewInt(10), validator.BondedTokens()))
|
||||
assert.True(sdk.DecEq(t, sdk.NewDec(10), validator.DelegatorShares))
|
||||
}
|
||||
|
||||
@ -116,7 +117,7 @@ func TestAddTokensValidatorUnbonding(t *testing.T) {
|
||||
|
||||
assert.True(sdk.DecEq(t, sdk.NewDec(10), delShares))
|
||||
assert.Equal(t, types.Unbonding, validator.Status)
|
||||
assert.True(sdk.IntEq(t, sdk.NewInt(10), validator.Tokens))
|
||||
assert.True(math.IntEq(t, sdk.NewInt(10), validator.Tokens))
|
||||
assert.True(sdk.DecEq(t, sdk.NewDec(10), validator.DelegatorShares))
|
||||
}
|
||||
|
||||
@ -127,7 +128,7 @@ func TestAddTokensValidatorUnbonded(t *testing.T) {
|
||||
|
||||
assert.True(sdk.DecEq(t, sdk.NewDec(10), delShares))
|
||||
assert.Equal(t, types.Unbonded, validator.Status)
|
||||
assert.True(sdk.IntEq(t, sdk.NewInt(10), validator.Tokens))
|
||||
assert.True(math.IntEq(t, sdk.NewInt(10), validator.Tokens))
|
||||
assert.True(sdk.DecEq(t, sdk.NewDec(10), validator.DelegatorShares))
|
||||
}
|
||||
|
||||
@ -151,7 +152,7 @@ func TestRemoveDelShares(t *testing.T) {
|
||||
validator := mkValidator(5102, sdk.NewDec(115))
|
||||
_, tokens := validator.RemoveDelShares(sdk.NewDec(29))
|
||||
|
||||
require.True(sdk.IntEq(t, sdk.NewInt(1286), tokens))
|
||||
require.True(math.IntEq(t, sdk.NewInt(1286), tokens))
|
||||
}
|
||||
|
||||
func TestAddTokensFromDel(t *testing.T) {
|
||||
@ -160,12 +161,12 @@ func TestAddTokensFromDel(t *testing.T) {
|
||||
validator, shares := validator.AddTokensFromDel(sdk.NewInt(6))
|
||||
require.True(sdk.DecEq(t, sdk.NewDec(6), shares))
|
||||
require.True(sdk.DecEq(t, sdk.NewDec(6), validator.DelegatorShares))
|
||||
require.True(sdk.IntEq(t, sdk.NewInt(6), validator.Tokens))
|
||||
require.True(math.IntEq(t, sdk.NewInt(6), validator.Tokens))
|
||||
|
||||
validator, shares = validator.AddTokensFromDel(sdk.NewInt(3))
|
||||
require.True(sdk.DecEq(t, sdk.NewDec(3), shares))
|
||||
require.True(sdk.DecEq(t, sdk.NewDec(9), validator.DelegatorShares))
|
||||
require.True(sdk.IntEq(t, sdk.NewInt(9), validator.Tokens))
|
||||
require.True(math.IntEq(t, sdk.NewInt(9), validator.Tokens))
|
||||
}
|
||||
|
||||
func TestUpdateStatus(t *testing.T) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user