Skip to content

Commit

Permalink
Merge pull request #7626 from cosmos/am-validator-pubkey
Browse files Browse the repository at this point in the history
Use gRPC in GetCmdQueryValidators
  • Loading branch information
robert-zaremba authored Oct 22, 2020
2 parents bfc93a3 + 1cae118 commit 334253f
Show file tree
Hide file tree
Showing 41 changed files with 92 additions and 119 deletions.
2 changes: 1 addition & 1 deletion baseapp/msg_service_router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

func TestMsgService(t *testing.T) {
priv, _, _ := testdata.KeyTestPubAddr()
encCfg := simapp.MakeEncodingConfigTests()
encCfg := simapp.MakeEncodingConfig()
db := dbm.NewMemDB()
app := baseapp.NewBaseApp("test", log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, encCfg.TxConfig.TxDecoder())
app.SetInterfaceRegistry(encCfg.InterfaceRegistry)
Expand Down
2 changes: 1 addition & 1 deletion client/grpc/simulate/simulate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (s *IntegrationTestSuite) SetupSuite() {
app.BankKeeper.SetParams(sdkCtx, banktypes.DefaultParams())

// Set up TxConfig.
encodingConfig := simapp.MakeEncodingConfigTests()
encodingConfig := simapp.MakeEncodingConfig()
clientCtx := client.Context{}.WithTxConfig(encodingConfig.TxConfig)

// Create new simulation server.
Expand Down
13 changes: 0 additions & 13 deletions client/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,6 @@ func (ctx Context) QueryABCI(req abci.RequestQuery) (abci.ResponseQuery, error)
return ctx.queryABCI(req)
}

// QuerySubspace performs a query to a Tendermint node with the provided
// store name and subspace. It returns key value pair and height of the query
// upon success or an error if the query fails.
func (ctx Context) QuerySubspace(subspace []byte, storeName string) (res []sdk.KVPair, height int64, err error) {
resRaw, height, err := ctx.queryStore(subspace, storeName, "subspace")
if err != nil {
return res, height, err
}

ctx.LegacyAmino.MustUnmarshalBinaryBare(resRaw, &res)
return
}

// GetFromAddress returns the from address from the context's name.
func (ctx Context) GetFromAddress() sdk.AccAddress {
return ctx.FromAddress
Expand Down
2 changes: 1 addition & 1 deletion client/tx/legacy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type TestSuite struct {
}

func (s *TestSuite) SetupSuite() {
encCfg := simapp.MakeEncodingConfigTests()
encCfg := simapp.MakeEncodingConfig()
s.encCfg = encCfg
s.protoCfg = tx.NewTxConfig(codec.NewProtoCodec(encCfg.InterfaceRegistry), tx.DefaultSignModes)
s.aminoCfg = legacytx.StdTxConfig{Cdc: encCfg.Amino}
Expand Down
2 changes: 1 addition & 1 deletion client/tx/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
)

func NewTestTxConfig() client.TxConfig {
cfg := simapp.MakeEncodingConfigTests()
cfg := simapp.MakeEncodingConfig()
return cfg.TxConfig
}

Expand Down
4 changes: 2 additions & 2 deletions server/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, *t

logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
db := dbm.NewMemDB()
encCfg := simapp.MakeEncodingConfigTests()
encCfg := simapp.MakeEncodingConfig()
app := simapp.NewSimApp(logger, db, nil, true, map[int64]bool{}, tempDir, 0, encCfg)

serverCtx := server.NewDefaultContext()
Expand All @@ -149,7 +149,7 @@ func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, *t

cmd := server.ExportCmd(
func(_ log.Logger, _ dbm.DB, _ io.Writer, height int64, forZeroHeight bool, jailAllowedAddrs []string) (types.ExportedApp, error) {
encCfg := simapp.MakeEncodingConfigTests()
encCfg := simapp.MakeEncodingConfig()

var simApp *simapp.SimApp
if height != -1 {
Expand Down
2 changes: 1 addition & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ func NewSimApp(
// simapp. It is useful for tests and clients who do not want to construct the
// full simapp
func MakeCodecs() (codec.Marshaler, *codec.LegacyAmino) {
config := MakeEncodingConfigTests()
config := MakeEncodingConfig()
return config.Marshaler, config.Amino
}

Expand Down
6 changes: 3 additions & 3 deletions simapp/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

func TestSimAppExport(t *testing.T) {
db := dbm.NewMemDB()
app := NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, MakeEncodingConfigTests())
app := NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, MakeEncodingConfig())

genesisState := NewDefaultGenesisState()
stateBytes, err := json.MarshalIndent(genesisState, "", " ")
Expand All @@ -30,15 +30,15 @@ func TestSimAppExport(t *testing.T) {
app.Commit()

// Making a new app object with the db, so that initchain hasn't been called
app2 := NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, MakeEncodingConfigTests())
app2 := NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, MakeEncodingConfig())
_, err = app2.ExportAppStateAndValidators(false, []string{})
require.NoError(t, err, "ExportAppStateAndValidators should not have an error")
}

// ensure that blocked addresses are properly set in bank keeper
func TestBlockedAddrs(t *testing.T) {
db := dbm.NewMemDB()
app := NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, MakeEncodingConfigTests())
app := NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, MakeEncodingConfig())

for acc := range maccPerms {
require.Equal(t, !allowedReceivingModAcc[acc], app.BankKeeper.BlockedAddr(app.AccountKeeper.GetModuleAddress(acc)))
Expand Down
10 changes: 7 additions & 3 deletions simapp/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ package simapp

import (
simapparams "github.com/cosmos/cosmos-sdk/simapp/params"
"github.com/cosmos/cosmos-sdk/std"
)

// MakeEncodingConfigTests creates an EncodingConfig for testing
func MakeEncodingConfigTests() simapparams.EncodingConfig {
// MakeEncodingConfig creates an EncodingConfig for testing
func MakeEncodingConfig() simapparams.EncodingConfig {
encodingConfig := simapparams.MakeEncodingConfig()
encodingConfig.RegisterCodecsTests(ModuleBasics)
std.RegisterLegacyAminoCodec(encodingConfig.Amino)
std.RegisterInterfaces(encodingConfig.InterfaceRegistry)
ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino)
ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry)
return encodingConfig
}
2 changes: 1 addition & 1 deletion simapp/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ type GenesisState map[string]json.RawMessage

// NewDefaultGenesisState generates the default state for the application.
func NewDefaultGenesisState() GenesisState {
encCfg := MakeEncodingConfigTests()
encCfg := MakeEncodingConfig()
return ModuleBasics.DefaultGenesis(encCfg.Marshaler)
}
13 changes: 0 additions & 13 deletions simapp/params/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/std"
"github.com/cosmos/cosmos-sdk/types/module"
)

// EncodingConfig specifies the concrete encoding types to use for a given app.
Expand All @@ -16,14 +14,3 @@ type EncodingConfig struct {
TxConfig client.TxConfig
Amino *codec.LegacyAmino
}

// RegisterCodecsTests registars codecs from the config to the global and
// modules scope (mbm != nil).
func (ec *EncodingConfig) RegisterCodecsTests(mbm module.BasicManager) {
std.RegisterLegacyAminoCodec(ec.Amino)
std.RegisterInterfaces(ec.InterfaceRegistry)
if mbm != nil {
mbm.RegisterLegacyAminoCodec(ec.Amino)
mbm.RegisterInterfaces(ec.InterfaceRegistry)
}
}
8 changes: 4 additions & 4 deletions simapp/sim_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func BenchmarkFullAppSimulation(b *testing.B) {
}
}()

