diff --git a/CHANGELOG.md b/CHANGELOG.md index 7023783dcb4..54b45815f27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -269,6 +269,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/authz) [\#11512](https://github.com/cosmos/cosmos-sdk/pull/11512) Fix response of a panic to error, when subtracting balances. * (rosetta) [\#11590](https://github.com/cosmos/cosmos-sdk/pull/11590) `/block` returns an error with nil pointer when a request has both of index and hash and increase timeout for huge genesis. * (x/feegrant) [\#11813](https://github.com/cosmos/cosmos-sdk/pull/11813) Fix pagination total count in `AllowancesByGranter` query. +* (simapp) [\#11855](https://github.com/cosmos/cosmos-sdk/pull/11855) Use `sdkmath.Int` instead of `int64` for `SimulationState.InitialStake`. ### State Machine Breaking diff --git a/simapp/state.go b/simapp/state.go index f888a45bcd8..add654b55f3 100644 --- a/simapp/state.go +++ b/simapp/state.go @@ -11,6 +11,7 @@ import ( tmjson "github.com/tendermint/tendermint/libs/json" tmtypes "github.com/tendermint/tendermint/types" + sdkmath "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" @@ -147,10 +148,13 @@ func AppStateRandomizedFn( // generate a random amount of initial stake coins and a random initial // number of bonded accounts - var initialStake, numInitiallyBonded int64 + var ( + numInitiallyBonded int64 + initialStake sdkmath.Int + ) appParams.GetOrGenerate( cdc, simappparams.StakePerAccount, &initialStake, r, - func(r *rand.Rand) { initialStake = r.Int63n(1e12) }, + func(r *rand.Rand) { initialStake = sdkmath.NewInt(r.Int63n(1e12)) }, ) appParams.GetOrGenerate( cdc, simappparams.InitiallyBondedValidators, &numInitiallyBonded, r, diff --git a/types/module/simulation.go b/types/module/simulation.go index 252cf268f83..21e6d99d7fb 100644 --- a/types/module/simulation.go +++ b/types/module/simulation.go @@ -6,6 +6,7 @@ import ( "math/rand" "time" + sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/simulation" @@ -103,7 +104,7 @@ type SimulationState struct { Rand *rand.Rand // random number GenState map[string]json.RawMessage // genesis state Accounts []simulation.Account // simulation accounts - InitialStake int64 // initial coins per account + InitialStake sdkmath.Int // initial coins per account NumBonded int64 // number of initially bonded accounts GenTimestamp time.Time // genesis timestamp UnbondTime time.Duration // staking unbond time stored to use it as the slashing maximum evidence duration diff --git a/x/auth/simulation/genesis.go b/x/auth/simulation/genesis.go index 2da36b54fa8..4b31bf7d49e 100644 --- a/x/auth/simulation/genesis.go +++ b/x/auth/simulation/genesis.go @@ -35,7 +35,7 @@ func RandomGenesisAccounts(simState *module.SimulationState) types.GenesisAccoun continue } - initialVesting := sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, simState.Rand.Int63n(simState.InitialStake))) + initialVesting := sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, simState.Rand.Int63n(simState.InitialStake.Int64()))) var endTime int64 startTime := simState.GenTimestamp.Unix() diff --git a/x/auth/simulation/genesis_test.go b/x/auth/simulation/genesis_test.go index 830a264ff4c..4b8f48ef76b 100644 --- a/x/auth/simulation/genesis_test.go +++ b/x/auth/simulation/genesis_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" + sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/types/module" @@ -31,7 +32,7 @@ func TestRandomizedGenState(t *testing.T) { Rand: r, NumBonded: 3, Accounts: simtypes.RandomAccounts(r, 3), - InitialStake: 1000, + InitialStake: sdkmath.NewInt(1000), GenState: make(map[string]json.RawMessage), } diff --git a/x/authz/simulation/genesis_test.go b/x/authz/simulation/genesis_test.go index 4236b068055..8f313be8eab 100644 --- a/x/authz/simulation/genesis_test.go +++ b/x/authz/simulation/genesis_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" + sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" @@ -26,7 +27,7 @@ func TestRandomizedGenState(t *testing.T) { Rand: r, NumBonded: 3, Accounts: simtypes.RandomAccounts(r, 3), - InitialStake: 1000, + InitialStake: sdkmath.NewInt(1000), GenState: make(map[string]json.RawMessage), } diff --git a/x/bank/simulation/genesis.go b/x/bank/simulation/genesis.go index 9031d033645..38e3b34b30d 100644 --- a/x/bank/simulation/genesis.go +++ b/x/bank/simulation/genesis.go @@ -43,7 +43,7 @@ func RandomGenesisBalances(simState *module.SimulationState) []types.Balance { for _, acc := range simState.Accounts { genesisBalances = append(genesisBalances, types.Balance{ Address: acc.Address.String(), - Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(simState.InitialStake))), + Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, simState.InitialStake)), }) } @@ -65,7 +65,7 @@ func RandomizedGenState(simState *module.SimulationState) { ) numAccs := int64(len(simState.Accounts)) - totalSupply := sdk.NewInt(simState.InitialStake * (numAccs + simState.NumBonded)) + totalSupply := simState.InitialStake.Mul(sdk.NewInt((numAccs + simState.NumBonded))) supply := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, totalSupply)) bankGenesis := types.GenesisState{ diff --git a/x/bank/simulation/genesis_test.go b/x/bank/simulation/genesis_test.go index fc31ca38e9e..d2b38f6d06e 100644 --- a/x/bank/simulation/genesis_test.go +++ b/x/bank/simulation/genesis_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" + sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/types/module" @@ -29,7 +30,7 @@ func TestRandomizedGenState(t *testing.T) { Rand: r, NumBonded: 3, Accounts: simtypes.RandomAccounts(r, 3), - InitialStake: 1000, + InitialStake: sdkmath.NewInt(1000), GenState: make(map[string]json.RawMessage), } diff --git a/x/capability/simulation/genesis_test.go b/x/capability/simulation/genesis_test.go index 16d54c177a5..14eb344cc09 100644 --- a/x/capability/simulation/genesis_test.go +++ b/x/capability/simulation/genesis_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" + sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/types/module" @@ -29,7 +30,7 @@ func TestRandomizedGenState(t *testing.T) { Rand: r, NumBonded: 3, Accounts: simtypes.RandomAccounts(r, 3), - InitialStake: 1000, + InitialStake: sdkmath.NewInt(1000), GenState: make(map[string]json.RawMessage), } diff --git a/x/distribution/simulation/genesis_test.go b/x/distribution/simulation/genesis_test.go index e923fbd4c83..259f0512d7a 100644 --- a/x/distribution/simulation/genesis_test.go +++ b/x/distribution/simulation/genesis_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" + sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -30,7 +31,7 @@ func TestRandomizedGenState(t *testing.T) { Rand: r, NumBonded: 3, Accounts: simtypes.RandomAccounts(r, 3), - InitialStake: 1000, + InitialStake: sdkmath.NewInt(1000), GenState: make(map[string]json.RawMessage), } diff --git a/x/evidence/simulation/genesis_test.go b/x/evidence/simulation/genesis_test.go index 8cfa086adc9..4999015bfd6 100644 --- a/x/evidence/simulation/genesis_test.go +++ b/x/evidence/simulation/genesis_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" + sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/types/module" @@ -30,7 +31,7 @@ func TestRandomizedGenState(t *testing.T) { Rand: r, NumBonded: 3, Accounts: simtypes.RandomAccounts(r, 3), - InitialStake: 1000, + InitialStake: sdkmath.NewInt(1000), GenState: make(map[string]json.RawMessage), } diff --git a/x/feegrant/simulation/genesis_test.go b/x/feegrant/simulation/genesis_test.go index 88f057dd0ff..44669c04be9 100644 --- a/x/feegrant/simulation/genesis_test.go +++ b/x/feegrant/simulation/genesis_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" + sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" @@ -28,7 +29,7 @@ func TestRandomizedGenState(t *testing.T) { Rand: r, NumBonded: 3, Accounts: accounts, - InitialStake: 1000, + InitialStake: sdkmath.NewInt(1000), GenState: make(map[string]json.RawMessage), } diff --git a/x/gov/simulation/genesis_test.go b/x/gov/simulation/genesis_test.go index 35de56cd275..281487751e3 100644 --- a/x/gov/simulation/genesis_test.go +++ b/x/gov/simulation/genesis_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" + sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -32,7 +33,7 @@ func TestRandomizedGenState(t *testing.T) { Rand: r, NumBonded: 3, Accounts: simtypes.RandomAccounts(r, 3), - InitialStake: 1000, + InitialStake: sdkmath.NewInt(1000), GenState: make(map[string]json.RawMessage), } diff --git a/x/group/simulation/genesis_test.go b/x/group/simulation/genesis_test.go index cf7b1cda673..03d660bf66a 100644 --- a/x/group/simulation/genesis_test.go +++ b/x/group/simulation/genesis_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" + sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" @@ -26,7 +27,7 @@ func TestRandomizedGenState(t *testing.T) { Rand: r, NumBonded: 3, Accounts: simtypes.RandomAccounts(r, 3), - InitialStake: 1000, + InitialStake: sdkmath.NewInt(1000), GenState: make(map[string]json.RawMessage), } diff --git a/x/mint/simulation/genesis_test.go b/x/mint/simulation/genesis_test.go index ac57da7acc0..93abcff65d9 100644 --- a/x/mint/simulation/genesis_test.go +++ b/x/mint/simulation/genesis_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" + sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -31,7 +32,7 @@ func TestRandomizedGenState(t *testing.T) { Rand: r, NumBonded: 3, Accounts: simtypes.RandomAccounts(r, 3), - InitialStake: 1000, + InitialStake: sdkmath.NewInt(1000), GenState: make(map[string]json.RawMessage), } diff --git a/x/nft/simulation/genesis_test.go b/x/nft/simulation/genesis_test.go index cfd3d1f6fde..3586229497a 100644 --- a/x/nft/simulation/genesis_test.go +++ b/x/nft/simulation/genesis_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" + sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" @@ -26,7 +27,7 @@ func TestRandomizedGenState(t *testing.T) { Rand: r, NumBonded: 3, Accounts: simtypes.RandomAccounts(r, 3), - InitialStake: 1000, + InitialStake: sdkmath.NewInt(1000), GenState: make(map[string]json.RawMessage), } diff --git a/x/slashing/simulation/genesis_test.go b/x/slashing/simulation/genesis_test.go index a386588d836..52ac75f7590 100644 --- a/x/slashing/simulation/genesis_test.go +++ b/x/slashing/simulation/genesis_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/require" + sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -32,7 +33,7 @@ func TestRandomizedGenState(t *testing.T) { Rand: r, NumBonded: 3, Accounts: simtypes.RandomAccounts(r, 3), - InitialStake: 1000, + InitialStake: sdkmath.NewInt(1000), GenState: make(map[string]json.RawMessage), } diff --git a/x/staking/simulation/genesis.go b/x/staking/simulation/genesis.go index f8737f7f7e0..afd393c1c77 100644 --- a/x/staking/simulation/genesis.go +++ b/x/staking/simulation/genesis.go @@ -89,11 +89,11 @@ func RandomizedGenState(simState *module.SimulationState) { if err != nil { panic(err) } - validator.Tokens = sdk.NewInt(simState.InitialStake) - validator.DelegatorShares = sdk.NewDec(simState.InitialStake) + validator.Tokens = simState.InitialStake + validator.DelegatorShares = sdk.NewDecFromInt(simState.InitialStake) validator.Commission = commission - delegation := types.NewDelegation(simState.Accounts[i].Address, valAddr, sdk.NewDec(simState.InitialStake)) + delegation := types.NewDelegation(simState.Accounts[i].Address, valAddr, sdk.NewDecFromInt(simState.InitialStake)) validators = append(validators, validator) delegations = append(delegations, delegation) diff --git a/x/staking/simulation/genesis_test.go b/x/staking/simulation/genesis_test.go index b7dae7dfb97..cbd2196b55a 100644 --- a/x/staking/simulation/genesis_test.go +++ b/x/staking/simulation/genesis_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" + sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" @@ -32,7 +33,7 @@ func TestRandomizedGenState(t *testing.T) { Rand: r, NumBonded: 3, Accounts: simtypes.RandomAccounts(r, 3), - InitialStake: 1000, + InitialStake: sdkmath.NewInt(1000), GenState: make(map[string]json.RawMessage), } @@ -94,7 +95,7 @@ func TestRandomizedGenState1(t *testing.T) { Rand: r, NumBonded: 4, Accounts: simtypes.RandomAccounts(r, 3), - InitialStake: 1000, + InitialStake: sdkmath.NewInt(1000), GenState: make(map[string]json.RawMessage), }, "invalid memory address or nil pointer dereference"}, }