From 28682e12d0389c3fedcdaf661c75b058b8457dc1 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Fri, 24 Jul 2020 11:51:42 -0400 Subject: [PATCH 1/5] Start to remove HybridCodec --- codec/codec.go | 11 +++-- simapp/app.go | 2 +- tests/mocks/types_module_module.go | 13 ++--- types/module/module.go | 10 ++-- types/module/module_test.go | 6 ++- x/auth/ante/ante_test.go | 5 +- x/auth/ante/basic_test.go | 1 + x/auth/keeper/keeper.go | 4 +- x/auth/keeper/querier.go | 16 +++---- x/auth/keeper/querier_test.go | 2 +- x/auth/module.go | 6 +-- x/bank/keeper/keeper.go | 4 +- x/bank/keeper/querier.go | 32 ++++++------- x/bank/keeper/querier_test.go | 10 ++-- x/bank/module.go | 6 +-- x/capability/module.go | 4 +- x/crisis/module.go | 4 +- x/distribution/keeper/keeper.go | 2 +- x/distribution/keeper/querier.go | 68 +++++++++++++-------------- x/distribution/keeper/querier_test.go | 2 +- x/distribution/module.go | 6 +-- x/evidence/module.go | 4 +- x/gov/module.go | 4 +- x/ibc-transfer/module.go | 4 +- x/ibc/module.go | 4 +- x/mint/module.go | 4 +- x/params/module.go | 4 +- x/slashing/module.go | 4 +- x/staking/module.go | 4 +- x/upgrade/abci_test.go | 2 +- x/upgrade/module.go | 4 +- 31 files changed, 129 insertions(+), 123 deletions(-) diff --git a/codec/codec.go b/codec/codec.go index dee51a9da789..ac31d39b53d8 100644 --- a/codec/codec.go +++ b/codec/codec.go @@ -17,9 +17,13 @@ type ( // // 1. AminoCodec: Provides full Amino serialization compatibility. // 2. ProtoCodec: Provides full Protobuf serialization compatibility. - // 3. HybridCodec: Provides Protobuf serialization for binary encoding and Amino - // for JSON encoding. Marshaler interface { + BinaryMarshaler + JSONMarshaler + types.AnyUnpacker + } + + BinaryMarshaler interface { MarshalBinaryBare(o ProtoMarshaler) ([]byte, error) MustMarshalBinaryBare(o ProtoMarshaler) []byte @@ -31,9 +35,6 @@ type ( UnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshaler) error MustUnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshaler) - - JSONMarshaler - types.AnyUnpacker } JSONMarshaler interface { diff --git a/simapp/app.go b/simapp/app.go index 6d194a3fd58f..42db3c35376b 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -328,7 +328,7 @@ func NewSimApp( ) app.mm.RegisterInvariants(&app.CrisisKeeper) - app.mm.RegisterRoutes(app.Router(), app.QueryRouter()) + app.mm.RegisterRoutes(app.Router(), app.QueryRouter(), codec.NewAminoCodec(encodingConfig.Amino)) app.mm.RegisterQueryServices(app.GRPCQueryRouter()) // add test gRPC service for testing gRPC queries in isolation diff --git a/tests/mocks/types_module_module.go b/tests/mocks/types_module_module.go index 947b750d9420..9fa369d95fee 100644 --- a/tests/mocks/types_module_module.go +++ b/tests/mocks/types_module_module.go @@ -6,6 +6,8 @@ package mocks import ( json "encoding/json" + reflect "reflect" + client "github.com/cosmos/cosmos-sdk/client" codec "github.com/cosmos/cosmos-sdk/codec" types "github.com/cosmos/cosmos-sdk/codec/types" @@ -15,7 +17,6 @@ import ( mux "github.com/gorilla/mux" cobra "github.com/spf13/cobra" types1 "github.com/tendermint/tendermint/abci/types" - reflect "reflect" ) // MockAppModuleBasic is a mock of AppModuleBasic interface @@ -501,18 +502,18 @@ func (mr *MockAppModuleMockRecorder) QuerierRoute() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QuerierRoute", reflect.TypeOf((*MockAppModule)(nil).QuerierRoute)) } -// NewQuerierHandler mocks base method -func (m *MockAppModule) NewQuerierHandler() types0.Querier { +// LegacyQueryHandler mocks base method +func (m *MockAppModule) LegacyQueryHandler(codec.JSONMarshaler) types0.Querier { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "NewQuerierHandler") + ret := m.ctrl.Call(m, "LegacyQueryHandler") ret0, _ := ret[0].(types0.Querier) return ret0 } -// NewQuerierHandler indicates an expected call of NewQuerierHandler +// LegacyQueryHandler indicates an expected call of LegacyQueryHandler func (mr *MockAppModuleMockRecorder) NewQuerierHandler() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewQuerierHandler", reflect.TypeOf((*MockAppModule)(nil).NewQuerierHandler)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LegacyQueryHandler", reflect.TypeOf((*MockAppModule)(nil).LegacyQueryHandler)) } // RegisterQueryService mocks base method diff --git a/types/module/module.go b/types/module/module.go index a56842992b48..28bf33033a34 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -160,7 +160,7 @@ type AppModule interface { // Deprecated: use RegisterQueryService QuerierRoute() string // Deprecated: use RegisterQueryService - NewQuerierHandler() sdk.Querier + LegacyQueryHandler(codec.JSONMarshaler) sdk.Querier // RegisterQueryService allows a module to register a gRPC query service RegisterQueryService(grpc.Server) @@ -192,8 +192,8 @@ func (GenesisOnlyAppModule) Route() sdk.Route { return sdk.Route{} } // QuerierRoute returns an empty module querier route func (GenesisOnlyAppModule) QuerierRoute() string { return "" } -// NewQuerierHandler returns an empty module querier -func (gam GenesisOnlyAppModule) NewQuerierHandler() sdk.Querier { return nil } +// LegacyQueryHandler returns an empty module querier +func (gam GenesisOnlyAppModule) LegacyQueryHandler(codec.JSONMarshaler) sdk.Querier { return nil } func (gam GenesisOnlyAppModule) RegisterQueryService(grpc.Server) {} @@ -264,13 +264,13 @@ func (m *Manager) RegisterInvariants(ir sdk.InvariantRegistry) { } // RegisterRoutes registers all module routes and module querier routes -func (m *Manager) RegisterRoutes(router sdk.Router, queryRouter sdk.QueryRouter) { +func (m *Manager) RegisterRoutes(router sdk.Router, queryRouter sdk.QueryRouter, legacyQuerierCdc codec.JSONMarshaler) { for _, module := range m.Modules { if !module.Route().Empty() { router.AddRoute(module.Route()) } if module.QuerierRoute() != "" { - queryRouter.AddRoute(module.QuerierRoute(), module.NewQuerierHandler()) + queryRouter.AddRoute(module.QuerierRoute(), module.LegacyQueryHandler(legacyQuerierCdc)) } } } diff --git a/types/module/module_test.go b/types/module/module_test.go index cc4fc9af3268..3330c32276a2 100644 --- a/types/module/module_test.go +++ b/types/module/module_test.go @@ -76,7 +76,7 @@ func TestGenesisOnlyAppModule(t *testing.T) { require.True(t, goam.Route().Empty()) require.Empty(t, goam.QuerierRoute()) - require.Nil(t, goam.NewQuerierHandler()) + require.Nil(t, goam.LegacyQueryHandler(nil)) // no-op goam.RegisterInvariants(mockInvariantRegistry) @@ -163,7 +163,9 @@ func TestManager_RegisterRoutes(t *testing.T) { mockAppModule1.EXPECT().NewQuerierHandler().Times(1).Return(handler3) queryRouter.EXPECT().AddRoute(gomock.Eq("querierRoute1"), gomock.Eq(handler3)).Times(1) - mm.RegisterRoutes(router, queryRouter) + amino := codec.New() + jsonCdc := codec.NewAminoCodec(amino) + mm.RegisterRoutes(router, queryRouter, jsonCdc) } func TestManager_RegisterQueryServices(t *testing.T) { diff --git a/x/auth/ante/ante_test.go b/x/auth/ante/ante_test.go index a6f565f52048..d51e063e0fb3 100644 --- a/x/auth/ante/ante_test.go +++ b/x/auth/ante/ante_test.go @@ -825,9 +825,10 @@ func (suite *AnteTestSuite) TestAnteHandlerSetPubKey() { // Manually create tx, and remove signature tx := suite.CreateTestTx(privs, accNums, accSeqs, suite.ctx.ChainID()) - sigs := tx.(types.StdTx).Signatures + sigs, err := tx.GetSignaturesV2() + suite.Require().NoError(err) sigs[0].PubKey = nil - _, err := suite.anteHandler(suite.ctx, tx, false) + _, err = suite.anteHandler(suite.ctx, tx, false) suite.Require().Error(err) suite.Require().Equal(err.Error(), "wrong number of signers; expected 0, got 1: unauthorized") suite.Require().True(errors.Is(err, sdkerrors.ErrUnauthorized)) diff --git a/x/auth/ante/basic_test.go b/x/auth/ante/basic_test.go index 4e8c83e9cc64..bbf13cd3244b 100644 --- a/x/auth/ante/basic_test.go +++ b/x/auth/ante/basic_test.go @@ -134,6 +134,7 @@ func (suite *AnteTestSuite) TestConsumeGasForTxSize() { suite.Require().Equal(expectedGas, consumedGas, "Decorator did not consume the correct amount of gas") // simulation must not underestimate gas of this decorator even with nil signatures + txBuilder2 := suite.clientCtx.TxConfig sigTx := tx.(types.StdTx) sigTx.Signatures = []types.StdSignature{{}} diff --git a/x/auth/keeper/keeper.go b/x/auth/keeper/keeper.go index 13018004cc24..2c089f709e62 100644 --- a/x/auth/keeper/keeper.go +++ b/x/auth/keeper/keeper.go @@ -19,7 +19,7 @@ import ( // encoding/decoding library. type AccountKeeper struct { key sdk.StoreKey - cdc codec.Marshaler + cdc codec.BinaryMarshaler paramSubspace paramtypes.Subspace permAddrs map[string]types.PermissionsForAddress @@ -30,7 +30,7 @@ type AccountKeeper struct { // NewAccountKeeper returns a new sdk.AccountKeeper that uses go-amino to // (binary) encode and decode concrete sdk.Accounts. func NewAccountKeeper( - cdc codec.Marshaler, key sdk.StoreKey, paramstore paramtypes.Subspace, proto func() types.AccountI, + cdc codec.BinaryMarshaler, key sdk.StoreKey, paramstore paramtypes.Subspace, proto func() types.AccountI, maccPerms map[string][]string, ) AccountKeeper { diff --git a/x/auth/keeper/querier.go b/x/auth/keeper/querier.go index f7810fbe0c5e..47d4a59227e4 100644 --- a/x/auth/keeper/querier.go +++ b/x/auth/keeper/querier.go @@ -10,14 +10,14 @@ import ( ) // NewQuerier creates a querier for auth REST endpoints -func NewQuerier(k AccountKeeper) sdk.Querier { +func NewQuerier(k AccountKeeper, cdc codec.JSONMarshaler) sdk.Querier { return func(ctx sdk.Context, path []string, req abci.RequestQuery) ([]byte, error) { switch path[0] { case types.QueryAccount: - return queryAccount(ctx, req, k) + return queryAccount(ctx, req, k, cdc) case types.QueryParams: - return queryParams(ctx, k) + return queryParams(ctx, k, cdc) default: return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown query path: %s", path[0]) @@ -25,9 +25,9 @@ func NewQuerier(k AccountKeeper) sdk.Querier { } } -func queryAccount(ctx sdk.Context, req abci.RequestQuery, k AccountKeeper) ([]byte, error) { +func queryAccount(ctx sdk.Context, req abci.RequestQuery, k AccountKeeper, cdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryAccountRequest - if err := k.cdc.UnmarshalJSON(req.Data, ¶ms); err != nil { + if err := cdc.UnmarshalJSON(req.Data, ¶ms); err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -36,7 +36,7 @@ func queryAccount(ctx sdk.Context, req abci.RequestQuery, k AccountKeeper) ([]by return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "account %s does not exist", params.Address) } - bz, err := codec.MarshalJSONIndent(k.cdc, account) + bz, err := codec.MarshalJSONIndent(cdc, account) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -44,10 +44,10 @@ func queryAccount(ctx sdk.Context, req abci.RequestQuery, k AccountKeeper) ([]by return bz, nil } -func queryParams(ctx sdk.Context, k AccountKeeper) ([]byte, error) { +func queryParams(ctx sdk.Context, k AccountKeeper, cdc codec.JSONMarshaler) ([]byte, error) { params := k.GetParams(ctx) - res, err := codec.MarshalJSONIndent(k.cdc, params) + res, err := codec.MarshalJSONIndent(cdc, params) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } diff --git a/x/auth/keeper/querier_test.go b/x/auth/keeper/querier_test.go index 88ea1a522792..09bd40b27ce5 100644 --- a/x/auth/keeper/querier_test.go +++ b/x/auth/keeper/querier_test.go @@ -23,7 +23,7 @@ func TestQueryAccount(t *testing.T) { } path := []string{types.QueryAccount} - querier := keep.NewQuerier(app.AccountKeeper) + querier := keep.NewQuerier(app.AccountKeeper, nil) bz, err := querier(ctx, []string{"other"}, req) require.Error(t, err) diff --git a/x/auth/module.go b/x/auth/module.go index 7ca63827ed2a..abc51b7dd75c 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -112,9 +112,9 @@ func (AppModule) QuerierRoute() string { return types.QuerierRoute } -// NewQuerierHandler returns the auth module sdk.Querier. -func (am AppModule) NewQuerierHandler() sdk.Querier { - return keeper.NewQuerier(am.accountKeeper) +// LegacyQueryHandler returns the auth module sdk.Querier. +func (am AppModule) LegacyQueryHandler(jsonCdc codec.JSONMarshaler) sdk.Querier { + return keeper.NewQuerier(am.accountKeeper, jsonCdc) } // RegisterQueryService registers a GRPC query service to respond to the diff --git a/x/bank/keeper/keeper.go b/x/bank/keeper/keeper.go index f4d539aeaf08..afa52724cda2 100644 --- a/x/bank/keeper/keeper.go +++ b/x/bank/keeper/keeper.go @@ -53,13 +53,13 @@ type BaseKeeper struct { BaseSendKeeper ak types.AccountKeeper - cdc codec.Marshaler + cdc codec.BinaryMarshaler storeKey sdk.StoreKey paramSpace paramtypes.Subspace } func NewBaseKeeper( - cdc codec.Marshaler, storeKey sdk.StoreKey, ak types.AccountKeeper, paramSpace paramtypes.Subspace, + cdc codec.BinaryMarshaler, storeKey sdk.StoreKey, ak types.AccountKeeper, paramSpace paramtypes.Subspace, blockedAddrs map[string]bool, ) BaseKeeper { diff --git a/x/bank/keeper/querier.go b/x/bank/keeper/querier.go index 4d5f838df09b..46597bec6d59 100644 --- a/x/bank/keeper/querier.go +++ b/x/bank/keeper/querier.go @@ -11,20 +11,20 @@ import ( ) // NewQuerier returns a new sdk.Keeper instance. -func NewQuerier(k Keeper) sdk.Querier { +func NewQuerier(k Keeper, cdc codec.JSONMarshaler) sdk.Querier { return func(ctx sdk.Context, path []string, req abci.RequestQuery) ([]byte, error) { switch path[0] { case types.QueryBalance: - return queryBalance(ctx, req, k) + return queryBalance(ctx, req, k, cdc) case types.QueryAllBalances: - return queryAllBalance(ctx, req, k) + return queryAllBalance(ctx, req, k, cdc) case types.QueryTotalSupply: - return queryTotalSupply(ctx, req, k) + return queryTotalSupply(ctx, req, k, cdc) case types.QuerySupplyOf: - return querySupplyOf(ctx, req, k) + return querySupplyOf(ctx, req, k, cdc) default: return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown %s query endpoint: %s", types.ModuleName, path[0]) @@ -32,16 +32,16 @@ func NewQuerier(k Keeper) sdk.Querier { } } -func queryBalance(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { +func queryBalance(ctx sdk.Context, req abci.RequestQuery, k Keeper, cdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryBalanceRequest - if err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms); err != nil { + if err := cdc.UnmarshalJSON(req.Data, ¶ms); err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } balance := k.GetBalance(ctx, params.Address, params.Denom) - bz, err := codec.MarshalJSONIndent(types.ModuleCdc, balance) + bz, err := codec.MarshalJSONIndent(cdc, balance) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -49,10 +49,10 @@ func queryBalance(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, err return bz, nil } -func queryAllBalance(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { +func queryAllBalance(ctx sdk.Context, req abci.RequestQuery, k Keeper, cdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryAllBalancesRequest - if err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms); err != nil { + if err := cdc.UnmarshalJSON(req.Data, ¶ms); err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -66,10 +66,10 @@ func queryAllBalance(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, return bz, nil } -func queryTotalSupply(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { +func queryTotalSupply(ctx sdk.Context, req abci.RequestQuery, k Keeper, cdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryTotalSupplyParams - err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms) + err := cdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -83,7 +83,7 @@ func queryTotalSupply(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, totalSupply = totalSupply[start:end] } - res, err := totalSupply.MarshalJSON() + res, err := cdc.MarshalJSON(totalSupply) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -91,10 +91,10 @@ func queryTotalSupply(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, return res, nil } -func querySupplyOf(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { +func querySupplyOf(ctx sdk.Context, req abci.RequestQuery, k Keeper, cdc codec.JSONMarshaler) ([]byte, error) { var params types.QuerySupplyOfParams - err := types.ModuleCdc.UnmarshalJSON(req.Data, ¶ms) + err := cdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -102,7 +102,7 @@ func querySupplyOf(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, er amount := k.GetSupply(ctx).GetTotal().AmountOf(params.Denom) supply := sdk.NewCoin(params.Denom, amount) - bz, err := codec.MarshalJSONIndent(types.ModuleCdc, supply) + bz, err := codec.MarshalJSONIndent(cdc, supply) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } diff --git a/x/bank/keeper/querier_test.go b/x/bank/keeper/querier_test.go index df7c6f79c0f4..a217e0303a15 100644 --- a/x/bank/keeper/querier_test.go +++ b/x/bank/keeper/querier_test.go @@ -19,7 +19,7 @@ func (suite *IntegrationTestSuite) TestQuerier_QueryBalance() { Data: []byte{}, } - querier := keeper.NewQuerier(app.BankKeeper) + querier := keeper.NewQuerier(app.BankKeeper, nil) res, err := querier(ctx, []string{types.QueryBalance}, req) suite.Require().NotNil(err) @@ -55,7 +55,7 @@ func (suite *IntegrationTestSuite) TestQuerier_QueryAllBalances() { Data: []byte{}, } - querier := keeper.NewQuerier(app.BankKeeper) + querier := keeper.NewQuerier(app.BankKeeper, nil) res, err := querier(ctx, []string{types.QueryAllBalances}, req) suite.Require().NotNil(err) @@ -93,7 +93,7 @@ func (suite *IntegrationTestSuite) TestQuerier_QueryTotalSupply() { Data: []byte{}, } - querier := keeper.NewQuerier(app.BankKeeper) + querier := keeper.NewQuerier(app.BankKeeper, nil) res, err := querier(ctx, []string{types.QueryTotalSupply}, req) suite.Require().NotNil(err) @@ -122,7 +122,7 @@ func (suite *IntegrationTestSuite) TestQuerier_QueryTotalSupplyOf() { Data: []byte{}, } - querier := keeper.NewQuerier(app.BankKeeper) + querier := keeper.NewQuerier(app.BankKeeper, nil) res, err := querier(ctx, []string{types.QuerySupplyOf}, req) suite.Require().NotNil(err) @@ -145,7 +145,7 @@ func (suite *IntegrationTestSuite) TestQuerierRouteNotFound() { Data: []byte{}, } - querier := keeper.NewQuerier(app.BankKeeper) + querier := keeper.NewQuerier(app.BankKeeper, nil) _, err := querier(ctx, []string{"invalid"}, req) suite.Error(err) } diff --git a/x/bank/module.go b/x/bank/module.go index cafa7a0f7d38..16d93c2e61a2 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -117,9 +117,9 @@ func (am AppModule) Route() sdk.Route { // QuerierRoute returns the bank module's querier route name. func (AppModule) QuerierRoute() string { return types.RouterKey } -// NewQuerierHandler returns the bank module sdk.Querier. -func (am AppModule) NewQuerierHandler() sdk.Querier { - return keeper.NewQuerier(am.keeper) +// LegacyQueryHandler returns the bank module sdk.Querier. +func (am AppModule) LegacyQueryHandler(jsonCdc codec.JSONMarshaler) sdk.Querier { + return keeper.NewQuerier(am.keeper, jsonCdc) } // InitGenesis performs genesis initialization for the bank module. It returns diff --git a/x/capability/module.go b/x/capability/module.go index 06ee437103ac..23a6aeeab2d9 100644 --- a/x/capability/module.go +++ b/x/capability/module.go @@ -106,8 +106,8 @@ func (AppModule) Route() sdk.Route { return sdk.Route{} } // QuerierRoute returns the capability module's query routing key. func (AppModule) QuerierRoute() string { return "" } -// NewQuerierHandler returns the capability module's Querier. -func (am AppModule) NewQuerierHandler() sdk.Querier { return nil } +// LegacyQueryHandler returns the capability module's Querier. +func (am AppModule) LegacyQueryHandler(codec.JSONMarshaler) sdk.Querier { return nil } // RegisterQueryService registers a GRPC query service to respond to the // module-specific GRPC queries. diff --git a/x/crisis/module.go b/x/crisis/module.go index 40af92e03c7f..d6f68cd2c836 100644 --- a/x/crisis/module.go +++ b/x/crisis/module.go @@ -106,8 +106,8 @@ func (am AppModule) Route() sdk.Route { // QuerierRoute returns no querier route. func (AppModule) QuerierRoute() string { return "" } -// NewQuerierHandler returns no sdk.Querier. -func (AppModule) NewQuerierHandler() sdk.Querier { return nil } +// LegacyQueryHandler returns no sdk.Querier. +func (AppModule) LegacyQueryHandler(codec.JSONMarshaler) sdk.Querier { return nil } // RegisterQueryService registers a GRPC query service to respond to the // module-specific GRPC queries. diff --git a/x/distribution/keeper/keeper.go b/x/distribution/keeper/keeper.go index bb7be3ed5e20..d4c9b34ec3cb 100644 --- a/x/distribution/keeper/keeper.go +++ b/x/distribution/keeper/keeper.go @@ -15,7 +15,7 @@ import ( // Keeper of the distribution store type Keeper struct { storeKey sdk.StoreKey - cdc codec.Marshaler + cdc codec.BinaryMarshaler paramSpace paramtypes.Subspace authKeeper types.AccountKeeper bankKeeper types.BankKeeper diff --git a/x/distribution/keeper/querier.go b/x/distribution/keeper/querier.go index 8603c22d326c..1e71beb892e6 100644 --- a/x/distribution/keeper/querier.go +++ b/x/distribution/keeper/querier.go @@ -12,35 +12,35 @@ import ( "github.com/cosmos/cosmos-sdk/x/staking/exported" ) -func NewQuerier(k Keeper) sdk.Querier { +func NewQuerier(k Keeper, cdc codec.JSONMarshaler) sdk.Querier { return func(ctx sdk.Context, path []string, req abci.RequestQuery) ([]byte, error) { switch path[0] { case types.QueryParams: - return queryParams(ctx, path[1:], req, k) + return queryParams(ctx, path[1:], req, k, cdc) case types.QueryValidatorOutstandingRewards: - return queryValidatorOutstandingRewards(ctx, path[1:], req, k) + return queryValidatorOutstandingRewards(ctx, path[1:], req, k, cdc) case types.QueryValidatorCommission: - return queryValidatorCommission(ctx, path[1:], req, k) + return queryValidatorCommission(ctx, path[1:], req, k, cdc) case types.QueryValidatorSlashes: - return queryValidatorSlashes(ctx, path[1:], req, k) + return queryValidatorSlashes(ctx, path[1:], req, k, cdc) case types.QueryDelegationRewards: - return queryDelegationRewards(ctx, path[1:], req, k) + return queryDelegationRewards(ctx, path[1:], req, k, cdc) case types.QueryDelegatorTotalRewards: - return queryDelegatorTotalRewards(ctx, path[1:], req, k) + return queryDelegatorTotalRewards(ctx, path[1:], req, k, cdc) case types.QueryDelegatorValidators: - return queryDelegatorValidators(ctx, path[1:], req, k) + return queryDelegatorValidators(ctx, path[1:], req, k, cdc) case types.QueryWithdrawAddr: - return queryDelegatorWithdrawAddress(ctx, path[1:], req, k) + return queryDelegatorWithdrawAddress(ctx, path[1:], req, k, cdc) case types.QueryCommunityPool: - return queryCommunityPool(ctx, path[1:], req, k) + return queryCommunityPool(ctx, path[1:], req, k, cdc) default: return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown query path: %s", path[0]) @@ -48,10 +48,10 @@ func NewQuerier(k Keeper) sdk.Querier { } } -func queryParams(ctx sdk.Context, _ []string, _ abci.RequestQuery, k Keeper) ([]byte, error) { +func queryParams(ctx sdk.Context, _ []string, _ abci.RequestQuery, k Keeper, cdc codec.JSONMarshaler) ([]byte, error) { params := k.GetParams(ctx) - res, err := codec.MarshalJSONIndent(k.cdc, params) + res, err := codec.MarshalJSONIndent(cdc, params) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -59,9 +59,9 @@ func queryParams(ctx sdk.Context, _ []string, _ abci.RequestQuery, k Keeper) ([] return res, nil } -func queryValidatorOutstandingRewards(ctx sdk.Context, _ []string, req abci.RequestQuery, k Keeper) ([]byte, error) { +func queryValidatorOutstandingRewards(ctx sdk.Context, _ []string, req abci.RequestQuery, k Keeper, cdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryValidatorOutstandingRewardsParams - err := k.cdc.UnmarshalJSON(req.Data, ¶ms) + err := cdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -71,7 +71,7 @@ func queryValidatorOutstandingRewards(ctx sdk.Context, _ []string, req abci.Requ rewards.Rewards = sdk.DecCoins{} } - bz, err := codec.MarshalJSONIndent(k.cdc, rewards) + bz, err := codec.MarshalJSONIndent(cdc, rewards) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -79,9 +79,9 @@ func queryValidatorOutstandingRewards(ctx sdk.Context, _ []string, req abci.Requ return bz, nil } -func queryValidatorCommission(ctx sdk.Context, _ []string, req abci.RequestQuery, k Keeper) ([]byte, error) { +func queryValidatorCommission(ctx sdk.Context, _ []string, req abci.RequestQuery, k Keeper, cdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryValidatorCommissionParams - err := k.cdc.UnmarshalJSON(req.Data, ¶ms) + err := cdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -91,7 +91,7 @@ func queryValidatorCommission(ctx sdk.Context, _ []string, req abci.RequestQuery commission.Commission = sdk.DecCoins{} } - bz, err := codec.MarshalJSONIndent(k.cdc, commission) + bz, err := codec.MarshalJSONIndent(cdc, commission) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -99,9 +99,9 @@ func queryValidatorCommission(ctx sdk.Context, _ []string, req abci.RequestQuery return bz, nil } -func queryValidatorSlashes(ctx sdk.Context, _ []string, req abci.RequestQuery, k Keeper) ([]byte, error) { +func queryValidatorSlashes(ctx sdk.Context, _ []string, req abci.RequestQuery, k Keeper, cdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryValidatorSlashesParams - err := k.cdc.UnmarshalJSON(req.Data, ¶ms) + err := cdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -114,7 +114,7 @@ func queryValidatorSlashes(ctx sdk.Context, _ []string, req abci.RequestQuery, k }, ) - bz, err := codec.MarshalJSONIndent(k.cdc, events) + bz, err := codec.MarshalJSONIndent(cdc, events) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -122,9 +122,9 @@ func queryValidatorSlashes(ctx sdk.Context, _ []string, req abci.RequestQuery, k return bz, nil } -func queryDelegationRewards(ctx sdk.Context, _ []string, req abci.RequestQuery, k Keeper) ([]byte, error) { +func queryDelegationRewards(ctx sdk.Context, _ []string, req abci.RequestQuery, k Keeper, cdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryDelegationRewardsParams - err := k.cdc.UnmarshalJSON(req.Data, ¶ms) + err := cdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -148,7 +148,7 @@ func queryDelegationRewards(ctx sdk.Context, _ []string, req abci.RequestQuery, rewards = sdk.DecCoins{} } - bz, err := codec.MarshalJSONIndent(k.cdc, rewards) + bz, err := codec.MarshalJSONIndent(cdc, rewards) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -156,9 +156,9 @@ func queryDelegationRewards(ctx sdk.Context, _ []string, req abci.RequestQuery, return bz, nil } -func queryDelegatorTotalRewards(ctx sdk.Context, _ []string, req abci.RequestQuery, k Keeper) ([]byte, error) { +func queryDelegatorTotalRewards(ctx sdk.Context, _ []string, req abci.RequestQuery, k Keeper, cdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryDelegatorParams - err := k.cdc.UnmarshalJSON(req.Data, ¶ms) + err := cdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -194,9 +194,9 @@ func queryDelegatorTotalRewards(ctx sdk.Context, _ []string, req abci.RequestQue return bz, nil } -func queryDelegatorValidators(ctx sdk.Context, _ []string, req abci.RequestQuery, k Keeper) ([]byte, error) { +func queryDelegatorValidators(ctx sdk.Context, _ []string, req abci.RequestQuery, k Keeper, cdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryDelegatorParams - err := k.cdc.UnmarshalJSON(req.Data, ¶ms) + err := cdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -214,7 +214,7 @@ func queryDelegatorValidators(ctx sdk.Context, _ []string, req abci.RequestQuery }, ) - bz, err := codec.MarshalJSONIndent(k.cdc, validators) + bz, err := codec.MarshalJSONIndent(cdc, validators) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -222,9 +222,9 @@ func queryDelegatorValidators(ctx sdk.Context, _ []string, req abci.RequestQuery return bz, nil } -func queryDelegatorWithdrawAddress(ctx sdk.Context, _ []string, req abci.RequestQuery, k Keeper) ([]byte, error) { +func queryDelegatorWithdrawAddress(ctx sdk.Context, _ []string, req abci.RequestQuery, k Keeper, cdc codec.JSONMarshaler) ([]byte, error) { var params types.QueryDelegatorWithdrawAddrParams - err := k.cdc.UnmarshalJSON(req.Data, ¶ms) + err := cdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error()) } @@ -233,7 +233,7 @@ func queryDelegatorWithdrawAddress(ctx sdk.Context, _ []string, req abci.Request ctx, _ = ctx.CacheContext() withdrawAddr := k.GetDelegatorWithdrawAddr(ctx, params.DelegatorAddress) - bz, err := codec.MarshalJSONIndent(k.cdc, withdrawAddr) + bz, err := codec.MarshalJSONIndent(cdc, withdrawAddr) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } @@ -241,13 +241,13 @@ func queryDelegatorWithdrawAddress(ctx sdk.Context, _ []string, req abci.Request return bz, nil } -func queryCommunityPool(ctx sdk.Context, _ []string, _ abci.RequestQuery, k Keeper) ([]byte, error) { +func queryCommunityPool(ctx sdk.Context, _ []string, _ abci.RequestQuery, k Keeper, cdc codec.JSONMarshaler) ([]byte, error) { pool := k.GetFeePoolCommunityCoins(ctx) if pool == nil { pool = sdk.DecCoins{} } - bz, err := k.cdc.MarshalJSON(pool) + bz, err := cdc.MarshalJSON(pool) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) } diff --git a/x/distribution/keeper/querier_test.go b/x/distribution/keeper/querier_test.go index f4cca58e1243..b7c78bb94e83 100644 --- a/x/distribution/keeper/querier_test.go +++ b/x/distribution/keeper/querier_test.go @@ -121,7 +121,7 @@ func TestQueries(t *testing.T) { valAddrs := simapp.ConvertAddrsToValAddrs(addr) valOpAddr1 := valAddrs[0] - querier := keeper.NewQuerier(app.DistrKeeper) + querier := keeper.NewQuerier(app.DistrKeeper, nil) // test param queries params := types.Params{ diff --git a/x/distribution/module.go b/x/distribution/module.go index fe20c76de228..aa3fdf7c36ca 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -128,9 +128,9 @@ func (AppModule) QuerierRoute() string { return types.QuerierRoute } -// NewQuerierHandler returns the distribution module sdk.Querier. -func (am AppModule) NewQuerierHandler() sdk.Querier { - return keeper.NewQuerier(am.keeper) +// LegacyQueryHandler returns the distribution module sdk.Querier. +func (am AppModule) LegacyQueryHandler(jsonCdc codec.JSONMarshaler) sdk.Querier { + return keeper.NewQuerier(am.keeper, jsonCdc) } // RegisterQueryService registers a GRPC query service to respond to the diff --git a/x/evidence/module.go b/x/evidence/module.go index 5ef5bd17d9a5..fc59e490324d 100644 --- a/x/evidence/module.go +++ b/x/evidence/module.go @@ -137,8 +137,8 @@ func (AppModule) QuerierRoute() string { return types.QuerierRoute } -// NewQuerierHandler returns the evidence module's Querier. -func (am AppModule) NewQuerierHandler() sdk.Querier { +// LegacyQueryHandler returns the evidence module's Querier. +func (am AppModule) LegacyQueryHandler(codec.JSONMarshaler) sdk.Querier { return keeper.NewQuerier(am.keeper) } diff --git a/x/gov/module.go b/x/gov/module.go index d0dcde556fed..9d5d9310176a 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -144,8 +144,8 @@ func (AppModule) QuerierRoute() string { return types.QuerierRoute } -// NewQuerierHandler returns no sdk.Querier. -func (am AppModule) NewQuerierHandler() sdk.Querier { +// LegacyQueryHandler returns no sdk.Querier. +func (am AppModule) LegacyQueryHandler(codec.JSONMarshaler) sdk.Querier { return keeper.NewQuerier(am.keeper) } diff --git a/x/ibc-transfer/module.go b/x/ibc-transfer/module.go index cb1c36294632..37294a9ed32c 100644 --- a/x/ibc-transfer/module.go +++ b/x/ibc-transfer/module.go @@ -113,8 +113,8 @@ func (AppModule) QuerierRoute() string { return types.QuerierRoute } -// NewQuerierHandler implements the AppModule interface -func (am AppModule) NewQuerierHandler() sdk.Querier { +// LegacyQueryHandler implements the AppModule interface +func (am AppModule) LegacyQueryHandler(codec.JSONMarshaler) sdk.Querier { return nil } diff --git a/x/ibc/module.go b/x/ibc/module.go index 34d16dd0ba0e..aebb75151ccf 100644 --- a/x/ibc/module.go +++ b/x/ibc/module.go @@ -119,8 +119,8 @@ func (AppModule) QuerierRoute() string { return host.QuerierRoute } -// NewQuerierHandler returns the ibc module sdk.Querier. -func (am AppModule) NewQuerierHandler() sdk.Querier { +// LegacyQueryHandler returns the ibc module sdk.Querier. +func (am AppModule) LegacyQueryHandler(codec.JSONMarshaler) sdk.Querier { return keeper.NewQuerier(*am.keeper) } diff --git a/x/mint/module.go b/x/mint/module.go index e88ab00fc408..2a93e591b145 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -111,8 +111,8 @@ func (AppModule) QuerierRoute() string { return types.QuerierRoute } -// NewQuerierHandler returns the mint module sdk.Querier. -func (am AppModule) NewQuerierHandler() sdk.Querier { +// LegacyQueryHandler returns the mint module sdk.Querier. +func (am AppModule) LegacyQueryHandler(codec.JSONMarshaler) sdk.Querier { return keeper.NewQuerier(am.keeper) } diff --git a/x/params/module.go b/x/params/module.go index 249e92e794dc..83894f9366ec 100644 --- a/x/params/module.go +++ b/x/params/module.go @@ -96,8 +96,8 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) {} // QuerierRoute returns the x/param module's querier route name. func (AppModule) QuerierRoute() string { return types.QuerierRoute } -// NewQuerierHandler returns the x/params querier handler. -func (am AppModule) NewQuerierHandler() sdk.Querier { +// LegacyQueryHandler returns the x/params querier handler. +func (am AppModule) LegacyQueryHandler(codec.JSONMarshaler) sdk.Querier { return keeper.NewQuerier(am.keeper) } diff --git a/x/slashing/module.go b/x/slashing/module.go index c24f28bd9d1b..a1f940d324c3 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -126,8 +126,8 @@ func (AppModule) QuerierRoute() string { return types.QuerierRoute } -// NewQuerierHandler returns the slashing module sdk.Querier. -func (am AppModule) NewQuerierHandler() sdk.Querier { +// LegacyQueryHandler returns the slashing module sdk.Querier. +func (am AppModule) LegacyQueryHandler(codec.JSONMarshaler) sdk.Querier { return keeper.NewQuerier(am.keeper) } diff --git a/x/staking/module.go b/x/staking/module.go index 2b58af18dddc..bcdd52ed24c8 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -122,8 +122,8 @@ func (AppModule) QuerierRoute() string { return types.QuerierRoute } -// NewQuerierHandler returns the staking module sdk.Querier. -func (am AppModule) NewQuerierHandler() sdk.Querier { +// LegacyQueryHandler returns the staking module sdk.Querier. +func (am AppModule) LegacyQueryHandler(codec.JSONMarshaler) sdk.Querier { return keeper.NewQuerier(am.keeper) } diff --git a/x/upgrade/abci_test.go b/x/upgrade/abci_test.go index aa247bdab98f..dad486234adf 100644 --- a/x/upgrade/abci_test.go +++ b/x/upgrade/abci_test.go @@ -55,7 +55,7 @@ func setupTest(height int64, skip map[int64]bool) TestSuite { s.ctx = app.BaseApp.NewContext(false, abci.Header{Height: height, Time: time.Now()}) s.module = upgrade.NewAppModule(s.keeper) - s.querier = s.module.NewQuerierHandler() + s.querier = s.module.LegacyQueryHandler(nil) s.handler = upgrade.NewSoftwareUpgradeProposalHandler(s.keeper) return s } diff --git a/x/upgrade/module.go b/x/upgrade/module.go index c1ef30f73a48..1aa2b1fa369b 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -88,8 +88,8 @@ func (AppModule) Route() sdk.Route { return sdk.Route{} } // QuerierRoute returns the route we respond to for abci queries func (AppModule) QuerierRoute() string { return types.QuerierKey } -// NewQuerierHandler registers a query handler to respond to the module-specific queries -func (am AppModule) NewQuerierHandler() sdk.Querier { +// LegacyQueryHandler registers a query handler to respond to the module-specific queries +func (am AppModule) LegacyQueryHandler(codec.JSONMarshaler) sdk.Querier { return keeper.NewQuerier(am.keeper) } From 8402c76864ecc9083b7f29ed028ab5ac80d2bd9c Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Fri, 24 Jul 2020 11:54:31 -0400 Subject: [PATCH 2/5] Rename --- tests/mocks/types_module_module.go | 10 +++++----- types/module/module.go | 8 ++++---- types/module/module_test.go | 2 +- x/auth/module.go | 4 ++-- x/bank/module.go | 4 ++-- x/capability/module.go | 4 ++-- x/crisis/module.go | 4 ++-- x/distribution/module.go | 4 ++-- x/evidence/module.go | 4 ++-- x/gov/module.go | 4 ++-- x/ibc-transfer/module.go | 4 ++-- x/ibc/module.go | 4 ++-- x/mint/module.go | 4 ++-- x/params/module.go | 4 ++-- x/slashing/module.go | 4 ++-- x/staking/module.go | 4 ++-- x/upgrade/abci_test.go | 2 +- x/upgrade/module.go | 4 ++-- 18 files changed, 39 insertions(+), 39 deletions(-) diff --git a/tests/mocks/types_module_module.go b/tests/mocks/types_module_module.go index 9fa369d95fee..0b2051053d50 100644 --- a/tests/mocks/types_module_module.go +++ b/tests/mocks/types_module_module.go @@ -502,18 +502,18 @@ func (mr *MockAppModuleMockRecorder) QuerierRoute() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QuerierRoute", reflect.TypeOf((*MockAppModule)(nil).QuerierRoute)) } -// LegacyQueryHandler mocks base method -func (m *MockAppModule) LegacyQueryHandler(codec.JSONMarshaler) types0.Querier { +// LegacyQuerierHandler mocks base method +func (m *MockAppModule) LegacyQuerierHandler(codec.JSONMarshaler) types0.Querier { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "LegacyQueryHandler") + ret := m.ctrl.Call(m, "LegacyQuerierHandler") ret0, _ := ret[0].(types0.Querier) return ret0 } -// LegacyQueryHandler indicates an expected call of LegacyQueryHandler +// LegacyQuerierHandler indicates an expected call of LegacyQuerierHandler func (mr *MockAppModuleMockRecorder) NewQuerierHandler() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LegacyQueryHandler", reflect.TypeOf((*MockAppModule)(nil).LegacyQueryHandler)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LegacyQuerierHandler", reflect.TypeOf((*MockAppModule)(nil).LegacyQuerierHandler)) } // RegisterQueryService mocks base method diff --git a/types/module/module.go b/types/module/module.go index 28bf33033a34..d0dc558bd51f 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -160,7 +160,7 @@ type AppModule interface { // Deprecated: use RegisterQueryService QuerierRoute() string // Deprecated: use RegisterQueryService - LegacyQueryHandler(codec.JSONMarshaler) sdk.Querier + LegacyQuerierHandler(codec.JSONMarshaler) sdk.Querier // RegisterQueryService allows a module to register a gRPC query service RegisterQueryService(grpc.Server) @@ -192,8 +192,8 @@ func (GenesisOnlyAppModule) Route() sdk.Route { return sdk.Route{} } // QuerierRoute returns an empty module querier route func (GenesisOnlyAppModule) QuerierRoute() string { return "" } -// LegacyQueryHandler returns an empty module querier -func (gam GenesisOnlyAppModule) LegacyQueryHandler(codec.JSONMarshaler) sdk.Querier { return nil } +// LegacyQuerierHandler returns an empty module querier +func (gam GenesisOnlyAppModule) LegacyQuerierHandler(codec.JSONMarshaler) sdk.Querier { return nil } func (gam GenesisOnlyAppModule) RegisterQueryService(grpc.Server) {} @@ -270,7 +270,7 @@ func (m *Manager) RegisterRoutes(router sdk.Router, queryRouter sdk.QueryRouter, router.AddRoute(module.Route()) } if module.QuerierRoute() != "" { - queryRouter.AddRoute(module.QuerierRoute(), module.LegacyQueryHandler(legacyQuerierCdc)) + queryRouter.AddRoute(module.QuerierRoute(), module.LegacyQuerierHandler(legacyQuerierCdc)) } } } diff --git a/types/module/module_test.go b/types/module/module_test.go index 3330c32276a2..51a772987228 100644 --- a/types/module/module_test.go +++ b/types/module/module_test.go @@ -76,7 +76,7 @@ func TestGenesisOnlyAppModule(t *testing.T) { require.True(t, goam.Route().Empty()) require.Empty(t, goam.QuerierRoute()) - require.Nil(t, goam.LegacyQueryHandler(nil)) + require.Nil(t, goam.LegacyQuerierHandler(nil)) // no-op goam.RegisterInvariants(mockInvariantRegistry) diff --git a/x/auth/module.go b/x/auth/module.go index abc51b7dd75c..13e6ca5df347 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -112,8 +112,8 @@ func (AppModule) QuerierRoute() string { return types.QuerierRoute } -// LegacyQueryHandler returns the auth module sdk.Querier. -func (am AppModule) LegacyQueryHandler(jsonCdc codec.JSONMarshaler) sdk.Querier { +// LegacyQuerierHandler returns the auth module sdk.Querier. +func (am AppModule) LegacyQuerierHandler(jsonCdc codec.JSONMarshaler) sdk.Querier { return keeper.NewQuerier(am.accountKeeper, jsonCdc) } diff --git a/x/bank/module.go b/x/bank/module.go index 16d93c2e61a2..8452c9a7195f 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -117,8 +117,8 @@ func (am AppModule) Route() sdk.Route { // QuerierRoute returns the bank module's querier route name. func (AppModule) QuerierRoute() string { return types.RouterKey } -// LegacyQueryHandler returns the bank module sdk.Querier. -func (am AppModule) LegacyQueryHandler(jsonCdc codec.JSONMarshaler) sdk.Querier { +// LegacyQuerierHandler returns the bank module sdk.Querier. +func (am AppModule) LegacyQuerierHandler(jsonCdc codec.JSONMarshaler) sdk.Querier { return keeper.NewQuerier(am.keeper, jsonCdc) } diff --git a/x/capability/module.go b/x/capability/module.go index 23a6aeeab2d9..109e0292579d 100644 --- a/x/capability/module.go +++ b/x/capability/module.go @@ -106,8 +106,8 @@ func (AppModule) Route() sdk.Route { return sdk.Route{} } // QuerierRoute returns the capability module's query routing key. func (AppModule) QuerierRoute() string { return "" } -// LegacyQueryHandler returns the capability module's Querier. -func (am AppModule) LegacyQueryHandler(codec.JSONMarshaler) sdk.Querier { return nil } +// LegacyQuerierHandler returns the capability module's Querier. +func (am AppModule) LegacyQuerierHandler(codec.JSONMarshaler) sdk.Querier { return nil } // RegisterQueryService registers a GRPC query service to respond to the // module-specific GRPC queries. diff --git a/x/crisis/module.go b/x/crisis/module.go index d6f68cd2c836..adb5c918cd43 100644 --- a/x/crisis/module.go +++ b/x/crisis/module.go @@ -106,8 +106,8 @@ func (am AppModule) Route() sdk.Route { // QuerierRoute returns no querier route. func (AppModule) QuerierRoute() string { return "" } -// LegacyQueryHandler returns no sdk.Querier. -func (AppModule) LegacyQueryHandler(codec.JSONMarshaler) sdk.Querier { return nil } +// LegacyQuerierHandler returns no sdk.Querier. +func (AppModule) LegacyQuerierHandler(codec.JSONMarshaler) sdk.Querier { return nil } // RegisterQueryService registers a GRPC query service to respond to the // module-specific GRPC queries. diff --git a/x/distribution/module.go b/x/distribution/module.go index aa3fdf7c36ca..a0e469df56fb 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -128,8 +128,8 @@ func (AppModule) QuerierRoute() string { return types.QuerierRoute } -// LegacyQueryHandler returns the distribution module sdk.Querier. -func (am AppModule) LegacyQueryHandler(jsonCdc codec.JSONMarshaler) sdk.Querier { +// LegacyQuerierHandler returns the distribution module sdk.Querier. +func (am AppModule) LegacyQuerierHandler(jsonCdc codec.JSONMarshaler) sdk.Querier { return keeper.NewQuerier(am.keeper, jsonCdc) } diff --git a/x/evidence/module.go b/x/evidence/module.go index fc59e490324d..4f06c3112efd 100644 --- a/x/evidence/module.go +++ b/x/evidence/module.go @@ -137,8 +137,8 @@ func (AppModule) QuerierRoute() string { return types.QuerierRoute } -// LegacyQueryHandler returns the evidence module's Querier. -func (am AppModule) LegacyQueryHandler(codec.JSONMarshaler) sdk.Querier { +// LegacyQuerierHandler returns the evidence module's Querier. +func (am AppModule) LegacyQuerierHandler(codec.JSONMarshaler) sdk.Querier { return keeper.NewQuerier(am.keeper) } diff --git a/x/gov/module.go b/x/gov/module.go index 9d5d9310176a..f5b9541b1cd2 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -144,8 +144,8 @@ func (AppModule) QuerierRoute() string { return types.QuerierRoute } -// LegacyQueryHandler returns no sdk.Querier. -func (am AppModule) LegacyQueryHandler(codec.JSONMarshaler) sdk.Querier { +// LegacyQuerierHandler returns no sdk.Querier. +func (am AppModule) LegacyQuerierHandler(codec.JSONMarshaler) sdk.Querier { return keeper.NewQuerier(am.keeper) } diff --git a/x/ibc-transfer/module.go b/x/ibc-transfer/module.go index 37294a9ed32c..09698fee50ba 100644 --- a/x/ibc-transfer/module.go +++ b/x/ibc-transfer/module.go @@ -113,8 +113,8 @@ func (AppModule) QuerierRoute() string { return types.QuerierRoute } -// LegacyQueryHandler implements the AppModule interface -func (am AppModule) LegacyQueryHandler(codec.JSONMarshaler) sdk.Querier { +// LegacyQuerierHandler implements the AppModule interface +func (am AppModule) LegacyQuerierHandler(codec.JSONMarshaler) sdk.Querier { return nil } diff --git a/x/ibc/module.go b/x/ibc/module.go index aebb75151ccf..1655a4382901 100644 --- a/x/ibc/module.go +++ b/x/ibc/module.go @@ -119,8 +119,8 @@ func (AppModule) QuerierRoute() string { return host.QuerierRoute } -// LegacyQueryHandler returns the ibc module sdk.Querier. -func (am AppModule) LegacyQueryHandler(codec.JSONMarshaler) sdk.Querier { +// LegacyQuerierHandler returns the ibc module sdk.Querier. +func (am AppModule) LegacyQuerierHandler(codec.JSONMarshaler) sdk.Querier { return keeper.NewQuerier(*am.keeper) } diff --git a/x/mint/module.go b/x/mint/module.go index 2a93e591b145..b57a9901dba4 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -111,8 +111,8 @@ func (AppModule) QuerierRoute() string { return types.QuerierRoute } -// LegacyQueryHandler returns the mint module sdk.Querier. -func (am AppModule) LegacyQueryHandler(codec.JSONMarshaler) sdk.Querier { +// LegacyQuerierHandler returns the mint module sdk.Querier. +func (am AppModule) LegacyQuerierHandler(codec.JSONMarshaler) sdk.Querier { return keeper.NewQuerier(am.keeper) } diff --git a/x/params/module.go b/x/params/module.go index 83894f9366ec..f813d309c310 100644 --- a/x/params/module.go +++ b/x/params/module.go @@ -96,8 +96,8 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) {} // QuerierRoute returns the x/param module's querier route name. func (AppModule) QuerierRoute() string { return types.QuerierRoute } -// LegacyQueryHandler returns the x/params querier handler. -func (am AppModule) LegacyQueryHandler(codec.JSONMarshaler) sdk.Querier { +// LegacyQuerierHandler returns the x/params querier handler. +func (am AppModule) LegacyQuerierHandler(codec.JSONMarshaler) sdk.Querier { return keeper.NewQuerier(am.keeper) } diff --git a/x/slashing/module.go b/x/slashing/module.go index a1f940d324c3..4eac644fe72e 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -126,8 +126,8 @@ func (AppModule) QuerierRoute() string { return types.QuerierRoute } -// LegacyQueryHandler returns the slashing module sdk.Querier. -func (am AppModule) LegacyQueryHandler(codec.JSONMarshaler) sdk.Querier { +// LegacyQuerierHandler returns the slashing module sdk.Querier. +func (am AppModule) LegacyQuerierHandler(codec.JSONMarshaler) sdk.Querier { return keeper.NewQuerier(am.keeper) } diff --git a/x/staking/module.go b/x/staking/module.go index bcdd52ed24c8..daca2ec3c66f 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -122,8 +122,8 @@ func (AppModule) QuerierRoute() string { return types.QuerierRoute } -// LegacyQueryHandler returns the staking module sdk.Querier. -func (am AppModule) LegacyQueryHandler(codec.JSONMarshaler) sdk.Querier { +// LegacyQuerierHandler returns the staking module sdk.Querier. +func (am AppModule) LegacyQuerierHandler(codec.JSONMarshaler) sdk.Querier { return keeper.NewQuerier(am.keeper) } diff --git a/x/upgrade/abci_test.go b/x/upgrade/abci_test.go index dad486234adf..203a40837862 100644 --- a/x/upgrade/abci_test.go +++ b/x/upgrade/abci_test.go @@ -55,7 +55,7 @@ func setupTest(height int64, skip map[int64]bool) TestSuite { s.ctx = app.BaseApp.NewContext(false, abci.Header{Height: height, Time: time.Now()}) s.module = upgrade.NewAppModule(s.keeper) - s.querier = s.module.LegacyQueryHandler(nil) + s.querier = s.module.LegacyQuerierHandler(nil) s.handler = upgrade.NewSoftwareUpgradeProposalHandler(s.keeper) return s } diff --git a/x/upgrade/module.go b/x/upgrade/module.go index 1aa2b1fa369b..ccdada7f217d 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -88,8 +88,8 @@ func (AppModule) Route() sdk.Route { return sdk.Route{} } // QuerierRoute returns the route we respond to for abci queries func (AppModule) QuerierRoute() string { return types.QuerierKey } -// LegacyQueryHandler registers a query handler to respond to the module-specific queries -func (am AppModule) LegacyQueryHandler(codec.JSONMarshaler) sdk.Querier { +// LegacyQuerierHandler registers a query handler to respond to the module-specific queries +func (am AppModule) LegacyQuerierHandler(codec.JSONMarshaler) sdk.Querier { return keeper.NewQuerier(am.keeper) } From eaceab30e2ecefc1302dbb5416d4d68f12670b46 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Fri, 24 Jul 2020 12:58:13 -0400 Subject: [PATCH 3/5] Fixes --- codec/any.go | 4 ++-- codec/codec.go | 3 ++- x/auth/ante/ante_test.go | 5 ++--- x/auth/ante/basic_test.go | 1 - x/auth/keeper/keeper.go | 18 +----------------- x/auth/keeper/querier_test.go | 12 +++++++----- x/auth/simulation/decoder.go | 2 +- x/bank/keeper/keeper.go | 36 ----------------------------------- x/bank/keeper/send.go | 4 ++-- x/bank/keeper/view.go | 4 ++-- 10 files changed, 19 insertions(+), 70 deletions(-) diff --git a/codec/any.go b/codec/any.go index 91543b14ff52..075ad727e3e1 100644 --- a/codec/any.go +++ b/codec/any.go @@ -10,7 +10,7 @@ import ( // MarshalAny is a convenience function for packing the provided value in an // Any and then proto marshaling it to bytes -func MarshalAny(m Marshaler, x interface{}) ([]byte, error) { +func MarshalAny(m BinaryMarshaler, x interface{}) ([]byte, error) { msg, ok := x.(proto.Message) if !ok { return nil, fmt.Errorf("can't proto marshal %T", x) @@ -32,7 +32,7 @@ func MarshalAny(m Marshaler, x interface{}) ([]byte, error) { // Ex: // var x MyInterface // err := UnmarshalAny(unpacker, &x, bz) -func UnmarshalAny(m Marshaler, iface interface{}, bz []byte) error { +func UnmarshalAny(m BinaryMarshaler, iface interface{}, bz []byte) error { any := &types.Any{} err := m.UnmarshalBinaryBare(bz, any) diff --git a/codec/codec.go b/codec/codec.go index ac31d39b53d8..aff90cd3d91d 100644 --- a/codec/codec.go +++ b/codec/codec.go @@ -20,7 +20,6 @@ type ( Marshaler interface { BinaryMarshaler JSONMarshaler - types.AnyUnpacker } BinaryMarshaler interface { @@ -35,6 +34,8 @@ type ( UnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshaler) error MustUnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshaler) + + types.AnyUnpacker } JSONMarshaler interface { diff --git a/x/auth/ante/ante_test.go b/x/auth/ante/ante_test.go index d51e063e0fb3..a6f565f52048 100644 --- a/x/auth/ante/ante_test.go +++ b/x/auth/ante/ante_test.go @@ -825,10 +825,9 @@ func (suite *AnteTestSuite) TestAnteHandlerSetPubKey() { // Manually create tx, and remove signature tx := suite.CreateTestTx(privs, accNums, accSeqs, suite.ctx.ChainID()) - sigs, err := tx.GetSignaturesV2() - suite.Require().NoError(err) + sigs := tx.(types.StdTx).Signatures sigs[0].PubKey = nil - _, err = suite.anteHandler(suite.ctx, tx, false) + _, err := suite.anteHandler(suite.ctx, tx, false) suite.Require().Error(err) suite.Require().Equal(err.Error(), "wrong number of signers; expected 0, got 1: unauthorized") suite.Require().True(errors.Is(err, sdkerrors.ErrUnauthorized)) diff --git a/x/auth/ante/basic_test.go b/x/auth/ante/basic_test.go index bbf13cd3244b..4e8c83e9cc64 100644 --- a/x/auth/ante/basic_test.go +++ b/x/auth/ante/basic_test.go @@ -134,7 +134,6 @@ func (suite *AnteTestSuite) TestConsumeGasForTxSize() { suite.Require().Equal(expectedGas, consumedGas, "Decorator did not consume the correct amount of gas") // simulation must not underestimate gas of this decorator even with nil signatures - txBuilder2 := suite.clientCtx.TxConfig sigTx := tx.(types.StdTx) sigTx.Signatures = []types.StdSignature{{}} diff --git a/x/auth/keeper/keeper.go b/x/auth/keeper/keeper.go index 2c089f709e62..54dabc46c39a 100644 --- a/x/auth/keeper/keeper.go +++ b/x/auth/keeper/keeper.go @@ -8,7 +8,6 @@ import ( "github.com/tendermint/tendermint/libs/log" "github.com/cosmos/cosmos-sdk/codec" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -203,19 +202,4 @@ func (ak AccountKeeper) UnmarshalAccount(bz []byte) (types.AccountI, error) { return acc, nil } -// UnmarshalAccountJSON returns an AccountI from JSON encoded bytes -func (ak AccountKeeper) UnmarshalAccountJSON(bz []byte) (types.AccountI, error) { - var any codectypes.Any - if err := ak.cdc.UnmarshalJSON(bz, &any); err != nil { - return nil, err - } - - var acc types.AccountI - if err := ak.cdc.UnpackAny(&any, &acc); err != nil { - return nil, err - } - - return acc, nil -} - -func (ak AccountKeeper) GetCodec() codec.Marshaler { return ak.cdc } +func (ak AccountKeeper) GetCodec() codec.BinaryMarshaler { return ak.cdc } diff --git a/x/auth/keeper/querier_test.go b/x/auth/keeper/querier_test.go index 09bd40b27ce5..890f71b43241 100644 --- a/x/auth/keeper/querier_test.go +++ b/x/auth/keeper/querier_test.go @@ -4,6 +4,8 @@ import ( "fmt" "testing" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" @@ -15,7 +17,7 @@ import ( func TestQueryAccount(t *testing.T) { app, ctx := createTestApp(true) - cdc := app.Codec() + jsonCdc := codec.NewAminoCodec(app.Codec()) req := abci.RequestQuery{ Path: "", @@ -23,7 +25,7 @@ func TestQueryAccount(t *testing.T) { } path := []string{types.QueryAccount} - querier := keep.NewQuerier(app.AccountKeeper, nil) + querier := keep.NewQuerier(app.AccountKeeper, jsonCdc) bz, err := querier(ctx, []string{"other"}, req) require.Error(t, err) @@ -37,13 +39,13 @@ func TestQueryAccount(t *testing.T) { require.Error(t, err) require.Nil(t, res) - req.Data = cdc.MustMarshalJSON(types.QueryAccountRequest{Address: []byte("")}) + req.Data = jsonCdc.MustMarshalJSON(types.QueryAccountRequest{Address: []byte("")}) res, err = querier(ctx, path, req) require.Error(t, err) require.Nil(t, res) _, _, addr := testdata.KeyTestPubAddr() - req.Data = cdc.MustMarshalJSON(types.QueryAccountRequest{Address: addr}) + req.Data = jsonCdc.MustMarshalJSON(types.QueryAccountRequest{Address: addr}) res, err = querier(ctx, path, req) require.Error(t, err) require.Nil(t, res) @@ -58,6 +60,6 @@ func TestQueryAccount(t *testing.T) { require.NotNil(t, res) var account types.AccountI - err2 := cdc.UnmarshalJSON(res, &account) + err2 := jsonCdc.UnmarshalJSON(res, &account) require.Nil(t, err2) } diff --git a/x/auth/simulation/decoder.go b/x/auth/simulation/decoder.go index 3df011342df5..cf3ab69e0b95 100644 --- a/x/auth/simulation/decoder.go +++ b/x/auth/simulation/decoder.go @@ -13,7 +13,7 @@ import ( type AuthUnmarshaler interface { UnmarshalAccount([]byte) (types.AccountI, error) - GetCodec() codec.Marshaler + GetCodec() codec.BinaryMarshaler } // NewDecodeStore returns a decoder function closure that unmarshals the KVPair's diff --git a/x/bank/keeper/keeper.go b/x/bank/keeper/keeper.go index afa52724cda2..feb8c26dbd31 100644 --- a/x/bank/keeper/keeper.go +++ b/x/bank/keeper/keeper.go @@ -4,10 +4,7 @@ import ( "fmt" "time" - "github.com/gogo/protobuf/proto" - "github.com/cosmos/cosmos-sdk/codec" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -42,8 +39,6 @@ type Keeper interface { UndelegateCoins(ctx sdk.Context, moduleAccAddr, delegatorAddr sdk.AccAddress, amt sdk.Coins) error MarshalSupply(supplyI exported.SupplyI) ([]byte, error) UnmarshalSupply(bz []byte) (exported.SupplyI, error) - MarshalSupplyJSON(supply exported.SupplyI) ([]byte, error) - UnmarshalSupplyJSON(bz []byte) (exported.SupplyI, error) types.QueryServer } @@ -370,34 +365,3 @@ func (k BaseKeeper) UnmarshalSupply(bz []byte) (exported.SupplyI, error) { return evi, nil } - -// MarshalSupplyJSON JSON encodes a supply object implementing the Supply -// interface. -func (k BaseKeeper) MarshalSupplyJSON(supply exported.SupplyI) ([]byte, error) { - msg, ok := supply.(proto.Message) - if !ok { - return nil, fmt.Errorf("cannot proto marshal %T", supply) - } - - any, err := codectypes.NewAnyWithValue(msg) - if err != nil { - return nil, err - } - - return k.cdc.MarshalJSON(any) -} - -// UnmarshalSupplyJSON returns a Supply from JSON encoded bytes -func (k BaseKeeper) UnmarshalSupplyJSON(bz []byte) (exported.SupplyI, error) { - var any codectypes.Any - if err := k.cdc.UnmarshalJSON(bz, &any); err != nil { - return nil, err - } - - var supply exported.SupplyI - if err := k.cdc.UnpackAny(&any, &supply); err != nil { - return nil, err - } - - return supply, nil -} diff --git a/x/bank/keeper/send.go b/x/bank/keeper/send.go index 88d1018f2048..56283a068bf3 100644 --- a/x/bank/keeper/send.go +++ b/x/bank/keeper/send.go @@ -40,7 +40,7 @@ var _ SendKeeper = (*BaseSendKeeper)(nil) type BaseSendKeeper struct { BaseViewKeeper - cdc codec.Marshaler + cdc codec.BinaryMarshaler ak types.AccountKeeper storeKey sdk.StoreKey paramSpace paramtypes.Subspace @@ -50,7 +50,7 @@ type BaseSendKeeper struct { } func NewBaseSendKeeper( - cdc codec.Marshaler, storeKey sdk.StoreKey, ak types.AccountKeeper, paramSpace paramtypes.Subspace, blockedAddrs map[string]bool, + cdc codec.BinaryMarshaler, storeKey sdk.StoreKey, ak types.AccountKeeper, paramSpace paramtypes.Subspace, blockedAddrs map[string]bool, ) BaseSendKeeper { return BaseSendKeeper{ diff --git a/x/bank/keeper/view.go b/x/bank/keeper/view.go index fa707e6beba0..68a4765656d2 100644 --- a/x/bank/keeper/view.go +++ b/x/bank/keeper/view.go @@ -32,13 +32,13 @@ type ViewKeeper interface { // BaseViewKeeper implements a read only keeper implementation of ViewKeeper. type BaseViewKeeper struct { - cdc codec.Marshaler + cdc codec.BinaryMarshaler storeKey sdk.StoreKey ak types.AccountKeeper } // NewBaseViewKeeper returns a new BaseViewKeeper. -func NewBaseViewKeeper(cdc codec.Marshaler, storeKey sdk.StoreKey, ak types.AccountKeeper) BaseViewKeeper { +func NewBaseViewKeeper(cdc codec.BinaryMarshaler, storeKey sdk.StoreKey, ak types.AccountKeeper) BaseViewKeeper { return BaseViewKeeper{ cdc: cdc, storeKey: storeKey, From 638d5f9e6d23f868e9e039e5c5984cdb7cb88300 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Fri, 24 Jul 2020 13:09:17 -0400 Subject: [PATCH 4/5] Test fixes --- x/bank/keeper/querier_test.go | 17 ++++++++++++----- x/distribution/keeper/querier_test.go | 3 ++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/x/bank/keeper/querier_test.go b/x/bank/keeper/querier_test.go index a217e0303a15..8926644036ab 100644 --- a/x/bank/keeper/querier_test.go +++ b/x/bank/keeper/querier_test.go @@ -3,6 +3,8 @@ package keeper_test import ( "fmt" + "github.com/cosmos/cosmos-sdk/codec" + abci "github.com/tendermint/tendermint/abci/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" @@ -13,13 +15,14 @@ import ( func (suite *IntegrationTestSuite) TestQuerier_QueryBalance() { app, ctx := suite.app, suite.ctx + jsonCdc := codec.NewAminoCodec(app.Codec()) _, _, addr := testdata.KeyTestPubAddr() req := abci.RequestQuery{ Path: fmt.Sprintf("custom/%s/%s", types.ModuleName, types.QueryBalance), Data: []byte{}, } - querier := keeper.NewQuerier(app.BankKeeper, nil) + querier := keeper.NewQuerier(app.BankKeeper, jsonCdc) res, err := querier(ctx, []string{types.QueryBalance}, req) suite.Require().NotNil(err) @@ -49,13 +52,14 @@ func (suite *IntegrationTestSuite) TestQuerier_QueryBalance() { func (suite *IntegrationTestSuite) TestQuerier_QueryAllBalances() { app, ctx := suite.app, suite.ctx + jsonCdc := codec.NewAminoCodec(app.Codec()) _, _, addr := testdata.KeyTestPubAddr() req := abci.RequestQuery{ Path: fmt.Sprintf("custom/%s/%s", types.ModuleName, types.QueryAllBalances), Data: []byte{}, } - querier := keeper.NewQuerier(app.BankKeeper, nil) + querier := keeper.NewQuerier(app.BankKeeper, jsonCdc) res, err := querier(ctx, []string{types.QueryAllBalances}, req) suite.Require().NotNil(err) @@ -85,6 +89,7 @@ func (suite *IntegrationTestSuite) TestQuerier_QueryAllBalances() { func (suite *IntegrationTestSuite) TestQuerier_QueryTotalSupply() { app, ctx := suite.app, suite.ctx + jsonCdc := codec.NewAminoCodec(app.Codec()) expectedTotalSupply := types.NewSupply(sdk.NewCoins(sdk.NewInt64Coin("test", 400000000))) app.BankKeeper.SetSupply(ctx, expectedTotalSupply) @@ -93,7 +98,7 @@ func (suite *IntegrationTestSuite) TestQuerier_QueryTotalSupply() { Data: []byte{}, } - querier := keeper.NewQuerier(app.BankKeeper, nil) + querier := keeper.NewQuerier(app.BankKeeper, jsonCdc) res, err := querier(ctx, []string{types.QueryTotalSupply}, req) suite.Require().NotNil(err) @@ -111,6 +116,7 @@ func (suite *IntegrationTestSuite) TestQuerier_QueryTotalSupply() { func (suite *IntegrationTestSuite) TestQuerier_QueryTotalSupplyOf() { app, ctx := suite.app, suite.ctx + jsonCdc := codec.NewAminoCodec(app.Codec()) test1Supply := sdk.NewInt64Coin("test1", 4000000) test2Supply := sdk.NewInt64Coin("test2", 700000000) @@ -122,7 +128,7 @@ func (suite *IntegrationTestSuite) TestQuerier_QueryTotalSupplyOf() { Data: []byte{}, } - querier := keeper.NewQuerier(app.BankKeeper, nil) + querier := keeper.NewQuerier(app.BankKeeper, jsonCdc) res, err := querier(ctx, []string{types.QuerySupplyOf}, req) suite.Require().NotNil(err) @@ -140,12 +146,13 @@ func (suite *IntegrationTestSuite) TestQuerier_QueryTotalSupplyOf() { func (suite *IntegrationTestSuite) TestQuerierRouteNotFound() { app, ctx := suite.app, suite.ctx + jsonCdc := codec.NewAminoCodec(app.Codec()) req := abci.RequestQuery{ Path: fmt.Sprintf("custom/%s/invalid", types.ModuleName), Data: []byte{}, } - querier := keeper.NewQuerier(app.BankKeeper, nil) + querier := keeper.NewQuerier(app.BankKeeper, jsonCdc) _, err := querier(ctx, []string{"invalid"}, req) suite.Error(err) } diff --git a/x/distribution/keeper/querier_test.go b/x/distribution/keeper/querier_test.go index b7c78bb94e83..da9fdd53b7fe 100644 --- a/x/distribution/keeper/querier_test.go +++ b/x/distribution/keeper/querier_test.go @@ -113,6 +113,7 @@ func TestQueries(t *testing.T) { cdc := codec.New() types.RegisterCodec(cdc) banktypes.RegisterCodec(cdc) + jsonCdc := codec.NewAminoCodec(cdc) app := simapp.Setup(false) ctx := app.BaseApp.NewContext(false, abci.Header{}) @@ -121,7 +122,7 @@ func TestQueries(t *testing.T) { valAddrs := simapp.ConvertAddrsToValAddrs(addr) valOpAddr1 := valAddrs[0] - querier := keeper.NewQuerier(app.DistrKeeper, nil) + querier := keeper.NewQuerier(app.DistrKeeper, jsonCdc) // test param queries params := types.Params{ From 1781c4314dbe3c1583e0e5cb9ee2cc033ff7543d Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Fri, 24 Jul 2020 13:26:02 -0400 Subject: [PATCH 5/5] Cleanup --- x/distribution/keeper/keeper.go | 2 +- x/upgrade/abci_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/x/distribution/keeper/keeper.go b/x/distribution/keeper/keeper.go index d4c9b34ec3cb..0c2f25c83af4 100644 --- a/x/distribution/keeper/keeper.go +++ b/x/distribution/keeper/keeper.go @@ -28,7 +28,7 @@ type Keeper struct { // NewKeeper creates a new distribution Keeper instance func NewKeeper( - cdc codec.Marshaler, key sdk.StoreKey, paramSpace paramtypes.Subspace, + cdc codec.BinaryMarshaler, key sdk.StoreKey, paramSpace paramtypes.Subspace, ak types.AccountKeeper, bk types.BankKeeper, sk types.StakingKeeper, feeCollectorName string, blockedAddrs map[string]bool, ) Keeper { diff --git a/x/upgrade/abci_test.go b/x/upgrade/abci_test.go index 203a40837862..2f7cbdf3a708 100644 --- a/x/upgrade/abci_test.go +++ b/x/upgrade/abci_test.go @@ -55,7 +55,7 @@ func setupTest(height int64, skip map[int64]bool) TestSuite { s.ctx = app.BaseApp.NewContext(false, abci.Header{Height: height, Time: time.Now()}) s.module = upgrade.NewAppModule(s.keeper) - s.querier = s.module.LegacyQuerierHandler(nil) + s.querier = s.module.LegacyQuerierHandler(codec.NewAminoCodec(app.Codec())) s.handler = upgrade.NewSoftwareUpgradeProposalHandler(s.keeper) return s }