app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeEncodingConfigTests(), interBlockCacheOpt())
app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeEncodingConfig(), interBlockCacheOpt())

// run randomized simulation
_, simParams, simErr := simulation.SimulateFromSeed(
Expand All @@ -39,7 +39,7 @@ func BenchmarkFullAppSimulation(b *testing.B) {
SimulationOperations(app, app.AppCodec(), config),
app.ModuleAccountAddrs(),
config,
ModuleBasics,
app.AppCodec(),
)

// export state and simParams before the simulation error is checked
Expand Down Expand Up @@ -72,7 +72,7 @@ func BenchmarkInvariants(b *testing.B) {
}
}()

app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeEncodingConfigTests(), interBlockCacheOpt())
app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeEncodingConfig(), interBlockCacheOpt())

// run randomized simulation
_, simParams, simErr := simulation.SimulateFromSeed(
Expand All @@ -84,7 +84,7 @@ func BenchmarkInvariants(b *testing.B) {
SimulationOperations(app, app.AppCodec(), config),
app.ModuleAccountAddrs(),
config,
ModuleBasics,
app.AppCodec(),
)

// export state and simParams before the simulation error is checked
Expand Down
25 changes: 14 additions & 11 deletions simapp/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestFullAppSimulation(t *testing.T) {
require.NoError(t, os.RemoveAll(dir))
}()

app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeEncodingConfigTests(), fauxMerkleModeOpt)
app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeEncodingConfig(), fauxMerkleModeOpt)
require.Equal(t, "SimApp", app.Name())

