From 657f3d68de8c92caa65c2fa5cb55a4e74e66398b Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 27 Sep 2022 18:45:29 +0200 Subject: [PATCH 1/6] refactor!: extract simulation helpers out of simapp --- CHANGELOG.md | 5 +- baseapp/baseapp.go | 1 - simapp/app.go | 3 - simapp/app_legacy.go | 3 - simapp/sim_bench_test.go | 29 +++++--- simapp/sim_test.go | 67 +++++++++++-------- simapp/state.go | 7 +- testutil/rest.go | 40 +++++++++++ testutil/rest/rest.go | 48 ------------- testutil/sims/app_helpers.go | 6 +- .../sims/simulation_helpers.go | 33 ++++----- .../sims/simulation_helpers_test.go | 21 ++---- x/authz/client/testutil/grpc.go | 10 +-- .../client/testutil/grpc_query_suite.go | 11 ++- x/gov/client/testutil/grpc.go | 15 ++--- .../simulation/client/cli/flags.go | 2 +- 16 files changed, 146 insertions(+), 155 deletions(-) delete mode 100644 testutil/rest/rest.go rename simapp/utils.go => testutil/sims/simulation_helpers.go (81%) rename simapp/utils_test.go => testutil/sims/simulation_helpers_test.go (71%) rename simapp/config.go => x/simulation/client/cli/flags.go (99%) diff --git a/CHANGELOG.md b/CHANGELOG.md index d08dcb773d94..794d082af8bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -114,8 +114,11 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes +* [#]() Move simulation flags to `x/simulation/client/cli`. +* [#]() Move simulation helpers functions (`SetupSimulation`, `SimulationOperations`, `CheckExportSimulation`, `PrintStats`, `GetSimulationLog`) to `testutil/sims`. +* [#]() Move `testutil/rest` package to `testutil`. * [#13380](https://github.com/cosmos/cosmos-sdk/pull/13380) Remove deprecated `sdk.NewLevelDB`. -* [#13378](https://github.com/cosmos/cosmos-sdk/pull/13378) Move `simapp.App` to `runtime.AppI`. `simapp.App` is now an alias of `runtime.AppI`. +* [#13378](https://github.com/cosmos/cosmos-sdk/pull/13378) Move `simapp.App` to `runtime.AppI`. * (tx) [#12659](https://github.com/cosmos/cosmos-sdk/pull/12659) Remove broadcast mode `block`. * (db) [#13370](https://github.com/cosmos/cosmos-sdk/pull/13370) remove storev2alpha1, see also https://github.com/cosmos/cosmos-sdk/pull/13371 * (context) [#13063](https://github.com/cosmos/cosmos-sdk/pull/13063) Update `Context#CacheContext` to automatically emit all events on the parent context's `EventManager`. diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 98d4b3bedd42..247099390985 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -270,7 +270,6 @@ func (app *BaseApp) MountStore(key storetypes.StoreKey, typ storetypes.StoreType // LoadLatestVersion loads the latest application version. It will panic if // called more than once on a running BaseApp. func (app *BaseApp) LoadLatestVersion() error { - err := app.storeLoader(app.cms) if err != nil { return fmt.Errorf("failed to load latest version: %w", err) diff --git a/simapp/app.go b/simapp/app.go index e6e3d3a87482..2784de096a2d 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -89,9 +89,6 @@ import ( ) var ( - // App is deprecated, use runtime.AppI instead - App runtime.AppI - // DefaultNodeHome default home directories for the application daemon DefaultNodeHome string diff --git a/simapp/app_legacy.go b/simapp/app_legacy.go index ba664d41f225..4fa8ca9ce863 100644 --- a/simapp/app_legacy.go +++ b/simapp/app_legacy.go @@ -100,9 +100,6 @@ import ( const appName = "SimApp" var ( - // App is deprecated, use runtime.AppI instead - App runtime.AppI - // DefaultNodeHome default home directories for the application daemon DefaultNodeHome string diff --git a/simapp/sim_bench_test.go b/simapp/sim_bench_test.go index ef43924b10d1..be559a51ea40 100644 --- a/simapp/sim_bench_test.go +++ b/simapp/sim_bench_test.go @@ -13,13 +13,18 @@ import ( simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/simulation" + simcli "github.com/cosmos/cosmos-sdk/x/simulation/client/cli" ) // Profile with: // /usr/local/go/bin/go test -benchmem -run=^$ cosmossdk.io/simapp -bench ^BenchmarkFullAppSimulation$ -Commit=true -cpuprofile cpu.out func BenchmarkFullAppSimulation(b *testing.B) { b.ReportAllocs() - config, db, dir, logger, skip, err := SetupSimulation("goleveldb-app-sim", "Simulation") + + config := simcli.NewConfigFromFlags() + config.ChainID = SimAppChainID + + db, dir, logger, skip, err := simtestutil.SetupSimulation(config, "goleveldb-app-sim", "Simulation", simcli.FlagVerboseValue, simcli.FlagEnabledValue) if err != nil { b.Fatalf("simulation setup failed: %s", err.Error()) } @@ -35,7 +40,7 @@ func BenchmarkFullAppSimulation(b *testing.B) { appOptions := make(simtestutil.AppOptionsMap, 0) appOptions[flags.FlagHome] = DefaultNodeHome - appOptions[server.FlagInvCheckPeriod] = FlagPeriodValue + appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue app := NewSimApp(logger, db, nil, true, appOptions, interBlockCacheOpt()) @@ -46,14 +51,14 @@ func BenchmarkFullAppSimulation(b *testing.B) { app.BaseApp, AppStateFn(app.AppCodec(), app.SimulationManager()), simtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1 - SimulationOperations(app, app.AppCodec(), config), + simtestutil.SimulationOperations(app, app.AppCodec(), config), ModuleAccountAddrs(), config, app.AppCodec(), ) // export state and simParams before the simulation error is checked - if err = CheckExportSimulation(app, config, simParams); err != nil { + if err = simtestutil.CheckExportSimulation(app, config, simParams); err != nil { b.Fatal(err) } @@ -62,13 +67,17 @@ func BenchmarkFullAppSimulation(b *testing.B) { } if config.Commit { - PrintStats(db) + simtestutil.PrintStats(db) } } func BenchmarkInvariants(b *testing.B) { b.ReportAllocs() - config, db, dir, logger, skip, err := SetupSimulation("leveldb-app-invariant-bench", "Simulation") + + config := simcli.NewConfigFromFlags() + config.ChainID = SimAppChainID + + db, dir, logger, skip, err := simtestutil.SetupSimulation(config, "leveldb-app-invariant-bench", "Simulation", simcli.FlagVerboseValue, simcli.FlagEnabledValue) if err != nil { b.Fatalf("simulation setup failed: %s", err.Error()) } @@ -86,7 +95,7 @@ func BenchmarkInvariants(b *testing.B) { appOptions := make(simtestutil.AppOptionsMap, 0) appOptions[flags.FlagHome] = DefaultNodeHome - appOptions[server.FlagInvCheckPeriod] = FlagPeriodValue + appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue app := NewSimApp(logger, db, nil, true, appOptions, interBlockCacheOpt()) @@ -97,14 +106,14 @@ func BenchmarkInvariants(b *testing.B) { app.BaseApp, AppStateFn(app.AppCodec(), app.SimulationManager()), simtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1 - SimulationOperations(app, app.AppCodec(), config), + simtestutil.SimulationOperations(app, app.AppCodec(), config), ModuleAccountAddrs(), config, app.AppCodec(), ) // export state and simParams before the simulation error is checked - if err = CheckExportSimulation(app, config, simParams); err != nil { + if err = simtestutil.CheckExportSimulation(app, config, simParams); err != nil { b.Fatal(err) } @@ -113,7 +122,7 @@ func BenchmarkInvariants(b *testing.B) { } if config.Commit { - PrintStats(db) + simtestutil.PrintStats(db) } ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight() + 1}) diff --git a/simapp/sim_test.go b/simapp/sim_test.go index ed96329cbace..bfa4bd2d352e 100644 --- a/simapp/sim_test.go +++ b/simapp/sim_test.go @@ -34,13 +34,17 @@ import ( minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/cosmos/cosmos-sdk/x/simulation" + simcli "github.com/cosmos/cosmos-sdk/x/simulation/client/cli" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) +// SimAppChainID hardcoded chainID for simulation +const SimAppChainID = "simulation-app" + // Get flags every time the simulator is run func init() { - GetSimulatorFlags() + simcli.GetSimulatorFlags() } type StoreKeysPrefixes struct { @@ -62,7 +66,10 @@ func interBlockCacheOpt() func(*baseapp.BaseApp) { } func TestFullAppSimulation(t *testing.T) { - config, db, dir, logger, skip, err := SetupSimulation("leveldb-app-sim", "Simulation") + config := simcli.NewConfigFromFlags() + config.ChainID = SimAppChainID + + db, dir, logger, skip, err := simtestutil.SetupSimulation(config, "leveldb-app-sim", "Simulation", simcli.FlagVerboseValue, simcli.FlagEnabledValue) if skip { t.Skip("skipping application simulation") } @@ -75,7 +82,7 @@ func TestFullAppSimulation(t *testing.T) { appOptions := make(simtestutil.AppOptionsMap, 0) appOptions[flags.FlagHome] = DefaultNodeHome - appOptions[server.FlagInvCheckPeriod] = FlagPeriodValue + appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue app := NewSimApp(logger, db, nil, true, appOptions, fauxMerkleModeOpt) require.Equal(t, "SimApp", app.Name()) @@ -87,24 +94,27 @@ func TestFullAppSimulation(t *testing.T) { app.BaseApp, AppStateFn(app.AppCodec(), app.SimulationManager()), simtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1 - SimulationOperations(app, app.AppCodec(), config), + simtestutil.SimulationOperations(app, app.AppCodec(), config), ModuleAccountAddrs(), config, app.AppCodec(), ) // export state and simParams before the simulation error is checked - err = CheckExportSimulation(app, config, simParams) + err = simtestutil.CheckExportSimulation(app, config, simParams) require.NoError(t, err) require.NoError(t, simErr) if config.Commit { - PrintStats(db) + simtestutil.PrintStats(db) } } func TestAppImportExport(t *testing.T) { - config, db, dir, logger, skip, err := SetupSimulation("leveldb-app-sim", "Simulation") + config := simcli.NewConfigFromFlags() + config.ChainID = SimAppChainID + + db, dir, logger, skip, err := simtestutil.SetupSimulation(config, "leveldb-app-sim", "Simulation", simcli.FlagVerboseValue, simcli.FlagEnabledValue) if skip { t.Skip("skipping application import/export simulation") } @@ -117,7 +127,7 @@ func TestAppImportExport(t *testing.T) { appOptions := make(simtestutil.AppOptionsMap, 0) appOptions[flags.FlagHome] = DefaultNodeHome - appOptions[server.FlagInvCheckPeriod] = FlagPeriodValue + appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue app := NewSimApp(logger, db, nil, true, appOptions, fauxMerkleModeOpt) require.Equal(t, "SimApp", app.Name()) @@ -129,19 +139,19 @@ func TestAppImportExport(t *testing.T) { app.BaseApp, AppStateFn(app.AppCodec(), app.SimulationManager()), simtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1 - SimulationOperations(app, app.AppCodec(), config), + simtestutil.SimulationOperations(app, app.AppCodec(), config), ModuleAccountAddrs(), config, app.AppCodec(), ) // export state and simParams before the simulation error is checked - err = CheckExportSimulation(app, config, simParams) + err = simtestutil.CheckExportSimulation(app, config, simParams) require.NoError(t, err) require.NoError(t, simErr) if config.Commit { - PrintStats(db) + simtestutil.PrintStats(db) } fmt.Printf("exporting genesis...\n") @@ -151,7 +161,7 @@ func TestAppImportExport(t *testing.T) { fmt.Printf("importing genesis...\n") - _, newDB, newDir, _, _, err := SetupSimulation("leveldb-app-sim-2", "Simulation-2") + newDB, newDir, _, _, err := simtestutil.SetupSimulation(config, "leveldb-app-sim-2", "Simulation-2", simcli.FlagVerboseValue, simcli.FlagEnabledValue) require.NoError(t, err, "simulation setup failed") defer func() { @@ -212,12 +222,15 @@ func TestAppImportExport(t *testing.T) { require.Equal(t, len(failedKVAs), len(failedKVBs), "unequal sets of key-values to compare") fmt.Printf("compared %d different key/value pairs between %s and %s\n", len(failedKVAs), skp.A, skp.B) - require.Equal(t, 0, len(failedKVAs), GetSimulationLog(skp.A.Name(), app.SimulationManager().StoreDecoders, failedKVAs, failedKVBs)) + require.Equal(t, 0, len(failedKVAs), simtestutil.GetSimulationLog(skp.A.Name(), app.SimulationManager().StoreDecoders, failedKVAs, failedKVBs)) } } func TestAppSimulationAfterImport(t *testing.T) { - config, db, dir, logger, skip, err := SetupSimulation("leveldb-app-sim", "Simulation") + config := simcli.NewConfigFromFlags() + config.ChainID = SimAppChainID + + db, dir, logger, skip, err := simtestutil.SetupSimulation(config, "leveldb-app-sim", "Simulation", simcli.FlagVerboseValue, simcli.FlagEnabledValue) if skip { t.Skip("skipping application simulation after import") } @@ -230,7 +243,7 @@ func TestAppSimulationAfterImport(t *testing.T) { appOptions := make(simtestutil.AppOptionsMap, 0) appOptions[flags.FlagHome] = DefaultNodeHome - appOptions[server.FlagInvCheckPeriod] = FlagPeriodValue + appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue app := NewSimApp(logger, db, nil, true, appOptions, fauxMerkleModeOpt) require.Equal(t, "SimApp", app.Name()) @@ -242,19 +255,19 @@ func TestAppSimulationAfterImport(t *testing.T) { app.BaseApp, AppStateFn(app.AppCodec(), app.SimulationManager()), simtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1 - SimulationOperations(app, app.AppCodec(), config), + simtestutil.SimulationOperations(app, app.AppCodec(), config), ModuleAccountAddrs(), config, app.AppCodec(), ) // export state and simParams before the simulation error is checked - err = CheckExportSimulation(app, config, simParams) + err = simtestutil.CheckExportSimulation(app, config, simParams) require.NoError(t, err) require.NoError(t, simErr) if config.Commit { - PrintStats(db) + simtestutil.PrintStats(db) } if stopEarly { @@ -269,7 +282,7 @@ func TestAppSimulationAfterImport(t *testing.T) { fmt.Printf("importing genesis...\n") - _, newDB, newDir, _, _, err := SetupSimulation("leveldb-app-sim-2", "Simulation-2") + newDB, newDir, _, _, err := simtestutil.SetupSimulation(config, "leveldb-app-sim-2", "Simulation-2", simcli.FlagVerboseValue, simcli.FlagEnabledValue) require.NoError(t, err, "simulation setup failed") defer func() { @@ -290,7 +303,7 @@ func TestAppSimulationAfterImport(t *testing.T) { newApp.BaseApp, AppStateFn(app.AppCodec(), app.SimulationManager()), simtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1 - SimulationOperations(newApp, newApp.AppCodec(), config), + simtestutil.SimulationOperations(newApp, newApp.AppCodec(), config), ModuleAccountAddrs(), config, app.AppCodec(), @@ -301,16 +314,16 @@ func TestAppSimulationAfterImport(t *testing.T) { // TODO: Make another test for the fuzzer itself, which just has noOp txs // and doesn't depend on the application. func TestAppStateDeterminism(t *testing.T) { - if !FlagEnabledValue { + if !simcli.FlagEnabledValue { t.Skip("skipping application simulation") } - config := NewConfigFromFlags() + config := simcli.NewConfigFromFlags() config.InitialBlockHeight = 1 config.ExportParamsPath = "" config.OnOperation = false config.AllInvariants = false - config.ChainID = simtestutil.SimAppChainID + config.ChainID = SimAppChainID numSeeds := 3 numTimesToRunPerSeed := 5 @@ -318,14 +331,14 @@ func TestAppStateDeterminism(t *testing.T) { appOptions := make(simtestutil.AppOptionsMap, 0) appOptions[flags.FlagHome] = DefaultNodeHome - appOptions[server.FlagInvCheckPeriod] = FlagPeriodValue + appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue for i := 0; i < numSeeds; i++ { config.Seed = rand.Int63() for j := 0; j < numTimesToRunPerSeed; j++ { var logger log.Logger - if FlagVerboseValue { + if simcli.FlagVerboseValue { logger = log.TestingLogger() } else { logger = log.NewNopLogger() @@ -345,7 +358,7 @@ func TestAppStateDeterminism(t *testing.T) { app.BaseApp, AppStateFn(app.AppCodec(), app.SimulationManager()), simtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1 - SimulationOperations(app, app.AppCodec(), config), + simtestutil.SimulationOperations(app, app.AppCodec(), config), ModuleAccountAddrs(), config, app.AppCodec(), @@ -353,7 +366,7 @@ func TestAppStateDeterminism(t *testing.T) { require.NoError(t, err) if config.Commit { - PrintStats(db) + simtestutil.PrintStats(db) } appHash := app.LastCommitID().Hash diff --git a/simapp/state.go b/simapp/state.go index 0fb2a333d36a..29b3259ffe78 100644 --- a/simapp/state.go +++ b/simapp/state.go @@ -20,6 +20,7 @@ import ( simtypes "github.com/cosmos/cosmos-sdk/types/simulation" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + simcli "github.com/cosmos/cosmos-sdk/x/simulation/client/cli" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -29,10 +30,10 @@ import ( func AppStateFn(cdc codec.JSONCodec, simManager *module.SimulationManager) 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 { + if simcli.FlagGenesisTimeValue == 0 { genesisTimestamp = simtypes.RandTimestamp(r) } else { - genesisTimestamp = time.Unix(FlagGenesisTimeValue, 0) + genesisTimestamp = time.Unix(simcli.FlagGenesisTimeValue, 0) } chainID = config.ChainID @@ -44,7 +45,7 @@ func AppStateFn(cdc codec.JSONCodec, simManager *module.SimulationManager) simty // override the default chain-id from simapp to set it later to the config genesisDoc, accounts := AppStateFromGenesisFileFn(r, cdc, config.GenesisFile) - if FlagGenesisTimeValue == 0 { + if simcli.FlagGenesisTimeValue == 0 { // use genesis timestamp if no custom timestamp is provided (i.e no random timestamp) genesisTimestamp = genesisDoc.GenesisTime } diff --git a/testutil/rest.go b/testutil/rest.go index 58e6c39b197e..b3c52e3adbc3 100644 --- a/testutil/rest.go +++ b/testutil/rest.go @@ -1,6 +1,8 @@ package testutil import ( + "bytes" + "fmt" "io" "net/http" ) @@ -36,3 +38,41 @@ func GetRequestWithHeaders(url string, headers map[string]string) ([]byte, error return body, nil } + +// GetRequest defines a wrapper around an HTTP GET request with a provided URL. +// An error is returned if the request or reading the body fails. +func GetRequest(url string) ([]byte, error) { + res, err := http.Get(url) //nolint:gosec + if err != nil { + return nil, err + } + defer func() { + _ = res.Body.Close() + }() + + body, err := io.ReadAll(res.Body) + if err != nil { + return nil, err + } + + return body, nil +} + +// PostRequest defines a wrapper around an HTTP POST request with a provided URL and data. +// An error is returned if the request or reading the body fails. +func PostRequest(url string, contentType string, data []byte) ([]byte, error) { + res, err := http.Post(url, contentType, bytes.NewBuffer(data)) //nolint:gosec + if err != nil { + return nil, fmt.Errorf("error while sending post request: %w", err) + } + defer func() { + _ = res.Body.Close() + }() + + bz, err := io.ReadAll(res.Body) + if err != nil { + return nil, fmt.Errorf("error reading response body: %w", err) + } + + return bz, nil +} diff --git a/testutil/rest/rest.go b/testutil/rest/rest.go deleted file mode 100644 index 89a16b3ff286..000000000000 --- a/testutil/rest/rest.go +++ /dev/null @@ -1,48 +0,0 @@ -// Package rest provides HTTP types and primitives for REST -// requests validation and responses handling. -package rest - -import ( - "bytes" - "fmt" - "io" - "net/http" -) - -// GetRequest defines a wrapper around an HTTP GET request with a provided URL. -// An error is returned if the request or reading the body fails. -func GetRequest(url string) ([]byte, error) { - res, err := http.Get(url) //nolint:gosec - if err != nil { - return nil, err - } - defer func() { - _ = res.Body.Close() - }() - - body, err := io.ReadAll(res.Body) - if err != nil { - return nil, err - } - - return body, nil -} - -// PostRequest defines a wrapper around an HTTP POST request with a provided URL and data. -// An error is returned if the request or reading the body fails. -func PostRequest(url string, contentType string, data []byte) ([]byte, error) { - res, err := http.Post(url, contentType, bytes.NewBuffer(data)) //nolint:gosec - if err != nil { - return nil, fmt.Errorf("error while sending post request: %w", err) - } - defer func() { - _ = res.Body.Close() - }() - - bz, err := io.ReadAll(res.Body) - if err != nil { - return nil, fmt.Errorf("error reading response body: %w", err) - } - - return bz, nil -} diff --git a/testutil/sims/app_helpers.go b/testutil/sims/app_helpers.go index 08aa4597e15a..ff5d22a954da 100644 --- a/testutil/sims/app_helpers.go +++ b/testutil/sims/app_helpers.go @@ -29,11 +29,7 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) -// SimAppChainID hardcoded chainID for simulation -const ( - DefaultGenTxGas = 10000000 - SimAppChainID = "simulation-app" -) +const DefaultGenTxGas = 10000000 // DefaultConsensusParams defines the default Tendermint consensus params used in // SimApp testing. diff --git a/simapp/utils.go b/testutil/sims/simulation_helpers.go similarity index 81% rename from simapp/utils.go rename to testutil/sims/simulation_helpers.go index 4c2e7de0f470..420171b05ceb 100644 --- a/simapp/utils.go +++ b/testutil/sims/simulation_helpers.go @@ -1,35 +1,30 @@ -package simapp +package sims import ( "encoding/json" "fmt" "os" - "github.com/tendermint/tendermint/libs/log" - dbm "github.com/tendermint/tm-db" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/runtime" - simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/kv" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/tendermint/tendermint/libs/log" + dbm "github.com/tendermint/tm-db" ) -// SetupSimulation creates the config, db (levelDB), temporary directory and logger for -// the simulation tests. If `FlagEnabledValue` is false it skips the current test. +// SetupSimulation creates the config, db (levelDB), temporary directory and logger for the simulation tests. +// If `skip` is false it skips the current test. `skip` should be set using the `FlagEnabledValue` flag. // Returns error on an invalid db intantiation or temp dir creation. -func SetupSimulation(dirPrefix, dbName string) (simtypes.Config, dbm.DB, string, log.Logger, bool, error) { - if !FlagEnabledValue { - return simtypes.Config{}, nil, "", nil, true, nil +func SetupSimulation(config simtypes.Config, dirPrefix, dbName string, verbose, skip bool) (dbm.DB, string, log.Logger, bool, error) { + if !skip { + return nil, "", nil, true, nil } - config := NewConfigFromFlags() - config.ChainID = simtestutil.SimAppChainID - var logger log.Logger - if FlagVerboseValue { + if verbose { logger = log.TestingLogger() } else { logger = log.NewNopLogger() @@ -37,15 +32,15 @@ func SetupSimulation(dirPrefix, dbName string) (simtypes.Config, dbm.DB, string, dir, err := os.MkdirTemp("", dirPrefix) if err != nil { - return simtypes.Config{}, nil, "", nil, false, err + return nil, "", nil, false, err } db, err := dbm.NewDB(dbName, dbm.BackendType(config.DBBackend), dir) if err != nil { - return simtypes.Config{}, nil, "", nil, false, err + return nil, "", nil, false, err } - return config, db, dir, logger, false, nil + return db, dir, logger, false, nil } // SimulationOperations retrieves the simulation params from the provided file path @@ -74,9 +69,7 @@ func SimulationOperations(app runtime.AppI, cdc codec.JSONCodec, config simtypes // CheckExportSimulation exports the app state and simulation parameters to JSON // if the export paths are defined. -func CheckExportSimulation( - app runtime.AppI, config simtypes.Config, params simtypes.Params, -) error { +func CheckExportSimulation(app runtime.AppI, config simtypes.Config, params simtypes.Params) error { if config.ExportStatePath != "" { fmt.Println("exporting app state...") exported, err := app.ExportAppStateAndValidators(false, nil) diff --git a/simapp/utils_test.go b/testutil/sims/simulation_helpers_test.go similarity index 71% rename from simapp/utils_test.go rename to testutil/sims/simulation_helpers_test.go index 0240c482a558..1a262c35b4f6 100644 --- a/simapp/utils_test.go +++ b/testutil/sims/simulation_helpers_test.go @@ -1,30 +1,23 @@ -package simapp +package sims import ( "fmt" "testing" + "cosmossdk.io/depinject" "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/std" + "github.com/cosmos/cosmos-sdk/testutil/configurator" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/kv" - "github.com/cosmos/cosmos-sdk/types/module" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" ) -func makeCodec(bm module.BasicManager) *codec.LegacyAmino { - cdc := codec.NewLegacyAmino() - - bm.RegisterLegacyAminoCodec(cdc) - std.RegisterLegacyAminoCodec(cdc) - - return cdc -} - func TestGetSimulationLog(t *testing.T) { - cdc := makeCodec(ModuleBasics) + var legacyAmino *codec.LegacyAmino + err := depinject.Inject(configurator.NewAppConfig(), legacyAmino) + require.NoError(t, err) decoders := make(sdk.StoreDecoderRegistry) decoders[authtypes.StoreKey] = func(kvAs, kvBs kv.Pair) string { return "10" } @@ -41,7 +34,7 @@ func TestGetSimulationLog(t *testing.T) { }, { authtypes.StoreKey, - []kv.Pair{{Key: authtypes.GlobalAccountNumberKey, Value: cdc.MustMarshal(uint64(10))}}, + []kv.Pair{{Key: authtypes.GlobalAccountNumberKey, Value: legacyAmino.MustMarshal(uint64(10))}}, "10", }, { diff --git a/x/authz/client/testutil/grpc.go b/x/authz/client/testutil/grpc.go index f22ea3fbb910..4a3b5e793d65 100644 --- a/x/authz/client/testutil/grpc.go +++ b/x/authz/client/testutil/grpc.go @@ -5,7 +5,7 @@ import ( "time" "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/testutil/rest" + "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/authz" "github.com/cosmos/cosmos-sdk/x/authz/client/cli" @@ -62,7 +62,7 @@ func (s *IntegrationTestSuite) TestQueryGrantGRPC() { for _, tc := range testCases { tc := tc s.Run(tc.name, func() { - resp, _ := rest.GetRequest(tc.url) + resp, _ := testutil.GetRequest(tc.url) require := s.Require() if tc.expectErr { require.Contains(string(resp), tc.errorMsg) @@ -150,7 +150,7 @@ func (s *IntegrationTestSuite) TestQueryGrantsGRPC() { tc := tc s.Run(tc.name, func() { tc.preRun() - resp, err := rest.GetRequest(tc.url) + resp, err := testutil.GetRequest(tc.url) s.Require().NoError(err) if tc.expectErr { @@ -201,7 +201,7 @@ func (s *IntegrationTestSuite) TestQueryGranterGrantsGRPC() { } for _, tc := range testCases { s.Run(tc.name, func() { - resp, err := rest.GetRequest(tc.url) + resp, err := testutil.GetRequest(tc.url) require.NoError(err) if tc.expectErr { @@ -253,7 +253,7 @@ func (s *IntegrationTestSuite) TestQueryGranteeGrantsGRPC() { } for _, tc := range testCases { s.Run(tc.name, func() { - resp, err := rest.GetRequest(tc.url) + resp, err := testutil.GetRequest(tc.url) require.NoError(err) if tc.expectErr { diff --git a/x/distribution/client/testutil/grpc_query_suite.go b/x/distribution/client/testutil/grpc_query_suite.go index ddfa15a6f4b9..018f01126005 100644 --- a/x/distribution/client/testutil/grpc_query_suite.go +++ b/x/distribution/client/testutil/grpc_query_suite.go @@ -8,7 +8,6 @@ import ( sdktestutil "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/network" - "github.com/cosmos/cosmos-sdk/testutil/rest" sdk "github.com/cosmos/cosmos-sdk/types" grpctypes "github.com/cosmos/cosmos-sdk/types/grpc" "github.com/cosmos/cosmos-sdk/types/query" @@ -65,7 +64,7 @@ func (s *GRPCQueryTestSuite) TestQueryParamsGRPC() { for _, tc := range testCases { tc := tc - resp, err := rest.GetRequest(tc.url) + resp, err := sdktestutil.GetRequest(tc.url) s.Run(tc.name, func() { s.Require().NoError(err) s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(resp, tc.respType)) @@ -100,7 +99,7 @@ func (s *GRPCQueryTestSuite) TestQueryValidatorDistributionInfoGRPC() { for _, tc := range testCases { tc := tc - resp, err := rest.GetRequest(tc.url) + resp, err := sdktestutil.GetRequest(tc.url) s.Run(tc.name, func() { if tc.expErr { s.Require().Error(val.ClientCtx.Codec.UnmarshalJSON(resp, tc.respType)) @@ -265,7 +264,7 @@ func (s *GRPCQueryTestSuite) TestQuerySlashesGRPC() { for _, tc := range testCases { tc := tc - resp, err := rest.GetRequest(tc.url) + resp, err := sdktestutil.GetRequest(tc.url) s.Run(tc.name, func() { if tc.expErr { @@ -393,7 +392,7 @@ func (s *GRPCQueryTestSuite) TestQueryDelegatorValidatorsGRPC() { for _, tc := range testCases { tc := tc - resp, err := rest.GetRequest(tc.url) + resp, err := sdktestutil.GetRequest(tc.url) s.Run(tc.name, func() { if tc.expErr { @@ -445,7 +444,7 @@ func (s *GRPCQueryTestSuite) TestQueryWithdrawAddressGRPC() { for _, tc := range testCases { tc := tc - resp, err := rest.GetRequest(tc.url) + resp, err := sdktestutil.GetRequest(tc.url) s.Run(tc.name, func() { if tc.expErr { diff --git a/x/gov/client/testutil/grpc.go b/x/gov/client/testutil/grpc.go index 66e93ed2098c..17dec9e427e3 100644 --- a/x/gov/client/testutil/grpc.go +++ b/x/gov/client/testutil/grpc.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/cosmos/cosmos-sdk/testutil" - "github.com/cosmos/cosmos-sdk/testutil/rest" sdk "github.com/cosmos/cosmos-sdk/types" grpctypes "github.com/cosmos/cosmos-sdk/types/grpc" v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" @@ -39,7 +38,7 @@ func (s *IntegrationTestSuite) TestGetProposalGRPC() { for _, tc := range testCases { tc := tc s.Run(tc.name, func() { - resp, err := rest.GetRequest(tc.url) + resp, err := testutil.GetRequest(tc.url) s.Require().NoError(err) var proposal v1.QueryProposalResponse @@ -160,7 +159,7 @@ func (s *IntegrationTestSuite) TestGetProposalVoteGRPC() { for _, tc := range testCases { tc := tc s.Run(tc.name, func() { - resp, err := rest.GetRequest(tc.url) + resp, err := testutil.GetRequest(tc.url) s.Require().NoError(err) var vote v1.QueryVoteResponse @@ -204,7 +203,7 @@ func (s *IntegrationTestSuite) TestGetProposalVotesGRPC() { for _, tc := range testCases { tc := tc s.Run(tc.name, func() { - resp, err := rest.GetRequest(tc.url) + resp, err := testutil.GetRequest(tc.url) s.Require().NoError(err) var votes v1.QueryVotesResponse @@ -253,7 +252,7 @@ func (s *IntegrationTestSuite) TestGetProposalDepositGRPC() { for _, tc := range testCases { tc := tc s.Run(tc.name, func() { - resp, err := rest.GetRequest(tc.url) + resp, err := testutil.GetRequest(tc.url) s.Require().NoError(err) var deposit v1.QueryDepositResponse @@ -292,7 +291,7 @@ func (s *IntegrationTestSuite) TestGetProposalDepositsGRPC() { for _, tc := range testCases { tc := tc s.Run(tc.name, func() { - resp, err := rest.GetRequest(tc.url) + resp, err := testutil.GetRequest(tc.url) s.Require().NoError(err) var deposits v1.QueryDepositsResponse @@ -337,7 +336,7 @@ func (s *IntegrationTestSuite) TestGetTallyGRPC() { for _, tc := range testCases { tc := tc s.Run(tc.name, func() { - resp, err := rest.GetRequest(tc.url) + resp, err := testutil.GetRequest(tc.url) s.Require().NoError(err) var tally v1.QueryTallyResultResponse @@ -399,7 +398,7 @@ func (s *IntegrationTestSuite) TestGetParamsGRPC() { for _, tc := range testCases { tc := tc s.Run(tc.name, func() { - resp, err := rest.GetRequest(tc.url) + resp, err := testutil.GetRequest(tc.url) s.Require().NoError(err) err = val.ClientCtx.Codec.UnmarshalJSON(resp, tc.respType) diff --git a/simapp/config.go b/x/simulation/client/cli/flags.go similarity index 99% rename from simapp/config.go rename to x/simulation/client/cli/flags.go index 48cc053f2533..bec5b6e8b712 100644 --- a/simapp/config.go +++ b/x/simulation/client/cli/flags.go @@ -1,4 +1,4 @@ -package simapp +package cli import ( "flag" From f10e94406d3f838e1628fbebc4c625d890d9ae25 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 27 Sep 2022 18:46:42 +0200 Subject: [PATCH 2/6] update changelog --- CHANGELOG.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 794d082af8bc..45eb4c2b15eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -114,9 +114,9 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes -* [#]() Move simulation flags to `x/simulation/client/cli`. -* [#]() Move simulation helpers functions (`SetupSimulation`, `SimulationOperations`, `CheckExportSimulation`, `PrintStats`, `GetSimulationLog`) to `testutil/sims`. -* [#]() Move `testutil/rest` package to `testutil`. +* [#13402](https://github.com/cosmos/cosmos-sdk/pull/13402) Move simulation flags to `x/simulation/client/cli`. +* [#13402](https://github.com/cosmos/cosmos-sdk/pull/13402) Move simulation helpers functions (`SetupSimulation`, `SimulationOperations`, `CheckExportSimulation`, `PrintStats`, `GetSimulationLog`) to `testutil/sims`. +* [#13402](https://github.com/cosmos/cosmos-sdk/pull/13402) Move `testutil/rest` package to `testutil`. * [#13380](https://github.com/cosmos/cosmos-sdk/pull/13380) Remove deprecated `sdk.NewLevelDB`. * [#13378](https://github.com/cosmos/cosmos-sdk/pull/13378) Move `simapp.App` to `runtime.AppI`. * (tx) [#12659](https://github.com/cosmos/cosmos-sdk/pull/12659) Remove broadcast mode `block`. From 95563b8dbb5be44d2a1afd5e742835744beeec0b Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 27 Sep 2022 18:47:46 +0200 Subject: [PATCH 3/6] fix test --- testutil/sims/simulation_helpers_test.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/testutil/sims/simulation_helpers_test.go b/testutil/sims/simulation_helpers_test.go index 1a262c35b4f6..793fb9947a8d 100644 --- a/testutil/sims/simulation_helpers_test.go +++ b/testutil/sims/simulation_helpers_test.go @@ -4,21 +4,16 @@ import ( "fmt" "testing" - "cosmossdk.io/depinject" "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/testutil/configurator" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/kv" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" ) func TestGetSimulationLog(t *testing.T) { - var legacyAmino *codec.LegacyAmino - err := depinject.Inject(configurator.NewAppConfig(), legacyAmino) - require.NoError(t, err) - + legacyAmino := codec.NewLegacyAmino() decoders := make(sdk.StoreDecoderRegistry) decoders[authtypes.StoreKey] = func(kvAs, kvBs kv.Pair) string { return "10" } From afa28206c216a113724d1e9c13678f60a37ae4d6 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 27 Sep 2022 18:48:52 +0200 Subject: [PATCH 4/6] update upgrading.md --- UPGRADING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UPGRADING.md b/UPGRADING.md index ea8346c4a579..1720a4192f98 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -23,7 +23,7 @@ The constructor, `NewSimApp` has been simplified: * `NewSimApp` does not take encoding parameters (`encodingConfig`) as input, instead the encoding parameters are injected (when using app wiring), or directly created in the constructor. Instead, we can instantiate `SimApp` for getting the encoding configuration. * `NewSimApp` now uses `AppOptions` for getting the home path (`homePath`) and the invariant checks period (`invCheckPeriod`). These were unnecessary given as arguments as they were already present in the `AppOptions`. -SimApp should not be imported in your own app. Instead, you should import the `runtime.AppI` interface, that defines an `App`, and use the [`simtestutil` package](https://pkg.go.dev/github.com/cosmos/cosmos-sdk/testutil/sims) for application testing. +The `simapp` package **should not be imported in your own app**. Instead, you should import the `runtime.AppI` interface, that defines an `App`, and use the [`simtestutil` package](https://pkg.go.dev/github.com/cosmos/cosmos-sdk/testutil/sims) for application testing. ### Encoding From 464c46f9223e246cad7baef1fd624421d0f0af4b Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 27 Sep 2022 18:50:36 +0200 Subject: [PATCH 5/6] fix e2e tests --- tests/e2e/bank/client/grpc.go | 3 +-- tests/e2e/nft/grpc.go | 16 +++++++-------- tests/e2e/staking/client/testutil/grpc.go | 23 +++++++++++----------- tests/e2e/staking/client/testutil/suite.go | 4 ++-- tests/e2e/tx/service_test.go | 11 +++++------ 5 files changed, 27 insertions(+), 30 deletions(-) diff --git a/tests/e2e/bank/client/grpc.go b/tests/e2e/bank/client/grpc.go index 15814414f041..712d589ac27c 100644 --- a/tests/e2e/bank/client/grpc.go +++ b/tests/e2e/bank/client/grpc.go @@ -8,7 +8,6 @@ import ( "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/testutil" - "github.com/cosmos/cosmos-sdk/testutil/rest" sdk "github.com/cosmos/cosmos-sdk/types" grpctypes "github.com/cosmos/cosmos-sdk/types/grpc" "github.com/cosmos/cosmos-sdk/types/query" @@ -277,7 +276,7 @@ func (s *EndToEndTestSuite) TestBalancesGRPCHandler() { for _, tc := range testCases { tc := tc s.Run(tc.name, func() { - resp, err := rest.GetRequest(tc.url) + resp, err := testutil.GetRequest(tc.url) s.Require().NoError(err) s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(resp, tc.respType)) diff --git a/tests/e2e/nft/grpc.go b/tests/e2e/nft/grpc.go index 718793f0b8d0..6b6d84943fc4 100644 --- a/tests/e2e/nft/grpc.go +++ b/tests/e2e/nft/grpc.go @@ -3,7 +3,7 @@ package nft import ( "fmt" - "github.com/cosmos/cosmos-sdk/testutil/rest" + "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/x/nft" ) @@ -61,7 +61,7 @@ func (s *IntegrationTestSuite) TestQueryBalanceGRPC() { for _, tc := range testCases { uri := fmt.Sprintf(balanceURL, tc.args.Owner, tc.args.ClassID) s.Run(tc.name, func() { - resp, _ := rest.GetRequest(uri) + resp, _ := testutil.GetRequest(uri) if tc.expectErr { s.Require().Contains(string(resp), tc.errMsg) } else { @@ -153,7 +153,7 @@ func (s *IntegrationTestSuite) TestQueryOwnerGRPC() { for _, tc := range testCases { uri := fmt.Sprintf(ownerURL, tc.args.ClassID, tc.args.ID) s.Run(tc.name, func() { - resp, err := rest.GetRequest(uri) + resp, err := testutil.GetRequest(uri) if tc.expectErr { s.Require().Contains(string(resp), tc.errMsg) } else { @@ -215,7 +215,7 @@ func (s *IntegrationTestSuite) TestQuerySupplyGRPC() { for _, tc := range testCases { uri := fmt.Sprintf(supplyURL, tc.args.ClassID) s.Run(tc.name, func() { - resp, err := rest.GetRequest(uri) + resp, err := testutil.GetRequest(uri) if tc.expectErr { s.Require().Contains(string(resp), tc.errMsg) } else { @@ -312,7 +312,7 @@ func (s *IntegrationTestSuite) TestQueryNFTsGRPC() { for _, tc := range testCases { uri := fmt.Sprintf(nftsOfClassURL, tc.args.ClassID, tc.args.Owner) s.Run(tc.name, func() { - resp, err := rest.GetRequest(uri) + resp, err := testutil.GetRequest(uri) if tc.expectErr { s.Require().Contains(string(resp), tc.errorMsg) } else { @@ -401,7 +401,7 @@ func (s *IntegrationTestSuite) TestQueryNFTGRPC() { for _, tc := range testCases { uri := fmt.Sprintf(nftURL, tc.args.ClassID, tc.args.ID) s.Run(tc.name, func() { - resp, err := rest.GetRequest(uri) + resp, err := testutil.GetRequest(uri) if tc.expectErr { s.Require().Contains(string(resp), tc.errorMsg) } else { @@ -449,7 +449,7 @@ func (s *IntegrationTestSuite) TestQueryClassGRPC() { for _, tc := range testCases { uri := fmt.Sprintf(classURL, tc.args.ClassID) s.Run(tc.name, func() { - resp, err := rest.GetRequest(uri) + resp, err := testutil.GetRequest(uri) if tc.expectErr { s.Require().Contains(string(resp), tc.errorMsg) } else { @@ -466,7 +466,7 @@ func (s *IntegrationTestSuite) TestQueryClassGRPC() { func (s *IntegrationTestSuite) TestQueryClassesGRPC() { val := s.network.Validators[0] classURL := val.APIAddress + "/cosmos/nft/v1beta1/classes" - resp, err := rest.GetRequest(classURL) + resp, err := testutil.GetRequest(classURL) s.Require().NoError(err) var result nft.QueryClassesResponse err = val.ClientCtx.Codec.UnmarshalJSON(resp, &result) diff --git a/tests/e2e/staking/client/testutil/grpc.go b/tests/e2e/staking/client/testutil/grpc.go index 47378d51e7e1..d5673a8ff600 100644 --- a/tests/e2e/staking/client/testutil/grpc.go +++ b/tests/e2e/staking/client/testutil/grpc.go @@ -9,7 +9,6 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" - "github.com/cosmos/cosmos-sdk/testutil/rest" sdk "github.com/cosmos/cosmos-sdk/types" grpctypes "github.com/cosmos/cosmos-sdk/types/grpc" "github.com/cosmos/cosmos-sdk/types/query" @@ -46,7 +45,7 @@ func (s *IntegrationTestSuite) TestGRPCQueryValidatorsHandler() { for _, tc := range testCases { tc := tc s.Run(tc.name, func() { - resp, err := rest.GetRequest(tc.url) + resp, err := testutil.GetRequest(tc.url) s.Require().NoError(err) var valRes types.QueryValidatorsResponse @@ -94,7 +93,7 @@ func (s *IntegrationTestSuite) TestGRPCQueryValidator() { for _, tc := range testCases { tc := tc s.Run(tc.name, func() { - resp, err := rest.GetRequest(tc.url) + resp, err := testutil.GetRequest(tc.url) s.Require().NoError(err) var validator types.QueryValidatorResponse @@ -203,7 +202,7 @@ func (s *IntegrationTestSuite) TestGRPCQueryValidatorUnbondingDelegations() { for _, tc := range testCases { tc := tc s.Run(tc.name, func() { - resp, err := rest.GetRequest(tc.url) + resp, err := testutil.GetRequest(tc.url) s.Require().NoError(err) var ubds types.QueryValidatorUnbondingDelegationsResponse @@ -282,7 +281,7 @@ func (s *IntegrationTestSuite) TestGRPCQueryDelegation() { for _, tc := range testCases { tc := tc s.Run(tc.name, func() { - resp, err := rest.GetRequest(tc.url) + resp, err := testutil.GetRequest(tc.url) s.Require().NoError(err) s.T().Logf("%s", resp) err = val.ClientCtx.Codec.UnmarshalJSON(resp, tc.respType) @@ -336,7 +335,7 @@ func (s *IntegrationTestSuite) TestGRPCQueryUnbondingDelegation() { for _, tc := range testCases { tc := tc s.Run(tc.name, func() { - resp, err := rest.GetRequest(tc.url) + resp, err := testutil.GetRequest(tc.url) s.Require().NoError(err) var ubd types.QueryUnbondingDelegationResponse @@ -470,7 +469,7 @@ func (s *IntegrationTestSuite) TestGRPCQueryDelegatorUnbondingDelegations() { for _, tc := range testCases { tc := tc s.Run(tc.name, func() { - resp, err := rest.GetRequest(tc.url) + resp, err := testutil.GetRequest(tc.url) s.Require().NoError(err) var ubds types.QueryDelegatorUnbondingDelegationsResponse @@ -532,7 +531,7 @@ func (s *IntegrationTestSuite) TestGRPCQueryRedelegations() { for _, tc := range testCases { tc := tc s.Run(tc.name, func() { - resp, err := rest.GetRequest(tc.url) + resp, err := testutil.GetRequest(tc.url) s.Require().NoError(err) var redelegations types.QueryRedelegationsResponse @@ -581,7 +580,7 @@ func (s *IntegrationTestSuite) TestGRPCQueryDelegatorValidators() { for _, tc := range testCases { tc := tc s.Run(tc.name, func() { - resp, err := rest.GetRequest(tc.url) + resp, err := testutil.GetRequest(tc.url) s.Require().NoError(err) var validators types.QueryDelegatorValidatorsResponse @@ -638,7 +637,7 @@ func (s *IntegrationTestSuite) TestGRPCQueryDelegatorValidator() { for _, tc := range testCases { tc := tc s.Run(tc.name, func() { - resp, err := rest.GetRequest(tc.url) + resp, err := testutil.GetRequest(tc.url) s.Require().NoError(err) var validator types.QueryDelegatorValidatorResponse @@ -684,7 +683,7 @@ func (s *IntegrationTestSuite) TestGRPCQueryHistoricalInfo() { for _, tc := range testCases { tc := tc s.Run(tc.name, func() { - resp, err := rest.GetRequest(tc.url) + resp, err := testutil.GetRequest(tc.url) s.Require().NoError(err) var historicalInfo types.QueryHistoricalInfoResponse @@ -723,7 +722,7 @@ func (s *IntegrationTestSuite) TestGRPCQueryParams() { for _, tc := range testCases { tc := tc - resp, err := rest.GetRequest(tc.url) + resp, err := testutil.GetRequest(tc.url) s.Run(tc.name, func() { s.Require().NoError(err) s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(resp, tc.respType)) diff --git a/tests/e2e/staking/client/testutil/suite.go b/tests/e2e/staking/client/testutil/suite.go index f4ecf45c0688..c49723943e99 100644 --- a/tests/e2e/staking/client/testutil/suite.go +++ b/tests/e2e/staking/client/testutil/suite.go @@ -17,9 +17,9 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" + "github.com/cosmos/cosmos-sdk/testutil" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/cosmos/cosmos-sdk/testutil/network" - "github.com/cosmos/cosmos-sdk/testutil/rest" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/query" @@ -1406,7 +1406,7 @@ func (s *IntegrationTestSuite) TestNewCancelUnbondingDelegationCmd() { if !tc.expectErr && tc.expectedCode != sdkerrors.ErrNotFound.ABCICode() { getCreationHeight := func() int64 { // fethichg the unbonding delegations - resp, err := rest.GetRequest(fmt.Sprintf("%s/cosmos/staking/v1beta1/delegators/%s/unbonding_delegations", val.APIAddress, val.Address.String())) + resp, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/staking/v1beta1/delegators/%s/unbonding_delegations", val.APIAddress, val.Address.String())) s.Require().NoError(err) var ubds types.QueryDelegatorUnbondingDelegationsResponse diff --git a/tests/e2e/tx/service_test.go b/tests/e2e/tx/service_test.go index 881804e99e50..1b3896c0b4b8 100644 --- a/tests/e2e/tx/service_test.go +++ b/tests/e2e/tx/service_test.go @@ -21,7 +21,6 @@ import ( "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/cosmos/cosmos-sdk/testutil/network" - "github.com/cosmos/cosmos-sdk/testutil/rest" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -259,7 +258,7 @@ func (s IntegrationTestSuite) TestSimulateTx_GRPCGateway() { s.Run(tc.name, func() { req, err := val.ClientCtx.Codec.MarshalJSON(tc.req) s.Require().NoError(err) - res, err := rest.PostRequest(fmt.Sprintf("%s/cosmos/tx/v1beta1/simulate", val.APIAddress), "application/json", req) + res, err := testutil.PostRequest(fmt.Sprintf("%s/cosmos/tx/v1beta1/simulate", val.APIAddress), "application/json", req) s.Require().NoError(err) if tc.expErr { s.Require().Contains(string(res), tc.expErrMsg) @@ -413,7 +412,7 @@ func (s IntegrationTestSuite) TestGetTxEvents_GRPCGateway() { } for _, tc := range testCases { s.Run(tc.name, func() { - res, err := rest.GetRequest(tc.url) + res, err := testutil.GetRequest(tc.url) s.Require().NoError(err) if tc.expErr { s.Require().Contains(string(res), tc.expErrMsg) @@ -483,7 +482,7 @@ func (s IntegrationTestSuite) TestGetTx_GRPCGateway() { } for _, tc := range testCases { s.Run(tc.name, func() { - res, err := rest.GetRequest(tc.url) + res, err := testutil.GetRequest(tc.url) s.Require().NoError(err) if tc.expErr { s.Require().Contains(string(res), tc.expErrMsg) @@ -566,7 +565,7 @@ func (s IntegrationTestSuite) TestBroadcastTx_GRPCGateway() { s.Run(tc.name, func() { req, err := val.ClientCtx.Codec.MarshalJSON(tc.req) s.Require().NoError(err) - res, err := rest.PostRequest(fmt.Sprintf("%s/cosmos/tx/v1beta1/txs", val.APIAddress), "application/json", req) + res, err := testutil.PostRequest(fmt.Sprintf("%s/cosmos/tx/v1beta1/txs", val.APIAddress), "application/json", req) s.Require().NoError(err) if tc.expErr { s.Require().Contains(string(res), tc.expErrMsg) @@ -751,7 +750,7 @@ func (s IntegrationTestSuite) TestGetBlockWithTxs_GRPCGateway() { } for _, tc := range testCases { s.Run(tc.name, func() { - res, err := rest.GetRequest(tc.url) + res, err := testutil.GetRequest(tc.url) s.Require().NoError(err) if tc.expErr { s.Require().Contains(string(res), tc.expErrMsg) From 7a9f5ba7f009d294565f0504625a56b2fdcdc2c4 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 27 Sep 2022 20:59:51 +0200 Subject: [PATCH 6/6] updates --- .../e2e/client/grpc/tmservice/service_test.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/e2e/client/grpc/tmservice/service_test.go b/tests/e2e/client/grpc/tmservice/service_test.go index 34ca8a1b1280..a0cba3edb417 100644 --- a/tests/e2e/client/grpc/tmservice/service_test.go +++ b/tests/e2e/client/grpc/tmservice/service_test.go @@ -13,9 +13,9 @@ import ( "github.com/cosmos/cosmos-sdk/client/grpc/tmservice" codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/configurator" "github.com/cosmos/cosmos-sdk/testutil/network" - "github.com/cosmos/cosmos-sdk/testutil/rest" "github.com/cosmos/cosmos-sdk/types" qtypes "github.com/cosmos/cosmos-sdk/types/query" "github.com/cosmos/cosmos-sdk/version" @@ -72,7 +72,7 @@ func (s *IntegrationTestSuite) TestQueryNodeInfo() { s.Require().NoError(err) s.Require().Equal(res.ApplicationVersion.AppName, version.NewInfo().AppName) - restRes, err := rest.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/node_info", val.APIAddress)) + restRes, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/node_info", val.APIAddress)) s.Require().NoError(err) var getInfoRes tmservice.GetNodeInfoResponse s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(restRes, &getInfoRes)) @@ -85,7 +85,7 @@ func (s *IntegrationTestSuite) TestQuerySyncing() { _, err := s.queryClient.GetSyncing(context.Background(), &tmservice.GetSyncingRequest{}) s.Require().NoError(err) - restRes, err := rest.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/syncing", val.APIAddress)) + restRes, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/syncing", val.APIAddress)) s.Require().NoError(err) var syncingRes tmservice.GetSyncingResponse s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(restRes, &syncingRes)) @@ -97,7 +97,7 @@ func (s *IntegrationTestSuite) TestQueryLatestBlock() { _, err := s.queryClient.GetLatestBlock(context.Background(), &tmservice.GetLatestBlockRequest{}) s.Require().NoError(err) - restRes, err := rest.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/blocks/latest", val.APIAddress)) + restRes, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/blocks/latest", val.APIAddress)) s.Require().NoError(err) var blockInfoRes tmservice.GetLatestBlockResponse s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(restRes, &blockInfoRes)) @@ -110,7 +110,7 @@ func (s *IntegrationTestSuite) TestQueryBlockByHeight() { _, err := s.queryClient.GetBlockByHeight(context.Background(), &tmservice.GetBlockByHeightRequest{Height: 1}) s.Require().NoError(err) - restRes, err := rest.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/blocks/%d", val.APIAddress, 1)) + restRes, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/blocks/%d", val.APIAddress, 1)) s.Require().NoError(err) var blockInfoRes tmservice.GetBlockByHeightResponse s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(restRes, &blockInfoRes)) @@ -138,11 +138,11 @@ func (s *IntegrationTestSuite) TestQueryLatestValidatorSet() { s.Require().NoError(err) // rest request without pagination - _, err = rest.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/latest", val.APIAddress)) + _, err = testutil.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/latest", val.APIAddress)) s.Require().NoError(err) // rest request with pagination - restRes, err := rest.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/latest?pagination.offset=%d&pagination.limit=%d", val.APIAddress, 0, 1)) + restRes, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/latest?pagination.offset=%d&pagination.limit=%d", val.APIAddress, 0, 1)) s.Require().NoError(err) var validatorSetRes tmservice.GetLatestValidatorSetResponse s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(restRes, &validatorSetRes)) @@ -198,7 +198,7 @@ func (s *IntegrationTestSuite) TestLatestValidatorSet_GRPCGateway() { for _, tc := range testCases { tc := tc s.Run(tc.name, func() { - res, err := rest.GetRequest(tc.url) + res, err := testutil.GetRequest(tc.url) s.Require().NoError(err) if tc.expErr { s.Require().Contains(string(res), tc.expErrMsg) @@ -260,7 +260,7 @@ func (s *IntegrationTestSuite) TestValidatorSetByHeight_GRPCGateway() { for _, tc := range testCases { tc := tc s.Run(tc.name, func() { - res, err := rest.GetRequest(tc.url) + res, err := testutil.GetRequest(tc.url) s.Require().NoError(err) if tc.expErr { s.Require().Contains(string(res), tc.expErrMsg)