refactor!: extract simulation helpers out of simapp (#13402)

This commit is contained in:
Julien Robert 2022-09-27 21:19:44 +02:00 committed by GitHub
parent 9bae8a817f
commit 91d66f30e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 179 additions and 195 deletions

View File

@ -115,8 +115,11 @@ Ref: https://keepachangelog.com/en/1.0.0/
### API Breaking Changes
* [#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`. `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`.

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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})

View File

@ -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

View File

@ -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
}

View File

@ -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))

View File

@ -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)

View File

@ -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)

View File

@ -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))

View File

@ -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

View File

@ -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)

View File

@ -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
}

View File

@ -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
}

View File

@ -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.

View File

@ -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)

View File

@ -1,4 +1,4 @@
package simapp
package sims
import (
"fmt"
@ -7,25 +7,13 @@ import (
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/std"
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)
legacyAmino := codec.NewLegacyAmino()
decoders := make(sdk.StoreDecoderRegistry)
decoders[authtypes.StoreKey] = func(kvAs, kvBs kv.Pair) string { return "10" }
@ -41,7 +29,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",
},
{

View File

@ -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 {

View File

@ -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 {

View File

@ -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)

View File

@ -1,4 +1,4 @@
package simapp
package cli
import (
"flag"