// run randomized simulation
Expand All @@ -81,7 +81,7 @@ func TestFullAppSimulation(t *testing.T) {
SimulationOperations(app, app.AppCodec(), config),
app.ModuleAccountAddrs(),
config,
ModuleBasics,
app.AppCodec(),
)

// export state and simParams before the simulation error is checked
Expand All @@ -106,7 +106,7 @@ func TestAppImportExport(t *testing.T) {
require.NoError(t, os.RemoveAll(dir))
}()

app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeEncodingConfigTests(), fauxMerkleModeOpt)
app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeEncodingConfig(), fauxMerkleModeOpt)
require.Equal(t, "SimApp", app.Name())

// Run randomized simulation
Expand All @@ -119,7 +119,8 @@ func TestAppImportExport(t *testing.T) {
SimulationOperations(app, app.AppCodec(), config),
app.ModuleAccountAddrs(),
config,
ModuleBasics)
app.AppCodec(),
)

// export state and simParams before the simulation error is checked
err = CheckExportSimulation(app, config, simParams)
Expand All @@ -145,7 +146,7 @@ func TestAppImportExport(t *testing.T) {
require.NoError(t, os.RemoveAll(newDir))
}()

newApp := NewSimApp(log.NewNopLogger(), newDB, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeEncodingConfigTests(), fauxMerkleModeOpt)
newApp := NewSimApp(log.NewNopLogger(), newDB, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeEncodingConfig(), fauxMerkleModeOpt)
require.Equal(t, "SimApp", newApp.Name())

var genesisState GenesisState
Expand Down Expand Up @@ -202,7 +203,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
require.NoError(t, os.RemoveAll(dir))
}()

app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeEncodingConfigTests(), fauxMerkleModeOpt)
app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeEncodingConfig(), fauxMerkleModeOpt)
require.Equal(t, "SimApp", app.Name())

// Run randomized simulation
Expand All @@ -215,7 +216,8 @@ func TestAppSimulationAfterImport(t *testing.T) {
SimulationOperations(app, app.AppCodec(), config),
app.ModuleAccountAddrs(),
config,
ModuleBasics)
app.AppCodec(),
)

// export state and simParams before the simulation error is checked
err = CheckExportSimulation(app, config, simParams)
Expand Down Expand Up @@ -246,7 +248,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
require.NoError(t, os.RemoveAll(newDir))
}()

newApp := NewSimApp(log.NewNopLogger(), newDB, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeEncodingConfigTests(), fauxMerkleModeOpt)
newApp := NewSimApp(log.NewNopLogger(), newDB, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeEncodingConfig(), fauxMerkleModeOpt)
require.Equal(t, "SimApp", newApp.Name())

newApp.InitChain(abci.RequestInitChain{
Expand All @@ -262,7 +264,8 @@ func TestAppSimulationAfterImport(t *testing.T) {
SimulationOperations(newApp, newApp.AppCodec(), config),
app.ModuleAccountAddrs(),
config,
ModuleBasics)
app.AppCodec(),
)
require.NoError(t, err)
}

Expand Down Expand Up @@ -296,7 +299,7 @@ func TestAppStateDeterminism(t *testing.T) {
}

db := dbm.NewMemDB()
app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeEncodingConfigTests(), interBlockCacheOpt())
app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeEncodingConfig(), interBlockCacheOpt())

