fix: change SimulationState.InitialStake to sdkmath.Int (#11855)
* fix: change SimulationState.InitialStake to sdkmath.Int * cl * aleks' suggestion
This commit is contained in:
parent
348ff02276
commit
78618dbfa0
|
@ -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
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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"},
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue