Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: change SimulationState.InitialStake to sdkmath.Int #11855

Merged
merged 4 commits into from
May 2, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions simapp/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -147,10 +148,11 @@ 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
var initialStake sdkmath.Int
facundomedica marked this conversation as resolved.
Show resolved Hide resolved
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,
Expand Down
3 changes: 2 additions & 1 deletion types/module/simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion x/auth/simulation/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion x/auth/simulation/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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),
}

Expand Down
3 changes: 2 additions & 1 deletion x/authz/simulation/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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),
}

Expand Down
4 changes: 2 additions & 2 deletions x/bank/simulation/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
})
}

Expand All @@ -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{
Expand Down
3 changes: 2 additions & 1 deletion x/bank/simulation/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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),
}

Expand Down
3 changes: 2 additions & 1 deletion x/capability/simulation/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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),
}

Expand Down
3 changes: 2 additions & 1 deletion x/distribution/simulation/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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),
}

Expand Down
3 changes: 2 additions & 1 deletion x/evidence/simulation/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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),
}

Expand Down
3 changes: 2 additions & 1 deletion x/feegrant/simulation/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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),
}

Expand Down
3 changes: 2 additions & 1 deletion x/gov/simulation/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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),
}

Expand Down
3 changes: 2 additions & 1 deletion x/group/simulation/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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),
}

Expand Down
3 changes: 2 additions & 1 deletion x/mint/simulation/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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),
}

Expand Down
3 changes: 2 additions & 1 deletion x/nft/simulation/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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),
}

Expand Down
3 changes: 2 additions & 1 deletion x/slashing/simulation/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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),
}

Expand Down
6 changes: 3 additions & 3 deletions x/staking/simulation/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions x/staking/simulation/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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),
}

Expand Down Expand Up @@ -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"},
}
Expand Down