fmt.Printf(
"running non-determinism simulation; seed %d: %d/%d, attempt: %d/%d\n",
Expand All @@ -312,7 +315,7 @@ func TestAppStateDeterminism(t *testing.T) {
SimulationOperations(app, app.AppCodec(), config),
app.ModuleAccountAddrs(),
config,
ModuleBasics,
app.AppCodec(),
)
require.NoError(t, err)

Expand Down
6 changes: 3 additions & 3 deletions simapp/simd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (
// NewRootCmd creates a new root command for simd. It is called once in the
// main function.
func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
encodingConfig := simapp.MakeEncodingConfigTests()
encodingConfig := simapp.MakeEncodingConfig()
initClientCtx := client.Context{}.
WithJSONMarshaler(encodingConfig.Marshaler).
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
Expand Down Expand Up @@ -191,7 +191,7 @@ func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts serverty
logger, db, traceStore, true, skipUpgradeHeights,
cast.ToString(appOpts.Get(flags.FlagHome)),
cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)),
simapp.MakeEncodingConfigTests(), // Ideally, we would reuse the one created by NewRootCmd.
simapp.MakeEncodingConfig(), // Ideally, we would reuse the one created by NewRootCmd.
baseapp.SetPruning(pruningOpts),
baseapp.SetMinGasPrices(cast.ToString(appOpts.Get(server.FlagMinGasPrices))),
baseapp.SetHaltHeight(cast.ToUint64(appOpts.Get(server.FlagHaltHeight))),
Expand All @@ -211,7 +211,7 @@ func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts serverty
func createSimappAndExport(
logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool, jailAllowedAddrs []string,
) (servertypes.ExportedApp, error) {
encCfg := simapp.MakeEncodingConfigTests() // Ideally, we would reuse the one created by NewRootCmd.
encCfg := simapp.MakeEncodingConfig() // Ideally, we would reuse the one created by NewRootCmd.
encCfg.Marshaler = codec.NewProtoCodec(encCfg.InterfaceRegistry)
var simApp *simapp.SimApp
if height != -1 {
Expand Down
6 changes: 3 additions & 3 deletions simapp/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var DefaultConsensusParams = &abci.ConsensusParams{
// Setup initializes a new SimApp. A Nop logger is set in SimApp.
func Setup(isCheckTx bool) *SimApp {
db := dbm.NewMemDB()
app := NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 5, MakeEncodingConfigTests())
app := NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 5, MakeEncodingConfig())
if !isCheckTx {
// init chain must be called to stop deliverState from being nil
genesisState := NewDefaultGenesisState()
Expand Down Expand Up @@ -79,7 +79,7 @@ func Setup(isCheckTx bool) *SimApp {
// account. A Nop logger is set in SimApp.
func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *SimApp {
db := dbm.NewMemDB()
app := NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 5, MakeEncodingConfigTests())
app := NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 5, MakeEncodingConfig())

genesisState := NewDefaultGenesisState()

Expand Down Expand Up @@ -160,7 +160,7 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs
// accounts and possible balances.
func SetupWithGenesisAccounts(genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *SimApp {
db := dbm.NewMemDB()
app := NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, MakeEncodingConfigTests())
app := NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, MakeEncodingConfig())

// initialize the chain with the passed in genesis accounts
genesisState := NewDefaultGenesisState()
Expand Down
2 changes: 1 addition & 1 deletion testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ type Config struct {
// DefaultConfig returns a sane default configuration suitable for nearly all
// testing requirements.
func DefaultConfig() Config {
encCfg := simapp.MakeEncodingConfigTests()
encCfg := simapp.MakeEncodingConfig()

return Config{
Codec: encCfg.Marshaler,
Expand Down
2 changes: 1 addition & 1 deletion x/auth/ante/testutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (suite *AnteTestSuite) SetupTest(isCheckTx bool) {
suite.ctx = suite.ctx.WithBlockHeight(1)

// Set up TxConfig.
encodingConfig := simapp.MakeEncodingConfigTests()
encodingConfig := simapp.MakeEncodingConfig()
// We're using TestMsg encoding in some tests, so register it here.
encodingConfig.Amino.RegisterConcrete(&testdata.TestMsg{}, "testdata.TestMsg", nil)
testdata.RegisterInterfaces(encodingConfig.InterfaceRegistry)
Expand Down
4 changes: 2 additions & 2 deletions x/auth/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ func (s *IntegrationTestSuite) TestGetAccountCmd() {

func TestGetBroadcastCommand_OfflineFlag(t *testing.T) {
clientCtx := client.Context{}.WithOffline(true)
clientCtx = clientCtx.WithTxConfig(simapp.MakeEncodingConfigTests().TxConfig)
clientCtx = clientCtx.WithTxConfig(simapp.MakeEncodingConfig().TxConfig)

cmd := authcli.GetBroadcastCommand()
_ = testutil.ApplyMockIODiscardOutErr(cmd)
Expand All @@ -767,7 +767,7 @@ func TestGetBroadcastCommand_OfflineFlag(t *testing.T) {

func TestGetBroadcastCommand_WithoutOfflineFlag(t *testing.T) {
clientCtx := client.Context{}
txCfg := simapp.MakeEncodingConfigTests().TxConfig
txCfg := simapp.MakeEncodingConfig().TxConfig
clientCtx = clientCtx.WithTxConfig(txCfg)

ctx := context.Background()
Expand Down
Loading

0 comments on commit 334253f

Please sign in to comment.