-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
feat: add extend cb with genesisState for sim test (backport: #15305) #15349
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,14 +27,21 @@ import ( | |
// It panics if the user provides files for both of them. | ||
// If a file is not given for the genesis or the sim params, it creates a randomized one. | ||
func AppStateFn(cdc codec.JSONCodec, simManager *module.SimulationManager) simtypes.AppStateFn { | ||
return AppStateFnWithExtendedCb(cdc, simManager, nil) | ||
genesisState := NewDefaultGenesisState(cdc) | ||
return AppStateFnWithExtendedCb(cdc, simManager, genesisState, nil) | ||
} | ||
|
||
// AppStateFnWithExtendedCb returns the initial application state using a genesis or the simulation parameters. | ||
// It panics if the user provides files for both of them. | ||
// If a file is not given for the genesis or the sim params, it creates a randomized one. | ||
// genesisState is the genesis state of the app. | ||
// cb is the callback function to extend rawState. | ||
func AppStateFnWithExtendedCb(cdc codec.JSONCodec, simManager *module.SimulationManager, cb func(rawState map[string]json.RawMessage)) simtypes.AppStateFn { | ||
func AppStateFnWithExtendedCb( | ||
cdc codec.JSONCodec, | ||
simManager *module.SimulationManager, | ||
genesisState map[string]json.RawMessage, | ||
cb func(rawState map[string]json.RawMessage), | ||
) simtypes.AppStateFn { | ||
return func(r *rand.Rand, accs []simtypes.Account, config simtypes.Config, | ||
) (appState json.RawMessage, simAccs []simtypes.Account, chainID string, genesisTimestamp time.Time) { | ||
if FlagGenesisTimeValue == 0 { | ||
|
@@ -72,11 +79,11 @@ func AppStateFnWithExtendedCb(cdc codec.JSONCodec, simManager *module.Simulation | |
if err != nil { | ||
panic(err) | ||
} | ||
appState, simAccs = AppStateRandomizedFn(simManager, r, cdc, accs, genesisTimestamp, appParams) | ||
appState, simAccs = AppStateRandomizedFn(simManager, r, cdc, accs, genesisTimestamp, appParams, genesisState) | ||
|
||
default: | ||
appParams := make(simtypes.AppParams) | ||
appState, simAccs = AppStateRandomizedFn(simManager, r, cdc, accs, genesisTimestamp, appParams) | ||
appState, simAccs = AppStateRandomizedFn(simManager, r, cdc, accs, genesisTimestamp, appParams, genesisState) | ||
} | ||
|
||
rawState := make(map[string]json.RawMessage) | ||
|
@@ -154,9 +161,9 @@ func AppStateFnWithExtendedCb(cdc codec.JSONCodec, simManager *module.Simulation | |
func AppStateRandomizedFn( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doing this is API breaking in v0.46, can we have a changelog or revert? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can add a change log, but is it ok to pass in genesisState in since simapp might contains less modules? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know you've recently switched in Cronos and Crypto.org to use simapp's functions, but this was precisely why (but not clear) simapp should not be used, as it is specific to simapp. In v0.47 we've extracted these functions to be reusable by apps (#13379 (comment)). |
||
simManager *module.SimulationManager, r *rand.Rand, cdc codec.JSONCodec, | ||
accs []simtypes.Account, genesisTimestamp time.Time, appParams simtypes.AppParams, | ||
genesisState map[string]json.RawMessage, | ||
) (json.RawMessage, []simtypes.Account) { | ||
numAccs := int64(len(accs)) | ||
genesisState := NewDefaultGenesisState(cdc) | ||
|
||
// generate a random amount of initial stake coins and a random initial | ||
// number of bonded accounts | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.