From 153af67da09483798531f4cd6de5d3196824a506 Mon Sep 17 00:00:00 2001 From: tom Date: Thu, 23 Mar 2023 12:00:37 -0300 Subject: [PATCH] Revert "feat: add extend cb with genesisState for sim test (backport: #15305) (#15349)" This reverts commit f939979e11c21cfa8896cab7fbd6d2bdfa380063. --- CHANGELOG.md | 5 +---- simapp/state.go | 26 +++++++++++--------------- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a1cacf02a104..db9d0f2aacc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,10 +36,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ # Changelog ## [Unreleased] - -### Improvements - -* (simapp) [#15305](https://github.com/cosmos/cosmos-sdk/pull/15305) Add `AppStateFnWithExtendedCb` with callback function to extend rawState and `AppStateRandomizedFnWithState` with extra genesisState argument which is the genesis state of the app. +* (simapp) [#15305](https://github.com/cosmos/cosmos-sdk/pull/15305) Add `AppStateFnWithExtendedCb` with callback function to extend rawState. ### Bug Fixes diff --git a/simapp/state.go b/simapp/state.go index b5b858942c82..168fb9190b2c 100644 --- a/simapp/state.go +++ b/simapp/state.go @@ -27,6 +27,14 @@ 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) +} + +// 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. +// 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 { 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 { @@ -64,11 +72,11 @@ func AppStateFn(cdc codec.JSONCodec, simManager *module.SimulationManager) simty if err != nil { panic(err) } - appState, simAccs = AppStateRandomizedFnWithState(simManager, r, cdc, accs, genesisTimestamp, appParams, genesisState) + appState, simAccs = AppStateRandomizedFn(simManager, r, cdc, accs, genesisTimestamp, appParams) default: appParams := make(simtypes.AppParams) - appState, simAccs = AppStateRandomizedFnWithState(simManager, r, cdc, accs, genesisTimestamp, appParams, genesisState) + appState, simAccs = AppStateRandomizedFn(simManager, r, cdc, accs, genesisTimestamp, appParams) } rawState := make(map[string]json.RawMessage) @@ -141,21 +149,9 @@ func AppStateFn(cdc codec.JSONCodec, simManager *module.SimulationManager) simty func AppStateRandomizedFn( simManager *module.SimulationManager, r *rand.Rand, cdc codec.JSONCodec, accs []simtypes.Account, genesisTimestamp time.Time, appParams simtypes.AppParams, -) (json.RawMessage, []simtypes.Account) { - genesisState := NewDefaultGenesisState(cdc) - return AppStateRandomizedFnWithState(simManager, r, cdc, accs, genesisTimestamp, appParams, genesisState) -} - -// AppStateRandomizedFnWithState creates calls each module's GenesisState generator function -// and creates the simulation params -// genesisState is the genesis state of the app. -// This function will not exist in v0.47, but be replaced by AppStateRandomizedFn with an extra genesisState argument. -func AppStateRandomizedFnWithState( - 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