Merge PR #56: Update to latest SDK: Supply
This commit is contained in:
committed by
Alexander Bezobchuk
parent
534e56abd1
commit
bab3694437
509
app/sim_test.go
509
app/sim_test.go
@@ -14,26 +14,18 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
"github.com/tendermint/tendermint/crypto/secp256k1"
|
||||
dbm "github.com/tendermint/tendermint/libs/db"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/genaccounts"
|
||||
authsim "github.com/cosmos/cosmos-sdk/x/auth/simulation"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank"
|
||||
distr "github.com/cosmos/cosmos-sdk/x/distribution"
|
||||
distrsim "github.com/cosmos/cosmos-sdk/x/distribution/simulation"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov"
|
||||
govsim "github.com/cosmos/cosmos-sdk/x/gov/simulation"
|
||||
"github.com/cosmos/cosmos-sdk/x/mint"
|
||||
paramsim "github.com/cosmos/cosmos-sdk/x/params/simulation"
|
||||
"github.com/cosmos/cosmos-sdk/x/simulation"
|
||||
"github.com/cosmos/cosmos-sdk/x/slashing"
|
||||
slashingsim "github.com/cosmos/cosmos-sdk/x/slashing/simulation"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||
stakingsim "github.com/cosmos/cosmos-sdk/x/staking/simulation"
|
||||
@@ -76,38 +68,35 @@ func getSimulateFromSeedInput(tb testing.TB, w io.Writer, app *GaiaApp) (
|
||||
testAndRunTxs(app), invariants(app), numBlocks, blockSize, commit, lean, onOperation
|
||||
}
|
||||
|
||||
func appStateFromGenesisFileFn(
|
||||
r *rand.Rand, _ []simulation.Account, _ time.Time,
|
||||
) (json.RawMessage, []simulation.Account, string) {
|
||||
func appStateFn(
|
||||
r *rand.Rand, accs []simulation.Account, genesisTimestamp time.Time,
|
||||
) (appState json.RawMessage, simAccs []simulation.Account, chainID string) {
|
||||
|
||||
var genesis tmtypes.GenesisDoc
|
||||
cdc := MakeCodec()
|
||||
|
||||
bytes, err := ioutil.ReadFile(genesisFile)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
switch {
|
||||
case paramsFile != "" && genesisFile != "":
|
||||
panic("cannot provide both a genesis file and a params file")
|
||||
|
||||
case genesisFile != "":
|
||||
appState, simAccs, chainID = simapp.AppStateFromGenesisFileFn(r, accs, genesisTimestamp)
|
||||
|
||||
case paramsFile != "":
|
||||
appParams := make(simulation.AppParams)
|
||||
bz, err := ioutil.ReadFile(paramsFile)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
cdc.MustUnmarshalJSON(bz, &appParams)
|
||||
appState, simAccs, chainID = appStateRandomizedFn(r, accs, genesisTimestamp, appParams)
|
||||
|
||||
default:
|
||||
appParams := make(simulation.AppParams)
|
||||
appState, simAccs, chainID = appStateRandomizedFn(r, accs, genesisTimestamp, appParams)
|
||||
}
|
||||
|
||||
cdc.MustUnmarshalJSON(bytes, &genesis)
|
||||
|
||||
var appState GenesisState
|
||||
cdc.MustUnmarshalJSON(genesis.AppState, &appState)
|
||||
|
||||
accounts := genaccounts.GetGenesisStateFromAppState(cdc, appState)
|
||||
|
||||
var newAccs []simulation.Account
|
||||
for _, acc := range accounts {
|
||||
// Pick a random private key, since we don't know the actual key
|
||||
// This should be fine as it's only used for mock Tendermint validators
|
||||
// and these keys are never actually used to sign by mock Tendermint.
|
||||
privkeySeed := make([]byte, 15)
|
||||
r.Read(privkeySeed)
|
||||
|
||||
privKey := secp256k1.GenPrivKeySecp256k1(privkeySeed)
|
||||
newAccs = append(newAccs, simulation.Account{privKey, privKey.PubKey(), acc.Address})
|
||||
}
|
||||
|
||||
return genesis.AppState, newAccs, genesis.ChainID
|
||||
return appState, simAccs, chainID
|
||||
}
|
||||
|
||||
// TODO refactor out random initialization code to the modules
|
||||
@@ -116,7 +105,7 @@ func appStateRandomizedFn(
|
||||
) (json.RawMessage, []simulation.Account, string) {
|
||||
|
||||
cdc := MakeCodec()
|
||||
genesisState := NewDefaultGenesisState()
|
||||
genesisState := simapp.NewDefaultGenesisState()
|
||||
|
||||
var (
|
||||
amount int64
|
||||
@@ -142,14 +131,15 @@ func appStateRandomizedFn(
|
||||
`, amount, numInitiallyBonded,
|
||||
)
|
||||
|
||||
genGenesisAccounts(cdc, r, accs, genesisTimestamp, amount, numInitiallyBonded, genesisState)
|
||||
genAuthGenesisState(cdc, r, appParams, genesisState)
|
||||
genBankGenesisState(cdc, r, appParams, genesisState)
|
||||
genGovGenesisState(cdc, r, appParams, genesisState)
|
||||
genMintGenesisState(cdc, r, appParams, genesisState)
|
||||
genDistrGenesisState(cdc, r, appParams, genesisState)
|
||||
stakingGen := genStakingGenesisState(cdc, r, accs, amount, numAccs, numInitiallyBonded, appParams, genesisState)
|
||||
genSlashingGenesisState(cdc, r, stakingGen, appParams, genesisState)
|
||||
simapp.GenGenesisAccounts(cdc, r, accs, genesisTimestamp, amount, numInitiallyBonded, genesisState)
|
||||
simapp.GenAuthGenesisState(cdc, r, appParams, genesisState)
|
||||
simapp.GenBankGenesisState(cdc, r, appParams, genesisState)
|
||||
simapp.GenSupplyGenesisState(cdc, amount, numInitiallyBonded, int64(len(accs)), genesisState)
|
||||
simapp.GenGovGenesisState(cdc, r, appParams, genesisState)
|
||||
simapp.GenMintGenesisState(cdc, r, appParams, genesisState)
|
||||
simapp.GenDistrGenesisState(cdc, r, appParams, genesisState)
|
||||
stakingGen := simapp.GenStakingGenesisState(cdc, r, accs, amount, numAccs, numInitiallyBonded, appParams, genesisState)
|
||||
simapp.GenSlashingGenesisState(cdc, r, stakingGen, appParams, genesisState)
|
||||
|
||||
appState, err := MakeCodec().MarshalJSON(genesisState)
|
||||
if err != nil {
|
||||
@@ -159,417 +149,6 @@ func appStateRandomizedFn(
|
||||
return appState, accs, "simulation"
|
||||
}
|
||||
|
||||
func appStateFn(
|
||||
r *rand.Rand, accs []simulation.Account, genesisTimestamp time.Time,
|
||||
) (appState json.RawMessage, simAccs []simulation.Account, chainID string) {
|
||||
|
||||
cdc := MakeCodec()
|
||||
|
||||
switch {
|
||||
case paramsFile != "" && genesisFile != "":
|
||||
panic("cannot provide both a genesis file and a params file")
|
||||
|
||||
case genesisFile != "":
|
||||
appState, simAccs, chainID = appStateFromGenesisFileFn(r, accs, genesisTimestamp)
|
||||
|
||||
case paramsFile != "":
|
||||
appParams := make(simulation.AppParams)
|
||||
bz, err := ioutil.ReadFile(paramsFile)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
cdc.MustUnmarshalJSON(bz, &appParams)
|
||||
appState, simAccs, chainID = appStateRandomizedFn(r, accs, genesisTimestamp, appParams)
|
||||
|
||||
default:
|
||||
appParams := make(simulation.AppParams)
|
||||
appState, simAccs, chainID = appStateRandomizedFn(r, accs, genesisTimestamp, appParams)
|
||||
}
|
||||
|
||||
return appState, simAccs, chainID
|
||||
}
|
||||
|
||||
func genAuthGenesisState(cdc *codec.Codec, r *rand.Rand, ap simulation.AppParams, genesisState map[string]json.RawMessage) {
|
||||
authGenesis := auth.NewGenesisState(
|
||||
nil,
|
||||
auth.NewParams(
|
||||
func(r *rand.Rand) uint64 {
|
||||
var v uint64
|
||||
ap.GetOrGenerate(cdc, simulation.MaxMemoChars, &v, r,
|
||||
func(r *rand.Rand) {
|
||||
v = simulation.ModuleParamSimulator[simulation.MaxMemoChars](r).(uint64)
|
||||
})
|
||||
return v
|
||||
}(r),
|
||||
func(r *rand.Rand) uint64 {
|
||||
var v uint64
|
||||
ap.GetOrGenerate(cdc, simulation.TxSigLimit, &v, r,
|
||||
func(r *rand.Rand) {
|
||||
v = simulation.ModuleParamSimulator[simulation.TxSigLimit](r).(uint64)
|
||||
})
|
||||
return v
|
||||
}(r),
|
||||
func(r *rand.Rand) uint64 {
|
||||
var v uint64
|
||||
ap.GetOrGenerate(cdc, simulation.TxSizeCostPerByte, &v, r,
|
||||
func(r *rand.Rand) {
|
||||
v = simulation.ModuleParamSimulator[simulation.TxSizeCostPerByte](r).(uint64)
|
||||
})
|
||||
return v
|
||||
}(r),
|
||||
func(r *rand.Rand) uint64 {
|
||||
var v uint64
|
||||
ap.GetOrGenerate(cdc, simulation.SigVerifyCostED25519, &v, r,
|
||||
func(r *rand.Rand) {
|
||||
v = simulation.ModuleParamSimulator[simulation.SigVerifyCostED25519](r).(uint64)
|
||||
})
|
||||
return v
|
||||
}(r),
|
||||
func(r *rand.Rand) uint64 {
|
||||
var v uint64
|
||||
ap.GetOrGenerate(cdc, simulation.SigVerifyCostSECP256K1, &v, r,
|
||||
func(r *rand.Rand) {
|
||||
v = simulation.ModuleParamSimulator[simulation.SigVerifyCostSECP256K1](r).(uint64)
|
||||
})
|
||||
return v
|
||||
}(r),
|
||||
),
|
||||
)
|
||||
|
||||
fmt.Printf("Selected randomly generated auth parameters:\n%s\n", codec.MustMarshalJSONIndent(cdc, authGenesis.Params))
|
||||
genesisState[auth.ModuleName] = cdc.MustMarshalJSON(authGenesis)
|
||||
}
|
||||
|
||||
func genBankGenesisState(cdc *codec.Codec, r *rand.Rand, ap simulation.AppParams, genesisState map[string]json.RawMessage) {
|
||||
bankGenesis := bank.NewGenesisState(
|
||||
func(r *rand.Rand) bool {
|
||||
var v bool
|
||||
ap.GetOrGenerate(cdc, simulation.SendEnabled, &v, r,
|
||||
func(r *rand.Rand) {
|
||||
v = simulation.ModuleParamSimulator[simulation.SendEnabled](r).(bool)
|
||||
})
|
||||
return v
|
||||
}(r),
|
||||
)
|
||||
|
||||
fmt.Printf("Selected randomly generated bank parameters:\n%s\n", codec.MustMarshalJSONIndent(cdc, bankGenesis))
|
||||
genesisState[bank.ModuleName] = cdc.MustMarshalJSON(bankGenesis)
|
||||
}
|
||||
|
||||
func genGenesisAccounts(
|
||||
cdc *codec.Codec, r *rand.Rand, accs []simulation.Account,
|
||||
genesisTimestamp time.Time, amount, numInitiallyBonded int64,
|
||||
genesisState map[string]json.RawMessage,
|
||||
) {
|
||||
|
||||
var genesisAccounts []genaccounts.GenesisAccount
|
||||
|
||||
// randomly generate some genesis accounts
|
||||
for i, acc := range accs {
|
||||
coins := sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(amount))}
|
||||
bacc := auth.NewBaseAccountWithAddress(acc.Address)
|
||||
bacc.SetCoins(coins)
|
||||
|
||||
var gacc genaccounts.GenesisAccount
|
||||
|
||||
// Only consider making a vesting account once the initial bonded validator
|
||||
// set is exhausted due to needing to track DelegatedVesting.
|
||||
if int64(i) > numInitiallyBonded && r.Intn(100) < 50 {
|
||||
var (
|
||||
vacc auth.VestingAccount
|
||||
endTime int64
|
||||
)
|
||||
|
||||
startTime := genesisTimestamp.Unix()
|
||||
|
||||
// Allow for some vesting accounts to vest very quickly while others very slowly.
|
||||
if r.Intn(100) < 50 {
|
||||
endTime = int64(simulation.RandIntBetween(r, int(startTime), int(startTime+(60*60*24*30))))
|
||||
} else {
|
||||
endTime = int64(simulation.RandIntBetween(r, int(startTime), int(startTime+(60*60*12))))
|
||||
}
|
||||
|
||||
if startTime == endTime {
|
||||
endTime++
|
||||
}
|
||||
|
||||
if r.Intn(100) < 50 {
|
||||
vacc = auth.NewContinuousVestingAccount(&bacc, startTime, endTime)
|
||||
} else {
|
||||
vacc = auth.NewDelayedVestingAccount(&bacc, endTime)
|
||||
}
|
||||
|
||||
var err error
|
||||
gacc, err = genaccounts.NewGenesisAccountI(vacc)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
} else {
|
||||
gacc = genaccounts.NewGenesisAccount(&bacc)
|
||||
}
|
||||
|
||||
genesisAccounts = append(genesisAccounts, gacc)
|
||||
}
|
||||
|
||||
genesisState[genaccounts.ModuleName] = cdc.MustMarshalJSON(genesisAccounts)
|
||||
}
|
||||
|
||||
func genGovGenesisState(cdc *codec.Codec, r *rand.Rand, ap simulation.AppParams, genesisState map[string]json.RawMessage) {
|
||||
var vp time.Duration
|
||||
ap.GetOrGenerate(cdc, simulation.VotingParamsVotingPeriod, &vp, r,
|
||||
func(r *rand.Rand) {
|
||||
vp = simulation.ModuleParamSimulator[simulation.VotingParamsVotingPeriod](r).(time.Duration)
|
||||
})
|
||||
|
||||
govGenesis := gov.NewGenesisState(
|
||||
uint64(r.Intn(100)),
|
||||
gov.NewDepositParams(
|
||||
func(r *rand.Rand) sdk.Coins {
|
||||
var v sdk.Coins
|
||||
ap.GetOrGenerate(cdc, simulation.DepositParamsMinDeposit, &v, r,
|
||||
func(r *rand.Rand) {
|
||||
v = simulation.ModuleParamSimulator[simulation.DepositParamsMinDeposit](r).(sdk.Coins)
|
||||
})
|
||||
return v
|
||||
}(r),
|
||||
vp,
|
||||
),
|
||||
gov.NewVotingParams(vp),
|
||||
gov.NewTallyParams(
|
||||
func(r *rand.Rand) sdk.Dec {
|
||||
var v sdk.Dec
|
||||
ap.GetOrGenerate(cdc, simulation.TallyParamsQuorum, &v, r,
|
||||
func(r *rand.Rand) {
|
||||
v = simulation.ModuleParamSimulator[simulation.TallyParamsQuorum](r).(sdk.Dec)
|
||||
})
|
||||
return v
|
||||
}(r),
|
||||
func(r *rand.Rand) sdk.Dec {
|
||||
var v sdk.Dec
|
||||
ap.GetOrGenerate(cdc, simulation.TallyParamsThreshold, &v, r,
|
||||
func(r *rand.Rand) {
|
||||
v = simulation.ModuleParamSimulator[simulation.TallyParamsThreshold](r).(sdk.Dec)
|
||||
})
|
||||
return v
|
||||
}(r),
|
||||
func(r *rand.Rand) sdk.Dec {
|
||||
var v sdk.Dec
|
||||
ap.GetOrGenerate(cdc, simulation.TallyParamsVeto, &v, r,
|
||||
func(r *rand.Rand) {
|
||||
v = simulation.ModuleParamSimulator[simulation.TallyParamsVeto](r).(sdk.Dec)
|
||||
})
|
||||
return v
|
||||
}(r),
|
||||
),
|
||||
)
|
||||
|
||||
fmt.Printf("Selected randomly generated governance parameters:\n%s\n", codec.MustMarshalJSONIndent(cdc, govGenesis))
|
||||
genesisState[gov.ModuleName] = cdc.MustMarshalJSON(govGenesis)
|
||||
}
|
||||
|
||||
func genMintGenesisState(cdc *codec.Codec, r *rand.Rand, ap simulation.AppParams, genesisState map[string]json.RawMessage) {
|
||||
mintGenesis := mint.NewGenesisState(
|
||||
mint.InitialMinter(
|
||||
func(r *rand.Rand) sdk.Dec {
|
||||
var v sdk.Dec
|
||||
ap.GetOrGenerate(cdc, simulation.Inflation, &v, r,
|
||||
func(r *rand.Rand) {
|
||||
v = simulation.ModuleParamSimulator[simulation.Inflation](r).(sdk.Dec)
|
||||
})
|
||||
return v
|
||||
}(r),
|
||||
),
|
||||
mint.NewParams(
|
||||
sdk.DefaultBondDenom,
|
||||
func(r *rand.Rand) sdk.Dec {
|
||||
var v sdk.Dec
|
||||
ap.GetOrGenerate(cdc, simulation.InflationRateChange, &v, r,
|
||||
func(r *rand.Rand) {
|
||||
v = simulation.ModuleParamSimulator[simulation.InflationRateChange](r).(sdk.Dec)
|
||||
})
|
||||
return v
|
||||
}(r),
|
||||
func(r *rand.Rand) sdk.Dec {
|
||||
var v sdk.Dec
|
||||
ap.GetOrGenerate(cdc, simulation.InflationMax, &v, r,
|
||||
func(r *rand.Rand) {
|
||||
v = simulation.ModuleParamSimulator[simulation.InflationMax](r).(sdk.Dec)
|
||||
})
|
||||
return v
|
||||
}(r),
|
||||
func(r *rand.Rand) sdk.Dec {
|
||||
var v sdk.Dec
|
||||
ap.GetOrGenerate(cdc, simulation.InflationMin, &v, r,
|
||||
func(r *rand.Rand) {
|
||||
v = simulation.ModuleParamSimulator[simulation.InflationMin](r).(sdk.Dec)
|
||||
})
|
||||
return v
|
||||
}(r),
|
||||
func(r *rand.Rand) sdk.Dec {
|
||||
var v sdk.Dec
|
||||
ap.GetOrGenerate(cdc, simulation.GoalBonded, &v, r,
|
||||
func(r *rand.Rand) {
|
||||
v = simulation.ModuleParamSimulator[simulation.GoalBonded](r).(sdk.Dec)
|
||||
})
|
||||
return v
|
||||
}(r),
|
||||
uint64(60*60*8766/5),
|
||||
),
|
||||
)
|
||||
|
||||
fmt.Printf("Selected randomly generated minting parameters:\n%s\n", codec.MustMarshalJSONIndent(cdc, mintGenesis.Params))
|
||||
genesisState[mint.ModuleName] = cdc.MustMarshalJSON(mintGenesis)
|
||||
}
|
||||
|
||||
func genDistrGenesisState(cdc *codec.Codec, r *rand.Rand, ap simulation.AppParams, genesisState map[string]json.RawMessage) {
|
||||
distrGenesis := distr.GenesisState{
|
||||
FeePool: distr.InitialFeePool(),
|
||||
CommunityTax: func(r *rand.Rand) sdk.Dec {
|
||||
var v sdk.Dec
|
||||
ap.GetOrGenerate(cdc, simulation.CommunityTax, &v, r,
|
||||
func(r *rand.Rand) {
|
||||
v = simulation.ModuleParamSimulator[simulation.CommunityTax](r).(sdk.Dec)
|
||||
})
|
||||
return v
|
||||
}(r),
|
||||
BaseProposerReward: func(r *rand.Rand) sdk.Dec {
|
||||
var v sdk.Dec
|
||||
ap.GetOrGenerate(cdc, simulation.BaseProposerReward, &v, r,
|
||||
func(r *rand.Rand) {
|
||||
v = simulation.ModuleParamSimulator[simulation.BaseProposerReward](r).(sdk.Dec)
|
||||
})
|
||||
return v
|
||||
}(r),
|
||||
BonusProposerReward: func(r *rand.Rand) sdk.Dec {
|
||||
var v sdk.Dec
|
||||
ap.GetOrGenerate(cdc, simulation.BonusProposerReward, &v, r,
|
||||
func(r *rand.Rand) {
|
||||
v = simulation.ModuleParamSimulator[simulation.BonusProposerReward](r).(sdk.Dec)
|
||||
})
|
||||
return v
|
||||
}(r),
|
||||
}
|
||||
|
||||
fmt.Printf("Selected randomly generated distribution parameters:\n%s\n", codec.MustMarshalJSONIndent(cdc, distrGenesis))
|
||||
genesisState[distr.ModuleName] = cdc.MustMarshalJSON(distrGenesis)
|
||||
}
|
||||
|
||||
func genSlashingGenesisState(
|
||||
cdc *codec.Codec, r *rand.Rand, stakingGen staking.GenesisState,
|
||||
ap simulation.AppParams, genesisState map[string]json.RawMessage,
|
||||
) {
|
||||
slashingGenesis := slashing.NewGenesisState(
|
||||
slashing.NewParams(
|
||||
stakingGen.Params.UnbondingTime,
|
||||
func(r *rand.Rand) int64 {
|
||||
var v int64
|
||||
ap.GetOrGenerate(cdc, simulation.SignedBlocksWindow, &v, r,
|
||||
func(r *rand.Rand) {
|
||||
v = simulation.ModuleParamSimulator[simulation.SignedBlocksWindow](r).(int64)
|
||||
})
|
||||
return v
|
||||
}(r),
|
||||
func(r *rand.Rand) sdk.Dec {
|
||||
var v sdk.Dec
|
||||
ap.GetOrGenerate(cdc, simulation.MinSignedPerWindow, &v, r,
|
||||
func(r *rand.Rand) {
|
||||
v = simulation.ModuleParamSimulator[simulation.MinSignedPerWindow](r).(sdk.Dec)
|
||||
})
|
||||
return v
|
||||
}(r),
|
||||
func(r *rand.Rand) time.Duration {
|
||||
var v time.Duration
|
||||
ap.GetOrGenerate(cdc, simulation.DowntimeJailDuration, &v, r,
|
||||
func(r *rand.Rand) {
|
||||
v = simulation.ModuleParamSimulator[simulation.DowntimeJailDuration](r).(time.Duration)
|
||||
})
|
||||
return v
|
||||
}(r),
|
||||
func(r *rand.Rand) sdk.Dec {
|
||||
var v sdk.Dec
|
||||
ap.GetOrGenerate(cdc, simulation.SlashFractionDoubleSign, &v, r,
|
||||
func(r *rand.Rand) {
|
||||
v = simulation.ModuleParamSimulator[simulation.SlashFractionDoubleSign](r).(sdk.Dec)
|
||||
})
|
||||
return v
|
||||
}(r),
|
||||
func(r *rand.Rand) sdk.Dec {
|
||||
var v sdk.Dec
|
||||
ap.GetOrGenerate(cdc, simulation.SlashFractionDowntime, &v, r,
|
||||
func(r *rand.Rand) {
|
||||
v = simulation.ModuleParamSimulator[simulation.SlashFractionDowntime](r).(sdk.Dec)
|
||||
})
|
||||
return v
|
||||
}(r),
|
||||
),
|
||||
nil,
|
||||
nil,
|
||||
)
|
||||
|
||||
fmt.Printf("Selected randomly generated slashing parameters:\n%s\n", codec.MustMarshalJSONIndent(cdc, slashingGenesis.Params))
|
||||
genesisState[slashing.ModuleName] = cdc.MustMarshalJSON(slashingGenesis)
|
||||
}
|
||||
|
||||
func genStakingGenesisState(
|
||||
cdc *codec.Codec, r *rand.Rand, accs []simulation.Account, amount, numAccs, numInitiallyBonded int64,
|
||||
ap simulation.AppParams, genesisState map[string]json.RawMessage,
|
||||
) staking.GenesisState {
|
||||
|
||||
stakingGenesis := staking.NewGenesisState(
|
||||
staking.InitialPool(),
|
||||
staking.NewParams(
|
||||
func(r *rand.Rand) time.Duration {
|
||||
var v time.Duration
|
||||
ap.GetOrGenerate(cdc, simulation.UnbondingTime, &v, r,
|
||||
func(r *rand.Rand) {
|
||||
v = simulation.ModuleParamSimulator[simulation.UnbondingTime](r).(time.Duration)
|
||||
})
|
||||
return v
|
||||
}(r),
|
||||
func(r *rand.Rand) uint16 {
|
||||
var v uint16
|
||||
ap.GetOrGenerate(cdc, simulation.MaxValidators, &v, r,
|
||||
func(r *rand.Rand) {
|
||||
v = simulation.ModuleParamSimulator[simulation.MaxValidators](r).(uint16)
|
||||
})
|
||||
return v
|
||||
}(r),
|
||||
7,
|
||||
sdk.DefaultBondDenom,
|
||||
),
|
||||
nil,
|
||||
nil,
|
||||
)
|
||||
|
||||
var (
|
||||
validators []staking.Validator
|
||||
delegations []staking.Delegation
|
||||
)
|
||||
|
||||
valAddrs := make([]sdk.ValAddress, numInitiallyBonded)
|
||||
for i := 0; i < int(numInitiallyBonded); i++ {
|
||||
valAddr := sdk.ValAddress(accs[i].Address)
|
||||
valAddrs[i] = valAddr
|
||||
|
||||
validator := staking.NewValidator(valAddr, accs[i].PubKey, staking.Description{})
|
||||
validator.Tokens = sdk.NewInt(amount)
|
||||
validator.DelegatorShares = sdk.NewDec(amount)
|
||||
delegation := staking.NewDelegation(accs[i].Address, valAddr, sdk.NewDec(amount))
|
||||
validators = append(validators, validator)
|
||||
delegations = append(delegations, delegation)
|
||||
}
|
||||
|
||||
stakingGenesis.Pool.NotBondedTokens = sdk.NewInt((amount * numAccs) + (numInitiallyBonded * amount))
|
||||
stakingGenesis.Validators = validators
|
||||
stakingGenesis.Delegations = delegations
|
||||
|
||||
fmt.Printf("Selected randomly generated staking parameters:\n%s\n", codec.MustMarshalJSONIndent(cdc, stakingGenesis.Params))
|
||||
genesisState[staking.ModuleName] = cdc.MustMarshalJSON(stakingGenesis)
|
||||
|
||||
return stakingGenesis
|
||||
}
|
||||
|
||||
func testAndRunTxs(app *GaiaApp) []simulation.WeightedOperation {
|
||||
cdc := MakeCodec()
|
||||
ap := make(simulation.AppParams)
|
||||
@@ -593,7 +172,7 @@ func testAndRunTxs(app *GaiaApp) []simulation.WeightedOperation {
|
||||
})
|
||||
return v
|
||||
}(nil),
|
||||
authsim.SimulateDeductFee(app.accountKeeper, app.feeCollectionKeeper),
|
||||
authsim.SimulateDeductFee(app.accountKeeper, app.supplyKeeper),
|
||||
},
|
||||
{
|
||||
func(_ *rand.Rand) int {
|
||||
@@ -764,6 +343,11 @@ func testAndRunTxs(app *GaiaApp) []simulation.WeightedOperation {
|
||||
}
|
||||
|
||||
func invariants(app *GaiaApp) []sdk.Invariant {
|
||||
// TODO: fix PeriodicInvariants, it doesn't seem to call individual invariants for a period of 1
|
||||
// Ref: https://github.com/cosmos/cosmos-sdk/issues/4631
|
||||
if period == 1 {
|
||||
return app.crisisKeeper.Invariants()
|
||||
}
|
||||
return simulation.PeriodicInvariants(app.crisisKeeper.Invariants(), period, 0)
|
||||
}
|
||||
|
||||
@@ -891,7 +475,7 @@ func TestAppImportExport(t *testing.T) {
|
||||
newApp := NewGaiaApp(log.NewNopLogger(), newDB, nil, true, 0, fauxMerkleModeOpt)
|
||||
require.Equal(t, "GaiaApp", newApp.Name())
|
||||
|
||||
var genesisState GenesisState
|
||||
var genesisState simapp.GenesisState
|
||||
err = app.cdc.UnmarshalJSON(appState, &genesisState)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -917,7 +501,7 @@ func TestAppImportExport(t *testing.T) {
|
||||
{app.keySlashing, newApp.keySlashing, [][]byte{}},
|
||||
{app.keyMint, newApp.keyMint, [][]byte{}},
|
||||
{app.keyDistr, newApp.keyDistr, [][]byte{}},
|
||||
{app.keyFeeCollection, newApp.keyFeeCollection, [][]byte{}},
|
||||
{app.keySupply, newApp.keySupply, [][]byte{}},
|
||||
{app.keyParams, newApp.keyParams, [][]byte{}},
|
||||
{app.keyGov, newApp.keyGov, [][]byte{}},
|
||||
}
|
||||
@@ -930,10 +514,7 @@ func TestAppImportExport(t *testing.T) {
|
||||
storeB := ctxB.KVStore(storeKeyB)
|
||||
kvA, kvB, count, equal := sdk.DiffKVStores(storeA, storeB, prefixes)
|
||||
fmt.Printf("Compared %d key/value pairs between %s and %s\n", count, storeKeyA, storeKeyB)
|
||||
require.True(t, equal,
|
||||
"unequal stores: %s / %s:\nstore A %X => %X\nstore B %X => %X",
|
||||
storeKeyA, storeKeyB, kvA.Key, kvA.Value, kvB.Key, kvB.Value,
|
||||
)
|
||||
require.True(t, equal, simapp.GetSimulationLog(storeKeyA.Name(), app.cdc, newApp.cdc, kvA, kvB))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1077,7 +658,7 @@ func BenchmarkInvariants(b *testing.B) {
|
||||
for _, cr := range app.crisisKeeper.Routes() {
|
||||
b.Run(fmt.Sprintf("%s/%s", cr.ModuleName, cr.Route), func(b *testing.B) {
|
||||
if err := cr.Invar(ctx); err != nil {
|
||||
fmt.Println(err)
|
||||
fmt.Printf("broken invariant at block %d of %d\n%s", ctx.BlockHeight()-1, numBlocks, err)
|
||||
b.FailNow()
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user